public override void ExecuteCmdlet()
        {
            try
            {
                var importDataContainerRequest = new MigrationImportDataContainerRequest();
                switch (ParameterSetName)
                {
                    case StorSimpleCmdletParameterSet.MigrateAllContainer:
                        {
                            importDataContainerRequest.DataContainerNames = new List<string>();
                            break;
                        }
                    case StorSimpleCmdletParameterSet.MigrateSpecificContainer:
                        {
                            importDataContainerRequest.DataContainerNames =
                                    new List<string>(LegacyContainerNames.ToList().Distinct(
                                        StringComparer.InvariantCultureIgnoreCase));
                            break;
                        }
                    default:
                        {
                            // unexpected code path.
                            throw new ParameterBindingException(
                                string.Format(Resources.MigrationParameterSetNotFound, ParameterSetName));
                        }
                }

                importDataContainerRequest.ForceOnOtherDevice = Force.IsPresent;
                importDataContainerRequest.SkipACRs = SkipACRs.IsPresent;

                var migrationJobStatus = StorSimpleClient.MigrationImportDataContainer(LegacyConfigId,
                    importDataContainerRequest);
                MigrationCommonModelFormatter opFormatter = new MigrationCommonModelFormatter();
                WriteObject(opFormatter.GetResultMessage(Resources.MigrationImportDataContainerSuccessMessage,
                    migrationJobStatus));
            }
            catch (Exception except)
            {
                this.HandleException(except);
            }
        }
 public MigrationJobStatus MigrationImportDataContainer(string configId, MigrationImportDataContainerRequest request)
 {
     return this.GetStorSimpleClient().MigrateLegacyAppliance.MigrationImportDataContainer(configId, request, this.GetCustomRequestHeaders());
 }
 /// <summary>
 /// Hydra spec for import data container rest apiThe rest api initiates
 /// the migration of volume containers for all/specific data
 /// container(s) in the given config
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.StorSimple.IMigrationOperations.
 /// </param>
 /// <param name='configId'>
 /// Required. Unique identifier for config specified while importing
 /// the config to service
 /// </param>
 /// <param name='importDCRequest'>
 /// Required. Import data container request which specifies the list of
 /// data containers to be migrated
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Required. The Custom Request Headers which client must use.
 /// </param>
 /// <returns>
 /// The response model for migration job status.
 /// </returns>
 public static MigrationJobStatus MigrationImportDataContainer(this IMigrationOperations operations, string configId, MigrationImportDataContainerRequest importDCRequest, CustomRequestHeaders customRequestHeaders)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IMigrationOperations)s).MigrationImportDataContainerAsync(configId, importDCRequest, customRequestHeaders);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// Hydra spec for import data container rest apiThe rest api initiates
 /// the migration of volume containers for all/specific data
 /// container(s) in the given config
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.StorSimple.IMigrationOperations.
 /// </param>
 /// <param name='configId'>
 /// Required. Unique identifier for config specified while importing
 /// the config to service
 /// </param>
 /// <param name='importDCRequest'>
 /// Required. Import data container request which specifies the list of
 /// data containers to be migrated
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Required. The Custom Request Headers which client must use.
 /// </param>
 /// <returns>
 /// The response model for migration job status.
 /// </returns>
 public static Task<MigrationJobStatus> MigrationImportDataContainerAsync(this IMigrationOperations operations, string configId, MigrationImportDataContainerRequest importDCRequest, CustomRequestHeaders customRequestHeaders)
 {
     return operations.MigrationImportDataContainerAsync(configId, importDCRequest, customRequestHeaders, CancellationToken.None);
 }
        public void VerifyMigration()
        {
            using (var context = UndoContext.Current)
            {
                context.Start();

                var client = GetServiceClient<StorSimpleManagementClient>();
                LegacyApplianceConfig config = CreateConfig();

                List<MigrationDataContainer> dcList = new List<MigrationDataContainer>(config.CloudConfigurations);
                List<string> dcNameList = dcList.Select(migrationDC => migrationDC.Name).ToList();

                // Import legacy appliance config returns void, other than http status code. An exception from hydra spec if the http response code is not expected
                client.MigrateLegacyAppliance.ImportLegacyApplianceConfig(config.InstanceId, config, GetCustomRequestHeaders());

                MigrationPlanStartRequest startMigrationPlanRequest = new MigrationPlanStartRequest() { ConfigId = config.InstanceId, DataContainerNameList = dcNameList};
                client.MigrateLegacyAppliance.StartMigrationPlan(startMigrationPlanRequest, GetCustomRequestHeaders());
                client.MigrateLegacyAppliance.UpdateMigrationPlan(config.InstanceId, GetCustomRequestHeaders());
                var getmigrationPlanResponse = client.MigrateLegacyAppliance.GetMigrationPlan(config.InstanceId, GetCustomRequestHeaders());
                Assert.NotNull(getmigrationPlanResponse);
                Assert.NotNull(getmigrationPlanResponse.MigrationPlans);
                Assert.True(1 == getmigrationPlanResponse.MigrationPlans.Count);
                Assert.NotNull(getmigrationPlanResponse.MigrationPlans[0].MigrationPlanInfo);                
                Assert.True(dcList.Count == getmigrationPlanResponse.MigrationPlans[0].MigrationPlanInfo.Count);
                List<MigrationPlanInfo> migrationPlanInfoList = new List<MigrationPlanInfo>(getmigrationPlanResponse.MigrationPlans[0].MigrationPlanInfo);
                
                Assert.True(0 == migrationPlanInfoList.FindAll(plan=>!dcNameList.Contains(plan.DataContainerName)).Count);

                var getmigrationAllPlanResponse = client.MigrateLegacyAppliance.GetAllMigrationPlan(GetCustomRequestHeaders());
                Assert.NotNull(getmigrationAllPlanResponse);                 
                Assert.NotNull(getmigrationAllPlanResponse.MigrationPlans);
                Assert.True(0 < getmigrationAllPlanResponse.MigrationPlans.Count);
                List<MigrationPlan> allPlans = new List<MigrationPlan>(getmigrationAllPlanResponse.MigrationPlans);
                Assert.True(null != allPlans.Find(plan => plan.ConfigId == config.InstanceId));


                MigrationImportDataContainerRequest importDCRequest = new MigrationImportDataContainerRequest() { DataContainerNames = new List<string>() };
                client.MigrateLegacyAppliance.MigrationImportDataContainer(config.InstanceId, importDCRequest, GetCustomRequestHeaders());
                client.MigrateLegacyAppliance.UpdateDataContainerMigrationStatus(config.InstanceId, GetCustomRequestHeaders());
                var getMigrationStatus = client.MigrateLegacyAppliance.GetDataContainerMigrationStatus(config.InstanceId, GetCustomRequestHeaders());
                Assert.NotNull(getMigrationStatus);
                Assert.NotNull(getMigrationStatus.MigrationDataContainerStatuses);
                List<MigrationDataContainerStatus> migrationStatusList = new List<MigrationDataContainerStatus>(getMigrationStatus.MigrationDataContainerStatuses);
                Assert.True(dcList.Count == migrationStatusList.Count);
                Assert.True(0 == migrationStatusList.FindAll(status=>!dcNameList.Contains(status.CloudConfigurationName)).Count);

                // Migration will start only after 12mins and will take roughly around 14mins to complete for single dc.
                TestUtilities.Wait(14 * 60 * 1000);

                DateTime timeOutTime = DateTime.UtcNow.AddMinutes(6);
                while (true)
                {
                    if(0 <= DateTime.UtcNow.CompareTo(timeOutTime))
                    {
                        throw new System.TimeoutException("Import DC did not completed in expected time");
                    }
                    client.MigrateLegacyAppliance.UpdateDataContainerMigrationStatus(config.InstanceId, GetCustomRequestHeaders());
                    var migrationStatus = client.MigrateLegacyAppliance.GetDataContainerMigrationStatus(config.InstanceId, GetCustomRequestHeaders());
                    List<MigrationDataContainerStatus> statusList = new List<MigrationDataContainerStatus>(migrationStatus.MigrationDataContainerStatuses);
                    if(dcList.Count != statusList.FindAll(status=>MigrationStatus.Completed == status.Status || MigrationStatus.Failed == status.Status).Count)
                    {
                        TestUtilities.Wait(30 * 1000);
                    }
                    else
                    {
                        break;
                    }
                }

                MigrationConfirmStatusRequest confirmRequest = new MigrationConfirmStatusRequest() { DataContainerNameList = new List<string>(), Operation = MigrationOperation.Commit };
                client.MigrateLegacyAppliance.ConfirmMigration(config.InstanceId, confirmRequest, GetCustomRequestHeaders());
                client.MigrateLegacyAppliance.UpdateMigrationConfirmStatus(config.InstanceId, GetCustomRequestHeaders());
                var getConfirmStatus = client.MigrateLegacyAppliance.GetMigrationConfirmStatus(config.InstanceId, GetCustomRequestHeaders());
                Assert.NotNull(getConfirmStatus);
                Assert.NotNull(getConfirmStatus.ContainerConfirmStatus);
                List<MigrationContainerConfirmStatus> confirmStatusList = new List<MigrationContainerConfirmStatus>(getConfirmStatus.ContainerConfirmStatus);
                Assert.True(dcList.Count == confirmStatusList.Count);
                Assert.True(0 == confirmStatusList.FindAll(status => !dcNameList.Contains(status.CloudConfigurationName)).Count);
            }
        }