Skip to content

RemoteApp cmdlet bug fixes #276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Mar 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
eca12ce
Updating unit tests to work with xunit, mocking rdfe registering, min…
robertla Mar 13, 2015
7f45762
Bug fixes: 1908985, 1907418, 1898689,1901426
robertla Mar 16, 2015
d9b6c1c
Bug fixes: 1908985, 1907418, 1898689,1901426
robertla Mar 16, 2015
7df80e8
Bug fixes for: 1974862, 1907078
robertla Mar 17, 2015
56eb2f5
Bug fixes: 1908985, 1907418, 1898689,1901426
robertla Mar 18, 2015
8b315c5
conflicts from merging with UpdateCmdlets2
robertla Mar 18, 2015
d43dab7
Bug fixes: 1908985, 1907418, 1898689,1901426
robertla Mar 18, 2015
b327f02
Fixing pipeline usability issues
robertla Mar 18, 2015
c6a70a3
force git to see this is a new file
robertla Mar 18, 2015
280e478
Bug fixes: 1908985, 1907418, 1898689,1901426
robertla Mar 18, 2015
e84ecfe
Merge branch 'UpdateCmdlets3' into UpdateCmdlets4
robertla Mar 18, 2015
09a1ded
Bug fixes: 1908985, 1907418, 1898689,1901426
robertla Mar 18, 2015
f989810
Bug fixes: 1908985, 1907418, 1898689,1901426. Fixing TemplateImage RegEx
robertla Mar 18, 2015
6600231
merged conflicts from updatecmdlets2
robertla Mar 18, 2015
7a97f9b
Merge branch 'UpdateCmdlets3' into UpdateCmdlets4
robertla Mar 18, 2015
6f1d78a
Merge branch 'UpdateCmdlets4' into scratch
robertla Mar 18, 2015
33abef8
Bug 2065636:$[Mohoro] AzurePowershell should set "ForceRedeploy=true"
yadavbdev Mar 18, 2015
4853239
Merge branch 'UpdateCmdlets4' into scratch
robertla Mar 18, 2015
5141229
Merge branch 'scratch' of https://github.com/robertla/azure-powershel…
robertla Mar 18, 2015
8c69a64
Merge branch 'scratch' of https://github.com/robertla/azure-powershel…
yadavbdev Mar 18, 2015
8f28ed7
Revert "Merge branch 'scratch' of https://github.com/robertla/azure-p…
yadavb Mar 19, 2015
fbde495
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
yadavb Mar 19, 2015
cf24d1d
Revert "Revert "Merge branch 'scratch' of https://github.com/robertla…
yadavb Mar 19, 2015
2d03221
Merge branch 'scratch' of https://github.com/robertla/azure-powershel…
robertla Mar 18, 2015
c8a5d3f
Merge branch 'scratch' of https://github.com/robertla/azure-powershel…
robertla Mar 19, 2015
433a106
Merge branch 'scratch' of https://github.com/robertla/azure-powershel…
yadavbdev Mar 19, 2015
8dfbfcb
Merge branch 'from_bob' into dev
yadavbdev Mar 19, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ namespace Microsoft.Azure.Management.RemoteApp.Cmdlets
public class GetAzureRemoteAppCollection : RdsCmdlet
{
[Parameter(Mandatory = false,
Position = 1,
Position = 0,
ValueFromPipelineByPropertyName = true,
HelpMessage = "RemoteApp collection name. Wildcards are permitted.")]
[ValidatePattern(NameValidatorStringWithWildCards)]
[Alias("Name")]
public string CollectionName { get; set; }

private bool showAllCollections = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,24 @@
using Microsoft.Azure.Management.RemoteApp;
using Microsoft.Azure.Management.RemoteApp.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Management.Automation;
using System.Net;


namespace Microsoft.Azure.Management.RemoteApp.Cmdlets
{

[Cmdlet(VerbsCommon.Get, "AzureRemoteAppCollectionUsageDetails"), OutputType(typeof(string))]
public class GetAzureRemoteAppCollectionUsageDetails : RdsCmdlet
{
[Parameter(
Position = 0,
Mandatory = true,
ValueFromPipelineByPropertyName = true,
HelpMessage = "RemoteApp collection name")]
[Parameter(Mandatory = true,
Position = 0,
ValueFromPipelineByPropertyName = true,
HelpMessage = "RemoteApp collection name")]
[ValidatePattern(NameValidatorString)]
[Alias("Name")]
public string CollectionName { get; set; }

[Parameter(Mandatory = false,
Expand All @@ -47,73 +48,39 @@ public class GetAzureRemoteAppCollectionUsageDetails : RdsCmdlet
[ValidatePattern(FullYearPattern)]
public string UsageYear { get; set; }

public override void ExecuteCmdlet()
{
DateTime today = DateTime.Now;
CollectionUsageDetailsResult detailsUsage = null;
string locale = String.Empty;
RemoteAppOperationStatusResult operationResult = null;
int maxRetryCount = 60;

if (String.IsNullOrWhiteSpace(UsageMonth))
{
UsageMonth = today.Month.ToString();
}

if (String.IsNullOrWhiteSpace(UsageYear))
{
UsageYear = today.Year.ToString();
}

locale = System.Globalization.CultureInfo.CurrentCulture.ToString();
[Parameter(Mandatory = false,
HelpMessage = "Allows running the cmdlet in the background as a PS job.")]
public SwitchParameter AsJob { get; set; }

detailsUsage = CallClient(() => Client.Collections.GetUsageDetails(CollectionName, UsageYear, UsageMonth, locale), Client.Collections);
private LongRunningTask<GetAzureRemoteAppCollectionUsageDetails> task = null;

if (detailsUsage == null)
{
return;
}
private void GetUsageDetails(CollectionUsageDetailsResult detailsUsage)
{
RemoteAppOperationStatusResult operationResult = null;

// The request is async and we have to wait for the usage details to be produced here
do
{

System.Threading.Thread.Sleep(5000);

operationResult = CallClient(() => Client.OperationResults.Get(detailsUsage.UsageDetails.OperationTrackingId), Client.OperationResults);
}
while(operationResult.RemoteAppOperationResult.Status != RemoteAppOperationStatus.Success &&
operationResult.RemoteAppOperationResult.Status != RemoteAppOperationStatus.Failed &&
--maxRetryCount > 0);
while (operationResult.RemoteAppOperationResult.Status != RemoteAppOperationStatus.Success &&
operationResult.RemoteAppOperationResult.Status != RemoteAppOperationStatus.Failed);

if (operationResult.RemoteAppOperationResult.Status == RemoteAppOperationStatus.Success)
{
WriteUsageDetails(detailsUsage);
}
else
{
if (operationResult.RemoteAppOperationResult.Status == RemoteAppOperationStatus.Failed)
{
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
Commands_RemoteApp.DetailedUsageFailureMessage,
String.Empty,
Client.Collections,
ErrorCategory.ResourceUnavailable);
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
Commands_RemoteApp.DetailedUsageFailureMessage,
String.Empty,
Client.Collections,
ErrorCategory.ResourceUnavailable);

WriteError(error);
}
else if (maxRetryCount <= 0)
{
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
String.Format(System.Globalization.CultureInfo.InvariantCulture,
Commands_RemoteApp.RequestTimedOutFormat,
detailsUsage.UsageDetails.OperationTrackingId),
String.Empty,
Client.Collections,
ErrorCategory.OperationTimeout);

WriteError(error);
}
WriteError(error);
}
}

Expand All @@ -129,11 +96,19 @@ private void WriteUsageDetails(CollectionUsageDetailsResult detailsUsage)
try
{
response = (HttpWebResponse)request.GetResponse();
if (response == null)
{
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
"Unable to retrieve Usage data", String.Empty, null, ErrorCategory.InvalidResult);
WriteError(error);
return;
}
}
catch (Exception e)
{
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromException(e, String.Empty, Client.Collections, ErrorCategory.InvalidResult);
WriteError(error);
return;
}

using (Stream dataStream = response.GetResponseStream())
Expand All @@ -145,5 +120,50 @@ private void WriteUsageDetails(CollectionUsageDetailsResult detailsUsage)
}
}
}

