Example #1
0
        public void RP_PFO_Failback_Test()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetSiteRecoveryClient(CustomHttpHandler);

                var requestHeaders = RequestHeaders;
                requestHeaders.AgentAuthenticationHeader = GenerateAgentAuthenticationHeader(requestHeaders.ClientRequestId);

                var responseRP = client.RecoveryPlan.List(RequestHeaders);

                JobResponse response = new JobResponse();
                foreach (var rp in responseRP.RecoveryPlans)
                {
                    RpPlannedFailoverRequest request = new RpPlannedFailoverRequest();
                    request.FailoverDirection = "RecoveryToPrimary";
                    request.ReplicationProvider = "HyperVReplicaAzure";
                    AzureFailbackInput fbInput = new AzureFailbackInput();
                    fbInput.CreateRecoveryVmIfDoesntExist = true;
                    fbInput.SkipDataSync = true;
                    request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailbackInput>
                        (fbInput);
                    response = client.RecoveryPlan.RecoveryPlanPlannedFailover(
                        rp.ID,
                        request,
                        requestHeaders);
                }

                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 Planned failover.
 /// </summary>
 /// <param name="recoveryPlanId">Recovery Plan ID</param>
 /// <param name="recoveryPlanPlannedFailoverRequest">Recovery Plan Planned failover request</param>
 /// <returns>Job response</returns>
 public JobResponse StartAzureSiteRecoveryPlannedFailover(
     string recoveryPlanId, 
     RpPlannedFailoverRequest recoveryPlanPlannedFailoverRequest)
 {
     return this.GetSiteRecoveryClient().RecoveryPlan.RecoveryPlanPlannedFailover(
         recoveryPlanId,
         recoveryPlanPlannedFailoverRequest, 
         this.GetRequestHeaders());
 }
        /// <summary>
        /// Starts RP Planned failover.
        /// </summary>
        private void StartRpPlannedFailover()
        {
            RpPlannedFailoverRequest request = new RpPlannedFailoverRequest();

            if (this.RecoveryPlan == null)
            {
                var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(
                    this.RPId);
                this.RecoveryPlan = new ASRRecoveryPlan(rp.RecoveryPlan);

                this.ValidateUsageById(
                    this.RecoveryPlan.ReplicationProvider,
                    Constants.RPId);
            }

            if (this.RecoveryPlan.ReplicationProvider == Constants.HyperVReplicaAzure)
            {
                if (this.Direction == Constants.PrimaryToRecovery)
                {
                    var blob = new AzureFailoverInput();
                    blob.VaultLocation = this.GetCurrentValutLocation();
                    request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailoverInput>(blob);
                }
                else
                {
                    var blob = new AzureFailbackInput();
                    blob.CreateRecoveryVmIfDoesntExist = false;
                    blob.SkipDataSync = this.Optimize == Constants.ForDowntime ? true : false;
                    request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailbackInput>(blob);
                }
            }

            request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
            request.FailoverDirection = this.Direction;

            this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryPlannedFailover(
                this.RPId, 
                request);

            this.WriteJob(this.jobResponse.Job);

            if (this.WaitForCompletion.IsPresent)
            {
                this.WaitForJobCompletion(this.jobResponse.Job.ID);
            }
        }
 /// <summary>
 /// PlannedFailover for the recovery plan.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.SiteRecovery.IRecoveryPlanOperations.
 /// </param>
 /// <param name='recoveryPlanId'>
 /// Required. RecoveryPlan ID.
 /// </param>
 /// <param name='parameters'>
 /// Optional.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// The response model for the Job details object.
 /// </returns>
 public static Task<JobResponse> RecoveryPlanPlannedFailoverAsync(this IRecoveryPlanOperations operations, string recoveryPlanId, RpPlannedFailoverRequest parameters, CustomRequestHeaders customRequestHeaders)
 {
     return operations.RecoveryPlanPlannedFailoverAsync(recoveryPlanId, parameters, customRequestHeaders, CancellationToken.None);
 }
 /// <summary>
 /// PlannedFailover for the recovery plan.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.SiteRecovery.IRecoveryPlanOperations.
 /// </param>
 /// <param name='recoveryPlanId'>
 /// Required. RecoveryPlan ID.
 /// </param>
 /// <param name='parameters'>
 /// Optional.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// The response model for the Job details object.
 /// </returns>
 public static JobResponse RecoveryPlanPlannedFailover(this IRecoveryPlanOperations operations, string recoveryPlanId, RpPlannedFailoverRequest parameters, CustomRequestHeaders customRequestHeaders)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IRecoveryPlanOperations)s).RecoveryPlanPlannedFailoverAsync(recoveryPlanId, parameters, customRequestHeaders);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
        /// <summary>
        /// Starts RP Planned failover.
        /// </summary>
        private void StartRpPlannedFailover()
        {
            RpPlannedFailoverRequest recoveryPlanPlannedFailoverRequest = new RpPlannedFailoverRequest();
            recoveryPlanPlannedFailoverRequest.FailoverDirection = this.Direction;
            this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryPlannedFailover(
                this.RPId, 
                recoveryPlanPlannedFailoverRequest);

            this.WriteJob(this.jobResponse.Job);

            if (this.WaitForCompletion.IsPresent)
            {
                this.WaitForJobCompletion(this.jobResponse.Job.ID);
            }
        }