Skip to content

Commit 7b13c1c

Browse files
Merge pull request #4 from balukambala/dev
Node configuration - rollup status
2 parents 890d549 + e3d386e commit 7b13c1c

9 files changed

+180
-26
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,30 @@ public class GetAzureAutomationDscCompilationJob : AzureAutomationBaseCmdlet
4040
/// <summary>
4141
/// Gets or sets the runbook name of the job.
4242
/// </summary>
43-
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = true, HelpMessage = "The configuration name of the job.")]
43+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = true, HelpMessage = "The configuration name of the compilation job.")]
4444
[Alias("Name")]
4545
public string ConfigurationName { get; set; }
4646

4747
/// <summary>
4848
/// Gets or sets the status of a job.
4949
/// </summary>
50-
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = false, HelpMessage = "The configuration name of the job.")]
50+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = false, HelpMessage = "Filter jobs based on their status.")]
5151
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAll, Mandatory = false, HelpMessage = "Filter jobs based on their status.")]
5252
[ValidateSet("Completed", "Failed", "Queued", "Starting", "Resuming", "Running", "Stopped", "Stopping", "Suspended", "Suspending", "Activating")]
5353
public string Status { get; set; }
5454

5555
/// <summary>
5656
/// Gets or sets the start time filter.
5757
/// </summary>
58-
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = false, HelpMessage = "The configuration name of the job.")]
59-
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAll, Mandatory = false, HelpMessage = "Filter jobs so that job start time >= StartTime.")]
58+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = false, HelpMessage = "Filter compilation jobs so that the compilation job start time >= StartTime.")]
59+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAll, Mandatory = false, HelpMessage = "Filter compilation jobs so that the compilation job start time >= StartTime.")]
6060
public DateTimeOffset? StartTime { get; set; }
6161

6262
/// <summary>
6363
/// Gets or sets the end time filter.
6464
/// </summary>
65-
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = false, HelpMessage = "The configuration name of the job.")]
66-
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAll, Mandatory = false, HelpMessage = "Filter jobs so that job end time <= EndTime.")]
65+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = false, HelpMessage = "Filter compilation jobs so that the compilation job end time <= EndTime.")]
66+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAll, Mandatory = false, HelpMessage = "Filter compilation jobs so that the compilation job end time <= EndTime.")]
6767
public DateTimeOffset? EndTime { get; set; }
6868

6969
/// <summary>

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ public class GetAzureAutomationDscCompilationJobOutput : AzureAutomationBaseCmdl
3434
/// Gets or sets the job id
3535
/// </summary>
3636
[Alias("JobId")]
37-
[Parameter(Mandatory = true, Position = 2, ValueFromPipelineByPropertyName = true, HelpMessage = "The job Id")]
37+
[Parameter(Mandatory = true, Position = 2, ValueFromPipelineByPropertyName = true, HelpMessage = "The compilation job Id")]
3838
public Guid Id { get; set; }
3939

40-
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The stream type. Defaults to Any.")]
40+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The stream type.")]
41+
[ValidateSet("Output", "Warning", "Error", "Debug", "Verbose", "Any")]
4142
public StreamType Stream { get; set; }
4243

4344
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Retrieves output created after this time")]
@@ -49,6 +50,11 @@ public class GetAzureAutomationDscCompilationJobOutput : AzureAutomationBaseCmdl
4950
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
5051
protected override void AutomationExecuteCmdlet()
5152
{
53+
if (Stream.Equals(StreamType.Progress))
54+
{
55+
Stream = StreamType.Any;
56+
}
57+
5258
var ret = this.AutomationClient.GetDscCompilationJobStream(this.ResourceGroupName, this.AutomationAccountName, this.Id, this.StartTime, this.Stream.ToString());
5359

5460
this.GenerateCmdletOutput(ret);

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ public class GetAzureAutomationDscNode : AzureAutomationBaseCmdlet
5959
[ValidateNotNullOrEmpty]
6060
public string NodeConfigurationName { get; set; }
6161

62+
/// <summary>
63+
/// Gets or sets the configuration name.
64+
/// </summary>
65+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = true, HelpMessage = "The configuration name.")]
66+
[ValidateNotNullOrEmpty]
67+
public string ConfigurationName { get; set; }
68+
6269
/// <summary>
6370
/// Execute this cmdlet.
6471
/// </summary>
@@ -90,6 +97,14 @@ public override void ExecuteCmdlet()
9097
this.NodeConfigurationName,
9198
this.Status);
9299
}
100+
else if (this.ParameterSetName == AutomationCmdletParameterSets.ByConfigurationName)
101+
{
102+
ret = this.AutomationClient.ListDscNodesByConfiguration(
103+
this.ResourceGroupName,
104+
this.AutomationAccountName,
105+
this.ConfigurationName,
106+
this.Status);
107+
}
93108
else
94109
{
95110
// ByAll

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ public class GetAzureAutomationDscNodeConfiguration : AzureAutomationBaseCmdlet
4343
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = true, HelpMessage = "The configuration name.")]
4444
public string ConfigurationName { get; set; }
4545

