/// <summary>
 /// Starts Azure Site Recovery Unplanned failover.
 /// </summary>
 /// <param name="recoveryPlanId">Recovery Plan ID</param>
 /// <param name="recoveryPlanUnPlannedFailoverRequest">Recovery Plan Unplanned failover request</param>
 /// <returns>Job response</returns>
 public JobResponse StartAzureSiteRecoveryUnplannedFailover(
     string recoveryPlanId,
     RpUnplannedFailoverRequest recoveryPlanUnPlannedFailoverRequest)
 {
     return this.GetSiteRecoveryClient().RecoveryPlan.RecoveryPlanUnplannedFailover(
         recoveryPlanId,
         recoveryPlanUnPlannedFailoverRequest, 
         this.GetRequestHeaders());
 }
        /// <summary>
        /// Starts RP Planned failover.
        /// </summary>
        private void StartRpUnPlannedFailover()
        {
            RpUnplannedFailoverRequest recoveryPlanUnPlannedFailoverRequest = new RpUnplannedFailoverRequest();
            recoveryPlanUnPlannedFailoverRequest.FailoverDirection = this.Direction;
            recoveryPlanUnPlannedFailoverRequest.PrimaryAction = this.PrimaryAction;
            this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryUnplannedFailover(
                this.RPId,
                recoveryPlanUnPlannedFailoverRequest);

            this.WriteJob(this.jobResponse.Job);

            if (this.WaitForCompletion.IsPresent)
            {
                this.WaitForJobCompletion(this.jobResponse.Job.ID);
            }
        }
        /// <summary>
        /// Starts RP Planned failover.
        /// </summary>
        private void StartRpUnPlannedFailover()
        {
            RpUnplannedFailoverRequest request = new RpUnplannedFailoverRequest();

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

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

            request.ReplicationProviderSettings = string.Empty;

            if (this.RecoveryPlan.ReplicationProvider == Constants.HyperVReplicaAzure)
            {
                request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
                if (this.Direction == Constants.PrimaryToRecovery)
                {
                    var blob = new AzureFailoverInput();
                    blob.VaultLocation = this.GetCurrentValutLocation();
                    request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailoverInput>(blob);
                }
            }

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

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

            this.WriteJob(this.jobResponse.Job);

            if (this.WaitForCompletion.IsPresent)
            {
                this.WaitForJobCompletion(this.jobResponse.Job.ID);
            }
        }
Exemplo n.º 4
0
        public void RP_UFO_E2A_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)
                {
                    RpUnplannedFailoverRequest request = new RpUnplannedFailoverRequest();
                    request.FailoverDirection = "PrimaryToRecovery";
                    request.ReplicationProvider = "HyperVReplicaAzure";
                    AzureFailoverInput foInput = new AzureFailoverInput();
                    foInput.VaultLocation = VaultLocation;
                    request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailoverInput>
                        (foInput);
                    response = client.RecoveryPlan.RecoveryPlanUnplannedFailover(
                        rp.ID,
                        request,
                        requestHeaders);
                }

                Assert.NotNull(response.Job);
                Assert.NotNull(response.Job.ID);
                Assert.True(response.Job.Errors.Count < 1, "Errors found while doing unplanned failover operation");
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            }
        }
 /// <summary>
 /// UnplannedFailover 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> RecoveryPlanUnplannedFailoverAsync(this IRecoveryPlanOperations operations, string recoveryPlanId, RpUnplannedFailoverRequest parameters, CustomRequestHeaders customRequestHeaders)
 {
     return operations.RecoveryPlanUnplannedFailoverAsync(recoveryPlanId, parameters, customRequestHeaders, CancellationToken.None);
 }
 /// <summary>
 /// UnplannedFailover 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 RecoveryPlanUnplannedFailover(this IRecoveryPlanOperations operations, string recoveryPlanId, RpUnplannedFailoverRequest parameters, CustomRequestHeaders customRequestHeaders)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IRecoveryPlanOperations)s).RecoveryPlanUnplannedFailoverAsync(recoveryPlanId, parameters, customRequestHeaders);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }