From c0b9b3c6d473883d30de64e7f78793698c74a980 Mon Sep 17 00:00:00 2001 From: Sumanth-SK Date: Thu, 9 Apr 2015 13:35:58 +0530 Subject: [PATCH 1/3] Bug fix #2211889: Get-AzureStorSimpleJob doesn't let me filter with both Type and Status --- .../DeviceJobs/GetAzureStorSimpleJob.cs | 70 +++++++------------ 1 file changed, 26 insertions(+), 44 deletions(-) diff --git a/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/DeviceJobs/GetAzureStorSimpleJob.cs b/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/DeviceJobs/GetAzureStorSimpleJob.cs index c596286ca1c1..9d26b76ed91e 100644 --- a/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/DeviceJobs/GetAzureStorSimpleJob.cs +++ b/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/DeviceJobs/GetAzureStorSimpleJob.cs @@ -28,67 +28,61 @@ namespace Microsoft.WindowsAzure.Commands.StorSimple.Cmdlets /// /// Stop the specified device job if its in progress and is cancellable. /// - [Cmdlet(VerbsCommon.Get, "AzureStorSimpleJob", DefaultParameterSetName=StorSimpleCmdletParameterSet.IdentifyByDeviceName), - OutputType(typeof(IList), typeof(DeviceJobDetails))] + [Cmdlet(VerbsCommon.Get, "AzureStorSimpleJob"), OutputType(typeof(IList), typeof(DeviceJobDetails))] public class GetAzureStorSimpleJob : StorSimpleCmdletBase { #region params /// /// Name of StorSimple device for which to fetch jobs /// - [Parameter(Mandatory = true, Position = 0, ParameterSetName = StorSimpleCmdletParameterSet.IdentifyByDeviceName, - HelpMessage=StorSimpleCmdletHelpMessage.DeviceName)] + [Parameter(Mandatory = false, Position = 0, HelpMessage=StorSimpleCmdletHelpMessage.DeviceName)] [ValidateNotNullOrEmpty] public string DeviceName { get; set; } - /// /// InstanceId/JobId of the job to retrieve /// - [Parameter(Mandatory=true, Position = 0, ParameterSetName = StorSimpleCmdletParameterSet.IdentifyById, - HelpMessage = StorSimpleCmdletHelpMessage.DeviceJobId)] + [Parameter(Mandatory = false, Position = 1, HelpMessage = StorSimpleCmdletHelpMessage.DeviceJobId)] [ValidateNotNullOrEmpty] public string InstanceId { get; set; } /// /// Filter jobs by their status. /// - [Parameter(Mandatory = true, Position = 0, ParameterSetName = StorSimpleCmdletParameterSet.IdentifyByStatus, - HelpMessage=StorSimpleCmdletHelpMessage.DeviceJobStatus)] + [Parameter(Mandatory = false, Position = 2, HelpMessage=StorSimpleCmdletHelpMessage.DeviceJobStatus)] [ValidateSetAttribute(new string[] { "Running", "Completed", "Cancelled", "Failed", "Cancelling", "CompletedWithErrors" })] public string Status { get; set; } /// /// Filter jobs by their status. /// - [Parameter(Mandatory = true, Position = 0, ParameterSetName = StorSimpleCmdletParameterSet.IdentifyByType, - HelpMessage=StorSimpleCmdletHelpMessage.DeviceJobType)] + [Parameter(Mandatory = false, Position = 3, HelpMessage=StorSimpleCmdletHelpMessage.DeviceJobType)] [ValidateSetAttribute(new string[] { "Backup", "ManualBackup", "Restore", "CloneWorkflow", "DeviceRestore", "Update", "SupportPackage", "VirtualApplianceProvisioning" })] public string Type { get; set; } /// /// Filter jobs that were created after specified time /// - [Parameter(Position = 1, Mandatory=false, HelpMessage = StorSimpleCmdletHelpMessage.FromTime)] + [Parameter(Mandatory = false, Position = 4, HelpMessage = StorSimpleCmdletHelpMessage.FromTime)] public DateTime? From { get; set; } /// /// Filter jobs that were created till specified time /// /// Number of results to skip /// - [Parameter(Position = 3, Mandatory=false, HelpMessage = StorSimpleCmdletHelpMessage.SkipDesc)] + [Parameter(Mandatory = false, Position = 6, HelpMessage = StorSimpleCmdletHelpMessage.SkipDesc)] [ValidateRange(0, Int32.MaxValue)] public int? Skip { get; set; } /// /// Number of results to include. /// - [Parameter(Position = 4, Mandatory=false, HelpMessage = StorSimpleCmdletHelpMessage.FirstDesc)] + [Parameter(Mandatory = false, Position = 7, HelpMessage = StorSimpleCmdletHelpMessage.FirstDesc)] [ValidateRange(0, Int32.MaxValue)] public int? First { get; set; } #endregion params @@ -108,41 +102,29 @@ public override void ExecuteCmdlet() // Make call to get device jobs. var response = StorSimpleClient.GetDeviceJobs(deviceId, Type, Status, InstanceId, fromDateTimeIsoString, toDateTimeIsoString, (int)Skip, (int)First); - if (ParameterSetName == StorSimpleCmdletParameterSet.IdentifyById) + WriteObject(response.DeviceJobList, true); + WriteVerbose(string.Format(Resources.DeviceJobsReturnedCount, response.DeviceJobList.Count, + response.DeviceJobList.Count > 1 ? "s" : string.Empty)); + if (response.NextPageUri != null + && response.NextPageStartIdentifier != "-1") { - if (response == null || response.DeviceJobList.Count < 1) + if (First != null) { - throw new ArgumentException(string.Format(Resources.NoDeviceJobFoundWithGivenIdMessage, InstanceId)); - } - WriteObject(response.DeviceJobList.First()); - return; - } - else - { - WriteObject(response.DeviceJobList, true); - WriteVerbose(string.Format(Resources.DeviceJobsReturnedCount, response.DeviceJobList.Count, - response.DeviceJobList.Count > 1 ? "s" : string.Empty)); - if (response.NextPageUri != null - && response.NextPageStartIdentifier != "-1") - { - if (First != null) - { - //user has provided First(Top) parameter while calling the commandlet - //so we need to provide it to him for calling the next page - WriteVerbose(string.Format(Resources.DeviceJobsNextPageFormatMessage, First, response.NextPageStartIdentifier)); - } - else - { - //user has NOT provided First(Top) parameter while calling the commandlet - //so we DONT need to provide it to him for calling the next page - WriteVerbose(string.Format(Resources.DeviceJobsNextPagewithNoFirstMessage, response.NextPageStartIdentifier)); - } + //user has provided First(Top) parameter while calling the commandlet + //so we need to provide it to him for calling the next page + WriteVerbose(string.Format(Resources.DeviceJobsNextPageFormatMessage, First, response.NextPageStartIdentifier)); } else { - WriteVerbose(Resources.DeviceJobsNoMorePagesMessage); + //user has NOT provided First(Top) parameter while calling the commandlet + //so we DONT need to provide it to him for calling the next page + WriteVerbose(string.Format(Resources.DeviceJobsNextPagewithNoFirstMessage, response.NextPageStartIdentifier)); } } + else + { + WriteVerbose(Resources.DeviceJobsNoMorePagesMessage); + } } catch (Exception exception) { @@ -164,7 +146,7 @@ private void ProcessParameters() deviceId = null; - if (ParameterSetName == StorSimpleCmdletParameterSet.IdentifyByDeviceName) + if (DeviceName != null) { deviceId = StorSimpleClient.GetDeviceId(DeviceName); if (deviceId == null) From 37067c1d437ff83de0d66489c1441a137cfe67c3 Mon Sep 17 00:00:00 2001 From: Sumanth-SK Date: Thu, 9 Apr 2015 13:42:15 +0530 Subject: [PATCH 2/3] Revert "Revert "Added check to ensure volume container creation is allowed only if mandatory config has been done"" This reverts commit 484c4d8081d4d5958ed47e416ce174dd2c95fad3. --- ...NewAzureStorSimpleDeviceVolumeContainer.cs | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/DataContainer/NewAzureStorSimpleDeviceVolumeContainer.cs b/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/DataContainer/NewAzureStorSimpleDeviceVolumeContainer.cs index 96aef25c89b3..a64988ef7e9f 100644 --- a/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/DataContainer/NewAzureStorSimpleDeviceVolumeContainer.cs +++ b/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/DataContainer/NewAzureStorSimpleDeviceVolumeContainer.cs @@ -60,12 +60,25 @@ public override void ExecuteCmdlet() string deviceid = StorSimpleClient.GetDeviceId(DeviceName); if (deviceid == null) { - WriteVerbose(string.Format(Resources.NoDeviceFoundWithGivenNameInResourceMessage, StorSimpleContext.ResourceName, DeviceName)); - WriteObject(null); - return; + throw new ArgumentException(string.Format(Resources.NoDeviceFoundWithGivenNameInResourceMessage, StorSimpleContext.ResourceName, DeviceName)); } - if(EncryptionEnabled == true && (string.IsNullOrEmpty(EncryptionKey) || !IsValidAsciiString(EncryptionKey))) + // Get the current device details. + var deviceDetails = StorSimpleClient.GetDeviceDetails(deviceid); + if (deviceDetails == null || deviceDetails.DeviceProperties == null) + { + throw new ArgumentException(string.Format(Resources.NoDeviceFoundWithGivenNameInResourceMessage, StorSimpleContext.ResourceName, DeviceName)); + } + + // If the device has not yet been configured with the mandatory params, then don't allow the volume-container creation + // TBD : This check should ideally be in the service code, but is being put here as we want to avoud a major change + // to the service so late in the current release cycle. Once this fix has been migrated to the service, this check can be removed from here + if (!deviceDetails.DeviceProperties.IsConfigUpdated) + { + throw new ArgumentException(Resources.DeviceNotConfiguredMessage); + } + + if (EncryptionEnabled == true && (string.IsNullOrEmpty(EncryptionKey) || !IsValidAsciiString(EncryptionKey))) { throw new ArgumentException(Resources.EncryptionKeyNotAcceptableMessage); } From db4b58e0b94c59dd7d5822d268581c8d62dc30e0 Mon Sep 17 00:00:00 2001 From: Sumanth-SK Date: Thu, 9 Apr 2015 13:51:47 +0530 Subject: [PATCH 3/3] Revert "Revert "Revert "Added check to ensure volume container creation is allowed only if mandatory config has been done""" This reverts commit 37067c1d437ff83de0d66489c1441a137cfe67c3. --- ...NewAzureStorSimpleDeviceVolumeContainer.cs | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/DataContainer/NewAzureStorSimpleDeviceVolumeContainer.cs b/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/DataContainer/NewAzureStorSimpleDeviceVolumeContainer.cs index a64988ef7e9f..96aef25c89b3 100644 --- a/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/DataContainer/NewAzureStorSimpleDeviceVolumeContainer.cs +++ b/src/ServiceManagement/StorSimple/Commands.StorSimple/Cmdlets/DataContainer/NewAzureStorSimpleDeviceVolumeContainer.cs @@ -60,25 +60,12 @@ public override void ExecuteCmdlet() string deviceid = StorSimpleClient.GetDeviceId(DeviceName); if (deviceid == null) { - throw new ArgumentException(string.Format(Resources.NoDeviceFoundWithGivenNameInResourceMessage, StorSimpleContext.ResourceName, DeviceName)); + WriteVerbose(string.Format(Resources.NoDeviceFoundWithGivenNameInResourceMessage, StorSimpleContext.ResourceName, DeviceName)); + WriteObject(null); + return; } - // Get the current device details. - var deviceDetails = StorSimpleClient.GetDeviceDetails(deviceid); - if (deviceDetails == null || deviceDetails.DeviceProperties == null) - { - throw new ArgumentException(string.Format(Resources.NoDeviceFoundWithGivenNameInResourceMessage, StorSimpleContext.ResourceName, DeviceName)); - } - - // If the device has not yet been configured with the mandatory params, then don't allow the volume-container creation - // TBD : This check should ideally be in the service code, but is being put here as we want to avoud a major change - // to the service so late in the current release cycle. Once this fix has been migrated to the service, this check can be removed from here - if (!deviceDetails.DeviceProperties.IsConfigUpdated) - { - throw new ArgumentException(Resources.DeviceNotConfiguredMessage); - } - - if (EncryptionEnabled == true && (string.IsNullOrEmpty(EncryptionKey) || !IsValidAsciiString(EncryptionKey))) + if(EncryptionEnabled == true && (string.IsNullOrEmpty(EncryptionKey) || !IsValidAsciiString(EncryptionKey))) { throw new ArgumentException(Resources.EncryptionKeyNotAcceptableMessage); }