/// <summary>
 /// Begin a backup operation for the policyId and backupRequest
 /// specified.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.StorSimple.IBackupOperations.
 /// </param>
 /// <param name='deviceId'>
 /// Required. The device id for which the call will be made.
 /// </param>
 /// <param name='policyId'>
 /// Required. The policy id for which the call will be made.
 /// </param>
 /// <param name='backupRequest'>
 /// Required. Parameters supplied to the Begin Backup 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 BeginCreatingBackup(this IBackupOperations operations, string deviceId, string policyId, BackupNowRequest backupRequest, CustomRequestHeaders customRequestHeaders)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IBackupOperations)s).BeginCreatingBackupAsync(deviceId, policyId, backupRequest, customRequestHeaders);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
Exemplo n.º 2
0
        public void CanGetDeviceJobsTest()
        {
            using (var context = UndoContext.Current)
            {
                context.Start();

                var client = GetServiceClient<StorSimpleManagementClient>();

                var headers = GetCustomRequestHeaders();

                // Get all devices.
                var devices = client.Devices.List(headers);

                // Get hold of an online device.
                var onlineDevice = devices.LastOrDefault(device => device.Status == DeviceStatus.Online);
                if (onlineDevice == null)
                {
                    throw new ArgumentException("Need an online device to try scheduling and retrieving device jobs");
                }

                //Get hold of a backup policy 
                BackupPolicy policy;
                var policiesResponse = client.BackupPolicy.List(onlineDevice.DeviceId, headers);
                if (policiesResponse == null)
                {
                    policy = null;
                }
                else
                {
                    policy = policiesResponse.BackupPolicies.FirstOrDefault();
                }
                if(policy == null){
                    throw new ArgumentException("The online device must have a backup policy to schedule and get device jobs");
                }

                // Schedule a backup

                var backupNowRequest = new BackupNowRequest();
                backupNowRequest.Type = BackupType.CloudSnapshot;
                var taskStatus = client.Backup.Create(onlineDevice.DeviceId, policy.InstanceId, backupNowRequest, headers);

                // Make sure the backup job was created

                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                // Get a list of device jobs for this device now.
                var response = client.DeviceJob.Get(onlineDevice.DeviceId, null, null, null, null, null, 0, 10, headers);
                Assert.NotNull(response);
                Assert.True(response.Count > 0);
                Assert.NotEmpty(response.DeviceJobList);
            }
        }
        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");
            }
        }
         private void ProcessParameters()
        {
            deviceId = StorSimpleClient.GetDeviceId(DeviceName);

            if (deviceId == null)
            {
                WriteVerbose(Resources.NotFoundMessageDevice);
            }

             BackupType backupTypeSelected = Management.StorSimple.Models.BackupType.Invalid;
             switch (ParameterSetName)
             {
                 case StorSimpleCmdletParameterSet.Empty:
                     backupTypeSelected = Microsoft.WindowsAzure.Management.StorSimple.Models.BackupType.LocalSnapshot;
                     break;
                 case PARAMETERSET_BACKUPTYPE:
                     backupTypeSelected = (BackupType)Enum.Parse(typeof(BackupType), BackupType);
                     break;
             }
             backupNowRequest = new BackupNowRequest();
             backupNowRequest.Type = backupTypeSelected;
        }
Exemplo n.º 5
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);

            }
        }
Exemplo n.º 6
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));
            }

        }
