Skip to content

Commit

Permalink
Merge pull request #44 from AzCiS/onesdk-p2-sumanths
Browse files Browse the repository at this point in the history
Bug fix #2288119: Get-AzureStorSimpleJob doesnt let me filter with both Type and Status
  • Loading branch information
parvezah committed Apr 9, 2015
2 parents 03e323a + db4b58e commit 26b7417
Showing 1 changed file with 26 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,67 +28,61 @@ namespace Microsoft.WindowsAzure.Commands.StorSimple.Cmdlets
/// <summary>
/// Stop the specified device job if its in progress and is cancellable.
/// </summary>
[Cmdlet(VerbsCommon.Get, "AzureStorSimpleJob", DefaultParameterSetName=StorSimpleCmdletParameterSet.IdentifyByDeviceName),
OutputType(typeof(IList<DeviceJobDetails>), typeof(DeviceJobDetails))]
[Cmdlet(VerbsCommon.Get, "AzureStorSimpleJob"), OutputType(typeof(IList<DeviceJobDetails>), typeof(DeviceJobDetails))]
public class GetAzureStorSimpleJob : StorSimpleCmdletBase
{
#region params
/// <summary>
/// Name of StorSimple device for which to fetch jobs
/// </summary>
[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; }


/// <summary>
/// InstanceId/JobId of the job to retrieve
/// </summary>
[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; }

/// <summary>
/// Filter jobs by their status.
/// </summary>
[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; }

/// <summary>
/// Filter jobs by their status.
/// </summary>
[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; }

/// <summary>
/// Filter jobs that were created after specified time
/// </summary>
[Parameter(Position = 1, Mandatory=false, HelpMessage = StorSimpleCmdletHelpMessage.FromTime)]
[Parameter(Mandatory = false, Position = 4, HelpMessage = StorSimpleCmdletHelpMessage.FromTime)]
public DateTime? From { get; set; }

/// <summary>
/// Filter jobs that were created till specified time
/// </summary
[Parameter(Position = 2, Mandatory=false, HelpMessage = StorSimpleCmdletHelpMessage.ToTime)]
[Parameter(Mandatory = false, Position = 5, HelpMessage = StorSimpleCmdletHelpMessage.ToTime)]
public DateTime? To { get; set; }

/// <summary>
/// Number of results to skip
/// </summary>
[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; }

/// <summary>
/// Number of results to include.
/// </summary>
[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
Expand All @@ -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)
{
Expand All @@ -164,7 +146,7 @@ private void ProcessParameters()

deviceId = null;

if (ParameterSetName == StorSimpleCmdletParameterSet.IdentifyByDeviceName)
if (DeviceName != null)
{
deviceId = StorSimpleClient.GetDeviceId(DeviceName);
if (deviceId == null)
Expand Down

0 comments on commit 26b7417

Please sign in to comment.