public void FetchNodesListAndAutoProtectionPolicy(List <ProtectableItemBase> itemModels, string vaultName, string resourceGroupName) { foreach (var itemModel in itemModels) { AzureWorkloadProtectableItem protectableItem = ((AzureWorkloadProtectableItem)itemModel); string itemType = ""; string itemName = ""; string containerUri = ""; string backupManagementType = ""; Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(protectableItem.Id); itemType = HelperUtils.GetProtectableItemUri(keyValueDict, protectableItem.Id).Split(';')[0]; itemName = HelperUtils.GetProtectableItemUri(keyValueDict, protectableItem.Id).Split(';')[1]; containerUri = HelperUtils.GetContainerUri(keyValueDict, protectableItem.Id); // fetch AutoProtectionPolicy for non DBs if (protectableItem.ProtectableItemType != "SQLDataBase") { // fetch the policy using backup intent ODataQuery <ServiceClientModel.ProtectionIntentQueryObject> queryParams = null; backupManagementType = ServiceClientModel.BackupManagementType.AzureWorkload; queryParams = new ODataQuery <ServiceClientModel.ProtectionIntentQueryObject>( q => q.ItemType == itemType && q.ItemName == itemName && q.ParentName == containerUri && q.BackupManagementType == backupManagementType); var intentList = ServiceClientAdapter.ListProtectionIntent( queryParams, vaultName: vaultName, resourceGroupName: resourceGroupName); foreach (var intent in intentList) { protectableItem.AutoProtectionPolicy = intent.Properties.PolicyId; } } // fetch Nodelist for SQLAGs if (protectableItem.ProtectableItemType == "SQLAvailabilityGroup") { // add the NodeList ProtectionContainerResource cont = ServiceClientAdapter.GetContainer(vaultName, resourceGroupName, containerUri); AzureSQLAGWorkloadContainerProtectionContainer protectionContainer = (AzureSQLAGWorkloadContainerProtectionContainer)cont.Properties; if (protectionContainer.ExtendedInfo != null) { protectableItem.NodesList = protectionContainer.ExtendedInfo.NodesList; } } } }
private static ProtectableItemBase GetAzureWorkloadProtectableItemModel(ServiceClientModel.WorkloadProtectableItemResource protectableItem) { ProtectableItemBase itemModel; string containerUri = HelperUtils.GetContainerUri( HelperUtils.ParseUri(protectableItem.Id), protectableItem.Id); itemModel = new AzureWorkloadProtectableItem( protectableItem, containerUri, ContainerType.AzureVMAppContainer); return(itemModel); }
private RestAzureNS.AzureOperationResponse <ProtectedItemResource> EnableOrModifyProtection(bool disableWithRetentionData = false) { string vaultName = (string)ProviderData[VaultParams.VaultName]; string vaultResourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName]; PolicyBase policy = ProviderData.ContainsKey(ItemParams.Policy) ? (PolicyBase)ProviderData[ItemParams.Policy] : null; ProtectableItemBase protectableItemBase = ProviderData.ContainsKey(ItemParams.ProtectableItem) ? (ProtectableItemBase)ProviderData[ItemParams.ProtectableItem] : null; AzureWorkloadProtectableItem protectableItem = ProviderData.ContainsKey(ItemParams.ProtectableItem) ? (AzureWorkloadProtectableItem)ProviderData[ItemParams.ProtectableItem] : null; ItemBase itemBase = ProviderData.ContainsKey(ItemParams.Item) ? (ItemBase)ProviderData[ItemParams.Item] : null; AzureWorkloadSQLDatabaseProtectedItem item = ProviderData.ContainsKey(ItemParams.Item) ? (AzureWorkloadSQLDatabaseProtectedItem)ProviderData[ItemParams.Item] : null; AzureVmWorkloadSQLDatabaseProtectedItem properties = new AzureVmWorkloadSQLDatabaseProtectedItem(); string containerUri = ""; string protectedItemUri = ""; if (disableWithRetentionData) { //Disable protection while retaining backup data ValidateAzureWorkloadDisableProtectionRequest(itemBase); Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.Id); containerUri = HelperUtils.GetContainerUri(keyValueDict, item.Id); protectedItemUri = HelperUtils.GetProtectedItemUri(keyValueDict, item.Id); properties.PolicyId = string.Empty; properties.ProtectionState = ProtectionState.ProtectionStopped; properties.SourceResourceId = item.SourceResourceId; } else { if (protectableItem != null) { Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(protectableItem.Id); containerUri = HelperUtils.GetContainerUri( keyValueDict, protectableItem.Id); protectedItemUri = HelperUtils.GetProtectableItemUri( keyValueDict, protectableItem.Id); properties.PolicyId = policy.Id; } else if (item != null) { Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.Id); containerUri = HelperUtils.GetContainerUri( keyValueDict, item.Id); protectedItemUri = HelperUtils.GetProtectedItemUri( keyValueDict, item.Id); properties.PolicyId = policy.Id; } } ProtectedItemResource serviceClientRequest = new ProtectedItemResource() { Properties = properties }; return(ServiceClientAdapter.CreateOrUpdateProtectedItem( containerUri, protectedItemUri, serviceClientRequest, vaultName: vaultName, resourceGroupName: vaultResourceGroupName)); }