public override void ExecuteCmdlet()
        {
            try
            {
                newConfig = new NewBackupPolicyConfig();
                newConfig.Name = BackupPolicyName;

                if (!ProcessParameters())
                    return;

                if (WaitForComplete.IsPresent)
                {
                    var taskStatusInfo = StorSimpleClient.CreateBackupPolicy(deviceId, newConfig);
                    HandleSyncTaskResponse(taskStatusInfo, "add");
                    if (taskStatusInfo.AsyncTaskAggregatedResult == AsyncTaskAggregatedResult.Succeeded)
                    {
                        var createdBackupPolicy = StorSimpleClient.GetBackupPolicyByName(deviceId, BackupPolicyName);
                        WriteObject(createdBackupPolicy.BackupPolicyDetails);
                    }
                }
                else
                {
                    var taskresult = StorSimpleClient.CreateBackupPolicyAsync(deviceId, newConfig);
                    HandleAsyncTaskResponse(taskresult, "add");
                }
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
 /// <summary>
 /// The BeginCreatingBackupPolicy operation creates a new backup policy
 /// for this given volume with the given schedules.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.StorSimple.IBackupPolicyOperations.
 /// </param>
 /// <param name='deviceId'>
 /// Required. The device id for which the call will be made.
 /// </param>
 /// <param name='backupPolicy'>
 /// Required. Parameters supplied to the Create Backup Policy operation.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Required. The Custom Request Headers which client must use.
 /// </param>
 /// <returns>
 /// This is the Task Response for all Async Calls
 /// </returns>
 public static TaskResponse BeginCreatingBackupPolicy(this IBackupPolicyOperations operations, string deviceId, NewBackupPolicyConfig backupPolicy, CustomRequestHeaders customRequestHeaders)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IBackupPolicyOperations)s).BeginCreatingBackupPolicyAsync(deviceId, backupPolicy, customRequestHeaders);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
        public void DeviceRestoreScenarioTest()
        {
            using (var context = UndoContext.Current)
            {
                context.Start();

                var client = GetServiceClient<StorSimpleManagementClient>();

                // Listing all Devices
                var devices = client.Devices.List(GetCustomRequestHeaders());

                var onlineDeviceIds = from deviceInfo in devices.Devices
                                      where deviceInfo.Status == DeviceStatus.Online
                                      select deviceInfo.DeviceId;
                Assert.True(onlineDeviceIds.Count() >= 2);
                var sourceDeviceId = onlineDeviceIds.ElementAt(0);
                var targetDeviceId = onlineDeviceIds.ElementAt(1);

                CustomRequestHeaders hdrs = new CustomRequestHeaders();
                hdrs.ClientRequestId = Guid.NewGuid().ToString();
                hdrs.Language = "en-us";
                
                //Get service configuration
                var serviceConfigList = client.ServiceConfig.Get(GetCustomRequestHeaders());

                Assert.True(serviceConfigList != null);

                var existingSac = serviceConfigList.CredentialChangeList.Updated.FirstOrDefault();

                Assert.True(existingSac != null);

                var dataContainerName = TestUtilities.GenerateName("DCName");

                // new Data container request object
                var dc = new DataContainerRequest();

                dc.IsDefault = false;
                dc.Name = dataContainerName;
                dc.BandwidthRate = 256;
                dc.VolumeCount = 0;
                dc.IsEncryptionEnabled = false;
                dc.PrimaryStorageAccountCredential = existingSac;

                //Create DataContainer call
                var taskStatus = client.DataContainer.Create(sourceDeviceId, dc, hdrs);

                //Assert the task status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //Get Data Container call
                var Createddatacontainer = client.DataContainer.Get(sourceDeviceId, dataContainerName, hdrs);

                //Assert the returned data container object
                Assert.True(Createddatacontainer != null);
                Assert.True(Createddatacontainer.DataContainerInfo.Name.Equals(dataContainerName));

                //ACR list for Virtual disk creation
                List<AccessControlRecord> acrList = new List<AccessControlRecord>();

                for (var i = 0; i < 1; i++)
                {
                    AccessControlRecord acr = new AccessControlRecord()
                    {
                        Name = TestUtilities.GenerateName("VDnewTestAcr"),
                        InitiatorName = TestUtilities.GenerateName("VDinitiator") + i
                    };
                    acrList.Add(acr);
                }

                //Virtual disk create request object
                var virtualDiskToCreate = new VirtualDiskRequest()
                {
                    Name = TestUtilities.GenerateName("VD1Name"),
                    AccessType = AccessType.ReadWrite,
                    AcrList = acrList,
                    AppType = AppType.PrimaryVolume,
                    IsDefaultBackupEnabled = true,
                    SizeInBytes = 10737418240,
                    DataContainer = Createddatacontainer.DataContainerInfo,
                    Online = true
                };

                //Virtual disk create call
                taskStatus = client.VirtualDisk.Create(sourceDeviceId, virtualDiskToCreate, hdrs);

                //Asserting the task status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //Virtual disk get call
                var createdVirtualDisk = client.VirtualDisk.GetByName(sourceDeviceId, virtualDiskToCreate.Name, hdrs);

                Assert.True(createdVirtualDisk != null);
                Assert.True(createdVirtualDisk.VirtualDiskInfo.Name.Equals(virtualDiskToCreate.Name));

                var volumeIds = new List<string>();
                volumeIds.Add(createdVirtualDisk.VirtualDiskInfo.InstanceId);

                var dailySchedule = new BackupScheduleBase();
                dailySchedule.BackupType = BackupType.CloudSnapshot;
                dailySchedule.Status = ScheduleStatus.Enabled;
                dailySchedule.RetentionCount = 5;
                dailySchedule.StartTime = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz");
                dailySchedule.Recurrence = new ScheduleRecurrence();
                dailySchedule.Recurrence.RecurrenceType = RecurrenceType.Daily;
                dailySchedule.Recurrence.RecurrenceValue = 5;

                var backupPolicyToCreate = new NewBackupPolicyConfig();
                backupPolicyToCreate.Name = TestUtilities.GenerateName("PolicyName");
                backupPolicyToCreate.VolumeIds = volumeIds;
                backupPolicyToCreate.BackupSchedules = new List<BackupScheduleBase>();
                backupPolicyToCreate.BackupSchedules.Add(dailySchedule);

                //BackupPolicy create call
                taskStatus = client.BackupPolicy.Create(sourceDeviceId, backupPolicyToCreate, hdrs);

                //Asserting the task status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //BackupPolicy get by name call
                var createdBackupPolicy = client.BackupPolicy.GetBackupPolicyDetailsByName(sourceDeviceId, backupPolicyToCreate.Name, hdrs);

                //Assert the returned BackupPolicy object
                Assert.True(createdBackupPolicy != null);
                Assert.True(createdBackupPolicy.BackupPolicyDetails.Name.Equals(backupPolicyToCreate.Name));

                BackupNowRequest backupNowRequest = new BackupNowRequest();
                backupNowRequest.Type = BackupType.CloudSnapshot;


                //BackupSets Create call
                taskStatus = client.Backup.Create(sourceDeviceId, createdBackupPolicy.BackupPolicyDetails.InstanceId, backupNowRequest, hdrs);

                //Asserting the task status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                GetBackupResponse backupSetResult;

                do
                {
                    //BackupSets Get call
                    backupSetResult = client.Backup.Get(sourceDeviceId, "BackupPolicy", Boolean.FalseString, createdBackupPolicy.BackupPolicyDetails.InstanceId, null, null, null, null, hdrs);
                    TestUtilities.Wait(1000);
                } while (!backupSetResult.BackupSetsList.Any());
                
                var dcGroupsGetResponse = client.DeviceFailover.ListDCGroups(sourceDeviceId, hdrs);

                var dcIdList = from drDc in dcGroupsGetResponse.DataContainerGroupResponse.DCGroups[0].DCGroup
                    select drDc.InstanceId;

                var drRequest = new DeviceFailoverRequest();
                drRequest.CleanupPrimary = false;
                drRequest.DataContainerIds = dcIdList.ToList();
                drRequest.ReturnWorkflowId = true;
                drRequest.TargetDeviceId = targetDeviceId;

                //trigger failover call
                var jobResponse = client.DeviceFailover.Trigger(sourceDeviceId, drRequest, hdrs);

                //Asserting the task status
                Assert.NotNull(jobResponse);

                //track device job for its completion
                var deviceJobResponse = new GetDeviceJobResponse();
                int retryLimit = 30;
                int pollInterval = 60 * 1000;
                int retryCount = 0;
                bool found = false;

                do
                {
                    TestUtilities.Wait(pollInterval);
                    deviceJobResponse = client.DeviceJob.Get(null, null, null, jobResponse.JobId, null, null, 0, 1, hdrs);
                    if(deviceJobResponse != null)
                    {
                        found = true;
                    }
                    retryCount++;
                } while ((!found || deviceJobResponse.DeviceJobList[0].Status == "Running") && (retryCount < retryLimit));

                Assert.NotNull(deviceJobResponse);
                Assert.Equal(deviceJobResponse.DeviceJobList[0].Status, "Completed");
            }
        }
