public void TestFailoverTest() { 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); JobResponse response = new JobResponse(); bool desiredPEFound = false; foreach (var pc in responsePC.ProtectionContainers) { var responsePEs = client.ProtectionEntity.List(pc.ID, RequestHeaders); response = null; foreach (var pe in responsePEs.ProtectionEntities) { if (pe.Protected == true) { TestFailoverRequest request = new TestFailoverRequest(); request.FailoverDirection = "PrimaryToRecovery"; request.ReplicationProvider = pe.ReplicationProvider; if (pe.ReplicationProvider == "HyperVReplicaAzure") { AzureFailoverInput blob = new AzureFailoverInput(); blob.VaultLocation = VaultLocation; request.ReplicationProviderSettings = DataContractUtils.Serialize <AzureFailoverInput>(blob); } else { request.ReplicationProviderSettings = ""; } request.NetworkID = "ID"; request.NetworkType = "Type"; response = client.ProtectionEntity.TestFailover( pe.ProtectionContainerId, pe.ID, request, 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 planned failover operation"); Assert.Equal(HttpStatusCode.OK, response.StatusCode); } }
/// <summary> /// Starts Azure Site Recovery Unplanned failover. /// </summary> /// <param name="protectionContainerId">Protection Container ID</param> /// <param name="protectionEntityId">Protection entity ID</param> /// <param name="testFailoverRequest">Test failover request</param> /// <returns>Job response</returns> public JobResponse StartAzureSiteRecoveryTestFailover( string protectionContainerId, string protectionEntityId, TestFailoverRequest testFailoverRequest) { return(this.GetSiteRecoveryClient().ProtectionEntity.TestFailover( protectionContainerId, protectionEntityId, testFailoverRequest, this.GetRequestHeaders())); }
public async Task Run() { var failoverInterval = TimeSpan.FromSeconds(3); await Task.Delay(failoverInterval); var testFailoverRequest = new TestFailoverRequest { ReplicationGroupId = "dentoncache2", NodeGroupId = "dentoncache2-0001" }; Console.WriteLine("Failing over..."); var testFailoverResponse = await _AmazonElastiCache.TestFailoverAsync(testFailoverRequest); Console.WriteLine($"Response status code {testFailoverResponse.HttpStatusCode}"); }
/// <summary> /// Starts PE Test failover. /// </summary> private void StartPETestFailover() { var request = new TestFailoverRequest(); if (this.ProtectionEntity == null) { var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity( this.ProtectionContainerId, this.ProtectionEntityId); this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity); this.ValidateUsageById( this.ProtectionEntity.ReplicationProvider, Constants.ProtectionEntityId); } request.ReplicationProviderSettings = string.Empty; if (this.ProtectionEntity.ReplicationProvider == Constants.HyperVReplicaAzure) { if (this.Direction == Constants.PrimaryToRecovery) { var blob = new AzureFailoverInput(); blob.VaultLocation = this.GetCurrentValutLocation(); request.ReplicationProviderSettings = DataContractUtils.Serialize <AzureFailoverInput>(blob); } } request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider; request.FailoverDirection = this.Direction; request.NetworkID = this.networkId; request.NetworkType = this.networkType; this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryTestFailover( this.ProtectionContainerId, this.ProtectionEntityId, request); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }
/// <summary> /// Starts PE Test failover. /// </summary> private void StartPETestFailover() { var tfoReqeust = new TestFailoverRequest(); tfoReqeust.NetworkID = this.networkId; tfoReqeust.FailoverDirection = this.Direction; tfoReqeust.NetworkType = this.networkType; tfoReqeust.ReplicationProvider = string.Empty; tfoReqeust.ReplicationProviderSettings = string.Empty; this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryTestFailover( this.ProtectionContainerId, this.ProtectionEntityId, tfoReqeust); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }
/// <summary> /// Starts PE Test failover. /// </summary> private void StartPETestFailover() { var request = new TestFailoverRequest(); if (this.ProtectionEntity == null) { var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity( this.ProtectionEntity.ProtectionContainerId, this.ProtectionEntity.Name); this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity); /* this.ValidateUsageById( * this.ProtectionEntity.ReplicationProvider, * Constants.ProtectionEntityId); */ } request.ReplicationProviderSettings = string.Empty; request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider; request.FailoverDirection = this.Direction; request.NetworkID = this.networkId; request.NetworkType = this.networkType; LongRunningOperationResponse response = RecoveryServicesClient.StartAzureSiteRecoveryTestFailover( this.ProtectionEntity.ProtectionContainerId, this.ProtectionEntity.Name, request); JobResponse jobResponse = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); WriteObject(new ASRJob(jobResponse.Job)); }
/// <summary> /// Test failover of a protection entity. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.SiteRecovery.IProtectionEntityOperations. /// </param> /// <param name='protectionContainerId'> /// Required. Parent Protection Container ID. /// </param> /// <param name='protectionEntityId'> /// Required. Protection entity ID. /// </param> /// <param name='parameters'> /// Required. Test failover request. /// </param> /// <param name='customRequestHeaders'> /// Optional. Request header parameters. /// </param> /// <returns> /// The response model for the Job details object. /// </returns> public static Task <JobResponse> TestFailoverAsync(this IProtectionEntityOperations operations, string protectionContainerId, string protectionEntityId, TestFailoverRequest parameters, CustomRequestHeaders customRequestHeaders) { return(operations.TestFailoverAsync(protectionContainerId, protectionEntityId, parameters, customRequestHeaders, CancellationToken.None)); }
/// <summary> /// Test failover of a protection entity. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.SiteRecovery.IProtectionEntityOperations. /// </param> /// <param name='protectionContainerId'> /// Required. Parent Protection Container ID. /// </param> /// <param name='protectionEntityId'> /// Required. Protection entity ID. /// </param> /// <param name='parameters'> /// Required. Test failover request. /// </param> /// <param name='customRequestHeaders'> /// Optional. Request header parameters. /// </param> /// <returns> /// The response model for the Job details object. /// </returns> public static JobResponse TestFailover(this IProtectionEntityOperations operations, string protectionContainerId, string protectionEntityId, TestFailoverRequest parameters, CustomRequestHeaders customRequestHeaders) { return(Task.Factory.StartNew((object s) => { return ((IProtectionEntityOperations)s).TestFailoverAsync(protectionContainerId, protectionEntityId, parameters, customRequestHeaders); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Starts PE Test failover. /// </summary> private void StartPETestFailover() { var request = new TestFailoverRequest(); if (this.ProtectionEntity == null) { var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity( this.ProtectionEntity.ProtectionContainerId, this.ProtectionEntity.Name); this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity); } request.FailoverDirection = this.Direction; request.NetworkID = this.networkId; request.NetworkType = this.networkType; if (string.IsNullOrEmpty(this.ProtectionEntity.ReplicationProvider)) { // fetch the latest PE object // As get PE by name is failing before protection, get all & filter. // Once after we fix get pe by name, change the logic to use the same. ProtectionEntityListResponse protectionEntityListResponse = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity( this.ProtectionEntity.ProtectionContainerId); foreach (ProtectionEntity pe in protectionEntityListResponse.ProtectionEntities) { if (0 == string.Compare(this.ProtectionEntity.FriendlyName, pe.Properties.FriendlyName, true)) { this.ProtectionEntity = new ASRProtectionEntity(pe); break; } } } request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider; request.ReplicationProviderSettings = new FailoverReplicationProviderSpecificInput(); if (0 == string.Compare( this.ProtectionEntity.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase)) { AzureFailoverInput failoverInput = new AzureFailoverInput() { PrimaryKekCertificatePfx = string.Empty, SecondaryKekCertificatePfx = string.Empty, VaultLocation = this.GetCurrentValutLocation() }; request.ReplicationProviderSettings = failoverInput; } LongRunningOperationResponse response = RecoveryServicesClient.StartAzureSiteRecoveryTestFailover( this.ProtectionEntity.ProtectionContainerId, this.ProtectionEntity.Name, request); JobResponse jobResponse = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); WriteObject(new ASRJob(jobResponse.Job)); }
/// <summary> /// Creates a profile /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.SiteRecovery.IProtectionEntityOperations. /// </param> /// <param name='pcName'> /// Required. Parent Protection Container name. /// </param> /// <param name='name'> /// Required. Protection entity name. /// </param> /// <param name='parameters'> /// Required. Test failover request. /// </param> /// <param name='customRequestHeaders'> /// Optional. Request header parameters. /// </param> /// <returns> /// A standard service response for long running operations. /// </returns> public static Task <LongRunningOperationResponse> TestFailoverAsync(this IProtectionEntityOperations operations, string pcName, string name, TestFailoverRequest parameters, CustomRequestHeaders customRequestHeaders) { return(operations.TestFailoverAsync(pcName, name, parameters, customRequestHeaders, CancellationToken.None)); }
/// <summary> /// Test failover of a protection entity. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.SiteRecovery.IProtectionEntityOperations. /// </param> /// <param name='pcName'> /// Required. Parent Protection Container name. /// </param> /// <param name='name'> /// Required. Protection entity name. /// </param> /// <param name='parameters'> /// Required. Test failover request. /// </param> /// <param name='customRequestHeaders'> /// Optional. Request header parameters. /// </param> /// <returns> /// A standard service response for long running operations. /// </returns> public static LongRunningOperationResponse BeginTestFailover(this IProtectionEntityOperations operations, string pcName, string name, TestFailoverRequest parameters, CustomRequestHeaders customRequestHeaders) { return(Task.Factory.StartNew((object s) => { return ((IProtectionEntityOperations)s).BeginTestFailoverAsync(pcName, name, parameters, customRequestHeaders); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
public void SanE2ETest() { using (UndoContext context = UndoContext.Current) { try { context.Start(); var client = GetSiteRecoveryClient(CustomHttpHandler); var requestHeaders = RequestHeaders; requestHeaders.AgentAuthenticationHeader = GenerateAgentAuthenticationHeader(requestHeaders.ClientRequestId); string containerId = "fc1e58ee-b96a-46fe-8afe-330f7ea545a1_d6a83495-5a6a-4ceb-9dc3-2829f6719032"; string entityId = "a7b4f73c-7a02-4fa2-b895-ddfcfceb0d7d"; string primaryServerId = "fc1e58ee-b96a-46fe-8afe-330f7ea545a1"; string recoveryServerId = "e19be056-3a6b-4239-8d01-b0820bc1aeaf"; //var responseServer = client.Servers.List(requestHeaders); //var responsePE = client.ProtectionEntity.Get(containerId, entityId, RequestHeaders); var responseStoragePoolPaired = client.StoragePoolMappings.List(primaryServerId, recoveryServerId, requestHeaders); var responseStoragePrimary = client.Storages.List(primaryServerId, requestHeaders); AsrStorage storagePoolPrimary = null; foreach (var storage in responseStoragePrimary.Storages) { if (storage.Type == "Pool") { if (storage.StoragePools.Count > 0) { storagePoolPrimary = storage; } } } var responseStorageRecovery = client.Storages.List(recoveryServerId, requestHeaders); AsrStorage storagePoolRecovery = null; foreach (var storage in responseStorageRecovery.Storages) { if (storage.Type == "Pool") { if (storage.StoragePools.Count > 0) { storagePoolRecovery = storage; } } } StoragePoolMappingInput storagePoolMappingInput = new StoragePoolMappingInput(); storagePoolMappingInput.PrimaryServerId = primaryServerId; storagePoolMappingInput.RecoveryServerId = recoveryServerId; storagePoolMappingInput.PrimaryArrayId = storagePoolPrimary.ID; storagePoolMappingInput.RecoveryArrayId = storagePoolRecovery.ID; storagePoolMappingInput.PrimaryStoragePoolId = storagePoolPrimary.StoragePools[0].ID; storagePoolMappingInput.RecoveryStoragePoolId = storagePoolRecovery.StoragePools[0].ID; var responseStoragePoolPair = client.StoragePoolMappings.Create(storagePoolMappingInput, requestHeaders); var responseStoragePoolUnpair = client.StoragePoolMappings.Delete(storagePoolMappingInput, requestHeaders); FailoverRequest request = new FailoverRequest(); // Planned Failover RG request = new PlannedFailoverRequest(); request.ReplicationProvider = "San"; request.FailoverDirection = "PrimaryToRecovery"; var response = client.ProtectionEntity.PlannedFailover(containerId, entityId, (PlannedFailoverRequest)request, requestHeaders); ValidateResponse(response); WaitForJobToComplete(client, response.Job.ID); // Reverse protect RG request = new ReprotectRequest(); request.ReplicationProvider = "San"; request.FailoverDirection = "RecoveryToPrimary"; response = client.ProtectionEntity.Reprotect(containerId, entityId, (ReprotectRequest)request, requestHeaders); ValidateResponse(response); WaitForJobToComplete(client, response.Job.ID); // UnPlanned Failover RG request = new UnplannedFailoverRequest(); request.ReplicationProvider = "San"; request.FailoverDirection = "RecoveryToPrimary"; response = client.ProtectionEntity.UnplannedFailover(containerId, entityId, (UnplannedFailoverRequest)request, requestHeaders); ValidateResponse(response); WaitForJobToComplete(client, response.Job.ID); // Reverse protect RG request = new ReprotectRequest(); request.ReplicationProvider = "San"; request.FailoverDirection = "PrimaryToRecovery"; response = client.ProtectionEntity.Reprotect(containerId, entityId, (ReprotectRequest)request, requestHeaders); ValidateResponse(response); WaitForJobToComplete(client, response.Job.ID); // Test Failover RG request = new TestFailoverRequest(); request.ReplicationProvider = "San"; request.FailoverDirection = "PrimaryToRecovery"; ((TestFailoverRequest)request).NetworkType = "NoNetworkAttachAsInput"; ((TestFailoverRequest)request).NetworkID = "xxx"; response = client.ProtectionEntity.TestFailover(containerId, entityId, (TestFailoverRequest)request, requestHeaders); ValidateResponse(response); } catch { //skip } } }