Skip to content

Commit 7d81fa2

Browse files
committed
Adding RunOn support and other issue fixes.
Adding runOn support for Scheduled Job and Webhook cmdlets; Also adding alias for Modules in New/Set Modules. The changes were required for couple of issues raised earlier.
1 parent f4c9f4d commit 7d81fa2

File tree

11 files changed

+49
-20
lines changed

11 files changed

+49
-20
lines changed

src/ResourceManager/Automation/ChangeLog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
## Current Release
2121
* Made changes to AutomationDSC* cmdlets to pull more than 100 records
2222
* Resolved the issue where the Verbose streams stop working after calling some Automation cmdlets (for example Get-AzureRmAutomationVariable, Get-AzureRmAutomationJob).
23+
* Bug fixes for existing issues - Fixes the alias issue is #3775 and the runOn alias and support for HybridWorkers.
24+
2325
## Version 3.2.1
2426
## Version 3.2.0
2527
* Properly setting TimeZone value for Weekly and Monthly schedules for New-AzureRmAutomationSchedule
@@ -40,4 +42,4 @@
4042

4143
## Version 2.4.0
4244

43-
## Version 2.3.0
45+
## Version 2.3.0

src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/NewAzureAutomationWebhookTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void NewAzureAutomationWebhookByNameSuccessful()
5353
DateTimeOffset expiryTime = DateTimeOffset.Now.AddDays(1);
5454

5555
this.mockAutomationClient.Setup(
56-
f => f.CreateWebhook(resourceGroupName, accountName, name, runbookName, true, expiryTime, null));
56+
f => f.CreateWebhook(resourceGroupName, accountName, name, runbookName, true, expiryTime, null, null));
5757

5858
// Test
5959
this.cmdlet.ResourceGroupName = resourceGroupName;
@@ -67,7 +67,7 @@ public void NewAzureAutomationWebhookByNameSuccessful()
6767

6868
// Assert
6969
this.mockAutomationClient.Verify(
70-
f => f.CreateWebhook(resourceGroupName, accountName, name, runbookName, true, expiryTime, null),
70+
f => f.CreateWebhook(resourceGroupName, accountName, name, runbookName, true, expiryTime, null, null),
7171
Times.Once());
7272
}
7373
}

src/ResourceManager/Automation/Commands.Automation.Test/UnitTests/RegisterAzureAutomationScheduledRunbookTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void RegisterAzureAutomationScheduledRunbookSuccessfull()
5353
string runOn = "hybridWorkerGroup";
5454

5555
this.mockAutomationClient.Setup(
56-
f => f.RegisterScheduledRunbook(resourceGroupName, accountName, runbookName, scheduleName, null, runOn));
56+
f => f.RegisterScheduledRunbook(resourceGroupName, accountName, runbookName, scheduleName, null, null));
5757

5858
// Test
5959
this.cmdlet.ResourceGroupName = resourceGroupName;
@@ -63,7 +63,7 @@ public void RegisterAzureAutomationScheduledRunbookSuccessfull()
6363
this.cmdlet.ExecuteCmdlet();
6464

6565
// Assert
66-
this.mockAutomationClient.Verify(f => f.RegisterScheduledRunbook(resourceGroupName, accountName, runbookName, scheduleName, null, runOn), Times.Once());
66+
this.mockAutomationClient.Verify(f => f.RegisterScheduledRunbook(resourceGroupName, accountName, runbookName, scheduleName, null, null), Times.Once());
6767
}
6868
}
6969
}

src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationModule.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,17 @@ public class NewAzureAutomationModule : AzureAutomationBaseCmdlet
3939
/// </summary>
4040
[Parameter(Position = 3, Mandatory = true, ValueFromPipelineByPropertyName = true,
4141
HelpMessage = "The url to a module zip package.")]
42+
[Alias("ContentLink")]
4243
[ValidateNotNullOrEmpty]
43-
public Uri ContentLink { get; set; }
44+
public Uri ContentLinkUri { get; set; }
4445

4546
/// <summary>
4647
/// Execute this cmdlet.
4748
/// </summary>
4849
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
4950
protected override void AutomationProcessRecord()
5051
{
51-
var createdModule = this.AutomationClient.CreateModule(this.ResourceGroupName, this.AutomationAccountName, ContentLink, Name);
52+
var createdModule = this.AutomationClient.CreateModule(this.ResourceGroupName, this.AutomationAccountName, ContentLinkUri, Name);
5253
this.WriteObject(createdModule);
5354
}
5455
}

src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationWebhook.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ public class NewAzureAutomationWebhook : AzureAutomationBaseCmdlet
7070
[Parameter(Mandatory = false, HelpMessage = "Skip warning message about one-time viewable webhook URL")]
7171
public SwitchParameter Force { get; set; }
7272

73+
/// <summary>
74+
/// Gets or sets the optional hybrid agent friendly name upon which the runbook should be executed.
75+
/// </summary>
76+
[Parameter(Mandatory = false,
77+
HelpMessage = "Optional name of the hybrid agent which should execute the runbook")]
78+
[Alias("HybridWorker")]
79+
public string RunOn { get; set; }
80+
7381
/// <summary>
7482
/// Execute this cmdlet.
7583
/// </summary>
@@ -90,7 +98,8 @@ protected override void AutomationProcessRecord()
9098
this.RunbookName,
9199
this.IsEnabled,
92100
this.ExpiryTime,
93-
this.Parameters)));
101+
this.Parameters,
102+
this.RunOn)));
94103

95104
}
96105
}

src/ResourceManager/Automation/Commands.Automation/Cmdlet/RegisterAzureAutomationScheduledRunbook.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,22 @@ public class RegisterAzureAutomationScheduledRunbook : AzureAutomationBaseCmdlet
5454
/// <summary>
5555
/// Gets or sets the optional hybrid agent friendly name upon which the runbook should be executed.
5656
/// </summary>
57-
[Alias("HybridWorker")]
5857
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByRunbookNameAndScheduleName, Mandatory = false, ValueFromPipelineByPropertyName = true,
59-
HelpMessage = "The name of the hybrid runbook worker group.")]
58+
HelpMessage = "Optional name of the hybrid agent which should execute the runbook")]
59+
[Alias("HybridWorker")]
6060
public string RunOn { get; set; }
6161

6262
/// <summary>
6363
/// Execute this cmdlet.
6464
/// </summary>
6565
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
6666
protected override void AutomationProcessRecord()
67-
{
68-
var jobSchedule = this.AutomationClient.RegisterScheduledRunbook(
67+
{
68+
JobSchedule jobSchedule;
69+
70+
jobSchedule = this.AutomationClient.RegisterScheduledRunbook(
6971
this.ResourceGroupName, this.AutomationAccountName, this.RunbookName, this.ScheduleName, this.Parameters, this.RunOn);
70-
72+
7173
this.WriteObject(jobSchedule);
7274
}
7375
}

src/ResourceManager/Automation/Commands.Automation/Cmdlet/SetAzureAutomationModule.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class SetAzureAutomationModule : AzureAutomationBaseCmdlet
4040
/// </summary>
4141
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true,
4242
HelpMessage = "The url to module zip file package.")]
43+
[Alias("ContentLink")]
4344
public Uri ContentLinkUri { get; set; }
4445

4546
/// <summary>

src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientWebhook.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public Model.Webhook CreateWebhook(
3535
string runbookName,
3636
bool isEnabled,
3737
DateTimeOffset expiryTime,
38-
IDictionary runbookParameters)
38+
IDictionary runbookParameters,
39+
string runOn)
3940
{
4041
Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
4142
Requires.Argument("AutomationAccountName", automationAccountName).NotNull();
@@ -51,7 +52,8 @@ public Model.Webhook CreateWebhook(
5152
this.automationManagementClient
5253
.Webhooks.GenerateUri(
5354
resourceGroupName,
54-
automationAccountName).Uri
55+
automationAccountName).Uri,
56+
RunOn = runOn
5557
};
5658
if (runbookParameters != null)
5759
{

src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ Model.Webhook CreateWebhook(
149149
string runbookName,
150150
bool isEnabled,
151151
DateTimeOffset expiryTime,
152-
IDictionary parameters);
152+
IDictionary parameters,
153+
string runOn);
153154

154155
Model.Webhook GetWebhook(string resourceGroupName, string automationAccountName, string name);
155156

@@ -295,8 +296,8 @@ IEnumerable<JobStream> GetJobStream(string resourceGroupName, string automationA
295296
IEnumerable<JobSchedule> ListJobSchedulesByRunbookName(string resourceGroupName, string automationAccountName, string runbookName);
296297

297298
IEnumerable<JobSchedule> ListJobSchedulesByScheduleName(string resourceGroupName, string automationAccountName, string scheduleName);
298-
299-
JobSchedule RegisterScheduledRunbook(string resourceGroupName, string automationAccountName, string runbookName, string scheduleName, IDictionary parameters, string RunOn);
299+
300+
JobSchedule RegisterScheduledRunbook(string resourceGroupName, string automationAccountName, string runbookName, string scheduleName, IDictionary parameters, string runOn);
300301

301302
void UnregisterScheduledRunbook(string resourceGroupName, string automationAccountName, Guid jobScheduleId);
302303

@@ -311,4 +312,4 @@ IEnumerable<JobStream> GetJobStream(string resourceGroupName, string automationA
311312

312313
#endregion
313314
}
314-
}
315+
}

src/ResourceManager/Automation/Commands.Automation/Model/JobSchedule.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public JobSchedule(string resourceGroupName, string automationAccountName, Azure
4646
this.RunbookName = jobSchedule.Properties.Runbook.Name;
4747
this.ScheduleName = jobSchedule.Properties.Schedule.Name;
4848
this.Parameters = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
49-
this.RunOn = jobSchedule.Properties.RunOn;
49+
this.HybridWorker = jobSchedule.Properties.RunOn;
5050
foreach (var kvp in jobSchedule.Properties.Parameters.Where(kvp => 0 != String.Compare(kvp.Key, Constants.JobStartedByParameterName, CultureInfo.InvariantCulture,
5151
CompareOptions.IgnoreCase)))
5252
{
@@ -92,5 +92,10 @@ public JobSchedule()
9292
/// Gets or sets the runbook parameters.
9393
/// </summary>
9494
public Hashtable Parameters { get; set; }
95+
96+
/// <summary>
97+
/// Gets or sets the HybridWorker.
98+
/// </summary>
99+
public string HybridWorker { get; set; }
95100
}
96101
}

src/ResourceManager/Automation/Commands.Automation/Model/Webhook.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public Webhook(
6969

7070
this.RunbookName = webhook.Properties.Runbook.Name;
7171
this.WebhookURI = webhookUri;
72+
this.HybridWorker = webhook.Properties.RunOn;
7273
}
7374

7475
public string ResourceGroupName { get; set; }
@@ -94,5 +95,10 @@ public Webhook(
9495
public string RunbookName { get; set; }
9596

9697
public string WebhookURI { get; set; }
98+
99+
/// <summary>
100+
/// Gets or sets the HybridWorker.
101+
/// </summary>
102+
public string HybridWorker { get; set; }
97103
}
98104
}

0 commit comments

Comments
 (0)