Skip to content

Commit 718743c

Browse files
committed
Merge pull request #276 from yadavbdev/dev
RemoteApp cmdlet bug fixes
2 parents 3535770 + 8dfbfcb commit 718743c

28 files changed

+310
-131
lines changed

src/ServiceManagement/RemoteApp/Commands.RemoteApp/Collection/GetAzureRemoteAppCollection.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ namespace Microsoft.Azure.Management.RemoteApp.Cmdlets
2626
public class GetAzureRemoteAppCollection : RdsCmdlet
2727
{
2828
[Parameter(Mandatory = false,
29-
Position = 1,
29+
Position = 0,
30+
ValueFromPipelineByPropertyName = true,
3031
HelpMessage = "RemoteApp collection name. Wildcards are permitted.")]
3132
[ValidatePattern(NameValidatorStringWithWildCards)]
33+
[Alias("Name")]
3234
public string CollectionName { get; set; }
3335

3436
private bool showAllCollections = false;

src/ServiceManagement/RemoteApp/Commands.RemoteApp/Collection/GetAzureRemoteAppCollectionUsageDetails.cs

Lines changed: 76 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,24 @@
1616
using Microsoft.Azure.Management.RemoteApp;
1717
using Microsoft.Azure.Management.RemoteApp.Models;
1818
using System;
19-
using System.Collections.Generic;
19+
using System.Collections.ObjectModel;
2020
using System.IO;
21-
using System.Linq;
2221
using System.Management.Automation;
2322
using System.Net;
2423

24+
2525
namespace Microsoft.Azure.Management.RemoteApp.Cmdlets
2626
{
2727

2828
[Cmdlet(VerbsCommon.Get, "AzureRemoteAppCollectionUsageDetails"), OutputType(typeof(string))]
2929
public class GetAzureRemoteAppCollectionUsageDetails : RdsCmdlet
3030
{
31-
[Parameter(
32-
Position = 0,
33-
Mandatory = true,
34-
ValueFromPipelineByPropertyName = true,
35-
HelpMessage = "RemoteApp collection name")]
31+
[Parameter(Mandatory = true,
32+
Position = 0,
33+
ValueFromPipelineByPropertyName = true,
34+
HelpMessage = "RemoteApp collection name")]
35+
[ValidatePattern(NameValidatorString)]
36+
[Alias("Name")]
3637
public string CollectionName { get; set; }
3738

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

50-
public override void ExecuteCmdlet()
51-
{
52-
DateTime today = DateTime.Now;
53-
CollectionUsageDetailsResult detailsUsage = null;
54-
string locale = String.Empty;
55-
RemoteAppOperationStatusResult operationResult = null;
56-
int maxRetryCount = 60;
57-
58-
if (String.IsNullOrWhiteSpace(UsageMonth))
59-
{
60-
UsageMonth = today.Month.ToString();
61-
}
62-
63-
if (String.IsNullOrWhiteSpace(UsageYear))
64-
{
65-
UsageYear = today.Year.ToString();
66-
}
67-
68-
locale = System.Globalization.CultureInfo.CurrentCulture.ToString();
51+
[Parameter(Mandatory = false,
52+
HelpMessage = "Allows running the cmdlet in the background as a PS job.")]
53+
public SwitchParameter AsJob { get; set; }
6954

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

72-
if (detailsUsage == null)
73-
{
74-
return;
75-
}
57+
private void GetUsageDetails(CollectionUsageDetailsResult detailsUsage)
58+
{
59+
RemoteAppOperationStatusResult operationResult = null;
7660

7761
// The request is async and we have to wait for the usage details to be produced here
7862
do
7963
{
80-
8164
System.Threading.Thread.Sleep(5000);
8265

8366
operationResult = CallClient(() => Client.OperationResults.Get(detailsUsage.UsageDetails.OperationTrackingId), Client.OperationResults);
8467
}
85-
while(operationResult.RemoteAppOperationResult.Status != RemoteAppOperationStatus.Success &&
86-
operationResult.RemoteAppOperationResult.Status != RemoteAppOperationStatus.Failed &&
87-
--maxRetryCount > 0);
68+
while (operationResult.RemoteAppOperationResult.Status != RemoteAppOperationStatus.Success &&
69+
operationResult.RemoteAppOperationResult.Status != RemoteAppOperationStatus.Failed);
8870

8971
if (operationResult.RemoteAppOperationResult.Status == RemoteAppOperationStatus.Success)
9072
{
9173
WriteUsageDetails(detailsUsage);
9274
}
9375
else
9476
{
95-
if (operationResult.RemoteAppOperationResult.Status == RemoteAppOperationStatus.Failed)
96-
{
97-
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
98-
Commands_RemoteApp.DetailedUsageFailureMessage,
99-
String.Empty,
100-
Client.Collections,
101-
ErrorCategory.ResourceUnavailable);
77+
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
78+
Commands_RemoteApp.DetailedUsageFailureMessage,
79+
String.Empty,
80+
Client.Collections,
81+
ErrorCategory.ResourceUnavailable);
10282

103-
WriteError(error);
104-
}
105-
else if (maxRetryCount <= 0)
106-
{
107-
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
108-
String.Format(System.Globalization.CultureInfo.InvariantCulture,
109-
Commands_RemoteApp.RequestTimedOutFormat,
110-
detailsUsage.UsageDetails.OperationTrackingId),
111-
String.Empty,
112-
Client.Collections,
113-
ErrorCategory.OperationTimeout);
114-
115-
WriteError(error);
116-
}
83+
WriteError(error);
11784
}
11885
}
11986

@@ -129,11 +96,19 @@ private void WriteUsageDetails(CollectionUsageDetailsResult detailsUsage)
12996
try
13097
{
13198
response = (HttpWebResponse)request.GetResponse();
99+
if (response == null)
100+
{
101+
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
102+
"Unable to retrieve Usage data", String.Empty, null, ErrorCategory.InvalidResult);
103+
WriteError(error);
104+
return;
105+
}
132106
}
133107
catch (Exception e)
134108
{
135109
ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromException(e, String.Empty, Client.Collections, ErrorCategory.InvalidResult);
136110
WriteError(error);
111+
return;
137112
}
138113

