private void CommitFailoverTest(string direction, string replicationProvider, bool SkipDataSync = false) { using (UndoContext context = UndoContext.Current) { context.Start(); var client = GetSiteRecoveryClient(CustomHttpHandler); var requestHeaders = RequestHeaders; requestHeaders.AgentAuthenticationHeader = GenerateAgentAuthenticationHeader(requestHeaders.ClientRequestId); var responsePC = client.ProtectionContainer.List(RequestHeaders); CommitFailoverRequest input = new CommitFailoverRequest(); input.FailoverDirection = direction; JobResponse response = new JobResponse(); bool desiredPEFound = false; foreach (var pc in responsePC.ProtectionContainers) { if (pc.Role == "Primary") { var responsePEs = client.ProtectionEntity.List(pc.ID, RequestHeaders); foreach (var pe in responsePEs.ProtectionEntities) { string activeLocation = string.Empty; if (direction == "PrimaryToRecovery") { activeLocation = "Recovery"; } else { activeLocation = "Primary"; } if (pe.CanCommit == true && pe.ActiveLocation == activeLocation && pe.ReplicationProvider == replicationProvider) { input.ReplicationProvider = pe.ReplicationProvider; if (direction == "RecoveryToPrimary") { AzureCommitFailbackInput blob = new AzureCommitFailbackInput(); blob.SkipDataSync = false; input.ReplicationProviderSettings = DataContractUtils.Serialize<AzureCommitFailbackInput> (blob); } else { input.ReplicationProviderSettings = string.Empty; } response = client.ProtectionEntity.CommitFailover( pe.ProtectionContainerId, pe.ID, input, requestHeaders); desiredPEFound = true; break; } } } if (desiredPEFound) { break; } } Assert.NotNull(response.Job); Assert.NotNull(response.Job.ID); Assert.True(response.Job.Errors.Count < 1, "Errors found while doing commit failover operation"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }
private void CommitFailoverTest(string direction, string replicationProvider, bool SkipDataSync = false) { using (UndoContext context = UndoContext.Current) { context.Start(); var client = GetSiteRecoveryClient(CustomHttpHandler); var requestHeaders = RequestHeaders; requestHeaders.AgentAuthenticationHeader = GenerateAgentAuthenticationHeader(requestHeaders.ClientRequestId); var responsePC = client.ProtectionContainer.List(RequestHeaders); CommitFailoverRequest input = new CommitFailoverRequest(); input.FailoverDirection = direction; JobResponse response = new JobResponse(); bool desiredPEFound = false; foreach (var pc in responsePC.ProtectionContainers) { if (pc.Role == "Primary") { var responsePEs = client.ProtectionEntity.List(pc.ID, RequestHeaders); foreach (var pe in responsePEs.ProtectionEntities) { string activeLocation = string.Empty; if (direction == "PrimaryToRecovery") { activeLocation = "Recovery"; } else { activeLocation = "Primary"; } if (pe.CanCommit == true && pe.ActiveLocation == activeLocation && pe.ReplicationProvider == replicationProvider) { input.ReplicationProvider = pe.ReplicationProvider; if (direction == "RecoveryToPrimary") { AzureCommitFailbackInput blob = new AzureCommitFailbackInput(); blob.SkipDataSync = false; input.ReplicationProviderSettings = DataContractUtils.Serialize <AzureCommitFailbackInput> (blob); } else { input.ReplicationProviderSettings = string.Empty; } response = client.ProtectionEntity.CommitFailover( pe.ProtectionContainerId, pe.ID, input, requestHeaders); desiredPEFound = true; break; } } } if (desiredPEFound) { break; } } Assert.NotNull(response.Job); Assert.NotNull(response.Job.ID); Assert.True(response.Job.Errors.Count < 1, "Errors found while doing commit failover operation"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }