public void RP_PFO_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)
                {
                    RpPlannedFailoverRequest request = new RpPlannedFailoverRequest();
                    request.FailoverDirection   = "PrimaryToRecovery";
                    request.ReplicationProvider = "HyperVReplicaAzure";
                    AzureFailoverInput foInput = new AzureFailoverInput();
                    foInput.VaultLocation = VaultLocation;
                    request.ReplicationProviderSettings = DataContractUtils.Serialize <AzureFailoverInput>
                                                              (foInput);
                    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 unplanned failover operation");
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            }
        }
예제 #2
0
        public void CreateAzureNetworkMappingTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetSiteRecoveryClient(CustomHttpHandler);

                // Get Servers
                var servers = client.Servers.List(RequestHeaders);

                // 57f95c35-6c83-42ce-bb21-2c4f10f92d8e
                var networks = client.Networks.List(servers.Servers[0].ID, RequestHeaders);

                CreateAzureNetworkMappingInput createAzureNetworkMappingInput = new CreateAzureNetworkMappingInput();
                createAzureNetworkMappingInput.PrimaryServerId     = servers.Servers[0].ID;
                createAzureNetworkMappingInput.PrimaryNetworkId    = networks.Networks[0].ID;
                createAzureNetworkMappingInput.RecoveryNetworkName = "Azure VM Network name";
                createAzureNetworkMappingInput.RecoveryNetworkId   = "Azure VM Network ID";

                NetworkMappingInput networkMappingInput = new NetworkMappingInput();
                networkMappingInput.NetworkTargetType         = NetworkTargetType.Azure.ToString();
                networkMappingInput.CreateNetworkMappingInput =
                    DataContractUtils.Serialize <CreateAzureNetworkMappingInput>(createAzureNetworkMappingInput);

                var response = client.NetworkMappings.Create(networkMappingInput, RequestHeaders);

                Assert.NotNull(response.Job);
                Assert.NotNull(response.Job.ID);
                Assert.True(response.Job.Errors.Count < 1, "Errors found while creating network mapping");
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            }
        }
        public void E2AFailbackTest()
        {
            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.CanFailover == true)
                        {
                            PlannedFailoverRequest request = new PlannedFailoverRequest();
                            request.ReplicationProvider = pe.ReplicationProvider;
                            if (pe.ActiveLocation == "Primary")
                            {
                                request.FailoverDirection = "PrimaryToRecovery";
                            }
                            else
                            {
                                request.FailoverDirection = "RecoveryToPrimary";
                            }

                            AzureFailbackInput blob = new AzureFailbackInput();
                            blob.CreateRecoveryVmIfDoesntExist = false;
                            blob.SkipDataSync = true;
                            request.ReplicationProviderSettings = DataContractUtils.Serialize <AzureFailbackInput>
                                                                      (blob);
                            response = client.ProtectionEntity.PlannedFailover(
                                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);
            }
        }
        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>
 /// Deserialize the string to the expected object type.
 /// </summary>
 /// <param name="xmlString">Serialized string.</param>
 /// <param name="result">Deserialized object.</param>
 public static void Deserialize <T>(string xmlString, out T result)
 {
     result = DataContractUtils <T> .Deserialize(xmlString);
 }
 /// <summary>
 /// Serializes the supplied object to the string.
 /// </summary>
 /// <typeparam name="T">The object type.</typeparam>
 /// <param name="obj">The object to serialize.</param>
 /// <returns>Serialized string.</returns>
 public static string Serialize <T>(T obj)
 {
     return(DataContractUtils <T> .Serialize(obj));
 }
        public void Update()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client         = GetSiteRecoveryClient(CustomHttpHandler);
                var requestHeaders = RequestHeaders;
                requestHeaders.AgentAuthenticationHeader = GenerateAgentAuthenticationHeader(requestHeaders.ClientRequestId);

                JobQueryParameter jqp = new JobQueryParameter();
                var responseRP        = client.ProtectionProfile.List(RequestHeaders);

                string serializedHyperVReplicaAzureProfileManagementInput = null;
                foreach (var profile in responseRP.ProtectionProfiles)
                {
                    if (profile.ReplicationProvider == "HyperVReplicaAzure")
                    {
                        string subsId = null;

                        var obj =
                            DataContractUtils <HyperVReplicaAzureProtectionProfileDetails> .Deserialize(
                                profile.ReplicationProviderSetting);

                        var settings = new HyperVReplicaAzureProtectionProfileInput();
                        settings.AppConsistencyFreq           = obj.AppConsistencyFreq;
                        settings.IsEncryptionEnabled          = obj.IsEncryptionEnabled;
                        settings.OnlineIrStartTime            = obj.OnlineIrStartTime;
                        settings.RecoveryPointHistoryDuration = obj.RecoveryPointHistoryDuration;
                        settings.ReplicationInterval          = obj.ReplicationInterval;
                        settings.StorageAccounts = new List <CustomerStorageAccount>();
                        var storageAccount = new CustomerStorageAccount();
                        storageAccount.StorageAccountName = obj.ActiveStorageAccount.StorageAccountName;
                        subsId = storageAccount.SubscriptionId;
                        storageAccount.SubscriptionId = "MySubscriptionId";
                        settings.StorageAccounts.Add(storageAccount);

                        serializedHyperVReplicaAzureProfileManagementInput =
                            DataContractUtils <HyperVReplicaAzureProtectionProfileInput> .Serialize(settings);

                        // update the profile object.
                        var input = new UpdateProtectionProfileInput();
                        input.ReplicationProviderSettings = serializedHyperVReplicaAzureProfileManagementInput;

                        var responseUpdate = client.ProtectionProfile.Update(input, profile.ID, RequestHeaders);
                        var responseGet    = client.ProtectionProfile.Get(profile.ID, RequestHeaders);

                        // check for subsid.
                        Assert.NotNull(responseGet.ProtectionProfile);

                        // revert the temp changes.
                        storageAccount.SubscriptionId = subsId;
                        serializedHyperVReplicaAzureProfileManagementInput =
                            DataContractUtils <HyperVReplicaAzureProtectionProfileInput> .Serialize(settings);

                        input.ReplicationProviderSettings = serializedHyperVReplicaAzureProfileManagementInput;
                        responseUpdate = client.ProtectionProfile.Update(
                            input,
                            profile.ID,
                            requestHeaders);
                        return;
                    }
                }
            }
        }
        public void CreateAndAssociateE2A(string provider)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client         = GetSiteRecoveryClient(CustomHttpHandler);
                var requestHeaders = RequestHeaders;
                requestHeaders.AgentAuthenticationHeader = GenerateAgentAuthenticationHeader(requestHeaders.ClientRequestId);

                JobQueryParameter jqp = new JobQueryParameter();
                var responseRP        = client.ProtectionProfile.List(RequestHeaders);

                string serializedHyperVReplicaAzureProfileManagementInput = null;
                foreach (var profile in responseRP.ProtectionProfiles)
                {
                    if (profile.AssociationDetail[0].AssociationStatus == "Paired")
                    {
                        // Instead of creating new set of values. Picking the values from already paired cloud.
                        var obj =
                            DataContractUtils <HyperVReplicaAzureProtectionProfileDetails> .Deserialize(
                                profile.ReplicationProviderSetting);

                        var settings = new HyperVReplicaAzureProtectionProfileInput();
                        settings.AppConsistencyFreq           = obj.AppConsistencyFreq;
                        settings.IsEncryptionEnabled          = obj.IsEncryptionEnabled;
                        settings.OnlineIrStartTime            = obj.OnlineIrStartTime;
                        settings.RecoveryPointHistoryDuration = obj.RecoveryPointHistoryDuration;
                        settings.ReplicationInterval          = obj.ReplicationInterval;
                        settings.StorageAccounts = new List <CustomerStorageAccount>();
                        var storageAccount = new CustomerStorageAccount();
                        storageAccount.StorageAccountName = obj.ActiveStorageAccount.StorageAccountName;
                        storageAccount.SubscriptionId     = obj.ActiveStorageAccount.SubscriptionId;
                        settings.StorageAccounts.Add(storageAccount);

                        serializedHyperVReplicaAzureProfileManagementInput =
                            DataContractUtils <HyperVReplicaAzureProtectionProfileInput> .Serialize(settings);
                    }
                }

                var responsePC = client.ProtectionContainer.List(RequestHeaders);

                foreach (var pc in responsePC.ProtectionContainers)
                {
                    if (string.IsNullOrWhiteSpace(pc.Role))
                    {
                        var input = new CreateAndAssociateProtectionProfileInput();

                        input.ProtectionProfileInput      = new CreateProtectionProfileInput();
                        input.ProtectionProfileInput.Name = "PP1";
                        input.ProtectionProfileInput.ReplicationProvider         = "HyperVReplicaAzure";
                        input.ProtectionProfileInput.ReplicationProviderSettings =
                            serializedHyperVReplicaAzureProfileManagementInput;

                        input.AssociationInput = new ProtectionProfileAssociationInput();
                        input.AssociationInput.PrimaryProtectionContainerId  = pc.ID;
                        input.AssociationInput.RecoveryProtectionContainerId = AzureProtectionContainerId;

                        client.ProtectionProfile.CreateAndAssociate(input, requestHeaders);
                    }
                }

                //Assert.NotNull(response.);
                //Assert.NotNull(response.RecoveryPlan.ID);
                //Assert.NotNull(response.RecoveryPlan.Name);
                //Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            }
        }
        public void CreateAndAssociateE2E()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client         = GetSiteRecoveryClient(CustomHttpHandler);
                var requestHeaders = RequestHeaders;
                requestHeaders.AgentAuthenticationHeader = GenerateAgentAuthenticationHeader(requestHeaders.ClientRequestId);

                string serializedHyperVReplicaAzureProfileManagementInput = null;

                var settings = new HyperVReplicaProtectionProfileInput();
                settings.AllowedAuthenticationType = 1;
                settings.AllowReplicaDeletion      = false;
                settings.ApplicationConsistentSnapshotFrequencyInHours = 0;
                settings.CompressionEnabled           = true;
                settings.OfflineReplicationExportPath = null;
                settings.OfflineReplicationImportPath = null;
                settings.OnlineReplicationMethod      = true;
                settings.OnlineReplicationStartTime   = null;
                settings.RecoveryPoints = 1;
                settings.ReplicationFrequencyInSeconds = 300;
                settings.ReplicationPort = 8083;

                serializedHyperVReplicaAzureProfileManagementInput =
                    DataContractUtils <HyperVReplicaProtectionProfileInput> .Serialize(settings);

                var responsePC = client.ProtectionContainer.List(RequestHeaders);

                string primaryPCId  = null;
                string recoveryPCId = null;
                foreach (var pc in responsePC.ProtectionContainers)
                {
                    if (string.IsNullOrWhiteSpace(pc.Role))
                    {
                        if (primaryPCId == null)
                        {
                            primaryPCId = pc.ID;
                            continue;
                        }

                        if (recoveryPCId == null)
                        {
                            recoveryPCId = pc.ID;
                            break;
                        }
                    }
                }

                var input = new CreateAndAssociateProtectionProfileInput();

                input.ProtectionProfileInput      = new CreateProtectionProfileInput();
                input.ProtectionProfileInput.Name = "E2E_Profile";
                input.ProtectionProfileInput.ReplicationProvider         = "HyperVReplica";
                input.ProtectionProfileInput.ReplicationProviderSettings =
                    serializedHyperVReplicaAzureProfileManagementInput;

                input.AssociationInput = new ProtectionProfileAssociationInput();
                input.AssociationInput.PrimaryProtectionContainerId  = primaryPCId;
                input.AssociationInput.RecoveryProtectionContainerId = recoveryPCId;

                JobResponse response = client.ProtectionProfile.CreateAndAssociate(input, requestHeaders);

                Assert.NotNull(response.Job);
                Assert.NotNull(response.Job.ID);
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            }
        }
