Skip to content

Commit f1c9319

Browse files
committed
Fixing the JobSchedule Id exception
1 parent f34c546 commit f1c9319

10 files changed

+232
-117
lines changed

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

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

15-
using System;
16-
using System.Collections.Generic;
17-
using System.Linq;
18-
using System.Text;
19-
using System.Threading.Tasks;
2015
using Microsoft.Azure.Commands.Automation.Model;
2116
using Microsoft.Azure.Commands.Automation.Properties;
22-
using System.Collections;
23-
using System.Globalization;
2417
using System.Management.Automation;
2518
using System.Security.Permissions;
2619
using Microsoft.Azure.Commands.Automation.Common;
@@ -29,12 +22,12 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet
2922
{
3023
[Cmdlet(VerbsLifecycle.Start, "AzureRmAutomationDscNodeConfigurationDeployment", SupportsShouldProcess = true,
3124
DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)]
32-
[OutputType(typeof(Model.NodeConfigurationDeployment))]
25+
[OutputType(typeof(NodeConfigurationDeployment))]
3326
public class StartAzureAutomationDscNodeConfigurationDeployment : AzureAutomationBaseCmdlet
3427
{
3528

3629
/// <summary>
37-
/// Gets or sets the ndoe configuration name.
30+
/// Gets or sets the node configuration name.
3831
/// </summary>
3932
[Parameter(Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = AutomationCmdletParameterSets.ByAll,
4033
HelpMessage = "The node configuration name to be deployed.")]
@@ -79,40 +72,42 @@ public class StartAzureAutomationDscNodeConfigurationDeployment : AzureAutomatio
7972
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
8073
protected override void AutomationProcessRecord()
8174
{
82-
if (this.ParameterSetName == AutomationCmdletParameterSets.ByInputObject)
75+
// ReSharper disable once SwitchStatementMissingSomeCases
76+
switch (ParameterSetName)
8377
{
84-
if (ShouldProcess(NodeConfigurationName, VerbsLifecycle.Start))
85-
{
86-
if (Force || ShouldContinue(Resources.StartAzureAutomationNodeConfigurationWarning,
87-
Resources.StartAzureAutomationNodeConfigurationDescription))
78+
case AutomationCmdletParameterSets.ByInputObject:
79+
if (ShouldProcess(NodeConfigurationName, VerbsLifecycle.Start))
8880
{
89-
NodeConfigurationDeployment nodeConfigurationDeployment = this.AutomationClient.StartNodeConfigurationDeployment(
90-
this.InputObject.ResourceGroupName,
91-
this.InputObject.AutomationAccountName,
92-
this.InputObject.NodeConfigurationName,
93-
this.NodeName,
94-
this.Schedule);
81+
if (Force || ShouldContinue(Resources.StartAzureAutomationNodeConfigurationWarning,
82+
Resources.StartAzureAutomationNodeConfigurationDescription))
83+
{
84+
var nodeConfigurationDeployment = AutomationClient.StartNodeConfigurationDeployment(
85+
InputObject.ResourceGroupName,
86+
InputObject.AutomationAccountName,
87+
InputObject.NodeConfigurationName,
88+
NodeName,
89+
Schedule);
9590

96-
this.WriteObject(nodeConfigurationDeployment);
91+
WriteObject(nodeConfigurationDeployment);
92+
}
9793
}
98-
}
99-
}
100-
else if (this.ParameterSetName == AutomationCmdletParameterSets.ByAll)
101-
{
102-
if (ShouldProcess(NodeConfigurationName, VerbsLifecycle.Start))
103-
{
104-
if (Force || ShouldContinue(Resources.StartAzureAutomationNodeConfigurationWarning,
105-
Resources.StartAzureAutomationNodeConfigurationDescription))
94+
break;
95+
case AutomationCmdletParameterSets.ByAll:
96+
if (ShouldProcess(NodeConfigurationName, VerbsLifecycle.Start))
10697
{
107-
NodeConfigurationDeployment nodeConfigurationDeployment = this.AutomationClient.StartNodeConfigurationDeployment(this.ResourceGroupName,
108-
this.AutomationAccountName,
109-
this.NodeConfigurationName,
110-
this.NodeName,
111-
this.Schedule);
98+
if (Force || ShouldContinue(Resources.StartAzureAutomationNodeConfigurationWarning,
99+
Resources.StartAzureAutomationNodeConfigurationDescription))
100+
{
101+
var nodeConfigurationDeployment = AutomationClient.StartNodeConfigurationDeployment(ResourceGroupName,
102+
AutomationAccountName,
103+
NodeConfigurationName,
104+
NodeName,
105+
Schedule);
112106

113-
this.WriteObject(nodeConfigurationDeployment);
107+
WriteObject(nodeConfigurationDeployment);
108+
}
114109
}
115-
}
110+
break;
116111
}
117112
}
118113
}

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

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,15 +1358,15 @@ public NodeConfigurationDeployment StartNodeConfigurationDeployment(string resou
13581358
}).JobSchedule;
13591359
}
13601360

1361-
return new NodeConfigurationDeployment(resourceGroupName, automationAccountName, nodeConfiguraionName, job);
1361+
return new NodeConfigurationDeployment(resourceGroupName, automationAccountName, nodeConfiguraionName, job, jobSchedule);
13621362
}
13631363