public override void ExecuteCmdlet()
{
DateTime today = DateTime.Now;
CollectionUsageDetailsResult detailsUsage = null;
string locale = String.Empty;

if (String.IsNullOrWhiteSpace(UsageMonth))
{
UsageMonth = today.Month.ToString();
}

if (String.IsNullOrWhiteSpace(UsageYear))
{
UsageYear = today.Year.ToString();
}

locale = System.Globalization.CultureInfo.CurrentCulture.ToString();

detailsUsage = CallClient(() => Client.Collections.GetUsageDetails(CollectionName, UsageYear, UsageMonth, locale), Client.Collections);

if (detailsUsage == null)
{
return;
}

if (AsJob.IsPresent)
{
task = new LongRunningTask<GetAzureRemoteAppCollectionUsageDetails>(this, "RemoteAppBackgroundTask", Commands_RemoteApp.UsageDetails);

task.ProcessJob(() =>
{
task.SetStatus(Commands_RemoteApp.DownloadingUsageDetails);
GetUsageDetails(detailsUsage);
task.SetStatus(Commands_RemoteApp.JobComplete);
});

WriteObject(task);

}
else
{
GetUsageDetails(detailsUsage);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Management.RemoteApp;
using Microsoft.Azure.Commands.RemoteApp;
using Microsoft.Azure.Management.RemoteApp.Models;
using System;
using System.Collections.Generic;
Expand All @@ -26,9 +27,11 @@ namespace Microsoft.Azure.Management.RemoteApp.Cmdlets
public class GetAzureRemoteAppCollectionUsageSummary : RdsCmdlet
{
[Parameter(Mandatory = true,
Position = 0,
ValueFromPipelineByPropertyName = true,
HelpMessage = "RemoteApp collection name")]
Position = 0,
ValueFromPipelineByPropertyName = true,
HelpMessage = "RemoteApp collection name")]
[ValidatePattern(NameValidatorString)]
[Alias("Name")]
public string CollectionName { get; set; }

[Parameter(Mandatory = false,
Expand Down Expand Up @@ -67,7 +70,7 @@ public override void ExecuteCmdlet()
}
else
{
WriteVerboseWithTimestamp("No usage found for the requested period.");
WriteVerboseWithTimestamp(Commands_RemoteApp.UseageNotFound);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ public class NewAzureRemoteAppCollection : RdsCmdlet
private const string NoDomain = "NoDomain";
private const string AzureVNet = "AzureVNet";

[Parameter (Mandatory = true,
Position = 0,
HelpMessage = "RemoteApp collection name")]
[ValidatePattern (NameValidatorString)]
[Parameter(Mandatory = true,
Position = 0,
ValueFromPipelineByPropertyName = true,
HelpMessage = "RemoteApp collection name")]
[ValidatePattern(NameValidatorString)]
[Alias("Name")]
public string CollectionName { get; set; }

[Parameter(Mandatory = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public class RemoveAzureRemoteAppCollection : RdsCmdlet
{
[Parameter(Mandatory = true,
Position = 0,
ValueFromPipelineByPropertyName = true,
HelpMessage = "RemoteApp collection name")]
[ValidatePattern(NameValidatorString)]
[Alias("Name")]
public string CollectionName { get; set; }

public override void ExecuteCmdlet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ public class SetAzureRemoteAppCollection : RdsCmdlet

[Parameter(Mandatory = true,
Position = 0,
ValueFromPipelineByPropertyName = true,
HelpMessage = "RemoteApp collection name")]
[ValidatePattern(NameValidatorString)]
[Alias("Name")]
public string CollectionName { get; set; }

[Parameter(Mandatory = false,
Expand Down Expand Up @@ -66,6 +68,7 @@ public override void ExecuteCmdlet()
CollectionCreationDetails details = null;
OperationResultWithTrackingId response = null;
Collection collection = null;
bool forceRedeploy = false;

collection = FindCollection(CollectionName);
if (collection == null)
Expand Down Expand Up @@ -107,11 +110,19 @@ public override void ExecuteCmdlet()
details.AdInfo.UserName = creds.UserName;
details.AdInfo.Password = creds.Password;
}

if (String.Equals("Inactive", collection.Status, StringComparison.OrdinalIgnoreCase))
{
// the collection may have failed due to bad domain join information before,
// re-trying with the new information
forceRedeploy = true;
}

break;
}
}

response = CallClient(() => Client.Collections.Set(CollectionName, false, false, details), Client.Collections);
response = CallClient(() => Client.Collections.Set(CollectionName, forceRedeploy, false, details), Client.Collections);
if (response != null)
{
TrackingResult trackingId = new TrackingResult(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Management.RemoteApp;
using Microsoft.Azure.Commands.RemoteApp;
using Microsoft.Azure.Management.RemoteApp.Models;
using System.Management.Automation;

Expand All @@ -22,20 +22,25 @@ namespace Microsoft.Azure.Management.RemoteApp.Cmdlets

public class UpdateAzureRemoteAppCollection : RdsCmdlet
{
[Parameter (Mandatory = true,
Position = 0,
HelpMessage = "RemoteApp collection name")]
[ValidatePattern (NameValidatorString)]
[Parameter(Mandatory = true,
Position = 0,
ValueFromPipelineByPropertyName = true,
HelpMessage = "RemoteApp collection name")]
[ValidatePattern(NameValidatorString)]
[Alias("Name")]
public string CollectionName { get; set; }


[Parameter(Mandatory = true,
Position = 1,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The name of the RemoteApp template image."
)]
public string ImageName { get; set; }

[Parameter(Mandatory = false,
HelpMessage = "Immediately log off users after update has successfully completed")]
public SwitchParameter ForceLogoffWhenUpdateComplete { get; set; }

public override void ExecuteCmdlet()
{
CollectionCreationDetails details = null;
Expand All @@ -50,12 +55,13 @@ public override void ExecuteCmdlet()
{
Name = CollectionName,
TemplateImageName = ImageName,
PlanName = collection.PlanName
PlanName = collection.PlanName,
WaitBeforeShutdownInMinutes = ForceLogoffWhenUpdateComplete ? -1 : 0
};

if (ShouldProcess(CollectionName, "Update collection"))
if (ShouldProcess(CollectionName, Commands_RemoteApp.UpdateCollection))
{
response = CallClient(() => Client.Collections.Set(CollectionName, false, false, details), Client.Collections);
response = CallClient(() => Client.Collections.Set(CollectionName, true, false, details), Client.Collections);
}

if (response != null)
Expand Down
Loading