46+
/// <summary>
47+
/// Gets or sets the status of a job.
48+
/// </summary>
49+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = false, HelpMessage = "Filter node configurations by RollupStatus.")]
50+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByNodeConfigurationName, Mandatory = false, HelpMessage = "Filter node configurations by RollupStatus.")]
51+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAll, Mandatory = false, HelpMessage = "Filter node configurations by RollupStatus.")]
52+
[ValidateSet("Good", "Bad")]
53+
public string RollupStatus { get; set; }
54+
4655
/// <summary>
4756
/// Execute this cmdlet.
4857
/// </summary>
@@ -54,17 +63,17 @@ protected override void AutomationExecuteCmdlet()
5463
if (this.Name != null && !Guid.Empty.Equals(this.Name))
5564
{
5665
// ByJobId
57-
nodeConfigurations = new List<NodeConfiguration> { this.AutomationClient.GetNodeConfiguration(this.ResourceGroupName, this.AutomationAccountName, this.Name) };
66+
nodeConfigurations = new List<NodeConfiguration> { this.AutomationClient.GetNodeConfiguration(this.ResourceGroupName, this.AutomationAccountName, this.Name, this.RollupStatus) };
5867
}
5968
else if (this.ConfigurationName != null)
6069
{
6170
// ByConfiguration
62-
nodeConfigurations = this.AutomationClient.ListNodeConfigurationsByConfigurationName(this.ResourceGroupName, this.AutomationAccountName, this.ConfigurationName);
71+
nodeConfigurations = this.AutomationClient.ListNodeConfigurationsByConfigurationName(this.ResourceGroupName, this.AutomationAccountName, this.ConfigurationName, this.RollupStatus);
6372
}
6473
else
6574
{
6675
// ByAll
67-
nodeConfigurations = this.AutomationClient.ListNodeConfigurations(this.ResourceGroupName, this.AutomationAccountName);
76+
nodeConfigurations = this.AutomationClient.ListNodeConfigurations(this.ResourceGroupName, this.AutomationAccountName, this.RollupStatus);
6877
}
6978

