Beispiel #1
0
        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;
                    }
                }
            }
        }