13641364
public NodeConfigurationDeployment GetNodeConfigurationDeployment(string resourceGroupName, string automationAccountName, Guid jobId)
13651365
{
13661366
Requires.Argument("ResourceGroupName", resourceGroupName).NotNullOrEmpty();
13671367
Requires.Argument("AutomationAccountName", automationAccountName).NotNullOrEmpty().ValidAutomationAccountName();
13681368

1369-
var nodesList = new List<IList<string>>();
1369+
var nodeLists = new List<IList<string>>();
13701370
var nodesStatus = new List<IDictionary<string, string>>();
13711371
Job job = null;
13721372
string nodeConfigurationName = null;
@@ -1375,24 +1375,18 @@ public NodeConfigurationDeployment GetNodeConfigurationDeployment(string resourc
13751375
{
13761376
job = this.automationManagementClient.Jobs.Get(resourceGroupName, automationAccountName, jobId).Job;
13771377

1378-
nodeConfigurationName = PowerShellJsonConverter.Serialize(job.Properties.Parameters["NodeConfigurationName"]);
1378+
nodeConfigurationName = PowerShellJsonConverter
1379+
.Deserialize(job.Properties.Parameters["NodeConfigurationName"]).ToString();
13791380

13801381
// Fetch Nodes from the Param List.
13811382
var nodesJsonArray = PowerShellJsonConverter.Serialize(job.Properties.Parameters["ListOfNodeNames"]);
1382-
var stringArray = Newtonsoft.Json.Linq.JArray.Parse(JsonConvert.DeserializeObject<string>(nodesJsonArray));
1383+
var stringArray =
1384+
Newtonsoft.Json.Linq.JArray.Parse(JsonConvert.DeserializeObject<string>(nodesJsonArray));
13831385

1384-
foreach (var jt in stringArray)
1385-
{
1386-
var nodes = new List<string>();
1387-
foreach (var node in jt)
1388-
{
1389-
nodes.Add(node.ToString());
1390-
}
1391-
nodesList.Add(nodes);
1392-
}
1386+
nodeLists.AddRange(stringArray.Select(jt => jt.Select(node => node.ToString()).ToList()));
13931387

13941388
// Fetch the status of each node.
1395-
foreach (var nodeList in nodesList)
1389+
foreach (var nodeList in nodeLists)
13961390
{
13971391
IDictionary<string, string> dscNodeGroup = new Dictionary<string, string>();
13981392
foreach (var node in nodeList)
@@ -1401,14 +1395,18 @@ public NodeConfigurationDeployment GetNodeConfigurationDeployment(string resourc
14011395
IEnumerable<Model.DscNode> dscNodes;
14021396
do
14031397
{
1404-
dscNodes = this.ListDscNodesByName(resourceGroupName, automationAccountName, node, null, ref nextLink);
1398+
dscNodes = this.ListDscNodesByName(resourceGroupName, automationAccountName, node, null,
1399+
ref nextLink);
14051400
} while (!string.IsNullOrEmpty(nextLink));
1406-
var dscNode = dscNodes.First();
1407-
dscNodeGroup.Add(node, dscNode.Status);
1401+
dscNodeGroup.Add(node, dscNodes.First().Status);
14081402
}
14091403
nodesStatus.Add(dscNodeGroup);
14101404
}
14111405
}
1406+
else
1407+
{
1408+
throw new ArgumentNullException(nameof(jobId), Resources.NoJobIdPassedToGetJobInformationCall);
1409+
}
14121410
return new NodeConfigurationDeployment(resourceGroupName, automationAccountName, nodeConfigurationName, job, nodesStatus);
14131411
}
14141412

@@ -1474,19 +1472,12 @@ public IEnumerable<NodeConfigurationDeployment> ListNodeConfigurationDeployment(
14741472

14751473
public IEnumerable<NodeConfigurationDeploymentSchedule> ListNodeConfigurationDeploymentSchedules(string resourceGroupName, string automationAccountName, ref string nextLink)
14761474
{
1477-
JobScheduleListResponse response;
14781475
const string runbookName = "Deploy-NodeConfigurationToAutomationDscNodesV1";
14791476

1480-
if (string.IsNullOrEmpty(nextLink))
1481-
{
1482-
response = this.automationManagementClient.JobSchedules.List(resourceGroupName, automationAccountName);
1483-
}
1484-
else
1485-
{
1486-
response = this.automationManagementClient.JobSchedules.ListNext(nextLink);
1487-
}
1477+
var response = string.IsNullOrEmpty(nextLink) ? this.automationManagementClient.JobSchedules.List(resourceGroupName, automationAccountName) : this.automationManagementClient.JobSchedules.ListNext(nextLink);
14881478

14891479
nextLink = response.NextLink;
1480+
14901481
return response.JobSchedules.Where(js => string.Equals(js.Properties.Runbook.Name, runbookName, StringComparison.OrdinalIgnoreCase)).
14911482
Select(js => new NodeConfigurationDeploymentSchedule(resourceGroupName, automationAccountName, js));
14921483
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,6 @@ internal static class AutomationCmdletParameterSets
165165
/// <summary>
166166
/// Parameter set for ByInputObject
167167
/// </summary>
168-
internal const string ByInputObject = "ByByInputObject";
168+
internal const string ByInputObject = "ByInputObject";
169169
}
170170
}

0 commit comments

Comments
 (0)