7079
this.WriteObject(nodeConfigurations, true);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet
2525
/// <summary>
2626
/// starts azure automation compilation job
2727
/// </summary>
28-
[Cmdlet(VerbsLifecycle.Start, "AzureAutomationDscCompilationJob", DefaultParameterSetName = AutomationCmdletParameterSets.ByConfigurationName)]
28+
[Cmdlet(VerbsLifecycle.Start, "AzureAutomationDscCompilationJob")]
2929
[OutputType(typeof(CompilationJob))]
3030
public class StartAzureAutomationDscCompilationJob : AzureAutomationBaseCmdlet
3131
{
@@ -38,7 +38,7 @@ public class StartAzureAutomationDscCompilationJob : AzureAutomationBaseCmdlet
3838
/// <summary>
3939
/// Gets or sets the configuration parameters.
4040
/// </summary>
41-
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The configuration parameters.")]
41+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The compilation job parameters.")]
4242
public IDictionary Parameters { get; set; }
4343

4444
/// <summary>

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

Lines changed: 120 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,46 @@ public Model.DscNode GetDscNodeById(
459459

460460
return dscNodes.Select(dscNode => new Model.DscNode(resourceGroupName, automationAccountName, dscNode));
461461
}
462-
462+
463+
public IEnumerable<Model.DscNode> ListDscNodesByConfiguration(
464+
string resourceGroupName,
465+
string automationAccountName,
466+
string configurationName,
467+
string status)
468+
{
469+
Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
470+
Requires.Argument("AutomationAccountName", automationAccountName).NotNull();
471+
Requires.Argument("ConfigurationName", configurationName).NotNull();
472+
473+
IEnumerable<Model.DscNode> listOfNodes = Enumerable.Empty<Model.DscNode>();
474+
475+
// first get the list of node configurations for the given configuration
476+
IEnumerable<Model.NodeConfiguration> listOfNodeConfigurations = this.EnumerateNodeConfigurationsByConfigurationName(
477+
resourceGroupName,
478+
automationAccountName,
479+
configurationName);
480+
481+
IEnumerable<Model.DscNode> listOfNodesForGivenNodeConfiguration;
482+
483+
// for each nodeconfiguration, get the list of nodes and concatenate
484+
foreach (var nodeConfiguration in listOfNodeConfigurations)
485+
{
486+
listOfNodesForGivenNodeConfiguration =
487+
this.ListDscNodesByNodeConfiguration(
488+
resourceGroupName,
489+
automationAccountName,
490+
nodeConfiguration.Name,
491+
status);
492+
493+
if (listOfNodesForGivenNodeConfiguration != null)
494+
{
495+
listOfNodes = listOfNodes.Concat(listOfNodesForGivenNodeConfiguration);
496+
}
497+
}
498+
499+
return listOfNodes;
500+
}
501+
463502
public IEnumerable<Model.DscNode> ListDscNodes(
464503
string resourceGroupName,
465504
string automationAccountName,
@@ -786,6 +825,10 @@ public Model.CompilationJob StartCompilationJob(string resourceGroupName, string
786825
{
787826
listParams.StreamType = streamType;
788827
}
828+
else
829+
{
830+
listParams.StreamType = StreamType.Any.ToString();
831+
}
789832

790833
var jobStreams = this.automationManagementClient.JobStreams.List(resourceGroupName, automationAccountName, jobId, listParams).JobStreams;
791834
return jobStreams.Select(stream => this.CreateJobStreamFromJobStreamModel(stream, automationAccountName, jobId)).ToList();
@@ -795,7 +838,7 @@ public Model.CompilationJob StartCompilationJob(string resourceGroupName, string
795838
#endregion
796839

797840
#region node configuration
798-
public Model.NodeConfiguration GetNodeConfiguration(string resourceGroupName, string automationAccountName, string nodeConfigurationName)
841+
public Model.NodeConfiguration GetNodeConfiguration(string resourceGroupName, string automationAccountName, string nodeConfigurationName, string rollupStatus)
799842
{
800843
using (var request = new RequestSettings(this.automationManagementClient))
801844
{
@@ -806,11 +849,18 @@ public Model.NodeConfiguration GetNodeConfiguration(string resourceGroupName, st
806849
string.Format(CultureInfo.CurrentCulture, Resources.NodeConfigurationNotFound, nodeConfigurationName));
807850
}
808851

809-
return new Model.NodeConfiguration(automationAccountName, nodeConfiguration);
852+
string computedRollupStatus = GetRollupStatus(resourceGroupName, automationAccountName, nodeConfigurationName);
853+
854+
if (string.IsNullOrEmpty(rollupStatus) || (rollupStatus != null && computedRollupStatus.Equals(rollupStatus)))
855+
{
856+
return new Model.NodeConfiguration(automationAccountName, nodeConfiguration, computedRollupStatus);
857+
}
858+
859+
return null;
810860
}
811861
}
812862

813-
public IEnumerable<Model.NodeConfiguration> ListNodeConfigurationsByConfigurationName(string resourceGroupName, string automationAccountName, string configurationName)
863+
public IEnumerable<Model.NodeConfiguration> ListNodeConfigurationsByConfigurationName(string resourceGroupName, string automationAccountName, string configurationName, string rollupStatus)
814864
{
815865
using (var request = new RequestSettings(this.automationManagementClient))
816866
{
@@ -829,12 +879,22 @@ public Model.NodeConfiguration GetNodeConfiguration(string resourceGroupName, st
829879
return new ResponseWithSkipToken<AutomationManagement.Models.DscNodeConfiguration>(response, response.DscNodeConfigurations);
830880
});
831881

882+
var nodeConfigurations = new List<Model.NodeConfiguration>();
883+
foreach (var nodeConfiguration in nodeConfigModels)
884+
{
885+
string computedRollupStatus = GetRollupStatus(resourceGroupName, automationAccountName, nodeConfiguration.Name);
886+
887+
if (string.IsNullOrEmpty(rollupStatus) || (rollupStatus != null && computedRollupStatus.Equals(rollupStatus)))
888+
{
889+
nodeConfigurations.Add(new Model.NodeConfiguration(automationAccountName, nodeConfiguration, computedRollupStatus));
890+
}
891+
}
832892

833-
return nodeConfigModels.Select(nodeConfigModel => new Commands.Automation.Model.NodeConfiguration(automationAccountName, nodeConfigModel));
893+
return nodeConfigurations.AsEnumerable<Model.NodeConfiguration>();
834894
}
835895
}
836896

837-
public IEnumerable<Model.NodeConfiguration> ListNodeConfigurations(string resourceGroupName, string automationAccountName)
897+
public IEnumerable<Model.NodeConfiguration> ListNodeConfigurations(string resourceGroupName, string automationAccountName, string rollupStatus)
838898
{
839899
using (var request = new RequestSettings(this.automationManagementClient))
840900
{
@@ -851,14 +911,67 @@ public Model.NodeConfiguration GetNodeConfiguration(string resourceGroupName, st
851911
return new ResponseWithSkipToken<AutomationManagement.Models.DscNodeConfiguration>(response, response.DscNodeConfigurations);
852912
});
853913

914+
var nodeConfigurations = new List<Model.NodeConfiguration>();
915+
foreach (var nodeConfiguration in nodeConfigModels)
916+
{
917+
string computedRollupStatus = GetRollupStatus(resourceGroupName, automationAccountName, nodeConfiguration.Name);
854918

855-
return nodeConfigModels.Select(nodeConfigModel => new Model.NodeConfiguration(automationAccountName, nodeConfigModel));
919+
if (string.IsNullOrEmpty(rollupStatus) || (rollupStatus != null && computedRollupStatus.Equals(rollupStatus)))
920+
{
921+
nodeConfigurations.Add(new Model.NodeConfiguration(automationAccountName, nodeConfiguration, computedRollupStatus));
922+
}
923+
}
924+
925+
return nodeConfigurations.AsEnumerable<Model.NodeConfiguration>();
856926
}
857927
}
858928

859929
#endregion
860930

861931
#region privatemethods
932+
/// <summary>
933+
/// Enumerate the list of NodeConfigurations for given configuration - without any rollup status
934+
/// </summary>
935+
/// <param name="resourceGroupName">Resource group name</param>
936+
/// <param name="automationAccountName">Automation account</param>
937+
/// <param name="configurationName">Name of configuration</param>
938+
/// <returns>List of NodeConfigurations</returns>
939+
private IEnumerable<Model.NodeConfiguration> EnumerateNodeConfigurationsByConfigurationName(string resourceGroupName, string automationAccountName, string configurationName)
940+
{
941+
using (var request = new RequestSettings(this.automationManagementClient))
942+
{
943+
IEnumerable<AutomationManagement.Models.DscNodeConfiguration> nodeConfigModels;
944+
945+
nodeConfigModels = AutomationManagementClient.ContinuationTokenHandler(
946+
skipToken =>
947+
{
948+
var response = this.automationManagementClient.NodeConfigurations.List(
949+
resourceGroupName,
950+
automationAccountName,
951+
new AutomationManagement.Models.DscNodeConfigurationListParameters
952+
{
953+
ConfigurationName = configurationName
954+
});
955+
return new ResponseWithSkipToken<AutomationManagement.Models.DscNodeConfiguration>(response, response.DscNodeConfigurations);
956+
});
957+
958+
return nodeConfigModels.Select(nodeConfigModel => new Commands.Automation.Model.NodeConfiguration(automationAccountName, nodeConfigModel, null));
959+
}
960+
}
961+
962+
private string GetRollupStatus(string resourceGroupName, string automationAccountName, string nodeConfigurationName)
963+
{
964+
var nodes = this.ListDscNodesByNodeConfiguration(resourceGroupName, automationAccountName, nodeConfigurationName, null);
965+
foreach (var node in nodes)
966+
{
967+
if (node.Status.Equals("Not Compliant") || node.Status.Equals("Failed") || node.Status.Equals("Unresponsive"))
968+
{
969+
return "Bad";
970+
}
971+
}
972+
973+
return "Good";
974+
}
862975

863976
private string FormatDateTime(DateTimeOffset dateTime)
864977
{

0 commit comments

Comments
 (0)