Esempio n. 4
0
        public void BackupScenarioTest()
        {
            using (var context = UndoContext.Current)
            {
                context.Start();

                var client = GetServiceClient<StorSimpleManagementClient>();

                // Listing all Devices
                var devices = client.Devices.List(GetCustomRequestHeaders());

                // Asserting that atleast One Device is returned.
                Assert.True(devices != null);
                Assert.True(devices.Any());

                var actualdeviceId = devices.FirstOrDefault().DeviceId;
                actualdeviceId = actualdeviceId.Trim();
                CustomRequestHeaders hdrs = new CustomRequestHeaders();
                hdrs.ClientRequestId = Guid.NewGuid().ToString();
                hdrs.Language = "en-us";

                //Get service configuration
                var serviceConfigList = client.ServiceConfig.Get(GetCustomRequestHeaders());

                Assert.True(serviceConfigList != null);

                var existingSac = serviceConfigList.CredentialChangeList.Updated.FirstOrDefault();

                Assert.True(existingSac != null);

                var dataContainerName = TestUtilities.GenerateName("DCName");

                // new Data container request object
                var dc = new DataContainerRequest();

                dc.IsDefault = false;
                dc.Name = dataContainerName;
                dc.BandwidthRate = 256;
                dc.VolumeCount = 0;
                dc.IsEncryptionEnabled = false;
                dc.PrimaryStorageAccountCredential = existingSac;
                
                //Create DataContainer call
                var taskStatus = client.DataContainer.Create(actualdeviceId, dc, hdrs);

                //Assert the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //Get Data Container call
                var Createddatacontainer = client.DataContainer.Get(actualdeviceId, dataContainerName, hdrs);

                //Assert the returned data container object
                Assert.True(Createddatacontainer != null);
                Assert.True(Createddatacontainer.DataContainerInfo.Name.Equals(dataContainerName));

                //ACR list for Virtual disk creation
                List<AccessControlRecord> acrList = new List<AccessControlRecord>();

                for (var i = 0; i < 1; i++)
                {
                    AccessControlRecord acr = new AccessControlRecord()
                    {
                        Name = TestUtilities.GenerateName("VDnewTestAcr"),
                        InitiatorName = TestUtilities.GenerateName("VDinitiator") + i
                    };
                    acrList.Add(acr);
                }

                //Virtual disk create request object
                var virtualDiskToCreate = new VirtualDiskRequest()
                {
                    Name = TestUtilities.GenerateName("VD1Name"),
                    AccessType = AccessType.ReadWrite,
                    AcrList = acrList,
                    AppType = AppType.PrimaryVolume,
                    IsDefaultBackupEnabled = true,
                    SizeInBytes = 10737418240,
                    DataContainer = Createddatacontainer.DataContainerInfo,
                    Online = true
                };

                //Virtual disk create call
                taskStatus = client.VirtualDisk.Create(actualdeviceId, virtualDiskToCreate, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //Virtual disk get call
                var createdVirtualDisk = client.VirtualDisk.GetByName(actualdeviceId, virtualDiskToCreate.Name, hdrs);

                Assert.True(createdVirtualDisk != null);
                Assert.True(createdVirtualDisk.VirtualDiskInfo.Name.Equals(virtualDiskToCreate.Name));

                var volumeIds = new List<string>();
                volumeIds.Add(createdVirtualDisk.VirtualDiskInfo.InstanceId);
                
                var dailySchedule = new BackupScheduleBase();
                dailySchedule.BackupType = BackupType.CloudSnapshot;
                dailySchedule.Status = ScheduleStatus.Enabled;
                dailySchedule.RetentionCount = 5;
                dailySchedule.StartTime = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz");
                dailySchedule.Recurrence = new ScheduleRecurrence();
                dailySchedule.Recurrence.RecurrenceType = RecurrenceType.Daily;
                dailySchedule.Recurrence.RecurrenceValue = 5;

                var backupPolicyToCreate = new NewBackupPolicyConfig();
                backupPolicyToCreate.Name = TestUtilities.GenerateName("PolicyName");
                backupPolicyToCreate.VolumeIds = volumeIds;
                backupPolicyToCreate.BackupSchedules = new List<BackupScheduleBase>();
                backupPolicyToCreate.BackupSchedules.Add(dailySchedule);

                //BackupPolicy create call
                taskStatus = client.BackupPolicy.Create(actualdeviceId, backupPolicyToCreate, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //BackupPolicy list call
                var allBackupPolicies = client.BackupPolicy.List(actualdeviceId, hdrs);

                //Assert the returned BackupPolicy object
                Assert.True(allBackupPolicies != null);
                Assert.True(allBackupPolicies.Any());

                //BackupPolicy get by name call
                var createdBackupPolicy = client.BackupPolicy.GetBackupPolicyDetailsByName(actualdeviceId, backupPolicyToCreate.Name, hdrs);

                //Assert the returned BackupPolicy object
                Assert.True(createdBackupPolicy != null);
                Assert.True(createdBackupPolicy.BackupPolicyDetails.Name.Equals(backupPolicyToCreate.Name));

                BackupNowRequest backupNowRequest = new BackupNowRequest();
                backupNowRequest.Type = BackupType.CloudSnapshot;
                

                //BackupSets Create call
                taskStatus = client.Backup.Create(actualdeviceId, createdBackupPolicy.BackupPolicyDetails.InstanceId, backupNowRequest, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                BackupScheduleBase hourlySchedule = new BackupScheduleBase();
                hourlySchedule.BackupType = BackupType.LocalSnapshot;
                hourlySchedule.Status = ScheduleStatus.Enabled;
                hourlySchedule.RetentionCount = 10;
                hourlySchedule.StartTime = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz");
                hourlySchedule.Recurrence = new ScheduleRecurrence();
                hourlySchedule.Recurrence.RecurrenceType = RecurrenceType.Hourly;
                hourlySchedule.Recurrence.RecurrenceValue = 12;

                List<BackupScheduleBase> backupSchedulesToBeAdded = new List<BackupScheduleBase>();
                backupSchedulesToBeAdded.Add(hourlySchedule);

                var updatePolicyRequest = new UpdateBackupPolicyConfig();
                updatePolicyRequest.InstanceId = createdBackupPolicy.BackupPolicyDetails.InstanceId;
                updatePolicyRequest.Name = createdBackupPolicy.BackupPolicyDetails.Name;
                updatePolicyRequest.BackupSchedulesToBeAdded = backupSchedulesToBeAdded;
                updatePolicyRequest.BackupSchedulesToBeUpdated = new List<BackupScheduleUpdateRequest>();
                updatePolicyRequest.BackupSchedulesToBeDeleted = new List<string>();
                updatePolicyRequest.VolumeIds = volumeIds;

                //Backup policy update call
                taskStatus = client.BackupPolicy.Update(actualdeviceId, createdBackupPolicy.BackupPolicyDetails.InstanceId, updatePolicyRequest, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                GetBackupResponse backupSetResult;

                do
                {
                    //BackupSets Get call
                    backupSetResult = client.Backup.Get(actualdeviceId, "BackupPolicy", Boolean.TrueString, null, null, null, null, null, hdrs);

                    Assert.True(backupSetResult != null);
                    Assert.True(backupSetResult.BackupSetsList != null);

                    TestUtilities.Wait(1000);
                } while (!backupSetResult.BackupSetsList.Any());

                var backupSetId = backupSetResult.BackupSetsList.First().InstanceId;
                var restoreBackupRequest = new RestoreBackupRequest()
                {
                    BackupSetId = backupSetId,
                    SnapshotId = null
                };

                //Restore call
                taskStatus = client.Backup.Restore(actualdeviceId, restoreBackupRequest, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //BackupSets Delete call
                taskStatus = client.Backup.Delete(actualdeviceId, backupSetId, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                TestUtilities.Wait(60*1000); //wait for 1min for the backup to be deleted

                //Backup Policy delete call
                taskStatus = client.BackupPolicy.Delete(actualdeviceId, createdBackupPolicy.BackupPolicyDetails.InstanceId, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

            }
        }
 public TaskResponse CreateBackupPolicyAsync(string deviceId, NewBackupPolicyConfig config)
 {
     return GetStorSimpleClient().BackupPolicy.BeginCreatingBackupPolicy(deviceId, config, GetCustomRequestHeaders());
 }
 public TaskStatusInfo CreateBackupPolicy(string deviceId, NewBackupPolicyConfig config)
 {
     return GetStorSimpleClient().BackupPolicy.Create(deviceId, config, GetCustomRequestHeaders());
 }
Esempio n. 7
0
        public void CloneScenarioMultipleDeviceTest()
        {
            using (var context = UndoContext.Current)
            {
                context.Start();

                var client = GetServiceClient<StorSimpleManagementClient>();

                // Listing all Devices
                var devices = client.Devices.List(GetCustomRequestHeaders());

                // Asserting that atleast One Device is returned.
                Assert.True(devices != null);
                Assert.True(devices.Any());

                var actualdeviceId = devices.FirstOrDefault().DeviceId;
                actualdeviceId = actualdeviceId.Trim();
                CustomRequestHeaders hdrs = new CustomRequestHeaders();
                hdrs.ClientRequestId = Guid.NewGuid().ToString();
                hdrs.Language = "en-us";

                //Get service configuration
                var serviceConfigList = client.ServiceConfig.Get(GetCustomRequestHeaders());

                Assert.True(serviceConfigList != null);

                var existingSac = serviceConfigList.CredentialChangeList.Updated.FirstOrDefault();

                Assert.True(existingSac != null);

                var dataContainerName = TestUtilities.GenerateName("DCName");

                // new Data container request object
                var dc = new DataContainerRequest();

                dc.IsDefault = false;
                dc.Name = dataContainerName;
                dc.BandwidthRate = 256;
                dc.VolumeCount = 0;
                dc.IsEncryptionEnabled = false;
                dc.PrimaryStorageAccountCredential = existingSac;

                //Create DataContainer call
                var taskStatus = client.DataContainer.Create(actualdeviceId, dc, hdrs);

                //Assert the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //Get Data Container call
                var Createddatacontainer = client.DataContainer.Get(actualdeviceId, dataContainerName, hdrs);

                //Assert the returned data container object
                Assert.True(Createddatacontainer != null);
                Assert.True(Createddatacontainer.DataContainerInfo.Name.Equals(dataContainerName));

                //ACR list for Virtual disk creation
                List<AccessControlRecord> acrList = new List<AccessControlRecord>();

                for (var i = 0; i < 1; i++)
                {
                    AccessControlRecord acr = new AccessControlRecord()
                    {
                        Name = TestUtilities.GenerateName("VDnewTestAcr"),
                        InitiatorName = TestUtilities.GenerateName("VDinitiator") + i
                    };
                    acrList.Add(acr);
                }

                //Virtual disk create request object
                var virtualDiskToCreate = new VirtualDiskRequest()
                {
                    Name = TestUtilities.GenerateName("VD1Name"),
                    AccessType = AccessType.ReadWrite,
                    AcrList = acrList,
                    AppType = AppType.PrimaryVolume,
                    IsDefaultBackupEnabled = true,
                    SizeInBytes = 10737418240,
                    DataContainer = Createddatacontainer.DataContainerInfo,
                    Online = true
                };

                //Virtual disk create call
                taskStatus = client.VirtualDisk.Create(actualdeviceId, virtualDiskToCreate, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //Virtual disk get call
                var createdVirtualDisk = client.VirtualDisk.GetByName(actualdeviceId, virtualDiskToCreate.Name, hdrs);

                Assert.True(createdVirtualDisk != null);
                Assert.True(createdVirtualDisk.VirtualDiskInfo.Name.Equals(virtualDiskToCreate.Name));

                var volumeIds = new List<string>();
                volumeIds.Add(createdVirtualDisk.VirtualDiskInfo.InstanceId);

                var dailySchedule = new BackupScheduleBase();
                dailySchedule.BackupType = BackupType.CloudSnapshot;
                dailySchedule.Status = ScheduleStatus.Enabled;
                dailySchedule.RetentionCount = 5;
                dailySchedule.StartTime = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz");
                dailySchedule.Recurrence = new ScheduleRecurrence();
                dailySchedule.Recurrence.RecurrenceType = RecurrenceType.Daily;
                dailySchedule.Recurrence.RecurrenceValue = 5;

                var backupPolicyToCreate = new NewBackupPolicyConfig();
                backupPolicyToCreate.Name = TestUtilities.GenerateName("PolicyName");
                backupPolicyToCreate.VolumeIds = volumeIds;
                backupPolicyToCreate.BackupSchedules = new List<BackupScheduleBase>();
                backupPolicyToCreate.BackupSchedules.Add(dailySchedule);

                //BackupPolicy create call
                taskStatus = client.BackupPolicy.Create(actualdeviceId, backupPolicyToCreate, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //BackupPolicy list call
                var allBackupPolicies = client.BackupPolicy.List(actualdeviceId, hdrs);

                //Assert the returned BackupPolicy object
                Assert.True(allBackupPolicies != null);
                Assert.True(allBackupPolicies.Any());

                //BackupPolicy get by name call
                var createdBackupPolicy = client.BackupPolicy.GetBackupPolicyDetailsByName(actualdeviceId, backupPolicyToCreate.Name, hdrs);

                //Assert the returned BackupPolicy object
                Assert.True(createdBackupPolicy != null);
                Assert.True(createdBackupPolicy.BackupPolicyDetails.Name.Equals(backupPolicyToCreate.Name));

                BackupNowRequest backupNowRequest = new BackupNowRequest();
                backupNowRequest.Type = BackupType.CloudSnapshot;


                //BackupSets Create call
                taskStatus = client.Backup.Create(actualdeviceId, createdBackupPolicy.BackupPolicyDetails.InstanceId, backupNowRequest, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                GetBackupResponse backupSetResult;

                do
                {
                    //BackupSets Get call
                    backupSetResult = client.Backup.Get(actualdeviceId, "BackupPolicy", Boolean.TrueString, null, null, null, null, null, hdrs);

                    Assert.True(backupSetResult != null);
                    Assert.True(backupSetResult.BackupSetsList != null);

                    TestUtilities.Wait(1000);
                } while (!backupSetResult.BackupSetsList.Any());

                var backupSet = backupSetResult.BackupSetsList.First();
                var clonedVolName = createdVirtualDisk.VirtualDiskInfo.Name + "_Cloned";
                var secondDeviceId = devices.Devices[1].DeviceId;
                var triggerCloneRequest = new TriggerCloneRequest()
                {
                    BackupSetId = backupSet.InstanceId,
                    SourceSnapshot = backupSet.Snapshots.First(),
                    TargetVolName = clonedVolName,
                    TargetDeviceId = secondDeviceId,
                    ReturnWorkflowId = true,
                    TargetACRList = createdVirtualDisk.VirtualDiskInfo.AcrList
                };

                var jobResponse = client.CloneVolume.Trigger(actualdeviceId, triggerCloneRequest, hdrs);
                //Asserting the job id.
                Assert.NotNull(jobResponse);
                Assert.True(jobResponse.JobId != Guid.Empty.ToString());

                GetDeviceJobResponse deviceJobResponse;
                do
                {
                    //DeviceJob Get call
                    deviceJobResponse = client.DeviceJob.Get(secondDeviceId, null, null, jobResponse.JobId, null, null, 0, 10, hdrs);
                    TestUtilities.Wait(1000);
                    Assert.True(deviceJobResponse.DeviceJobList != null);
                    Assert.True(deviceJobResponse.DeviceJobList.Count == 1);
                } while (deviceJobResponse.DeviceJobList.First().Status == "Running");

                Assert.True(deviceJobResponse.DeviceJobList != null);
                Assert.True(deviceJobResponse.DeviceJobList.First().Status.Equals("Completed", StringComparison.InvariantCultureIgnoreCase));
                VirtualDiskGetResponse virtualDiskGetResponse = client.VirtualDisk.GetByName(secondDeviceId, clonedVolName, GetCustomRequestHeaders());
                Assert.True(virtualDiskGetResponse != null);
                Assert.True(virtualDiskGetResponse.VirtualDiskInfo != null);
                Assert.True(virtualDiskGetResponse.VirtualDiskInfo.Name.Equals(clonedVolName, StringComparison.InvariantCultureIgnoreCase));
            }

        }
        /// <summary>
        /// In order to stop a job we need to first schedule a job that is going to run long 
        /// enough for it to be stopped.
        /// </summary>
        /// <param name="deviceInfo">Device details.</param>
        private void CreateSupportingVolumeAndBackupPolicy(DeviceInfo deviceInfo)
        {
            var client = GetServiceClient<StorSimpleManagementClient>();

            var actualdeviceId = deviceInfo.DeviceId;
            actualdeviceId = actualdeviceId.Trim();
            CustomRequestHeaders hdrs = new CustomRequestHeaders();
            hdrs.ClientRequestId = Guid.NewGuid().ToString();
            hdrs.Language = "en-us";

            //Get service configuration
            var serviceConfigList = client.ServiceConfig.Get(GetCustomRequestHeaders());

            Assert.True(serviceConfigList != null);

            var existingSac = serviceConfigList.CredentialChangeList.Updated.FirstOrDefault();

            Assert.True(existingSac != null);

            var dataContainerName = TestUtilities.GenerateName("DCName");

            // new Data container request object
            var dc = new DataContainerRequest();

            dc.IsDefault = false;
            dc.Name = dataContainerName;
            dc.BandwidthRate = 256;
            dc.VolumeCount = 0;
            dc.IsEncryptionEnabled = false;
            dc.PrimaryStorageAccountCredential = existingSac;

            //Create DataContainer call
            var taskStatus = client.DataContainer.Create(actualdeviceId, dc, hdrs);

            //Assert the job status
            Assert.NotNull(taskStatus);
            Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
            Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

            //Get Data Container call
            var Createddatacontainer = client.DataContainer.Get(actualdeviceId, dataContainerName, hdrs);

            //Assert the returned data container object
            Assert.True(Createddatacontainer != null);
            Assert.True(Createddatacontainer.DataContainerInfo.Name.Equals(dataContainerName));

            //ACR list for Virtual disk creation
            List<AccessControlRecord> acrList = new List<AccessControlRecord>();

            for (var i = 0; i < 1; i++)
            {
                AccessControlRecord acr = new AccessControlRecord()
                {
                    Name = TestUtilities.GenerateName("VDnewTestAcr"),
                    InitiatorName = TestUtilities.GenerateName("VDinitiator") + i
                };
                acrList.Add(acr);
            }

            //Virtual disk create request object
            var virtualDiskToCreate = new VirtualDiskRequest()
            {
                Name = TestUtilities.GenerateName("VD1Name"),
                AccessType = AccessType.ReadWrite,
                AcrList = acrList,
                AppType = AppType.PrimaryVolume,
                IsDefaultBackupEnabled = true,
                SizeInBytes = 107374182400,
                DataContainer = Createddatacontainer.DataContainerInfo,
                Online = true
            };

            //Virtual disk create call
            taskStatus = client.VirtualDisk.Create(actualdeviceId, virtualDiskToCreate, hdrs);

            //Asserting the job status
            Assert.NotNull(taskStatus);
            Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
            Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

            //Virtual disk get call
            var createdVirtualDisk = client.VirtualDisk.GetByName(actualdeviceId, virtualDiskToCreate.Name, hdrs);

            Assert.True(createdVirtualDisk != null);
            Assert.True(createdVirtualDisk.VirtualDiskInfo.Name.Equals(virtualDiskToCreate.Name));

            var volumeIds = new List<string>();
            volumeIds.Add(createdVirtualDisk.VirtualDiskInfo.InstanceId);

            var dailySchedule = new BackupScheduleBase();
            dailySchedule.BackupType = BackupType.CloudSnapshot;
            dailySchedule.Status = ScheduleStatus.Enabled;
            dailySchedule.RetentionCount = 5;
            dailySchedule.StartTime = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz");
            dailySchedule.Recurrence = new ScheduleRecurrence();
            dailySchedule.Recurrence.RecurrenceType = RecurrenceType.Daily;
            dailySchedule.Recurrence.RecurrenceValue = 5;

            var backupPolicyToCreate = new NewBackupPolicyConfig();
            backupPolicyToCreate.Name = TestUtilities.GenerateName("PolicyName");
            backupPolicyToCreate.VolumeIds = volumeIds;
            backupPolicyToCreate.BackupSchedules = new List<BackupScheduleBase>();
            backupPolicyToCreate.BackupSchedules.Add(dailySchedule);

            //BackupPolicy create call
            taskStatus = client.BackupPolicy.Create(actualdeviceId, backupPolicyToCreate, hdrs);

            //Asserting the job status
            Assert.NotNull(taskStatus);
            Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
            Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

            //BackupPolicy list call
            var allBackupPolicies = client.BackupPolicy.List(actualdeviceId, hdrs);

            //Assert the returned BackupPolicy object
            Assert.True(allBackupPolicies != null);
            Assert.True(allBackupPolicies.Any());
        }
 /// <summary>
 /// The BeginCreatingBackupPolicy operation creates a new backup policy
 /// for this given volume with the given schedules.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.StorSimple.IBackupPolicyOperations.
 /// </param>
 /// <param name='deviceId'>
 /// Required. The device id for which the call will be made.
 /// </param>
 /// <param name='backupPolicy'>
 /// Required. Parameters supplied to the Create Backup Policy operation.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Required. The Custom Request Headers which client must use.
 /// </param>
 /// <returns>
 /// This is the Task Response for all Async Calls
 /// </returns>
 public static Task<TaskResponse> BeginCreatingBackupPolicyAsync(this IBackupPolicyOperations operations, string deviceId, NewBackupPolicyConfig backupPolicy, CustomRequestHeaders customRequestHeaders)
 {
     return operations.BeginCreatingBackupPolicyAsync(deviceId, backupPolicy, customRequestHeaders, CancellationToken.None);
 }
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.StorSimple.IBackupPolicyOperations.
 /// </param>
 /// <param name='deviceId'>
 /// Required. The device id for which the call will be made.
 /// </param>
 /// <param name='backupPolicy'>
 /// Required. Parameters supplied to the Create Backup Policy operation.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Required. The Custom Request Headers which client must use.
 /// </param>
 /// <returns>
 /// Info about the async task
 /// </returns>
 public static Task<TaskStatusInfo> CreateAsync(this IBackupPolicyOperations operations, string deviceId, NewBackupPolicyConfig backupPolicy, CustomRequestHeaders customRequestHeaders)
 {
     return operations.CreateAsync(deviceId, backupPolicy, customRequestHeaders, CancellationToken.None);
 }