public void ListProtectableObjectTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"];

                var client = GetServiceClient<RecoveryServicesBackupManagementClient>(resourceNamespace);

                ProtectableObjectListQueryParameters queryParams = new ProtectableObjectListQueryParameters();

                PaginationRequest paginationParam = new PaginationRequest();

                ProtectableObjectTestHelper poTestHelper = new ProtectableObjectTestHelper(client);
                ProtectableObjectListResponse response = poTestHelper.ListProtectableObjects(queryParams, paginationParam);

                string protectableObjectName = ConfigurationManager.AppSettings["RsVaultIaasV1ContainerUniqueName"];
                Assert.True(
                    response.ItemList.ProtectableObjects.Any(
                        protectableObject =>
                        {
                            return protectableObject.Properties.GetType() == typeof(AzureIaaSClassicComputeVMProtectableItem) &&
                                    protectableObject.Name == protectableObjectName;
                        }),
                        "Retrieved list of containers doesn't contain AzureIaaSClassicComputeVMProtectable Item");
            }
        }
 /// <summary>
 /// Lists all the backup engines registered to your Recovery Services
 /// Vault based on the query parameters and the pagination parameters
 /// passed in the arguments.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.RecoveryServices.Backup.IBackupEngineOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. Resource group name of your recovery services vault.
 /// </param>
 /// <param name='resourceName'>
 /// Required. Name of your recovery services vault.
 /// </param>
 /// <param name='queryParams'>
 /// Required. Query parameters for listing backup engines.
 /// </param>
 /// <param name='paginationParams'>
 /// Optional. Pagination parameters for controlling the response.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Required. Request header parameters.
 /// </param>
 /// <returns>
 /// Response returned by the list backup engines operation.
 /// </returns>
 public static BackupEngineListResponse List(this IBackupEngineOperations operations, string resourceGroupName, string resourceName, BackupEngineListQueryParams queryParams, PaginationRequest paginationParams, CustomRequestHeaders customRequestHeaders)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IBackupEngineOperations)s).ListAsync(resourceGroupName, resourceName, queryParams, paginationParams, customRequestHeaders);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
        public JobListResponse ListJobs(CommonJobQueryFilters queryFilters, PaginationRequest paginationReq)
        {
            var response = Client.Jobs.ListAsync(rgName, rName, queryFilters, paginationReq, CommonTestHelper.GetCustomRequestHeaders()).Result;

            Assert.NotNull(response);
            Assert.NotNull(response.ItemList);
            Assert.Equal(response.StatusCode, HttpStatusCode.OK);

            return response;
        }
        public ProtectableObjectListResponse ListProtectableObjects(string rsVaultRgName, string rsVaultName, ProtectableObjectListQueryParameters queryParams, PaginationRequest paginationParams)
        {
            ProtectableObjectListResponse response = Client.ProtectableObjects.List(
                rsVaultRgName, rsVaultName, queryParams, paginationParams, CommonTestHelper.GetCustomRequestHeaders());

            Assert.NotNull(response);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.NotNull(response.ItemList);
            return response;
        }
        public BackupEngineListResponse ListBackupEngine(BackupEngineListQueryParams queryParams, PaginationRequest paginationParam)
        {
            string rsVaultRgName = CommonTestHelper.GetSetting(TestConstants.RsVaultRgName);
            string rsVaultName = CommonTestHelper.GetSetting(TestConstants.RsVaultName);

            BackupEngineListResponse response = Client.BackupEngines.List(rsVaultRgName, rsVaultName, queryParams, paginationParam, CommonTestHelper.GetCustomRequestHeaders());

            Assert.NotNull(response);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.NotNull(response.ItemList);
            return response;
        }
示例#6
0
 /// <summary>
 /// Fetches backup engines in the vault according to the query params
 /// </summary>
 /// <param name="parameters">Query parameters</param>
 /// <returns>List of backup engines</returns>
 public IEnumerable<BackupEngineResource> ListBackupEngines(BackupEngineListQueryParams queryParams)
 {
     PaginationRequest paginationParam = new PaginationRequest();
     paginationParam.Top = "200";
     var listResponse = BmsAdapter.Client.BackupEngines.ListAsync(
                                 BmsAdapter.GetResourceGroupName(), 
                                 BmsAdapter.GetResourceName(), 
                                 queryParams, 
                                 paginationParam, 
                                 BmsAdapter.GetCustomRequestHeaders(),
                                 BmsAdapter.CmdletCancellationToken).Result;
     return listResponse.ItemList.BackupEngines;
 }
        /// <summary>
        /// Lists protectable items according to the query filter and the pagination params
        /// </summary>
        /// <param name="queryFilter">Query filter</param>
        /// <param name="paginationRequest">Pagination parameters</param>
        /// <returns>List of protectable items</returns>
        public ProtectableObjectListResponse ListProtectableItem(
                ProtectableObjectListQueryParameters queryFilter,
                PaginationRequest paginationRequest = null)
        {
            string resourceName = BmsAdapter.GetResourceName();
            string resourceGroupName = BmsAdapter.GetResourceGroupName();

            return BmsAdapter.Client.ProtectableObjects.ListAsync(
                                     resourceGroupName,
                                     resourceName,
                                     queryFilter,
                                     paginationRequest,
                                     BmsAdapter.GetCustomRequestHeaders(),
                                     BmsAdapter.CmdletCancellationToken).Result;
        }
        public void ListDPMBakcupEngineTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"];

                var client = GetServiceClient<RecoveryServicesBackupManagementClient>(resourceNamespace);
                BackupEngineHelpers backupEngineTestHelper = new BackupEngineHelpers(client);
                BackupEngineListQueryParams queryParam = new BackupEngineListQueryParams();
                //queryParam.ProviderType = "DPM";
                PaginationRequest paginationParam = new PaginationRequest();
                paginationParam.Top = "200";
                AzureOperationResponse response = backupEngineTestHelper.ListBackupEngine(queryParam, paginationParam);
                BackupEngineListResponse  backupEngineResponse = response as BackupEngineListResponse;
                string backupEngineUniqueName = CommonTestHelper.GetSetting(TestConstants.RsVaultDpmContainerUniqueName);
                Assert.NotNull(backupEngineResponse.ItemList.BackupEngines[0].Properties as BackupEngineBase);
                Assert.Equal(backupEngineUniqueName, backupEngineResponse.ItemList.BackupEngines[0].Name); 
            }
        }
示例#9
0
        /// <summary>
        /// Lists jobs according to the parameters
        /// </summary>
        /// <param name="jobId">ID of the job</param>
        /// <param name="status">Status of the job</param>
        /// <param name="operation">Operation represented by the job</param>
        /// <param name="startTime">Time when the job started</param>
        /// <param name="endTime">Time when the job finished</param>
        /// <param name="backupManagementType">Backup management type of the item represented by the job</param>
        /// <param name="top">Top pagination param</param>
        /// <param name="skipToken">Skip token pagination param</param>
        /// <returns>Job list response from the service</returns>
        public JobListResponse GetJobs(
            string jobId,
            string status,
            string operation,
            DateTime startTime,
            DateTime endTime,
            string backupManagementType,
            int? top = null,
            string skipToken = null)
        {
            string resourceName = BmsAdapter.GetResourceName();
            string resourceGroupName = BmsAdapter.GetResourceGroupName();

            // build pagination request
            PaginationRequest pagReq = new PaginationRequest()
            {
                SkipToken = skipToken
            };
            // respecting top if provided
            if (top.HasValue)
            {
                pagReq.Top = top.ToString();
            }

            CommonJobQueryFilters commonFilters = GetQueryObject(
                backupManagementType,
                startTime,
                endTime,
                jobId,
                status,
                operation);

            return BmsAdapter.Client.Jobs.ListAsync(
                resourceGroupName,
                resourceName,
                commonFilters,
                pagReq,
                BmsAdapter.GetCustomRequestHeaders(),
                BmsAdapter.CmdletCancellationToken).Result;
        }
        public ProtectedItemListResponse ListProtectedItems(ProtectedItemListQueryParam queryParams, PaginationRequest paginationRequest = null)
        {
            string rsVaultRgName = CommonTestHelper.GetSetting(TestConstants.RsVaultRgName);
            string rsVaultName = CommonTestHelper.GetSetting(TestConstants.RsVaultName);

            var response = Client.ProtectedItems.List(rsVaultRgName, rsVaultName, queryParams, paginationRequest, CommonTestHelper.GetCustomRequestHeaders());

            Assert.NotNull(response);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.NotNull(response.ItemList);

            return response;
        }
 /// <summary>
 /// Lists all the jobs in your Recovery Services Vault according to the
 /// query filters and the pagination parameters.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.RecoveryServices.Backup.IJobOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. Resource group name of your recovery services vault.
 /// </param>
 /// <param name='resourceName'>
 /// Required. Name of your recovery services vault.
 /// </param>
 /// <param name='queryFilter'>
 /// Optional. Query parameters for listing jobs.
 /// </param>
 /// <param name='paginationParams'>
 /// Optional. Pagination parameters for controlling the response.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// List of job responses as returned by the list jobs API.
 /// </returns>
 public static Task<JobListResponse> ListAsync(this IJobOperations operations, string resourceGroupName, string resourceName, CommonJobQueryFilters queryFilter, PaginationRequest paginationParams, CustomRequestHeaders customRequestHeaders)
 {
     return operations.ListAsync(resourceGroupName, resourceName, queryFilter, paginationParams, customRequestHeaders, CancellationToken.None);
 }
        /// <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 all the backup engines registered to your Recovery Services
 /// Vault based on the query parameters and the pagination parameters
 /// passed in the arguments.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.RecoveryServices.Backup.IBackupEngineOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. Resource group name of your recovery services vault.
 /// </param>
 /// <param name='resourceName'>
 /// Required. Name of your recovery services vault.
 /// </param>
 /// <param name='queryParams'>
 /// Required. Query parameters for listing backup engines.
 /// </param>
 /// <param name='paginationParams'>
 /// Optional. Pagination parameters for controlling the response.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Required. Request header parameters.
 /// </param>
 /// <returns>
 /// Response returned by the list backup engines operation.
 /// </returns>
 public static Task<BackupEngineListResponse> ListAsync(this IBackupEngineOperations operations, string resourceGroupName, string resourceName, BackupEngineListQueryParams queryParams, PaginationRequest paginationParams, CustomRequestHeaders customRequestHeaders)
 {
     return operations.ListAsync(resourceGroupName, resourceName, queryParams, paginationParams, customRequestHeaders, CancellationToken.None);
 }
 /// <summary>
 /// Lists all the items protected by your Recovery Services Vault
 /// according to the query and pagination parameters supplied in the
 /// arguments.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.RecoveryServices.Backup.IProtectedItemOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. Resource group name of your recovery services vault.
 /// </param>
 /// <param name='resourceName'>
 /// Required. Name of your recovery services vault.
 /// </param>
 /// <param name='queryFilter'>
 /// Optional.
 /// </param>
 /// <param name='paginationParams'>
 /// Optional.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// List of protected items returned as a response by the list
 /// protected item API.
 /// </returns>
 public static Task<ProtectedItemListResponse> ListAsync(this IProtectedItemOperations operations, string resourceGroupName, string resourceName, ProtectedItemListQueryParam queryFilter, PaginationRequest paginationParams, CustomRequestHeaders customRequestHeaders)
 {
     return operations.ListAsync(resourceGroupName, resourceName, queryFilter, paginationParams, customRequestHeaders, CancellationToken.None);
 }