/// <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); }
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 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 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); } }