Skip to content

Commit

Permalink
Merge pull request #4 from balukambala/dev
Browse files Browse the repository at this point in the history
Node configuration - rollup status
  • Loading branch information
safeermohammed committed Apr 15, 2015
2 parents 890d549 + e3d386e commit 7b13c1c
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,30 @@ public class GetAzureAutomationDscCompilationJob : AzureAutomationBaseCmdlet
/// <summary>
/// Gets or sets the runbook name of the job.
/// </summary>
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = true, HelpMessage = "The configuration name of the job.")]
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = true, HelpMessage = "The configuration name of the compilation job.")]
[Alias("Name")]
public string ConfigurationName { get; set; }

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

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

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

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ public class GetAzureAutomationDscCompilationJobOutput : AzureAutomationBaseCmdl
/// Gets or sets the job id
/// </summary>
[Alias("JobId")]
[Parameter(Mandatory = true, Position = 2, ValueFromPipelineByPropertyName = true, HelpMessage = "The job Id")]
[Parameter(Mandatory = true, Position = 2, ValueFromPipelineByPropertyName = true, HelpMessage = "The compilation job Id")]
public Guid Id { get; set; }

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

[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Retrieves output created after this time")]
Expand All @@ -49,6 +50,11 @@ public class GetAzureAutomationDscCompilationJobOutput : AzureAutomationBaseCmdl
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
protected override void AutomationExecuteCmdlet()
{
if (Stream.Equals(StreamType.Progress))
{
Stream = StreamType.Any;
}

var ret = this.AutomationClient.GetDscCompilationJobStream(this.ResourceGroupName, this.AutomationAccountName, this.Id, this.StartTime, this.Stream.ToString());

this.GenerateCmdletOutput(ret);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ public class GetAzureAutomationDscNode : AzureAutomationBaseCmdlet
[ValidateNotNullOrEmpty]
public string NodeConfigurationName { get; set; }

/// <summary>
/// Gets or sets the configuration name.
/// </summary>
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = true, HelpMessage = "The configuration name.")]
[ValidateNotNullOrEmpty]
public string ConfigurationName { get; set; }

/// <summary>
/// Execute this cmdlet.
/// </summary>
Expand Down Expand Up @@ -90,6 +97,14 @@ public override void ExecuteCmdlet()
this.NodeConfigurationName,
this.Status);
}
else if (this.ParameterSetName == AutomationCmdletParameterSets.ByConfigurationName)
{
ret = this.AutomationClient.ListDscNodesByConfiguration(
this.ResourceGroupName,
this.AutomationAccountName,
this.ConfigurationName,
this.Status);
}
else
{
// ByAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ public class GetAzureAutomationDscNodeConfiguration : AzureAutomationBaseCmdlet
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = true, HelpMessage = "The configuration name.")]
public string ConfigurationName { get; set; }

/// <summary>
/// Gets or sets the status of a job.
/// </summary>
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = false, HelpMessage = "Filter node configurations by RollupStatus.")]
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByNodeConfigurationName, Mandatory = false, HelpMessage = "Filter node configurations by RollupStatus.")]
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAll, Mandatory = false, HelpMessage = "Filter node configurations by RollupStatus.")]
[ValidateSet("Good", "Bad")]
public string RollupStatus { get; set; }

/// <summary>
/// Execute this cmdlet.
/// </summary>
Expand All @@ -54,17 +63,17 @@ protected override void AutomationExecuteCmdlet()
if (this.Name != null && !Guid.Empty.Equals(this.Name))
{
// ByJobId
nodeConfigurations = new List<NodeConfiguration> { this.AutomationClient.GetNodeConfiguration(this.ResourceGroupName, this.AutomationAccountName, this.Name) };
nodeConfigurations = new List<NodeConfiguration> { this.AutomationClient.GetNodeConfiguration(this.ResourceGroupName, this.AutomationAccountName, this.Name, this.RollupStatus) };
}
else if (this.ConfigurationName != null)
{
// ByConfiguration
nodeConfigurations = this.AutomationClient.ListNodeConfigurationsByConfigurationName(this.ResourceGroupName, this.AutomationAccountName, this.ConfigurationName);
nodeConfigurations = this.AutomationClient.ListNodeConfigurationsByConfigurationName(this.ResourceGroupName, this.AutomationAccountName, this.ConfigurationName, this.RollupStatus);
}
else
{
// ByAll
nodeConfigurations = this.AutomationClient.ListNodeConfigurations(this.ResourceGroupName, this.AutomationAccountName);
nodeConfigurations = this.AutomationClient.ListNodeConfigurations(this.ResourceGroupName, this.AutomationAccountName, this.RollupStatus);
}

