Exemplo n.º 1
0
        public void GetJobDetailsTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetServiceClient<BackupServicesManagementClient>();
                //endTime%20eq%20'2015-08-13%2003:25:30%20PM'",
                DateTime startTime = new DateTime(2015, 8, 12, 15, 25, 30, DateTimeKind.Utc);
                DateTime endTime = new DateTime(2015, 8, 13, 15, 25, 30, DateTimeKind.Utc);
                var queryParams = new CSMJobQueryObject()
                {
                    StartTime = startTime.ToString("yyyy-MM-dd hh:mm:ss tt"),
                    EndTime = endTime.ToString("yyyy-MM-dd hh:mm:ss tt")
                };

                var jobResponse = client.Job.ListAsync(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, queryParams, GetCustomRequestHeaders()).Result.List.Value;
                var response = client.Job.GetAsync(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, jobResponse[0].Name, GetCustomRequestHeaders()).Result.Value;

                Assert.NotNull(response);
                ValidateJobDetailsResponse(response);
            }
        }
Exemplo n.º 2
0
        public void ListGetJobsTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetServiceClient<BackupServicesManagementClient>();
                DateTime startTime = new DateTime(2015, 6, 24, 15, 25, 9, DateTimeKind.Utc);
                DateTime endTime = new DateTime(2015, 8, 13, 15, 25, 9, DateTimeKind.Utc);
                var queryParams = new CSMJobQueryObject()
                {
                    StartTime = startTime.ToString("yyyy-MM-dd hh:mm:ss tt"),
                    EndTime = endTime.ToString("yyyy-MM-dd hh:mm:ss tt"),
                    Operation = "Register"
                };

                var response = client.Job.ListAsync(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, queryParams, GetCustomRequestHeaders()).Result.List.Value;

                Assert.NotNull(response);
                foreach (var job in response)
                {
                    ValidateJobResponse(job);
                }
            }
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                if (Job != null)
                {
                    Vault = new AzureRMBackupVault(Job.ResourceGroupName, Job.ResourceName, Job.Location);
                }

                InitializeAzureBackupCmdlet(Vault);

                if (Job != null)
                {
                    JobId = Job.InstanceId;
                }

                if (Type != null)
                {
                    Type = AzureBackupJobHelper.GetTypeForService(Type);
                }

                // validations
                if (!From.HasValue)
                {
                    if (To.HasValue)
                    {
                        throw new Exception(Resources.AzureBackupJobArguementException);
                    }
                    WriteDebug(Resources.SettingStartTime);
                    From = AzureBackupJobHelper.MinimumAllowedDate;
                }

                if (To.HasValue && To.Value > From.Value)
                {
                    // everything is good. don't do anything
                }
                else if (To.HasValue && To.Value <= From.Value)
                {
                    throw new Exception(Resources.TimeFilterNotCorrect);
                }
                else
                {
                    if (From != AzureBackupJobHelper.MinimumAllowedDate)
                    {
                        WriteDebug(Resources.EndTimeNotSet);
                        To = DateTime.Now;
                    }
                    else
                    {
                        WriteDebug(Resources.SettingEndTime);
                        To = AzureBackupJobHelper.MinimumAllowedDate;
                    }
                }

                From = TimeZoneInfo.ConvertTimeToUtc(From.Value);
                To   = TimeZoneInfo.ConvertTimeToUtc(To.Value);

                // if user hasn't specified any filters, then default filter fetches
                // all jobs that were created in last 24 hours.
                if (From == AzureBackupJobHelper.MinimumAllowedDate && To == AzureBackupJobHelper.MinimumAllowedDate &&
                    string.IsNullOrEmpty(Operation) && string.IsNullOrEmpty(Status) &&
                    string.IsNullOrEmpty(Type) && string.IsNullOrEmpty(JobId))
                {
                    From = DateTime.UtcNow.AddDays(-1);
                    To   = DateTime.UtcNow;
                }

                DateTimeFormatInfo format = new CultureInfo("en-US").DateTimeFormat;
                WriteDebug(String.Format(Resources.StartTimeFilter, System.Uri.EscapeDataString(From.Value.ToString("yyyy-MM-dd hh:mm:ss tt", format))));
                WriteDebug(String.Format(Resources.EndTimeFilter, System.Uri.EscapeDataString(To.Value.ToString("yyyy-MM-dd hh:mm:ss tt", format))));
                WriteDebug(String.Format(Resources.OperationFilter, Operation));
                WriteDebug(String.Format(Resources.StatusFilter, Status));
                WriteDebug(String.Format(Resources.TypeFilter, Type));
                WriteDebug(String.Format(Resources.JobIdFilter, JobId));

                Mgmt.CSMJobQueryObject queryParams = new Mgmt.CSMJobQueryObject()
                {
                    StartTime    = From.Value.ToString("yyyy-MM-dd hh:mm:ss tt", format),
                    EndTime      = To.Value.ToString("yyyy-MM-dd hh:mm:ss tt", format),
                    Operation    = Operation,
                    Status       = Status,
                    WorkloadType = Type,
                    Name         = JobId
                };

                var jobsList = AzureBackupClient.ListJobs(Vault.ResourceGroupName, Vault.Name, queryParams);
                List <AzureRMBackupJob> retrievedJobs = new List <AzureRMBackupJob>();

                foreach (Mgmt.CSMJobResponse serviceJob in jobsList)
                {
                    // TODO: Initialize vault from Job object when vault is made optional
                    retrievedJobs.Add(new AzureRMBackupJob(Vault, serviceJob.Properties, serviceJob.Name));
                }

                WriteDebug(String.Format(Resources.JobRetrieved, retrievedJobs.Count()));

                if (retrievedJobs.Count == 1)
                {
                    WriteObject(retrievedJobs.First());
                }
                else
                {
                    WriteObject(retrievedJobs);
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                if (Job != null)
                {
                    Vault = new AzureRMBackupVault(Job.ResourceGroupName, Job.ResourceName, Job.Location);
                }

                InitializeAzureBackupCmdlet(Vault);

                if (Job != null)
                {
                    JobId = Job.InstanceId;
                }

                if (Type != null)
                {
                    Type = AzureBackupJobHelper.GetTypeForService(Type);
                }

                // validations
                if (!From.HasValue)
                {
                    if (To.HasValue)
                    {
                        throw new Exception(Resources.AzureBackupJobArguementException);
                    }
                    WriteDebug(Resources.SettingStartTime);
                    From = new DateTime();
                    From = AzureBackupJobHelper.MinimumAllowedDate;
                }

                if (To.HasValue && To.Value > From.Value)
                {
                    // everything is good. don't do anything
                }
                else if (To.HasValue && To.Value <= From.Value)
                {
                    throw new Exception(Resources.TimeFilterNotCorrect);
                }
                else
                {
                    if (From != AzureBackupJobHelper.MinimumAllowedDate)
                    {
                        WriteDebug(Resources.EndTimeNotSet);
                        To = DateTime.Now;
                    }
                    else
                    {
                        WriteDebug(Resources.SettingEndTime);
                        To = new DateTime();
                        To = AzureBackupJobHelper.MinimumAllowedDate;
                    }
                }

                From = TimeZoneInfo.ConvertTimeToUtc(From.Value);
                To = TimeZoneInfo.ConvertTimeToUtc(To.Value);

                // if user hasn't specified any filters, then default filter fetches
                // all jobs that were created in last 24 hours.
                if (From == AzureBackupJobHelper.MinimumAllowedDate && To == AzureBackupJobHelper.MinimumAllowedDate &&
                    string.IsNullOrEmpty(Operation) && string.IsNullOrEmpty(Status) &&
                    string.IsNullOrEmpty(Type) && string.IsNullOrEmpty(JobId))
                {
                    From = DateTime.UtcNow.AddDays(-1);
                    To = DateTime.UtcNow;
                }

                DateTimeFormatInfo format = new CultureInfo("en-US").DateTimeFormat;
                WriteDebug(String.Format(Resources.StartTimeFilter, System.Uri.EscapeDataString(From.Value.ToString("yyyy-MM-dd hh:mm:ss tt", format))));
                WriteDebug(String.Format(Resources.EndTimeFilter, System.Uri.EscapeDataString(To.Value.ToString("yyyy-MM-dd hh:mm:ss tt", format))));
                WriteDebug(String.Format(Resources.OperationFilter, Operation));
                WriteDebug(String.Format(Resources.StatusFilter, Status));
                WriteDebug(String.Format(Resources.TypeFilter, Type));
                WriteDebug(String.Format(Resources.JobIdFilter, JobId));

                Mgmt.CSMJobQueryObject queryParams = new Mgmt.CSMJobQueryObject()
                {

                    StartTime = From.Value.ToString("yyyy-MM-dd hh:mm:ss tt", format),
                    EndTime = To.Value.ToString("yyyy-MM-dd hh:mm:ss tt", format),
                    Operation = Operation,
                    Status = Status,
                    WorkloadType = Type,
                    Name = JobId
                };

                var jobsList = AzureBackupClient.ListJobs(Vault.ResourceGroupName, Vault.Name, queryParams);
                List<AzureRMBackupJob> retrievedJobs = new List<AzureRMBackupJob>();

                foreach (Mgmt.CSMJobResponse serviceJob in jobsList)
                {
                    // TODO: Initialize vault from Job object when vault is made optional
                    retrievedJobs.Add(new AzureRMBackupJob(Vault, serviceJob.Properties, serviceJob.Name));
                }

                WriteDebug(String.Format(Resources.JobRetrieved, retrievedJobs.Count()));

                if (retrievedJobs.Count == 1)
                {
                    WriteObject(retrievedJobs.First());
                }
                else
                {
                    WriteObject(retrievedJobs);
                }
            });
        }
Exemplo n.º 5
0
 public IEnumerable<Mgmt.CSMJobResponse> ListJobs(string resourceGroupName, string resourceName, CSMJobQueryObject queryParams)
 {
     var response = AzureBackupClient.Job.ListAsync(resourceGroupName, resourceName, queryParams, GetCustomRequestHeaders(), CmdletCancellationToken).Result;
     return response.List.Value;
 }
 /// <summary>
 /// Get the list of all jobs queried by specified filters.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.BackupServices.IJobOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required.
 /// </param>
 /// <param name='resourceName'>
 /// Required.
 /// </param>
 /// <param name='parameters'>
 /// Optional. Job query parameter.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// Powershell response object
 /// </returns>
 public static Task<CSMJobList> ListAsync(this IJobOperations operations, string resourceGroupName, string resourceName, CSMJobQueryObject parameters, CustomRequestHeaders customRequestHeaders)
 {
     return operations.ListAsync(resourceGroupName, resourceName, parameters, customRequestHeaders, CancellationToken.None);
 }
 /// <summary>
 /// Get the list of all jobs queried by specified filters.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.BackupServices.IJobOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required.
 /// </param>
 /// <param name='resourceName'>
 /// Required.
 /// </param>
 /// <param name='parameters'>
 /// Optional. Job query parameter.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// Powershell response object
 /// </returns>
 public static CSMJobList List(this IJobOperations operations, string resourceGroupName, string resourceName, CSMJobQueryObject parameters, CustomRequestHeaders customRequestHeaders)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IJobOperations)s).ListAsync(resourceGroupName, resourceName, parameters, customRequestHeaders);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
Exemplo n.º 8
0
        public void CancelJobTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetServiceClient<BackupServicesManagementClient>();

                string containerName = ConfigurationManager.AppSettings["ContainerName"];
                string itemName = ConfigurationManager.AppSettings["ItemName"];

                var backupResponse = client.BackUp.TriggerBackUp(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, GetCustomRequestHeaders(), containerName, itemName);

                var opStatus = client.OperationStatus.CSMGetAsync(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, backupResponse.OperationId.ToString(), GetCustomRequestHeaders()).Result;
                while (opStatus.Status == "InProgress")
                {
                    opStatus = client.OperationStatus.CSMGetAsync(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, backupResponse.OperationId.ToString(), GetCustomRequestHeaders()).Result;
                }
                Assert.Equal(opStatus.Status, "Succeeded");
                Assert.True(opStatus.JobList.Count > 0);

                DateTime startTime = new DateTime(2015, 8, 12, 15, 40, 53, DateTimeKind.Utc);
                var queryParams = new CSMJobQueryObject()
                {
                    StartTime = startTime.ToString("yyyy-MM-dd hh:mm:ss tt"),
                    EndTime = startTime.AddDays(1).ToString("yyyy-MM-dd hh:mm:ss tt"),
                    Status = "InProgress",
                    Operation = "Backup",
                    Name = opStatus.JobList[0]
                };

                var jobResponse = client.Job.ListAsync(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, queryParams, GetCustomRequestHeaders()).Result.List.Value;
                var opId = client.Job.StopAsync(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, jobResponse[0].Name, GetCustomRequestHeaders()).Result;

                // TODO: Wait till the WF completes
                opStatus = client.OperationStatus.CSMGetAsync(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, opId.OperationId.ToString(), GetCustomRequestHeaders()).Result;
                while (opStatus.Status == "InProgress")
                {
                    opStatus = client.OperationStatus.CSMGetAsync(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, opId.OperationId.ToString(), GetCustomRequestHeaders()).Result;
                }
                Assert.Equal(opStatus.Status, "Succeeded");

                var response = client.Job.GetAsync(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, jobResponse[0].Name, GetCustomRequestHeaders()).Result.Value;
                Assert.True((response.JobDetailedProperties.Status.CompareTo("Cancelled") == 0) || (response.JobDetailedProperties.Status.CompareTo("Cancelling") == 0));
            }
        }