public override void ExecuteCmdlet()
 {
     try
     {
         var confirmMigrationRequest = new MigrationConfirmStatusRequest();
         confirmMigrationRequest.Operation =
             (MigrationOperation) Enum.Parse(typeof (MigrationOperation), MigrationOperation, true);
         confirmMigrationRequest.DataContainerNameList = (null != LegacyContainerNames)
             ? new List<string>(LegacyContainerNames.ToList().Distinct(StringComparer.InvariantCultureIgnoreCase))
             : new List<string>();
         var status = StorSimpleClient.ConfirmLegacyVolumeContainerStatus(LegacyConfigId, confirmMigrationRequest);
         MigrationCommonModelFormatter opFormatter = new MigrationCommonModelFormatter();
         WriteObject(opFormatter.GetResultMessage(Resources.ConfirmMigrationSuccessMessage, status));
     }
     catch (Exception except)
     {
         this.HandleException(except);
     }
 }
        public override void ExecuteCmdlet()
        {
            try
            {
                var confirmMigrationRequest = new MigrationConfirmStatusRequest();
                confirmMigrationRequest.Operation =
                    (MigrationOperation)Enum.Parse(typeof(MigrationOperation), MigrationOperation, true);
                switch (ParameterSetName)
                {
                    case StorSimpleCmdletParameterSet.MigrateAllContainer:
                        {
                            confirmMigrationRequest.DataContainerNameList = new List<string>();
                            break;
                        }
                    case StorSimpleCmdletParameterSet.MigrateSpecificContainer:
                        {
                            confirmMigrationRequest.DataContainerNameList =
                            new List<string>(LegacyContainerNames.ToList().Distinct(
                                StringComparer.InvariantCultureIgnoreCase));
                            break;
                        }
                    default:
                        {
                            // unexpected code path hit.
                            throw new ParameterBindingException(
                                string.Format(Resources.MigrationParameterSetNotFound, ParameterSetName));
                        }
                }

                var status = StorSimpleClient.ConfirmLegacyVolumeContainerStatus(LegacyConfigId, confirmMigrationRequest);
                MigrationCommonModelFormatter opFormatter = new MigrationCommonModelFormatter();
                WriteObject(opFormatter.GetResultMessage(Resources.ConfirmMigrationSuccessMessage, status));
            }
            catch (Exception except)
            {
                this.HandleException(except);
            }
        }
 public MigrationJobStatus ConfirmLegacyVolumeContainerStatus(string configId, MigrationConfirmStatusRequest request)
 {
     return this.GetStorSimpleClient().MigrateLegacyAppliance.ConfirmMigration(configId, request, this.GetCustomRequestHeaders());
 }
 /// <summary>
 /// Hydra spec for confirm migration rest apiThe rest api confirms the
 /// commit or rollback of the migrated data containers for all data
 /// container in the specified 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='confirmMigrationRequest'>
 /// Required. The confirm migration request specifies the list of
 /// volume containers and rollback/commit operation to be performed
 /// </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> ConfirmMigrationAsync(this IMigrationOperations operations, string configId, MigrationConfirmStatusRequest confirmMigrationRequest, CustomRequestHeaders customRequestHeaders)
 {
     return operations.ConfirmMigrationAsync(configId, confirmMigrationRequest, customRequestHeaders, CancellationToken.None);
 }
 /// <summary>
 /// Hydra spec for confirm migration rest apiThe rest api confirms the
 /// commit or rollback of the migrated data containers for all data
 /// container in the specified 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='confirmMigrationRequest'>
 /// Required. The confirm migration request specifies the list of
 /// volume containers and rollback/commit operation to be performed
 /// </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 ConfirmMigration(this IMigrationOperations operations, string configId, MigrationConfirmStatusRequest confirmMigrationRequest, CustomRequestHeaders customRequestHeaders)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IMigrationOperations)s).ConfirmMigrationAsync(configId, confirmMigrationRequest, customRequestHeaders);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
        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);
            }
        }