diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationDscCompilationJob.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationDscCompilationJob.cs new file mode 100644 index 000000000000..609856699363 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationDscCompilationJob.cs @@ -0,0 +1,96 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.WindowsAzure.Commands.Utilities.Common; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Gets Azure automation compilation job + /// + [Cmdlet(VerbsCommon.Get, "AzureAutomationDscCompilationJob", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)] + [OutputType(typeof(CompilationJob))] + public class GetAzureAutomationDscCompilationJob : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the job id. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByJobId, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc compilation job id.")] + [Alias("JobId")] + public Guid Id { get; set; } + + /// + /// Gets or sets the runbook name of the job. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = true, HelpMessage = "The configuration name of the job.")] + [Alias("Name")] + public string ConfigurationName { get; set; } + + /// + /// Gets or sets the status of a job. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = false, HelpMessage = "The configuration name of the job.")] + [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; } + + /// + /// Gets or sets the start time filter. + /// + [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.")] + public DateTimeOffset? StartTime { get; set; } + + /// + /// Gets or sets the end time filter. + /// + [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.")] + public DateTimeOffset? EndTime { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + IEnumerable jobs; + + if (this.Id != null && !Guid.Empty.Equals(this.Id)) + { + // ByJobId + jobs = new List { this.AutomationClient.GetCompilationJob(this.ResourceGroupName, this.AutomationAccountName, this.Id) }; + } + else if (this.ConfigurationName != null) + { + // ByConfiguration + jobs = this.AutomationClient.ListCompilationJobsByConfigurationName(this.ResourceGroupName, this.AutomationAccountName, this.ConfigurationName, this.StartTime, this.EndTime, this.Status); + } + else + { + // ByAll + jobs = this.AutomationClient.ListCompilationJobs(this.ResourceGroupName, this.AutomationAccountName, this.StartTime, this.EndTime, this.Status); + } + + this.WriteObject(jobs, true); + } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationDscCompilationJobOutput.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationDscCompilationJobOutput.cs new file mode 100644 index 000000000000..a9a1ee9e7b62 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationDscCompilationJobOutput.cs @@ -0,0 +1,57 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.WindowsAzure.Commands.Utilities.Common; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Gets stream for a compilation job + /// + [Cmdlet(VerbsCommon.Get, "AzureAutomationDscCompilationJobOutput")] + [OutputType(typeof(JobStream))] + public class GetAzureAutomationDscCompilationJobOutput : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the job id + /// + [Alias("JobId")] + [Parameter(Mandatory = true, Position = 2, ValueFromPipelineByPropertyName = true, HelpMessage = "The job Id")] + public Guid Id { get; set; } + + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The stream type. Defaults to Any.")] + public StreamType Stream { get; set; } + + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Retrieves output created after this time")] + public DateTimeOffset? StartTime { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + var ret = this.AutomationClient.GetDscCompilationJobStream(this.ResourceGroupName, this.AutomationAccountName, this.Id, this.StartTime, this.Stream.ToString()); + + this.GenerateCmdletOutput(ret); + } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationDscNodeConfiguration.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationDscNodeConfiguration.cs new file mode 100644 index 000000000000..05470a23f640 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/GetAzureAutomationDscNodeConfiguration.cs @@ -0,0 +1,73 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.WindowsAzure.Commands.Utilities.Common; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// Gets Azure automation node configurations + /// + [Cmdlet(VerbsCommon.Get, "AzureAutomationDscNodeConfiguration", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)] + [OutputType(typeof(CompilationJob))] + public class GetAzureAutomationDscNodeConfiguration : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the job id. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByNodeConfigurationName, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc node configuration name.")] + [Alias("NodeConfigurationName")] + public string Name { get; set; } + + /// + /// Gets or sets the runbook name of the job. + /// + [Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = true, HelpMessage = "The configuration name.")] + public string ConfigurationName { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + IEnumerable nodeConfigurations; + + if (this.Name != null && !Guid.Empty.Equals(this.Name)) + { + // ByJobId + nodeConfigurations = new List { this.AutomationClient.GetNodeConfiguration(this.ResourceGroupName, this.AutomationAccountName, this.Name) }; + } + else if (this.ConfigurationName != null) + { + // ByConfiguration + nodeConfigurations = this.AutomationClient.ListNodeConfigurationsByConfigurationName(this.ResourceGroupName, this.AutomationAccountName, this.ConfigurationName); + } + else + { + // ByAll + nodeConfigurations = this.AutomationClient.ListNodeConfigurations(this.ResourceGroupName, this.AutomationAccountName); + } + + this.WriteObject(nodeConfigurations, true); + } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Cmdlet/StartAzureAutomationDscCompilationJob.cs b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/StartAzureAutomationDscCompilationJob.cs new file mode 100644 index 000000000000..a35dc5022697 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Cmdlet/StartAzureAutomationDscCompilationJob.cs @@ -0,0 +1,57 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Collections; +using System.Collections.Generic; +using System.Management.Automation; +using System.Security.Permissions; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.WindowsAzure.Commands.Utilities.Common; + +namespace Microsoft.Azure.Commands.Automation.Cmdlet +{ + /// + /// starts azure automation compilation job + /// + [Cmdlet(VerbsLifecycle.Start, "AzureAutomationDscCompilationJob", DefaultParameterSetName = AutomationCmdletParameterSets.ByConfigurationName)] + [OutputType(typeof(CompilationJob))] + public class StartAzureAutomationDscCompilationJob : AzureAutomationBaseCmdlet + { + /// + /// Gets or sets the configuration name. + /// + [Parameter(Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The configuration name.")] + public string ConfigurationName { get; set; } + + /// + /// Gets or sets the configuration parameters. + /// + [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The configuration parameters.")] + public IDictionary Parameters { get; set; } + + /// + /// Execute this cmdlet. + /// + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + protected override void AutomationExecuteCmdlet() + { + CompilationJob job = null; + + job = this.AutomationClient.StartCompilationJob(this.ResourceGroupName, this.AutomationAccountName, this.ConfigurationName, this.Parameters); + + this.WriteObject(job); + } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj b/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj index 7a70fedf72cc..b9ea8668cdea 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj +++ b/src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj @@ -116,6 +116,10 @@ + + + + @@ -135,6 +139,7 @@ + @@ -145,9 +150,12 @@ + + + True diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClient.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClient.cs index 7782b7276e62..e869aea08925 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClient.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClient.cs @@ -21,8 +21,8 @@ using System.Net; using System.Security; using System.Security.Cryptography.X509Certificates; -using Microsoft.Azure.Commands.Automation.Properties; using Microsoft.Azure.Commands.Automation.Model; +using Microsoft.Azure.Commands.Automation.Properties; using Microsoft.Azure.Management.Automation; using Microsoft.Azure.Management.Automation.Models; using Microsoft.WindowsAzure.Commands.Common; @@ -190,5 +190,6 @@ public void DeleteAutomationAccount(string resourceGroupName, string automationA } #endregion + } } \ No newline at end of file diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs index 77a4a8397097..6f5bf52c02c4 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs @@ -24,10 +24,13 @@ using Microsoft.Azure.Management.Automation; using AutomationManagement = Microsoft.Azure.Management.Automation; using Microsoft.Azure.Management.Automation.Models; +using Newtonsoft.Json; using Hyak.Common; namespace Microsoft.Azure.Commands.Automation.Common { + + using DscNode = Microsoft.Azure.Management.Automation.Models.DscNode; public partial class AutomationClient : IAutomationClient @@ -569,6 +572,355 @@ public void DeleteDscNode(string resourceGroupName, string automationAccountName throw; } + } + #endregion + + #region compilationjob + + public Model.CompilationJob GetCompilationJob(string resourceGroupName, string automationAccountName, Guid Id) + { + using (var request = new RequestSettings(this.automationManagementClient)) + { + var job = this.automationManagementClient.CompilationJobs.Get(resourceGroupName, automationAccountName, Id).DscCompilationJob; + if (job == null) + { + throw new ResourceNotFoundException(typeof(Job), + string.Format(CultureInfo.CurrentCulture, Resources.CompilationJobNotFound, Id)); + } + + return new Model.CompilationJob(automationAccountName, job); + } + } + + public IEnumerable ListCompilationJobsByConfigurationName(string resourceGroupName, string automationAccountName, string configurationName, DateTimeOffset? startTime, DateTimeOffset? endTime, string jobStatus) + { + using (var request = new RequestSettings(this.automationManagementClient)) + { + IEnumerable jobModels; + + if (startTime.HasValue && endTime.HasValue) + { + jobModels = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = + this.automationManagementClient.CompilationJobs.List( + resourceGroupName, + automationAccountName, + new AutomationManagement.Models.DscCompilationJobListParameters + { + StartTime = FormatDateTime(startTime.Value), + EndTime = FormatDateTime(endTime.Value), + ConfigurationName = configurationName, + Status = jobStatus, + }); + return new ResponseWithSkipToken(response, response.DscCompilationJobs); + }); + } + else if (startTime.HasValue) + { + jobModels = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = + this.automationManagementClient.CompilationJobs.List( + resourceGroupName, + automationAccountName, + new AutomationManagement.Models.DscCompilationJobListParameters + { + StartTime = FormatDateTime(startTime.Value), + ConfigurationName = configurationName, + Status = jobStatus + }); + return new ResponseWithSkipToken(response, response.DscCompilationJobs); + }); + } + else if (endTime.HasValue) + { + jobModels = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = + this.automationManagementClient.CompilationJobs.List( + resourceGroupName, + automationAccountName, + new AutomationManagement.Models.DscCompilationJobListParameters + { + EndTime = FormatDateTime(endTime.Value), + ConfigurationName = configurationName, + Status = jobStatus, + }); + return new ResponseWithSkipToken(response, response.DscCompilationJobs); + }); + } + else + { + jobModels = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = this.automationManagementClient.CompilationJobs.List( + resourceGroupName, + automationAccountName, + new AutomationManagement.Models.DscCompilationJobListParameters + { + Status = jobStatus, + ConfigurationName = configurationName + }); + return new ResponseWithSkipToken(response, response.DscCompilationJobs); + }); + } + + return jobModels.Select(jobModel => new Commands.Automation.Model.CompilationJob(automationAccountName, jobModel)); + } + } + + public IEnumerable ListCompilationJobs(string resourceGroupName, string automationAccountName, DateTimeOffset? startTime, DateTimeOffset? endTime, string jobStatus) + { + using (var request = new RequestSettings(this.automationManagementClient)) + { + IEnumerable jobModels; + + if (startTime.HasValue && endTime.HasValue) + { + jobModels = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = + this.automationManagementClient.CompilationJobs.List( + resourceGroupName, + automationAccountName, + new AutomationManagement.Models.DscCompilationJobListParameters + { + StartTime = FormatDateTime(startTime.Value), + EndTime = FormatDateTime(endTime.Value), + Status = jobStatus, + }); + return new ResponseWithSkipToken(response, response.DscCompilationJobs); + }); + } + else if (startTime.HasValue) + { + jobModels = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = + this.automationManagementClient.CompilationJobs.List( + resourceGroupName, + automationAccountName, + new AutomationManagement.Models.DscCompilationJobListParameters + { + StartTime = FormatDateTime(startTime.Value), + Status = jobStatus, + }); + return new ResponseWithSkipToken(response, response.DscCompilationJobs); + }); + } + else if (endTime.HasValue) + { + jobModels = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = + this.automationManagementClient.CompilationJobs.List( + resourceGroupName, + automationAccountName, + new AutomationManagement.Models.DscCompilationJobListParameters + { + EndTime = FormatDateTime(endTime.Value), + Status = jobStatus, + }); + return new ResponseWithSkipToken(response, response.DscCompilationJobs); + }); + } + else + { + jobModels = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = this.automationManagementClient.CompilationJobs.List( + resourceGroupName, + automationAccountName, + new AutomationManagement.Models.DscCompilationJobListParameters { Status = jobStatus }); + return new ResponseWithSkipToken(response, response.DscCompilationJobs); + }); + } + + return jobModels.Select(jobModel => new Model.CompilationJob(automationAccountName, jobModel)); + } + } + + public Model.CompilationJob StartCompilationJob(string resourceGroupName, string automationAccountName, string configurationName, IDictionary parameters) + { + using (var request = new RequestSettings(this.automationManagementClient)) + { + var createJobParameters = new DscCompilationJobCreateParameters() + { + Properties = new DscCompilationJobCreateProperties() + { + Configuration = new DscConfigurationAssociationProperty() + { + Name = configurationName + }, + Parameters = this.ProcessConfigurationParameters(resourceGroupName, automationAccountName, configurationName, parameters) + } + }; + + var job = this.automationManagementClient.CompilationJobs.Create(resourceGroupName, automationAccountName, createJobParameters); + + return new Model.CompilationJob(automationAccountName, job.DscCompilationJob); + } + } + + public IEnumerable GetDscCompilationJobStream(string resourceGroupName, string automationAccountName, Guid jobId, DateTimeOffset? time, string streamType) + { + using (var request = new RequestSettings(this.automationManagementClient)) + { + var listParams = new AutomationManagement.Models.JobStreamListParameters(); + + if (time.HasValue) + { + listParams.Time = this.FormatDateTime(time.Value); + } + + if (streamType != null) + { + listParams.StreamType = streamType; + } + + var jobStreams = this.automationManagementClient.JobStreams.List(resourceGroupName, automationAccountName, jobId, listParams).JobStreams; + return jobStreams.Select(stream => this.CreateJobStreamFromJobStreamModel(stream, automationAccountName, jobId)).ToList(); + } + } + + #endregion + + #region node configuration + public Model.NodeConfiguration GetNodeConfiguration(string resourceGroupName, string automationAccountName, string nodeConfigurationName) + { + using (var request = new RequestSettings(this.automationManagementClient)) + { + var nodeConfiguration = this.automationManagementClient.NodeConfigurations.Get(resourceGroupName, automationAccountName, nodeConfigurationName).NodeConfiguration; + if (nodeConfiguration == null) + { + throw new ResourceNotFoundException(typeof(NodeConfiguration), + string.Format(CultureInfo.CurrentCulture, Resources.NodeConfigurationNotFound, nodeConfigurationName)); + } + + return new Model.NodeConfiguration(automationAccountName, nodeConfiguration); + } + } + + public IEnumerable ListNodeConfigurationsByConfigurationName(string resourceGroupName, string automationAccountName, string configurationName) + { + using (var request = new RequestSettings(this.automationManagementClient)) + { + IEnumerable nodeConfigModels; + + nodeConfigModels = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = this.automationManagementClient.NodeConfigurations.List( + resourceGroupName, + automationAccountName, + new AutomationManagement.Models.DscNodeConfigurationListParameters + { + ConfigurationName = configurationName + }); + return new ResponseWithSkipToken(response, response.DscNodeConfigurations); + }); + + + return nodeConfigModels.Select(nodeConfigModel => new Commands.Automation.Model.NodeConfiguration(automationAccountName, nodeConfigModel)); + } + } + + public IEnumerable ListNodeConfigurations(string resourceGroupName, string automationAccountName) + { + using (var request = new RequestSettings(this.automationManagementClient)) + { + IEnumerable nodeConfigModels; + + nodeConfigModels = AutomationManagementClient.ContinuationTokenHandler( + skipToken => + { + var response = this.automationManagementClient.NodeConfigurations.List( + resourceGroupName, + automationAccountName, + new AutomationManagement.Models.DscNodeConfigurationListParameters()); + + return new ResponseWithSkipToken(response, response.DscNodeConfigurations); + }); + + + return nodeConfigModels.Select(nodeConfigModel => new Model.NodeConfiguration(automationAccountName, nodeConfigModel)); + } + } + + #endregion + + #region privatemethods + + private string FormatDateTime(DateTimeOffset dateTime) + { + return string.Format(CultureInfo.InvariantCulture, "{0:O}", dateTime.ToUniversalTime()); + } + + private IDictionary ProcessConfigurationParameters(string resourceGroupName, string automationAccountName, string configurationName, IDictionary parameters) + { + parameters = parameters ?? new Dictionary(); + IEnumerable> configurationParameters = this.ListConfigurationParameters(resourceGroupName, automationAccountName, configurationName); + var filteredParameters = new Dictionary(); + + foreach (var configParameter in configurationParameters) + { + if (parameters.Contains(configParameter.Key)) + { + object paramValue = parameters[configParameter.Key]; + try + { + filteredParameters.Add(configParameter.Key, paramValue.ToString()); + } + catch (JsonSerializationException) + { + throw new ArgumentException( + string.Format( + CultureInfo.CurrentCulture, Resources.ConfigurationParameterCannotBeSerializedToJson, configParameter.Key)); + } + } + else if (configParameter.Value.IsMandatory) + { + throw new ArgumentException( + string.Format( + CultureInfo.CurrentCulture, Resources.ConfigurationParameterValueRequired, configParameter.Key)); + } + } + + if (filteredParameters.Count != parameters.Count) + { + throw new ArgumentException( + string.Format(CultureInfo.CurrentCulture, Resources.InvalidConfigurationParameters)); + } + + return filteredParameters; + } + + private IEnumerable> ListConfigurationParameters(string resourceGroupName, string automationAccountName, string configurationName) + { + Model.DscConfiguration configuration = this.GetConfiguration(resourceGroupName, automationAccountName, configurationName); + if (configuration == null || 0 == String.Compare(configuration.State, RunbookState.New, CultureInfo.InvariantCulture, + CompareOptions.IgnoreCase)) + { + throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.ConfigurationHasNoPublishedVersion, configurationName)); + } + return configuration.Parameters.Cast().ToDictionary(k => k.Key.ToString(), k => (DscConfigurationParameter)k.Value); + } + + private Model.JobStream CreateJobStreamFromJobStreamModel(AutomationManagement.Models.JobStream jobStream, string automationAccountName, Guid jobId) + { + Requires.Argument("jobStream", jobStream).NotNull(); + Requires.Argument("automationAccountName", automationAccountName).NotNull(); + Requires.Argument("jobId", jobId).NotNull(); + return new Model.JobStream(jobStream, automationAccountName, jobId); } #endregion diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationCmdletParameterSet.cs b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationCmdletParameterSet.cs index ec6a7c643405..a080ad294e16 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/AutomationCmdletParameterSet.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/AutomationCmdletParameterSet.cs @@ -79,6 +79,11 @@ internal static class AutomationCmdletParameterSets /// internal const string ByConfigurationName = "ByConfigurationName"; + /// + /// The Node Configuration name parameter set. + /// + internal const string ByNodeConfigurationName = "ByNodeConfigurationName"; + /// /// The Schedule name parameter set. /// diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs index 035c42d920d3..db6651fbe485 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs @@ -40,6 +40,27 @@ public interface IAutomationClient #endregion + #region Compilationjobs + + CompilationJob GetCompilationJob(string resourceGroupName, string automationAccountName, Guid id); + + IEnumerable ListCompilationJobsByConfigurationName(string resourceGroupName, string automationAccountName, string configurationName, DateTimeOffset? startTime, DateTimeOffset? endTime, string jobStatus); + + IEnumerable ListCompilationJobs(string resourceGroupName, string automationAccountName, DateTimeOffset? startTime, DateTimeOffset? endTime, string jobStatus); + + CompilationJob StartCompilationJob(string resourceGroupName, string automationAccountName, string configurationName, IDictionary parameters); + + IEnumerable GetDscCompilationJobStream(string resourceGroupName, string automationAccountname, Guid jobId, DateTimeOffset? time, string streamType); + #endregion + + #region NodeConfiguration + NodeConfiguration GetNodeConfiguration(string resourceGroupName, string automationAccountName, string nodeConfigurationName); + + IEnumerable ListNodeConfigurationsByConfigurationName(string resourceGroupName, string automationAccountName, string configurationName); + + IEnumerable ListNodeConfigurations(string resourceGroupName, string automationAccountName); + #endregion + #region Configurations IEnumerable ListDscConfigurations(string resourceGroupName, string automationAccountName); diff --git a/src/ResourceManager/Automation/Commands.Automation/Common/RequestSettings.cs b/src/ResourceManager/Automation/Commands.Automation/Common/RequestSettings.cs new file mode 100644 index 000000000000..86bae5056116 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Common/RequestSettings.cs @@ -0,0 +1,41 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Azure.Commands.Automation.Common; +using Microsoft.Azure.Management.Automation; + +namespace Microsoft.Azure.Commands.Automation +{ + public class RequestSettings : IDisposable + { + private readonly AutomationManagementClient client; + + public RequestSettings(IAutomationManagementClient automationClient) + { + client = ((AutomationManagementClient)automationClient); + client.HttpClient.DefaultRequestHeaders.Remove(Constants.ClientRequestIdHeaderName); + client.HttpClient.DefaultRequestHeaders.Add(Constants.ClientRequestIdHeaderName, Guid.NewGuid().ToString()); + } + + public void Dispose() + { + client.HttpClient.DefaultRequestHeaders.Remove(Constants.ClientRequestIdHeaderName); + } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/CompilationJob.cs b/src/ResourceManager/Automation/Commands.Automation/Model/CompilationJob.cs new file mode 100644 index 000000000000..5e346bec8e11 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Model/CompilationJob.cs @@ -0,0 +1,136 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Automation.Model +{ + using System; + using System.Collections; + using System.Globalization; + using System.Linq; + + using Microsoft.Azure.Commands.Automation.Common; + + using AutomationManagement = Microsoft.Azure.Management.Automation; + + /// + /// The Dsc Compilation Job + /// + public class CompilationJob + { + /// + /// Initializes a new instance of the class. + /// + /// + /// The account name. + /// + /// + /// The Job. + /// + /// + /// + public CompilationJob(string accountName, AutomationManagement.Models.DscCompilationJob job) + { + Requires.Argument("job", job).NotNull(); + Requires.Argument("accountName", accountName).NotNull(); + + this.AutomationAccountName = accountName; + + if (job.Properties == null) return; + + this.Id = job.Properties.JobId; + this.CreationTime = job.Properties.CreationTime.ToLocalTime(); + this.LastModifiedTime = job.Properties.LastModifiedTime.ToLocalTime(); + this.StartTime = job.Properties.StartTime.HasValue ? job.Properties.StartTime.Value.ToLocalTime() : (DateTimeOffset?)null; + this.Status = job.Properties.Status; + this.StatusDetails = job.Properties.StatusDetails; + this.ConfigurationName = job.Properties.Configuration.Name; + this.Exception = job.Properties.Exception; + this.EndTime = job.Properties.EndTime.HasValue ? job.Properties.EndTime.Value.ToLocalTime() : (DateTimeOffset?)null; + this.LastStatusModifiedTime = job.Properties.LastStatusModifiedTime; + this.JobParameters = new Hashtable(StringComparer.InvariantCultureIgnoreCase); + foreach (var kvp in job.Properties.Parameters.Where(kvp => 0 != String.Compare(kvp.Key, Constants.JobStartedByParameterName, CultureInfo.InvariantCulture, + CompareOptions.IgnoreCase))) + { + this.JobParameters.Add(kvp.Key, (object)(kvp.Value)); + } + } + + /// + /// Initializes a new instance of the class. + /// + public CompilationJob() + { + } + + /// + /// Gets or sets the automaiton account name. + /// + public string AutomationAccountName { get; set; } + + /// + /// Gets or sets the job id. + /// + public Guid Id { get; set; } + + /// + /// Gets or sets the tags. + /// + public DateTimeOffset CreationTime { get; set; } + + /// + /// Gets or sets the status of the job. + /// + public string Status { get; set; } + + /// + /// Gets or sets the status details of the job. + /// + public string StatusDetails { get; set; } + + /// + /// Gets or sets the start time of the job. + /// + public DateTimeOffset? StartTime { get; set; } + + /// + /// Gets or sets the end time of the job. + /// + public DateTimeOffset? EndTime { get; set; } + + /// + /// Gets or sets the exception of the job. + /// + public string Exception { get; set; } + + /// + /// Gets or sets the last modified time of the job. + /// + public DateTimeOffset LastModifiedTime { get; set; } + + /// + /// Gets or sets the last status modified time of the job." + /// + public DateTimeOffset LastStatusModifiedTime { get; set; } + + /// + /// Gets or sets the parameters of the job. + /// + public Hashtable JobParameters { get; set; } + + /// + /// Gets or sets the configuration. + /// + public string ConfigurationName { get; set; } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/JobStream.cs b/src/ResourceManager/Automation/Commands.Automation/Model/JobStream.cs new file mode 100644 index 000000000000..ee9c2f273da9 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Model/JobStream.cs @@ -0,0 +1,84 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using Microsoft.Azure.Commands.Automation.Common; + +namespace Microsoft.Azure.Commands.Automation.Model +{ + using AutomationManagement = Microsoft.Azure.Management.Automation; + + /// + /// The Job Stream. + /// + public class JobStream + { + /// + /// Initializes a new instance of the class. + /// + /// + /// The job stream. + /// + /// + /// + public JobStream(AutomationManagement.Models.JobStream jobStream, string automationAccountName, Guid jobId ) + { + Requires.Argument("jobStream", jobStream).NotNull(); + + this.JobStreamId = jobStream.Properties.JobStreamId; + this.Type = jobStream.Properties.StreamType; + this.Text = jobStream.Properties.Summary; + this.Time = jobStream.Properties.Time; + this.AutomationAccountName = automationAccountName; + this.Id = jobId; + } + + /// + /// Initializes a new instance of the class. + /// + public JobStream() + { + } + + /// + /// Gets or sets the automation account name. + /// + public string AutomationAccountName { get; set; } + + /// + /// Gets or sets the Job Id. + /// + public Guid Id { get; set; } + + /// + /// Gets or sets the stream id + /// + public string JobStreamId { get; set; } + + /// + /// Gets or sets the stream time. + /// + public DateTimeOffset Time { get; set; } + + /// + /// Gets or sets the stream text. + /// + public string Text { get; set; } + + /// + /// Gets or sets the stream Type. + /// + public string Type { get; set; } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Model/NodeConfiguration.cs b/src/ResourceManager/Automation/Commands.Automation/Model/NodeConfiguration.cs new file mode 100644 index 000000000000..155b9e3412b8 --- /dev/null +++ b/src/ResourceManager/Automation/Commands.Automation/Model/NodeConfiguration.cs @@ -0,0 +1,90 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.Automation.Model +{ + using System; + using System.Collections; + using System.Globalization; + using System.Linq; + + using Microsoft.Azure.Commands.Automation.Common; + + using AutomationManagement = Microsoft.Azure.Management.Automation; + + /// + /// The Dsc Node configuration + /// + public class NodeConfiguration + { + /// + /// Initializes a new instance of the class. + /// + /// + /// The account name. + /// + /// + /// The NodeConfiguration. + /// + /// + /// + public NodeConfiguration(string accountName, AutomationManagement.Models.DscNodeConfiguration nodeConfiguration) + { + Requires.Argument("nodeConfiguration", nodeConfiguration).NotNull(); + Requires.Argument("accountName", accountName).NotNull(); + + this.AutomationAccountName = accountName; + + this.Name = nodeConfiguration.Name; + this.CreationTime = nodeConfiguration.CreationTime.ToLocalTime(); + this.LastModifiedTime = nodeConfiguration.LastModifiedTime.ToLocalTime(); + if (nodeConfiguration.Configuration != null) + { + this.ConfigurationName = nodeConfiguration.Configuration.Name; + } + } + + /// + /// Initializes a new instance of the class. + /// + public NodeConfiguration() + { + } + + /// + /// Gets or sets the automaiton account name. + /// + public string AutomationAccountName { get; set; } + + /// + /// Gets or sets the node configuration name + /// + public string Name { get; set; } + + /// + /// Gets or sets the tags. + /// + public DateTimeOffset CreationTime { get; set; } + + /// + /// Gets or sets the last modified time of the job. + /// + public DateTimeOffset LastModifiedTime { get; set; } + + /// + /// Gets or sets the configuration. + /// + public string ConfigurationName { get; set; } + } +} diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs index b645ce13c588..6713ba9a0cb7 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34014 +// Runtime Version:4.0.30319.18449 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -122,6 +122,15 @@ internal static string ConfigurationAlreadyExists { return ResourceManager.GetString("ConfigurationAlreadyExists", resourceCulture); } } + + /// + /// Looks up a localized string similar to The Compilation Job having Id: {0} was not found.. + /// + internal static string CompilationJobNotFound { + get { + return ResourceManager.GetString("CompilationJobNotFound", resourceCulture); + } + } /// /// Looks up a localized string similar to Configuration can be imported in published state only in the current preview. Use the -Published switch.. @@ -131,6 +140,15 @@ internal static string ConfigurationNotPublished { return ResourceManager.GetString("ConfigurationNotPublished", resourceCulture); } } + + /// + /// Looks up a localized string similar to The configuration has no published version. Configuration name {0}.. + /// + internal static string ConfigurationHasNoPublishedVersion { + get { + return ResourceManager.GetString("ConfigurationHasNoPublishedVersion", resourceCulture); + } + } /// /// Looks up a localized string similar to Invalid SourcePath. Verify file path is valid and file exists.. @@ -140,6 +158,24 @@ internal static string ConfigurationSourcePathInvalid { return ResourceManager.GetString("ConfigurationSourcePathInvalid", resourceCulture); } } + + /// + /// Looks up a localized string similar to Configuration parameter cannot be serialized to json. Parameter name {0}.. + /// + internal static string ConfigurationParameterCannotBeSerializedToJson { + get { + return ResourceManager.GetString("ConfigurationParameterCannotBeSerializedToJson", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Configuration mandatory parameter not specified. Parameter name {0}.. + /// + internal static string ConfigurationParameterValueRequired { + get { + return ResourceManager.GetString("ConfigurationParameterValueRequired", resourceCulture); + } + } /// /// Looks up a localized string similar to The Connection already exists. Connection name: {0}.. @@ -203,6 +239,15 @@ internal static string InvalidFolderPath { return ResourceManager.GetString("InvalidFolderPath", resourceCulture); } } + + /// + /// Looks up a localized string similar to Invalid configuration parameters.. + /// + internal static string InvalidConfigurationParameters { + get { + return ResourceManager.GetString("InvalidConfigurationParameters", resourceCulture); + } + } /// /// Looks up a localized string similar to Invalid runbook parameters.. @@ -285,6 +330,15 @@ internal static string NumberOfFilesWritten { } } + /// + /// Looks up a localized string similar to NodeConfiguration {0} not found.. + /// + internal static string NodeConfigurationNotFound { + get { + return ResourceManager.GetString("NodeConfigurationNotFound", resourceCulture); + } + } + /// /// Looks up a localized string similar to {0} is empty.. /// diff --git a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx index e6122de67db3..0896c014054e 100644 --- a/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx +++ b/src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx @@ -324,6 +324,28 @@ Removing the Dsc node with Id {0}. + + + The Compilation Job having Id: {0} was not found. + + + The configuration has no published version. Configuration name {0}. + Automation + + + Configuration parameter cannot be serialized to json. Parameter name {0}. + Automation + + + Configuration mandatory parameter not specified. Parameter name {0}. + Automation + + + Invalid configuration parameters. + Automation + + + NodeConfiguration {0} not found. Automation \ No newline at end of file diff --git a/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.Designer.cs b/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.Designer.cs index 112e6f07708b..3db90ac47b88 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.Designer.cs +++ b/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34014 +// Runtime Version:4.0.30319.18449 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -114,6 +114,15 @@ internal static string CertificateNotFound { } } + /// + /// Looks up a localized string similar to The Compilation Job having Id: {0} was not found.. + /// + internal static string CompilationJobNotFound { + get { + return ResourceManager.GetString("CompilationJobNotFound", resourceCulture); + } + } + /// /// Looks up a localized string similar to The Connection already exists. Connection name: {0}.. /// diff --git a/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.resx b/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.resx index ac55f018ec24..d6811d83fa86 100644 --- a/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.resx +++ b/src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.resx @@ -275,4 +275,7 @@ Create account arguments are invalid. Provide valid account name and location. Account Name: {0}, Location: {1} Automation + + The Compilation Job having Id: {0} was not found. + \ No newline at end of file