From 2f2b2d36f9174ab6fcbba7abacc499ce6aa6a8b3 Mon Sep 17 00:00:00 2001 From: avirupch Date: Fri, 6 Mar 2015 12:12:50 +0530 Subject: [PATCH 1/2] enable piping in start-devicefailover --- .../StartAzureStorSimpleDeviceFailoverJob.cs | 5 ++-- .../Properties/Resources.Designer.cs | 4 +-- .../Properties/Resources.resx | 2 +- .../StorSimpleCmdletBase.cs | 27 ++++++++++++++++++- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/Failover/StartAzureStorSimpleDeviceFailoverJob.cs b/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/Failover/StartAzureStorSimpleDeviceFailoverJob.cs index 2d18e5784b28..5ed0ccf05cc9 100644 --- a/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/Failover/StartAzureStorSimpleDeviceFailoverJob.cs +++ b/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/Failover/StartAzureStorSimpleDeviceFailoverJob.cs @@ -32,7 +32,7 @@ public class StartAzureStorSimpleDeviceFailoverJob : StorSimpleCmdletBase [ValidateNotNullOrEmpty] public string DeviceName { get; set; } - [Parameter(Position = 1, Mandatory = true, HelpMessage = StorSimpleCmdletHelpMessage.VolumeContainerGroups)] + [Parameter(Position = 1, Mandatory = true, ValueFromPipeline = true, HelpMessage = StorSimpleCmdletHelpMessage.VolumeContainerGroups)] [ValidateNotNull] public List VolumecontainerGroups { get; set; } @@ -93,9 +93,8 @@ public override void ExecuteCmdlet() return; } - if(deviceId.Equals(targetDeviceId, StringComparison.InvariantCultureIgnoreCase)) + if (!ValidTargetDeviceForFailover(deviceId, targetDeviceId)) { - WriteVerbose(Resources.DeviceFailoverSourceAndTargetDeviceSameError); WriteObject(null); return; } diff --git a/src/ServiceManagement/StorSimple/Commands.StorSimple/Properties/Resources.Designer.cs b/src/ServiceManagement/StorSimple/Commands.StorSimple/Properties/Resources.Designer.cs index ee2461c9f3c8..87e1075e77a5 100644 --- a/src/ServiceManagement/StorSimple/Commands.StorSimple/Properties/Resources.Designer.cs +++ b/src/ServiceManagement/StorSimple/Commands.StorSimple/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.0 +// Runtime Version:4.0.30319.34014 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -1213,7 +1213,7 @@ internal static string ValidationSuccessfulRegistrationKey { } /// - /// Looks up a localized string similar to Volume Container Group \"{0}\" is not eligible for failover due to the reason: {1}. + /// Looks up a localized string similar to Volume Container Group "{0}" is not eligible for failover due to the reason: {1}. /// internal static string VolumeContainerGroupNotEligibleForFailoverError { get { diff --git a/src/ServiceManagement/StorSimple/Commands.StorSimple/Properties/Resources.resx b/src/ServiceManagement/StorSimple/Commands.StorSimple/Properties/Resources.resx index 95205bafe388..d02f0648d023 100644 --- a/src/ServiceManagement/StorSimple/Commands.StorSimple/Properties/Resources.resx +++ b/src/ServiceManagement/StorSimple/Commands.StorSimple/Properties/Resources.resx @@ -487,7 +487,7 @@ Are you sure you want to failover the selected volume containers from device {0} to device {1}? - Volume Container Group \"{0}\" is not eligible for failover due to the reason: {1} + Volume Container Group "{0}" is not eligible for failover due to the reason: {1} The {0} job is triggered successfully. Please use the command Get-AzureStorSimpleJob -InstanceId {1} for tracking the job's status diff --git a/src/ServiceManagement/StorSimple/Commands.StorSimple/StorSimpleCmdletBase.cs b/src/ServiceManagement/StorSimple/Commands.StorSimple/StorSimpleCmdletBase.cs index ce9d9fe02b84..60451bb0292c 100644 --- a/src/ServiceManagement/StorSimple/Commands.StorSimple/StorSimpleCmdletBase.cs +++ b/src/ServiceManagement/StorSimple/Commands.StorSimple/StorSimpleCmdletBase.cs @@ -193,7 +193,16 @@ internal virtual void HandleException(Exception exception) } else if (exType == typeof(ArgumentNullException)) { - var argEx = ex as ArgumentNullException; + var argNullEx = ex as ArgumentNullException; + if (argNullEx == null) + break; + WriteVerbose(string.Format(Resources.InvalidInputMessage, ex.Message)); + errorRecord = new ErrorRecord(argNullEx, string.Empty, ErrorCategory.InvalidData, null); + break; + } + else if (exType == typeof(ArgumentException)) + { + var argEx = ex as ArgumentException; if (argEx == null) break; WriteVerbose(string.Format(Resources.InvalidInputMessage, ex.Message)); @@ -479,5 +488,21 @@ internal bool ValidParamsForFirstDeviceConfiguration(NetworkConfig[] netConfigs, } return true; } + + /// + /// Validate that the target device is eligible for failover + /// + /// The source device identifier + /// The target device identifier + /// + internal bool ValidTargetDeviceForFailover(string sourceDeviceId, string targetDeviceId) + { + if (sourceDeviceId.Equals(targetDeviceId, StringComparison.InvariantCultureIgnoreCase)) + { + throw new ArgumentException(Resources.DeviceFailoverSourceAndTargetDeviceSameError); + } + + return true; + } } } \ No newline at end of file From e9c97ace1b3c93a35fe8ffcac5fc8a4191d7e736 Mon Sep 17 00:00:00 2001 From: avirupch Date: Fri, 6 Mar 2015 16:29:31 +0530 Subject: [PATCH 2/2] updating output type of Start-DeviceFailover cmdlet --- .../Cmdlets/Failover/StartAzureStorSimpleDeviceFailoverJob.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/Failover/StartAzureStorSimpleDeviceFailoverJob.cs b/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/Failover/StartAzureStorSimpleDeviceFailoverJob.cs index 5ed0ccf05cc9..e51b1633212c 100644 --- a/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/Failover/StartAzureStorSimpleDeviceFailoverJob.cs +++ b/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/Failover/StartAzureStorSimpleDeviceFailoverJob.cs @@ -21,7 +21,7 @@ namespace Microsoft.WindowsAzure.Commands.StorSimple.Cmdlets { [Cmdlet(VerbsLifecycle.Start, "AzureStorSimpleDeviceFailoverJob", DefaultParameterSetName = StorSimpleCmdletParameterSet.Empty), - OutputType(typeof(TaskResponse), typeof(TaskStatusInfo))] + OutputType(typeof(string))] public class StartAzureStorSimpleDeviceFailoverJob : StorSimpleCmdletBase { [Parameter(Position = 0, Mandatory = true, ParameterSetName = StorSimpleCmdletParameterSet.IdentifyById, HelpMessage = StorSimpleCmdletHelpMessage.DeviceId)]