139114
using (Stream dataStream = response.GetResponseStream())
@@ -145,5 +120,50 @@ private void WriteUsageDetails(CollectionUsageDetailsResult detailsUsage)
145120
}
146121
}
147122
}
123+
124+
public override void ExecuteCmdlet()
125+
{
126+
DateTime today = DateTime.Now;
127+
CollectionUsageDetailsResult detailsUsage = null;
128+
string locale = String.Empty;
129+
130+
if (String.IsNullOrWhiteSpace(UsageMonth))
131+
{
132+
UsageMonth = today.Month.ToString();
133+
}
134+
135+
if (String.IsNullOrWhiteSpace(UsageYear))
136+
{
137+
UsageYear = today.Year.ToString();
138+
}
139+
140+
locale = System.Globalization.CultureInfo.CurrentCulture.ToString();
141+
142+
detailsUsage = CallClient(() => Client.Collections.GetUsageDetails(CollectionName, UsageYear, UsageMonth, locale), Client.Collections);
143+
144+
if (detailsUsage == null)
145+
{
146+
return;
147+
}
148+
149+
if (AsJob.IsPresent)
150+
{
151+
task = new LongRunningTask<GetAzureRemoteAppCollectionUsageDetails>(this, "RemoteAppBackgroundTask", Commands_RemoteApp.UsageDetails);
152+
153+
task.ProcessJob(() =>
154+
{
155+
task.SetStatus(Commands_RemoteApp.DownloadingUsageDetails);
156+
GetUsageDetails(detailsUsage);
157+
task.SetStatus(Commands_RemoteApp.JobComplete);
158+
});
159+
160+
WriteObject(task);
161+
162+
}
163+
else
164+
{
165+
GetUsageDetails(detailsUsage);
166+
}
167+
}
148168
}
149169
}

src/ServiceManagement/RemoteApp/Commands.RemoteApp/Collection/GetAzureRemoteAppCollectionUsageSummary.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Management.RemoteApp;
16+
using Microsoft.Azure.Commands.RemoteApp;
1617
using Microsoft.Azure.Management.RemoteApp.Models;
1718
using System;
1819
using System.Collections.Generic;
@@ -26,9 +27,11 @@ namespace Microsoft.Azure.Management.RemoteApp.Cmdlets
2627
public class GetAzureRemoteAppCollectionUsageSummary : RdsCmdlet
2728
{
2829
[Parameter(Mandatory = true,
29-
Position = 0,
30-
ValueFromPipelineByPropertyName = true,
31-
HelpMessage = "RemoteApp collection name")]
30+
Position = 0,
31+
ValueFromPipelineByPropertyName = true,
32+
HelpMessage = "RemoteApp collection name")]
33+
[ValidatePattern(NameValidatorString)]
34+
[Alias("Name")]
3235
public string CollectionName { get; set; }
3336

3437
[Parameter(Mandatory = false,
@@ -67,7 +70,7 @@ public override void ExecuteCmdlet()
6770
}
6871
else
6972
{
70-
WriteVerboseWithTimestamp("No usage found for the requested period.");
73+
WriteVerboseWithTimestamp(Commands_RemoteApp.UseageNotFound);
7174
}
7275
}
7376
}

src/ServiceManagement/RemoteApp/Commands.RemoteApp/Collection/NewAzureRemoteAppCollection.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ public class NewAzureRemoteAppCollection : RdsCmdlet
3232
private const string NoDomain = "NoDomain";
3333
private const string AzureVNet = "AzureVNet";
3434

