Esempio n. 1
0
 public void ValidateJobResponse(JobBase job, CommonJobQueryFilters filters)
 {
     if (job.GetType() == typeof(AzureIaaSVMJob))
     {
         ValidateIaasVMJob(job as AzureIaaSVMJob, filters);
     }
 }
Esempio n. 2
0
        private void ValidateIaasVMJob(AzureIaaSVMJob job, CommonJobQueryFilters filters)
        {
            Assert.NotNull(job.Status);
            Assert.NotNull(job.BackupManagementType);
            Assert.NotNull(job.Operation);
            Assert.NotNull(job.EntityFriendlyName);

            if (filters != null)
            {
                if (!string.IsNullOrEmpty(filters.StartTime))
                {
                    Assert.True(job.StartTime.CompareTo(DateTime.ParseExact(filters.StartTime, "yyyy-MM-dd hh:mm:ss tt", CultureInfo.InvariantCulture)) >= 0);
                }

                if (!string.IsNullOrEmpty(filters.EndTime))
                {
                    Assert.True(job.StartTime.CompareTo(DateTime.ParseExact(filters.EndTime, "yyyy-MM-dd hh:mm:ss tt", CultureInfo.InvariantCulture)) <= 0);
                }

                if (!string.IsNullOrEmpty(filters.Status))
                {
                    Assert.Equal(filters.Status, job.Status);
                }

                if (!string.IsNullOrEmpty(filters.Operation))
                {
                    Assert.Equal(filters.Operation, job.Operation);
                }
            }

            if (job.ExtendedInfo != null)
            {
                Assert.NotNull(job.ExtendedInfo.PropertyBag);
            }
        }
        public void ListJobsAndGetJobTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"];
                string resourceGroupName = ConfigurationManager.AppSettings["RsVaultRgNameRP"];
                string resourceName      = ConfigurationManager.AppSettings["RsVaultNameRP"];
                string location          = ConfigurationManager.AppSettings["vaultLocationRP"];
                // TODO: Create VM instead of taking these parameters from config
                string containerUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMContainerUniqueNameRP"];
                string itemUniqueName      = ConfigurationManager.AppSettings["RsVaultIaasVMItemUniqueNameRP"];
                string containeType        = ConfigurationManager.AppSettings["IaaSVMContainerType"];
                string itemType            = ConfigurationManager.AppSettings["IaaSVMItemType"];
                string containerUri        = containeType + ";" + containerUniqueName;
                string itemUri             = itemType + ";" + itemUniqueName;
                string utcDateTimeFormat   = ConfigurationManager.AppSettings["UTCDateTimeFormat"];

                var client = GetServiceClient <RecoveryServicesBackupManagementClient>(resourceNamespace);

                // 1. Create vault
                VaultTestHelpers vaultTestHelper = new VaultTestHelpers(client);
                vaultTestHelper.CreateVault(resourceGroupName, resourceName, location);

                // 2. Get default policy
                PolicyTestHelpers policyTestHelper = new PolicyTestHelpers(client);
                string            policyId         = policyTestHelper.GetDefaultPolicyId(resourceGroupName, resourceName);

                // 3. Enable protection
                ProtectedItemTestHelpers protectedItemTestHelper = new ProtectedItemTestHelpers(client);
                DateTime protectionStartTime = DateTime.UtcNow;
                protectedItemTestHelper.EnableProtection(resourceGroupName, resourceName, policyId, containerUri, itemUri);
                DateTime protectionEndTime = DateTime.UtcNow;

                // ACTION: List jobs
                CommonJobQueryFilters commonFilters = new CommonJobQueryFilters();
                commonFilters.BackupManagementType = BackupManagementType.AzureIaasVM.ToString();
                commonFilters.StartTime            = protectionStartTime.ToString(utcDateTimeFormat);
                commonFilters.EndTime = protectionEndTime.ToString(utcDateTimeFormat);
                JobTestHelpers helper  = new JobTestHelpers(client);
                var            jobList = helper.ListJobs(resourceGroupName, resourceName, commonFilters, null);

                // VALIDATION
                foreach (var job in jobList.ItemList.Value)
                {
                    Assert.NotNull(job.Id);
                    Assert.NotNull(job.Name);
                    helper.ValidateJobResponse(job.Properties, commonFilters);

                    // validating getjob
                    var jobDetails = helper.GetJob(resourceGroupName, resourceName, job.Name);
                    Assert.NotNull(jobDetails);
                    Assert.NotNull(jobDetails.Item);
                    helper.ValidateJobResponse(jobDetails.Item.Properties, null);
                }
            }
        }
Esempio n. 4
0
        public JobListResponse ListJobs(string rgName, string rName, 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);
        }
Esempio n. 5
0
        public void CancelJobTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string resourceNamespace = null;

                if (string.IsNullOrEmpty(resourceNamespace))
                {
                    resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"];
                }

                var client = GetServiceClient <RecoveryServicesBackupManagementClient>(resourceNamespace);

                // take a protected item, and trigger backup
                // wait for it to complete. cancel it.
                CommonJobQueryFilters commonFilters = new CommonJobQueryFilters();
                commonFilters.Status    = JobStatus.InProgress.ToString();
                commonFilters.Operation = JobOperation.Backup.ToString();

                JobTestHelper helper  = new JobTestHelper(client);
                var           jobList = helper.ListJobs(commonFilters, null);

                if (jobList.ItemList.Value.Count > 0)
                {
                    string jobId, opId;
                    jobId = jobList.ItemList.Value[0].Name;
                    // cancel the first job
                    var cancelResponse = helper.CancelJob(jobId);
                    opId = helper.GetOpId(cancelResponse.Location);
                    var opStatus = helper.GetJobOperationStatus(jobId, opId);

                    while (opStatus.StatusCode == HttpStatusCode.Accepted)
                    {
                        if (HttpMockServer.Mode == HttpRecorderMode.Record)
                        {
                            Thread.Sleep(15 * 1000);
                        }
                        opStatus = helper.GetJobOperationStatus(jobId, opId);
                    }
                }
            }
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        /// <summary>
        /// Constructs the query object based on the input parameters
        /// </summary>
        /// <param name="backupManagementType">Backup management type of the item associated with the job</param>
        /// <param name="startTime">Time when the job started</param>
        /// <param name="endTime">Time when the job ended</param>
        /// <param name="jobId">ID of the job</param>
        /// <param name="status">Status of the job</param>
        /// <param name="operation">ID of operation associated with the job</param>
        /// <returns></returns>
        public CommonJobQueryFilters GetQueryObject(
            string backupManagementType,
            DateTime startTime,
            DateTime endTime,
            string jobId,
            string status,
            string operation)
        {
            // build query filters object.
            // currently we don't support any provider specific filters.
            // so we are initializing the object directly
            CommonJobQueryFilters commonFilters = new CommonJobQueryFilters()
            {
                BackupManagementType = backupManagementType,
                StartTime            = CommonHelpers.GetDateTimeStringForService(startTime),
                EndTime   = CommonHelpers.GetDateTimeStringForService(endTime),
                JobId     = jobId,
                Status    = status,
                Operation = operation
            };

            return(commonFilters);
        }
Esempio n. 8
0
        public void ListJobsAndGetJobTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string resourceNamespace = null;

                if (string.IsNullOrEmpty(resourceNamespace))
                {
                    resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"];
                }

                var client = GetServiceClient <RecoveryServicesBackupManagementClient>(resourceNamespace);

                CommonJobQueryFilters commonFilters = new CommonJobQueryFilters();
                commonFilters.BackupManagementType = BackupManagementType.AzureIaasVM.ToString();
                commonFilters.StartTime            = (new DateTime(2016, 4, 12, 20, 0, 0)).ToUniversalTime().ToString("yyyy-MM-dd hh:mm:ss tt");
                commonFilters.EndTime = (new DateTime(2016, 4, 13, 20, 0, 0)).ToUniversalTime().ToString("yyyy-MM-dd hh:mm:ss tt");

                JobTestHelper helper  = new JobTestHelper(client);
                var           jobList = helper.ListJobs(commonFilters, null);

                foreach (var job in jobList.ItemList.Value)
                {
                    Assert.NotNull(job.Id);
                    Assert.NotNull(job.Name);
                    helper.ValidateJobResponse(job.Properties, commonFilters);

                    // validating getjob
                    var jobDetalis = helper.GetJob(job.Name);
                    Assert.NotNull(jobDetalis);
                    Assert.NotNull(jobDetalis.Item);
                    helper.ValidateJobResponse(jobDetalis.Item.Properties, null);
                }
            }
        }
        public void CancelJobTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"];
                string resourceGroupName = ConfigurationManager.AppSettings["RsVaultRgNameRP"];
                string resourceName      = ConfigurationManager.AppSettings["RsVaultNameRP"];
                string location          = ConfigurationManager.AppSettings["vaultLocationRP"];
                // TODO: Create VM instead of taking these parameters from config
                string containerUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMContainerUniqueNameRP"];
                string itemUniqueName      = ConfigurationManager.AppSettings["RsVaultIaasVMItemUniqueNameRP"];
                string containeType        = ConfigurationManager.AppSettings["IaaSVMContainerType"];
                string itemType            = ConfigurationManager.AppSettings["IaaSVMItemType"];
                string containerUri        = containeType + ";" + containerUniqueName;
                string itemUri             = itemType + ";" + itemUniqueName;

                var client = GetServiceClient <RecoveryServicesBackupManagementClient>(resourceNamespace);

                // 1. Create vault
                VaultTestHelpers vaultTestHelper = new VaultTestHelpers(client);
                vaultTestHelper.CreateVault(resourceGroupName, resourceName, location);

                // 2. Get default policy
                PolicyTestHelpers policyTestHelper = new PolicyTestHelpers(client);
                string            policyId         = policyTestHelper.GetDefaultPolicyId(resourceGroupName, resourceName);

                // 3. Enable protection
                ProtectedItemTestHelpers protectedItemTestHelper = new ProtectedItemTestHelpers(client);
                DateTime protectionStartTime = DateTime.UtcNow;
                protectedItemTestHelper.EnableProtection(resourceGroupName, resourceName, policyId, containerUri, itemUri);
                DateTime protectionEndTime = DateTime.UtcNow;

                // 4. Trigger backup and get the job
                BackupTestHelpers     backupTestHelper = new BackupTestHelpers(client);
                string                jobId            = backupTestHelper.BackupProtectedItem(resourceGroupName, resourceName, containerUri, itemUri);
                CommonJobQueryFilters commonFilters    = new CommonJobQueryFilters();
                commonFilters.Status    = JobStatus.InProgress.ToString();
                commonFilters.Operation = JobOperation.Backup.ToString();
                JobTestHelpers helper = new JobTestHelpers(client);
                var            job    = helper.GetJob(resourceGroupName, resourceName, jobId);

                // ACTION: Cancel the job
                var cancelResponse = helper.CancelJob(resourceGroupName, resourceName, jobId);
                var opId           = helper.GetOpId(cancelResponse.Location);
                var opStatus       = helper.GetJobOperationStatus(resourceGroupName, resourceName, jobId, opId);
                TestUtilities.RetryActionWithTimeout(
                    () => opStatus = helper.GetJobOperationStatus(resourceGroupName, resourceName, jobId, opId),
                    () => opStatus.StatusCode != HttpStatusCode.Accepted,
                    TimeSpan.FromMinutes(30),
                    statusCode =>
                {
                    if (HttpMockServer.Mode == HttpRecorderMode.Record)
                    {
                        Thread.Sleep(15 * 1000);
                    }
                    return(true);
                });
            }
        }
Esempio n. 10
0
 /// <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));
 }
Esempio n. 11
0
 /// <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 JobListResponse List(this IJobOperations operations, string resourceGroupName, string resourceName, CommonJobQueryFilters queryFilter, PaginationRequest paginationParams, CustomRequestHeaders customRequestHeaders)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IJobOperations)s).ListAsync(resourceGroupName, resourceName, queryFilter, paginationParams, customRequestHeaders);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Esempio n. 12
0
 /// <summary>
 /// Exports all jobs which satisfy the provided filters as a serialized
 /// string to a blob for which you are given a SAS URL. The SAS URL
 /// will expire within 15 minutes of its creation.
 /// </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 to be exported.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Required. Request header parameters.
 /// </param>
 /// <returns>
 /// Base recovery job response for all the asynchronous operations.
 /// </returns>
 public static Task <BaseRecoveryServicesJobResponse> ExportJobAsync(this IJobOperations operations, string resourceGroupName, string resourceName, CommonJobQueryFilters queryFilter, CustomRequestHeaders customRequestHeaders)
 {
     return(operations.ExportJobAsync(resourceGroupName, resourceName, queryFilter, customRequestHeaders, CancellationToken.None));
 }
Esempio n. 13
0
 /// <summary>
 /// Exports all jobs which satisfy the provided filters as a serialized
 /// string to a blob for which you are given a SAS URL. The SAS URL
 /// will expire within 15 minutes of its creation.
 /// </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 to be exported.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Required. Request header parameters.
 /// </param>
 /// <returns>
 /// Base recovery job response for all the asynchronous operations.
 /// </returns>
 public static BaseRecoveryServicesJobResponse ExportJob(this IJobOperations operations, string resourceGroupName, string resourceName, CommonJobQueryFilters queryFilter, CustomRequestHeaders customRequestHeaders)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IJobOperations)s).ExportJobAsync(resourceGroupName, resourceName, queryFilter, customRequestHeaders);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }