Пример #1
0
        /// <summary>
        /// Sets RP Commit.
        /// </summary>
        private void SetRpCommit()
        {
            var request = new CommitFailoverRequest();

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

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

            request.ReplicationProvider         = this.RecoveryPlan.ReplicationProvider;
            request.ReplicationProviderSettings = string.Empty;

            request.FailoverDirection = this.Direction;

            this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryCommitFailover(
                this.RPId);

            this.WriteJob(this.jobResponse.Job);

            if (this.WaitForCompletion.IsPresent)
            {
                this.WaitForJobCompletion(this.jobResponse.Job.ID);
            }
        }
Пример #2
0
 /// <summary>
 /// Starts Azure Site Recovery Commit failover.
 /// </summary>
 /// <param name="protectionContainerId">Protection Container ID</param>
 /// <param name="protectionEntityId">Recovery Plan ID</param>
 /// <param name="request">Commit failover request.</param>
 /// <returns>Job response</returns>
 public JobResponse StartAzureSiteRecoveryCommitFailover(
     string protectionContainerId,
     string protectionEntityId,
     CommitFailoverRequest request)
 {
     return(this.GetSiteRecoveryClient().ProtectionEntity.CommitFailover(
                protectionContainerId,
                protectionEntityId,
                request,
                this.GetRequestHeaders()));
 }
Пример #3
0
        /// <summary>
        /// Start PE Commit.
        /// </summary>
        private void SetPECommit()
        {
            var request = new CommitFailoverRequest();

            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.ReplicationProvider         = this.ProtectionEntity.ReplicationProvider;
            request.ReplicationProviderSettings = string.Empty;

            if (this.ProtectionEntity.ActiveLocation == Constants.PrimaryLocation)
            {
                request.FailoverDirection = Constants.RecoveryToPrimary;
            }
            else
            {
                request.FailoverDirection = Constants.PrimaryToRecovery;
            }

            this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryCommitFailover(
                this.ProtectionContainerId,
                this.ProtectionEntityId,
                request);

            this.WriteJob(this.jobResponse.Job);

            if (this.WaitForCompletion.IsPresent)
            {
                this.WaitForJobCompletion(this.jobResponse.Job.ID);
            }
        }
        /// <summary>
        /// Start PE Commit.
        /// </summary>
        private void SetPECommit()
        {
            var request = new CommitFailoverRequest();

            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.ReplicationProvider         = this.ProtectionEntity.ReplicationProvider;
            request.ReplicationProviderSettings = string.Empty;
            request.FailoverDirection           = this.Direction;

            //if (this.ProtectionEntity.ActiveLocation == Constants.PrimaryLocation)
            //{
            //    request.FailoverDirection = Constants.RecoveryToPrimary;
            //}
            //else
            //{
            //    request.FailoverDirection = Constants.PrimaryToRecovery;
            //}

            LongRunningOperationResponse response = RecoveryServicesClient.StartAzureSiteRecoveryCommitFailover(
                this.protectionContainerId,
                this.protectionEntityId,
                request);

            JobResponse jobResponse =
                RecoveryServicesClient
                .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            WriteObject(new ASRJob(jobResponse.Job));
        }
Пример #5
0
        /// <summary>
        /// Start PE Commit.
        /// </summary>
        private void SetPECommit()
        {
            var request = new CommitFailoverRequest();

            request.FailoverDirection = this.Direction;

            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();

            LongRunningOperationResponse response = RecoveryServicesClient.StartAzureSiteRecoveryCommitFailover(
                this.protectionContainerId,
                this.protectionEntityId,
                request);

            JobResponse jobResponse =
                RecoveryServicesClient
                .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            WriteObject(new ASRJob(jobResponse.Job));
        }
 /// <summary>
 /// Commit 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. Commit 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> CommitFailoverAsync(this IProtectionEntityOperations operations, string protectionContainerId, string protectionEntityId, CommitFailoverRequest parameters, CustomRequestHeaders customRequestHeaders)
 {
     return(operations.CommitFailoverAsync(protectionContainerId, protectionEntityId, parameters, customRequestHeaders, CancellationToken.None));
 }
 /// <summary>
 /// Commit 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. Commit failover request.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// The response model for the Job details object.
 /// </returns>
 public static JobResponse CommitFailover(this IProtectionEntityOperations operations, string protectionContainerId, string protectionEntityId, CommitFailoverRequest parameters, CustomRequestHeaders customRequestHeaders)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IProtectionEntityOperations)s).CommitFailoverAsync(protectionContainerId, protectionEntityId, parameters, customRequestHeaders);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
 /// <summary>
 /// Commit 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. Commit 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> BeginCommitFailoverAsync(this IProtectionEntityOperations operations, string pcName, string name, CommitFailoverRequest parameters, CustomRequestHeaders customRequestHeaders)
 {
     return(operations.BeginCommitFailoverAsync(pcName, name, parameters, customRequestHeaders, CancellationToken.None));
 }
 /// <summary>
 /// Commit 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. Commit failover request.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// A standard service response for long running operations.
 /// </returns>
 public static LongRunningOperationResponse BeginCommitFailover(this IProtectionEntityOperations operations, string pcName, string name, CommitFailoverRequest parameters, CustomRequestHeaders customRequestHeaders)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IProtectionEntityOperations)s).BeginCommitFailoverAsync(pcName, name, parameters, customRequestHeaders);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
        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);
            }
        }