예제 #10
0
        public void EnableProtectionTest()
        {
            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)
                {
                    if (pc.Role == "Primary")
                    {
                        var responsePEs = client.ProtectionEntity.List(pc.ID, RequestHeaders);
                        response = null;
                        foreach (var pe in responsePEs.ProtectionEntities)
                        {
                            if (pe.Protected == false)
                            {
                                AzureVmDiskDetails diskDetails;
                                DataContractUtils.Deserialize <AzureVmDiskDetails>(
                                    pe.ReplicationProviderSettings, out diskDetails);
                                EnableProtectionInput input = new EnableProtectionInput();
                                int index = 0;
                                input.ProtectionProfileId = pc.AvailableProtectionProfiles[index].ID;
                                AzureEnableProtectionInput azureInput = new AzureEnableProtectionInput();
                                azureInput.HvHostVmId = pe.FabricObjectId;
                                azureInput.VmName     = pe.Name;
                                azureInput.VHDId      = diskDetails.VHDId;
                                azureInput.OSType     = diskDetails.OsType;

                                if (string.IsNullOrWhiteSpace(azureInput.OSType))
                                {
                                    azureInput.OSType = "Windows";
                                }

                                input.ReplicationProviderInput = DataContractUtils.Serialize <AzureEnableProtectionInput>(azureInput);

                                response = client.ProtectionEntity.EnableProtection(
                                    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 Enable protection 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);
            }
        }