public List <ItemBase> GetMABProtectedItems(string vaultName, string resourceGroupName, ContainerBase container = null) { ODataQuery <ProtectedItemQueryObject> queryParams = new ODataQuery <ProtectedItemQueryObject>( q => q.BackupManagementType == ServiceClientModel.BackupManagementType.MAB); List <ProtectedItemResource> protectedItems = ServiceClientAdapter.ListProtectedItem( queryParams, null, vaultName: vaultName, resourceGroupName: resourceGroupName); // filter by Container Name if given if (container != null) { protectedItems = protectedItems.Where(protectedItem => { Dictionary <CmdletModel.UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id); string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItem.Id); var delimIndex = containerUri.IndexOf(';'); string containerName = containerUri.Substring(delimIndex + 1); return(containerName.ToLower().Equals(container.Name.ToLower())); }).ToList(); } return(ConversionHelpers.GetItemModelList(protectedItems)); }
public List <CmdletModel.ItemBase> ListProtectedItemsByItemName( List <ProtectedItemResource> protectedItems, string itemName, string vaultName, string resourceGroupName, Action <CmdletModel.ItemBase, ProtectedItemResource> extendedInfoProcessor) { List <ProtectedItemResource> protectedItemGetResponses = new List <ProtectedItemResource>(); if (!string.IsNullOrEmpty(itemName)) { protectedItems = protectedItems.Where(protectedItem => { Dictionary <CmdletModel.UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItem.Id); return(protectedItemUri.ToLower().Contains(itemName.ToLower())); }).ToList(); ODataQuery <GetProtectedItemQueryObject> getItemQueryParams = new ODataQuery <GetProtectedItemQueryObject>(q => q.Expand == "extendedinfo"); for (int i = 0; i < protectedItems.Count; i++) { Dictionary <CmdletModel.UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItems[i].Id); string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItems[i].Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItems[i].Id); var getResponse = ServiceClientAdapter.GetProtectedItem( containerUri, protectedItemUri, getItemQueryParams, vaultName: vaultName, resourceGroupName: resourceGroupName); protectedItemGetResponses.Add(getResponse.Body); } } List <CmdletModel.ItemBase> itemModels = ConversionHelpers.GetItemModelList(protectedItems); if (!string.IsNullOrEmpty(itemName)) { for (int i = 0; i < itemModels.Count; i++) { extendedInfoProcessor(itemModels[i], protectedItemGetResponses[i]); } } return(itemModels); }
public List <ItemBase> GetMABProtectedItems(string vaultName, string resourceGroupName) { ODataQuery <ProtectedItemQueryObject> queryParams = new ODataQuery <ProtectedItemQueryObject>( q => q.BackupManagementType == BackupManagementType.MAB); List <ProtectedItemResource> protectedItems = ServiceClientAdapter.ListProtectedItem( queryParams, null, vaultName: vaultName, resourceGroupName: resourceGroupName); return(ConversionHelpers.GetItemModelList(protectedItems)); }
/// <summary> /// Lists protected items protected by the recovery services vault according to the provider data /// </summary> /// <returns>List of protected items</returns> public List <ItemBase> ListProtectedItems() { string vaultName = (string)ProviderData[VaultParams.VaultName]; string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName]; ContainerBase container = (ContainerBase)ProviderData[ItemParams.Container]; string name = (string)ProviderData[ItemParams.ItemName]; ItemProtectionStatus protectionStatus = (ItemProtectionStatus)ProviderData[ItemParams.ProtectionStatus]; ItemProtectionState status = (ItemProtectionState)ProviderData[ItemParams.ProtectionState]; CmdletModel.WorkloadType workloadType = (CmdletModel.WorkloadType)ProviderData[ItemParams.WorkloadType]; PolicyBase policy = (PolicyBase)ProviderData[PolicyParams.ProtectionPolicy]; ODataQuery <ProtectedItemQueryObject> queryParams = policy != null ? new ODataQuery <ProtectedItemQueryObject>( q => q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureSql && q.ItemType == DataSourceType.AzureSqlDb && q.PolicyName == policy.Name) : new ODataQuery <ProtectedItemQueryObject>( q => q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureSql && q.ItemType == DataSourceType.AzureSqlDb); List <ProtectedItemResource> protectedItems = new List <ProtectedItemResource>(); string skipToken = null; var listResponse = ServiceClientAdapter.ListProtectedItem( queryParams, skipToken, vaultName: vaultName, resourceGroupName: resourceGroupName); protectedItems.AddRange(listResponse); // 1. Filter by container if (container != null) { protectedItems = protectedItems.Where(protectedItem => { Dictionary <UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id); string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItem.Id); return(containerUri.Contains(container.Name)); }).ToList(); } List <ProtectedItemResource> protectedItemGetResponses = new List <ProtectedItemResource>(); // 2. Filter by item's friendly name if (!string.IsNullOrEmpty(name)) { protectedItems = protectedItems.Where(protectedItem => { Dictionary <UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItem.Id); return(protectedItemUri.ToLower().Contains(name.ToLower())); }).ToList(); ODataQuery <GetProtectedItemQueryObject> getItemQueryParams = new ODataQuery <GetProtectedItemQueryObject>(q => q.Expand == extendedInfo); for (int i = 0; i < protectedItems.Count; i++) { Dictionary <UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItems[i].Id); string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItems[i].Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItems[i].Id); var getResponse = ServiceClientAdapter.GetProtectedItem( containerUri, protectedItemUri, getItemQueryParams, vaultName: vaultName, resourceGroupName: resourceGroupName); protectedItemGetResponses.Add(getResponse.Body); } } List <ItemBase> itemModels = ConversionHelpers.GetItemModelList(protectedItems); if (!string.IsNullOrEmpty(name)) { for (int i = 0; i < itemModels.Count; i++) { AzureSqlProtectedItem azureSqlProtectedItem = (AzureSqlProtectedItem)protectedItemGetResponses[i].Properties; AzureSqlItemExtendedInfo extendedInfo = new AzureSqlItemExtendedInfo(); var hydraExtendedInfo = azureSqlProtectedItem.ExtendedInfo; if (hydraExtendedInfo.OldestRecoveryPoint.HasValue) { extendedInfo.OldestRecoveryPoint = hydraExtendedInfo.OldestRecoveryPoint; } extendedInfo.PolicyState = hydraExtendedInfo.PolicyState; extendedInfo.RecoveryPointCount = hydraExtendedInfo.RecoveryPointCount; ((AzureSqlItem)itemModels[i]).ExtendedInfo = extendedInfo; } } // 3. Filter by item's Protection Status if (protectionStatus != 0) { throw new Exception( string.Format( Resources.ProtectionStatusNotAllowedForAzureSqlItem, protectionStatus.ToString())); } // 4. Filter by item's Protection State if (status != 0) { if (status != ItemProtectionState.Protected) { throw new Exception( string.Format( Resources.ProtectionStateInvalidForAzureSqlItem, status.ToString())); } itemModels = itemModels.Where(itemModel => { return(((AzureSqlItem)itemModel).ProtectionState == status.ToString()); }).ToList(); } // 5. Filter by workload type if (workloadType != 0) { itemModels = itemModels.Where(itemModel => { return(itemModel.WorkloadType == workloadType); }).ToList(); } return(itemModels); }
public List <CmdletModel.ItemBase> ListProtectedItemsByItemName( List <ProtectedItemResource> protectedItems, string itemName, string vaultName, string resourceGroupName, Action <CmdletModel.ItemBase, ProtectedItemResource> extendedInfoProcessor, string friendlyName = null) { List <ProtectedItemResource> protectedItemGetResponses = new List <ProtectedItemResource>(); if (!string.IsNullOrEmpty(itemName) || !string.IsNullOrEmpty(friendlyName)) { protectedItems = protectedItems.Where(protectedItem => { Dictionary <CmdletModel.UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItem.Id); bool filteredByUniqueName = itemName != null && (protectedItemUri.ToLower().Contains(itemName.ToLower())); bool filteredByFriendlyName = false; if (protectedItem.Properties.BackupManagementType == "AzureStorage" && protectedItem.Properties.WorkloadType == "AzureFileShare") { string protectedItemFriendlyName = (protectedItem.Properties as AzureFileshareProtectedItem).FriendlyName; filteredByUniqueName = filteredByUniqueName || (itemName != null && protectedItemFriendlyName.ToLower() == itemName.ToLower()); filteredByFriendlyName = friendlyName != null && protectedItemFriendlyName.ToLower() == friendlyName.ToLower(); } return(filteredByUniqueName || filteredByFriendlyName); }).ToList(); ODataQuery <GetProtectedItemQueryObject> getItemQueryParams = new ODataQuery <GetProtectedItemQueryObject>(q => q.Expand == "extendedinfo"); for (int i = 0; i < protectedItems.Count; i++) { Dictionary <CmdletModel.UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItems[i].Id); string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItems[i].Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItems[i].Id); var getResponse = ServiceClientAdapter.GetProtectedItem( containerUri, protectedItemUri, getItemQueryParams, vaultName: vaultName, resourceGroupName: resourceGroupName); protectedItemGetResponses.Add(getResponse.Body); } } List <CmdletModel.ItemBase> itemModels = ConversionHelpers.GetItemModelList(protectedItems); if (!string.IsNullOrEmpty(itemName)) { for (int i = 0; i < itemModels.Count; i++) { extendedInfoProcessor(itemModels[i], protectedItemGetResponses[i]); } } return(itemModels); }
/// <summary> /// Lists protected items protected by the recovery services vault according to the provider data /// </summary> /// <returns>List of protected items</returns> public List <ItemBase> ListProtectedItems() { ContainerBase container = (ContainerBase)this.ProviderData[ItemParams.Container]; string name = (string)this.ProviderData[ItemParams.AzureVMName]; ItemProtectionStatus protectionStatus = (ItemProtectionStatus)this.ProviderData[ItemParams.ProtectionStatus]; ItemProtectionState status = (ItemProtectionState)this.ProviderData[ItemParams.ProtectionState]; Models.WorkloadType workloadType = (Models.WorkloadType) this.ProviderData[ItemParams.WorkloadType]; ProtectedItemListQueryParam queryParams = new ProtectedItemListQueryParam(); queryParams.DatasourceType = ServiceClientModel.WorkloadType.VM; queryParams.BackupManagementType = ServiceClientModel.BackupManagementType.AzureIaasVM.ToString(); List <ProtectedItemResource> protectedItems = new List <ProtectedItemResource>(); string skipToken = null; PaginationRequest paginationRequest = null; do { var listResponse = ServiceClientAdapter.ListProtectedItem(queryParams, paginationRequest); protectedItems.AddRange(listResponse.ItemList.Value); ServiceClientHelpers.GetSkipTokenFromNextLink(listResponse.ItemList.NextLink, out skipToken); if (skipToken != null) { paginationRequest = new PaginationRequest(); paginationRequest.SkipToken = skipToken; } } while (skipToken != null); // 1. Filter by container if (container != null) { protectedItems = protectedItems.Where(protectedItem => { Dictionary <UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id); string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItem.Id); return(containerUri.Contains(container.Name)); }).ToList(); } List <ProtectedItemResponse> protectedItemGetResponses = new List <ProtectedItemResponse>(); // 2. Filter by item's friendly name if (!string.IsNullOrEmpty(name)) { protectedItems = protectedItems.Where(protectedItem => { Dictionary <UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItem.Id); return(protectedItemUri.ToLower().Contains(name.ToLower())); }).ToList(); GetProtectedItemQueryParam getItemQueryParams = new GetProtectedItemQueryParam(); getItemQueryParams.Expand = "extendedinfo"; for (int i = 0; i < protectedItems.Count; i++) { Dictionary <UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItems[i].Id); string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItems[i].Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItems[i].Id); var getResponse = ServiceClientAdapter.GetProtectedItem(containerUri, protectedItemUri, getItemQueryParams); protectedItemGetResponses.Add(getResponse); } } List <ItemBase> itemModels = ConversionHelpers.GetItemModelList(protectedItems); if (!string.IsNullOrEmpty(name)) { for (int i = 0; i < itemModels.Count; i++) { AzureVmItemExtendedInfo extendedInfo = new AzureVmItemExtendedInfo(); var serviceClientExtendedInfo = ((AzureIaaSVMProtectedItem)protectedItemGetResponses[i].Item.Properties).ExtendedInfo; if (serviceClientExtendedInfo.OldestRecoveryPoint.HasValue) { extendedInfo.OldestRecoveryPoint = serviceClientExtendedInfo.OldestRecoveryPoint; } extendedInfo.PolicyState = serviceClientExtendedInfo.PolicyInconsistent.ToString(); extendedInfo.RecoveryPointCount = serviceClientExtendedInfo.RecoveryPointCount; ((AzureVmItem)itemModels[i]).ExtendedInfo = extendedInfo; } } // 3. Filter by item's Protection Status if (protectionStatus != 0) { itemModels = itemModels.Where(itemModel => { return(((AzureVmItem)itemModel).ProtectionStatus == protectionStatus); }).ToList(); } // 4. Filter by item's Protection State if (status != 0) { itemModels = itemModels.Where(itemModel => { return(((AzureVmItem)itemModel).ProtectionState == status); }).ToList(); } // 5. Filter by workload type if (workloadType != 0) { itemModels = itemModels.Where(itemModel => { return(itemModel.WorkloadType == workloadType); }).ToList(); } return(itemModels); }
/// <summary> /// Lists protected items protected by the recovery services vault according to the provider data /// </summary> /// <returns>List of protected items</returns> public List <ItemBase> ListProtectedItems() { ContainerBase container = (ContainerBase)ProviderData[ItemParams.Container]; string name = (string)ProviderData[ItemParams.AzureVMName]; ItemProtectionStatus protectionStatus = (ItemProtectionStatus)ProviderData[ItemParams.ProtectionStatus]; ItemProtectionState status = (ItemProtectionState)ProviderData[ItemParams.ProtectionState]; CmdletModel.WorkloadType workloadType = (CmdletModel.WorkloadType)ProviderData[ItemParams.WorkloadType]; ODataQuery <ProtectedItemQueryObject> queryParams = new ODataQuery <ProtectedItemQueryObject>( q => q.BackupManagementType == ServiceClientModel.BackupManagementType.AzureIaasVM && q.ItemType == DataSourceType.VM); List <ProtectedItemResource> protectedItems = new List <ProtectedItemResource>(); string skipToken = null; var listResponse = ServiceClientAdapter.ListProtectedItem(queryParams, skipToken); protectedItems.AddRange(listResponse); // 1. Filter by container if (container != null) { protectedItems = protectedItems.Where(protectedItem => { Dictionary <UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id); string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItem.Id); return(containerUri.Contains(container.Name)); }).ToList(); } List <ProtectedItemResource> protectedItemGetResponses = new List <ProtectedItemResource>(); // 2. Filter by item's friendly name if (!string.IsNullOrEmpty(name)) { protectedItems = protectedItems.Where(protectedItem => { Dictionary <UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItem.Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItem.Id); return(protectedItemUri.ToLower().Contains(name.ToLower())); }).ToList(); ODataQuery <GetProtectedItemQueryObject> getItemQueryParams = new ODataQuery <GetProtectedItemQueryObject>(q => q.Expand == "extendedinfo"); for (int i = 0; i < protectedItems.Count; i++) { Dictionary <UriEnums, string> dictionary = HelperUtils.ParseUri(protectedItems[i].Id); string containerUri = HelperUtils.GetContainerUri(dictionary, protectedItems[i].Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(dictionary, protectedItems[i].Id); var getResponse = ServiceClientAdapter.GetProtectedItem(containerUri, protectedItemUri, getItemQueryParams); protectedItemGetResponses.Add(getResponse.Body); } } List <ItemBase> itemModels = ConversionHelpers.GetItemModelList(protectedItems); if (!string.IsNullOrEmpty(name)) { for (int i = 0; i < itemModels.Count; i++) { AzureVmItemExtendedInfo extendedInfo = new AzureVmItemExtendedInfo(); var serviceClientExtendedInfo = ((AzureIaaSVMProtectedItem)protectedItemGetResponses[i].Properties).ExtendedInfo; if (serviceClientExtendedInfo.OldestRecoveryPoint.HasValue) { extendedInfo.OldestRecoveryPoint = serviceClientExtendedInfo.OldestRecoveryPoint; } extendedInfo.PolicyState = serviceClientExtendedInfo.PolicyInconsistent.ToString(); extendedInfo.RecoveryPointCount = (int)(serviceClientExtendedInfo.RecoveryPointCount.HasValue ? serviceClientExtendedInfo.RecoveryPointCount : 0); ((AzureVmItem)itemModels[i]).ExtendedInfo = extendedInfo; } } // 3. Filter by item's Protection Status if (protectionStatus != 0) { itemModels = itemModels.Where(itemModel => { return(((AzureVmItem)itemModel).ProtectionStatus == protectionStatus); }).ToList(); } // 4. Filter by item's Protection State if (status != 0) { itemModels = itemModels.Where(itemModel => { return(((AzureVmItem)itemModel).ProtectionState == status); }).ToList(); } // 5. Filter by workload type if (workloadType != 0) { itemModels = itemModels.Where(itemModel => { return(itemModel.WorkloadType == workloadType); }).ToList(); } return(itemModels); }