35-
[Parameter (Mandatory = true,
36-
Position = 0,
37-
HelpMessage = "RemoteApp collection name")]
38-
[ValidatePattern (NameValidatorString)]
35+
[Parameter(Mandatory = true,
36+
Position = 0,
37+
ValueFromPipelineByPropertyName = true,
38+
HelpMessage = "RemoteApp collection name")]
39+
[ValidatePattern(NameValidatorString)]
40+
[Alias("Name")]
3941
public string CollectionName { get; set; }
4042

4143
[Parameter(Mandatory = true,

src/ServiceManagement/RemoteApp/Commands.RemoteApp/Collection/RemoveAzureRemoteAppCollection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ public class RemoveAzureRemoteAppCollection : RdsCmdlet
2323
{
2424
[Parameter(Mandatory = true,
2525
Position = 0,
26+
ValueFromPipelineByPropertyName = true,
2627
HelpMessage = "RemoteApp collection name")]
2728
[ValidatePattern(NameValidatorString)]
29+
[Alias("Name")]
2830
public string CollectionName { get; set; }
2931

3032
public override void ExecuteCmdlet()

src/ServiceManagement/RemoteApp/Commands.RemoteApp/Collection/SetAzureRemoteAppCollection.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ public class SetAzureRemoteAppCollection : RdsCmdlet
2929

3030
[Parameter(Mandatory = true,
3131
Position = 0,
32+
ValueFromPipelineByPropertyName = true,
3233
HelpMessage = "RemoteApp collection name")]
3334
[ValidatePattern(NameValidatorString)]
35+
[Alias("Name")]
3436
public string CollectionName { get; set; }
3537

3638
[Parameter(Mandatory = false,
@@ -66,6 +68,7 @@ public override void ExecuteCmdlet()
6668
CollectionCreationDetails details = null;
6769
OperationResultWithTrackingId response = null;
6870
Collection collection = null;
71+
bool forceRedeploy = false;
6972

7073
collection = FindCollection(CollectionName);
7174
if (collection == null)
@@ -107,11 +110,19 @@ public override void ExecuteCmdlet()
107110
details.AdInfo.UserName = creds.UserName;
108111
details.AdInfo.Password = creds.Password;
109112
}
113+
114+
if (String.Equals("Inactive", collection.Status, StringComparison.OrdinalIgnoreCase))
115+
{
116+
// the collection may have failed due to bad domain join information before,
117+
// re-trying with the new information
118+
forceRedeploy = true;
119+
}
120+
110121
break;
111122
}
112123
}
113124

114-
response = CallClient(() => Client.Collections.Set(CollectionName, false, false, details), Client.Collections);
125+
response = CallClient(() => Client.Collections.Set(CollectionName, forceRedeploy, false, details), Client.Collections);
115126
if (response != null)
116127
{
117128
TrackingResult trackingId = new TrackingResult(response);

src/ServiceManagement/RemoteApp/Commands.RemoteApp/Collection/UpdateAzureRemoteAppCollection.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Management.RemoteApp;
15+
using Microsoft.Azure.Commands.RemoteApp;
1616
using Microsoft.Azure.Management.RemoteApp.Models;
1717
using System.Management.Automation;
1818

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

2323
public class UpdateAzureRemoteAppCollection : RdsCmdlet
2424
{
25-
[Parameter (Mandatory = true,
26-
Position = 0,
27-
HelpMessage = "RemoteApp collection name")]
28-
[ValidatePattern (NameValidatorString)]
25+
[Parameter(Mandatory = true,
26+
Position = 0,
27+
ValueFromPipelineByPropertyName = true,
28+
HelpMessage = "RemoteApp collection name")]
29+
[ValidatePattern(NameValidatorString)]
30+
[Alias("Name")]
2931
public string CollectionName { get; set; }
3032

31-
3233
[Parameter(Mandatory = true,
3334
Position = 1,
3435
ValueFromPipelineByPropertyName = true,
3536
HelpMessage = "The name of the RemoteApp template image."
3637
)]
3738
public string ImageName { get; set; }
3839

40+
[Parameter(Mandatory = false,
41+
HelpMessage = "Immediately log off users after update has successfully completed")]
42+
public SwitchParameter ForceLogoffWhenUpdateComplete { get; set; }
43+
3944
public override void ExecuteCmdlet()
4045
{
4146
CollectionCreationDetails details = null;
@@ -50,12 +55,13 @@ public override void ExecuteCmdlet()
5055
{
5156
Name = CollectionName,
5257
TemplateImageName = ImageName,
53-
PlanName = collection.PlanName
58+
PlanName = collection.PlanName,
59+
WaitBeforeShutdownInMinutes = ForceLogoffWhenUpdateComplete ? -1 : 0
5460
};
5561

56-
if (ShouldProcess(CollectionName, "Update collection"))
62+
if (ShouldProcess(CollectionName, Commands_RemoteApp.UpdateCollection))
5763
{
58-
response = CallClient(() => Client.Collections.Set(CollectionName, false, false, details), Client.Collections);
64+
response = CallClient(() => Client.Collections.Set(CollectionName, true, false, details), Client.Collections);
5965
}
6066

6167
if (response != null)

0 commit comments

Comments
 (0)