this.WriteObject(nodeConfigurations, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet
/// <summary>
/// starts azure automation compilation job
/// </summary>
[Cmdlet(VerbsLifecycle.Start, "AzureAutomationDscCompilationJob", DefaultParameterSetName = AutomationCmdletParameterSets.ByConfigurationName)]
[Cmdlet(VerbsLifecycle.Start, "AzureAutomationDscCompilationJob")]
[OutputType(typeof(CompilationJob))]
public class StartAzureAutomationDscCompilationJob : AzureAutomationBaseCmdlet
{
Expand All @@ -38,7 +38,7 @@ public class StartAzureAutomationDscCompilationJob : AzureAutomationBaseCmdlet
/// <summary>
/// Gets or sets the configuration parameters.
/// </summary>
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The configuration parameters.")]
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The compilation job parameters.")]
public IDictionary Parameters { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,46 @@ public Model.AgentRegistration GetAgentRegistration(string resourceGroupName, st

return dscNodes.Select(dscNode => new Model.DscNode(resourceGroupName, automationAccountName, dscNode));
}


public IEnumerable<Model.DscNode> ListDscNodesByConfiguration(
string resourceGroupName,
string automationAccountName,
string configurationName,
string status)
{
Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
Requires.Argument("AutomationAccountName", automationAccountName).NotNull();
Requires.Argument("ConfigurationName", configurationName).NotNull();

IEnumerable<Model.DscNode> listOfNodes = Enumerable.Empty<Model.DscNode>();

// first get the list of node configurations for the given configuration
IEnumerable<Model.NodeConfiguration> listOfNodeConfigurations = this.EnumerateNodeConfigurationsByConfigurationName(
resourceGroupName,
automationAccountName,
configurationName);

IEnumerable<Model.DscNode> listOfNodesForGivenNodeConfiguration;

// for each nodeconfiguration, get the list of nodes and concatenate
foreach (var nodeConfiguration in listOfNodeConfigurations)
{
listOfNodesForGivenNodeConfiguration =
this.ListDscNodesByNodeConfiguration(
resourceGroupName,
automationAccountName,
nodeConfiguration.Name,
status);

if (listOfNodesForGivenNodeConfiguration != null)
{
listOfNodes = listOfNodes.Concat(listOfNodesForGivenNodeConfiguration);
}
}

return listOfNodes;
}

public IEnumerable<Model.DscNode> ListDscNodes(
string resourceGroupName,
string automationAccountName,
Expand Down Expand Up @@ -786,6 +825,10 @@ public IEnumerable<Model.JobStream> GetDscCompilationJobStream(string resourceGr
{
listParams.StreamType = streamType;
}
else
{
listParams.StreamType = StreamType.Any.ToString();
}

var jobStreams = this.automationManagementClient.JobStreams.List(resourceGroupName, automationAccountName, jobId, listParams).JobStreams;
return jobStreams.Select(stream => this.CreateJobStreamFromJobStreamModel(stream, automationAccountName, jobId)).ToList();
Expand All @@ -795,7 +838,7 @@ public IEnumerable<Model.JobStream> GetDscCompilationJobStream(string resourceGr
#endregion

#region node configuration
public Model.NodeConfiguration GetNodeConfiguration(string resourceGroupName, string automationAccountName, string nodeConfigurationName)
public Model.NodeConfiguration GetNodeConfiguration(string resourceGroupName, string automationAccountName, string nodeConfigurationName, string rollupStatus)
{
using (var request = new RequestSettings(this.automationManagementClient))
{
Expand All @@ -806,11 +849,18 @@ public Model.NodeConfiguration GetNodeConfiguration(string resourceGroupName, st
string.Format(CultureInfo.CurrentCulture, Resources.NodeConfigurationNotFound, nodeConfigurationName));
}

return new Model.NodeConfiguration(automationAccountName, nodeConfiguration);
string computedRollupStatus = GetRollupStatus(resourceGroupName, automationAccountName, nodeConfigurationName);

if (string.IsNullOrEmpty(rollupStatus) || (rollupStatus != null && computedRollupStatus.Equals(rollupStatus)))
{
return new Model.NodeConfiguration(automationAccountName, nodeConfiguration, computedRollupStatus);
}

return null;
}
}

public IEnumerable<Model.NodeConfiguration> ListNodeConfigurationsByConfigurationName(string resourceGroupName, string automationAccountName, string configurationName)
public IEnumerable<Model.NodeConfiguration> ListNodeConfigurationsByConfigurationName(string resourceGroupName, string automationAccountName, string configurationName, string rollupStatus)
{
using (var request = new RequestSettings(this.automationManagementClient))
{
Expand All @@ -829,12 +879,22 @@ public IEnumerable<Model.NodeConfiguration> ListNodeConfigurationsByConfiguratio
return new ResponseWithSkipToken<AutomationManagement.Models.DscNodeConfiguration>(response, response.DscNodeConfigurations);
});

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

if (string.IsNullOrEmpty(rollupStatus) || (rollupStatus != null && computedRollupStatus.Equals(rollupStatus)))
{
nodeConfigurations.Add(new Model.NodeConfiguration(automationAccountName, nodeConfiguration, computedRollupStatus));
}
}

return nodeConfigModels.Select(nodeConfigModel => new Commands.Automation.Model.NodeConfiguration(automationAccountName, nodeConfigModel));
return nodeConfigurations.AsEnumerable<Model.NodeConfiguration>();
}
}

public IEnumerable<Model.NodeConfiguration> ListNodeConfigurations(string resourceGroupName, string automationAccountName)
public IEnumerable<Model.NodeConfiguration> ListNodeConfigurations(string resourceGroupName, string automationAccountName, string rollupStatus)
{
using (var request = new RequestSettings(this.automationManagementClient))
{
Expand All @@ -851,14 +911,67 @@ public IEnumerable<Model.NodeConfiguration> ListNodeConfigurations(string resour
return new ResponseWithSkipToken<AutomationManagement.Models.DscNodeConfiguration>(response, response.DscNodeConfigurations);
});

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

return nodeConfigModels.Select(nodeConfigModel => new Model.NodeConfiguration(automationAccountName, nodeConfigModel));
if (string.IsNullOrEmpty(rollupStatus) || (rollupStatus != null && computedRollupStatus.Equals(rollupStatus)))
{
nodeConfigurations.Add(new Model.NodeConfiguration(automationAccountName, nodeConfiguration, computedRollupStatus));
}
}

return nodeConfigurations.AsEnumerable<Model.NodeConfiguration>();
}
}