Exemplo n.º 7
0
        public void CanStopDeviceJobTest()
        {
            using (var context = UndoContext.Current)
            {
                context.Start();

                var client = GetServiceClient<StorSimpleManagementClient>();

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

                // Get hold of an online device.
                var onlineDevice = devices.LastOrDefault(device => device.Status == DeviceStatus.Online);
                if (onlineDevice == null)
                {
                    throw new ArgumentException("Need an online device to try scheduling and retrieving device jobs");
                }

                CreateSupportingVolumeAndBackupPolicy(onlineDevice);

                //Get hold of a backup policy 
                BackupPolicy policy;
                var policiesResponse = client.BackupPolicy.List(onlineDevice.DeviceId, GetCustomRequestHeaders());
                if (policiesResponse == null)
                {
                    policy = null;
                }
                else
                {
                    policy = policiesResponse.BackupPolicies.FirstOrDefault();
                }
                if (policy == null)
                {
                    throw new ArgumentException("The online device must have a backup policy to schedule and get device jobs");
                }

                // Schedule a backup
                var backupNowRequest = new BackupNowRequest();
                backupNowRequest.Type = BackupType.CloudSnapshot;
                var taskStatus = client.Backup.Create(onlineDevice.DeviceId, policy.InstanceId, backupNowRequest, GetCustomRequestHeaders());

                // Make sure the backup job was created
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                // Get all device jobs and get hold of a job that is running
                var jobsResponse = client.DeviceJob.Get(onlineDevice.DeviceId, null, null, null, null, null, 0, 10, GetCustomRequestHeaders());
                Assert.NotNull(jobsResponse);
                var runningCancellableJob = jobsResponse.DeviceJobList.FirstOrDefault(x => x.Status.Equals("Running") && x.IsJobCancellable);
                if (runningCancellableJob == null)
                {
                    throw new ArgumentException("No running cancellable job available to stop");
                }

                var updateRequest = new UpdateDeviceJobRequest ();
                updateRequest.DeviceJobAction = DeviceJobAction.Cancel;
                var updateTaskStatus = client.DeviceJob.UpdateDeviceJob(runningCancellableJob.Device.InstanceId, runningCancellableJob.InstanceId, updateRequest, GetCustomRequestHeaders());

                //Assert the job status
                Assert.NotNull(updateTaskStatus);
                Assert.True(updateTaskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(updateTaskStatus.Result == AsyncTaskResult.Succeeded);
            }
        }
 public TaskResponse DoBackupAsync(string deviceid, string backupPolicyId, BackupNowRequest request)
 {
     return GetStorSimpleClient().Backup.BeginCreatingBackup(deviceid, backupPolicyId, request, GetCustomRequestHeaders());
 }
 public TaskStatusInfo DoBackup(string deviceid, string backupPolicyId, BackupNowRequest request)
 {
     return GetStorSimpleClient().Backup.Create(deviceid, backupPolicyId, request, GetCustomRequestHeaders());
 }
 /// <summary>
 /// Begin a backup operation for the policyId and backupRequest
 /// specified.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.StorSimple.IBackupOperations.
 /// </param>
 /// <param name='deviceId'>
 /// Required. The device id for which the call will be made.
 /// </param>
 /// <param name='policyId'>
 /// Required. The policy id for which the call will be made.
 /// </param>
 /// <param name='backupRequest'>
 /// Required. Parameters supplied to the Begin Backup 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> BeginCreatingBackupAsync(this IBackupOperations operations, string deviceId, string policyId, BackupNowRequest backupRequest, CustomRequestHeaders customRequestHeaders)
 {
     return operations.BeginCreatingBackupAsync(deviceId, policyId, backupRequest, customRequestHeaders, CancellationToken.None);
 }
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.StorSimple.IBackupOperations.
 /// </param>
 /// <param name='deviceId'>
 /// Required. The device id for which the call will be made.
 /// </param>
 /// <param name='policyId'>
 /// Required. The policy id for which the call will be made.
 /// </param>
 /// <param name='backupRequest'>
 /// Required. Parameters supplied to the Begin Backup 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 IBackupOperations operations, string deviceId, string policyId, BackupNowRequest backupRequest, CustomRequestHeaders customRequestHeaders)
 {
     return operations.CreateAsync(deviceId, policyId, backupRequest, customRequestHeaders, CancellationToken.None);
 }
         private void ProcessParameters()
        {
            deviceId = StorSimpleClient.GetDeviceId(DeviceName);

            if (deviceId == null)
            {
                throw new ArgumentException(string.Format(Resources.NoDeviceFoundWithGivenNameInResourceMessage, StorSimpleContext.ResourceName, DeviceName));
            }

             BackupType backupTypeSelected = Management.StorSimple.Models.BackupType.Invalid;
             switch (ParameterSetName)
             {
                 case StorSimpleCmdletParameterSet.Empty:
                     backupTypeSelected = Microsoft.WindowsAzure.Management.StorSimple.Models.BackupType.LocalSnapshot;
                     break;
                 case PARAMETERSET_BACKUPTYPE:
                     backupTypeSelected = (BackupType)Enum.Parse(typeof(BackupType), BackupType);
                     break;
             }
             backupNowRequest = new BackupNowRequest();
             backupNowRequest.Type = backupTypeSelected;
        }