#endregion

#region privatemethods
/// <summary>
/// Enumerate the list of NodeConfigurations for given configuration - without any rollup status
/// </summary>
/// <param name="resourceGroupName">Resource group name</param>
/// <param name="automationAccountName">Automation account</param>
/// <param name="configurationName">Name of configuration</param>
/// <returns>List of NodeConfigurations</returns>
private IEnumerable<Model.NodeConfiguration> EnumerateNodeConfigurationsByConfigurationName(string resourceGroupName, string automationAccountName, string configurationName)
{
using (var request = new RequestSettings(this.automationManagementClient))
{
IEnumerable<AutomationManagement.Models.DscNodeConfiguration> nodeConfigModels;

nodeConfigModels = AutomationManagementClient.ContinuationTokenHandler(
skipToken =>
{
var response = this.automationManagementClient.NodeConfigurations.List(
resourceGroupName,
automationAccountName,
new AutomationManagement.Models.DscNodeConfigurationListParameters
{
ConfigurationName = configurationName
});
return new ResponseWithSkipToken<AutomationManagement.Models.DscNodeConfiguration>(response, response.DscNodeConfigurations);
});

return nodeConfigModels.Select(nodeConfigModel => new Commands.Automation.Model.NodeConfiguration(automationAccountName, nodeConfigModel, null));
}
}

private string GetRollupStatus(string resourceGroupName, string automationAccountName, string nodeConfigurationName)
{
var nodes = this.ListDscNodesByNodeConfiguration(resourceGroupName, automationAccountName, nodeConfigurationName, null);
foreach (var node in nodes)
{
if (node.Status.Equals("Not Compliant") || node.Status.Equals("Failed") || node.Status.Equals("Unresponsive"))
{
return "Bad";
}
}

return "Good";
}

private string FormatDateTime(DateTimeOffset dateTime)
{
Expand Down
Loading

0 comments on commit 7b13c1c

Please sign in to comment.