Skip to content

Commit b22b122

Browse files
committed
Merge pull request Azure#1393 from AzureAutomationTeam/dev
Dev: Azure Automation cmdlet changes
2 parents db806ae + ee95641 commit b22b122

File tree

9 files changed

+123
-13
lines changed

9 files changed

+123
-13
lines changed

src/ResourceManager/Automation/Commands.Automation/Commands.Automation.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@
227227
<Compile Include="Model\DscOnboardingMetaconfig.cs" />
228228
<Compile Include="Model\Job.cs" />
229229
<Compile Include="Model\JobSchedule.cs" />
230+
<Compile Include="Model\JobStreamRecord.cs" />
230231
<Compile Include="Model\JobStream.cs" />
231232
<Compile Include="Model\Module.cs" />
232233
<Compile Include="Model\NodeConfiguration.cs" />

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,13 @@ public IEnumerable<JobStream> GetJobStream(string resourceGroupName, string auto
989989
stream => this.CreateJobStreamFromJobStreamModel(stream, resourceGroupName, automationAccountName, jobId));
990990
}
991991

992+
public JobStreamRecord GetJobStreamRecord(string resourceGroupName, string automationAccountName, Guid jobId, string jobStreamId)
993+
{
994+
var response = this.automationManagementClient.JobStreams.Get(resourceGroupName, automationAccountName, jobId, jobStreamId);
995+
996+
return new JobStreamRecord(response.JobStream, resourceGroupName, automationAccountName, jobId);
997+
}
998+
992999
public Job GetJob(string resourceGroupName, string automationAccountName, Guid Id)
9931000
{
9941001
var job = this.automationManagementClient.Jobs.Get(resourceGroupName, automationAccountName, Id).Job;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ public void RegisterDscNode(string resourceGroupName,
809809
templateParameters.Add("rebootNodeIfNeeded", rebootFlag);
810810
templateParameters.Add("actionAfterReboot", actionAfterReboot);
811811
templateParameters.Add("allowModuleOverwrite", moduleOverwriteFlag);
812+
templateParameters.Add("timestamp", DateTimeOffset.UtcNow.ToString("o"));
812813

813814
// invoke the New-AzureRmResourceGroupDeployment cmdlet
814815
using (Pipeline pipe = Runspace.DefaultRunspace.CreateNestedPipeline())

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class Constants
3838

3939
public const string ClientRequestIdHeaderName = "x-ms-client-request-id";
4040

41+
public const string ActivityIdHeaderName = "x-ms-activity-id";
42+
4143
// default schedule expiry time for daily schedule, consistent with UX
4244
// 12/31/9999 12:00:00 AM
4345
public static readonly DateTimeOffset DefaultScheduleExpiryTime = DateTimeOffset.MaxValue;
@@ -59,13 +61,15 @@ public class AutomationAccountState
5961

6062
public const int PsCommandValueDepth = 10;
6163

64+
public const int JobSummaryLength = 80;
65+
6266
// The template file is a json
63-
public const string TemplateFile = @"https://eus2oaasibizamarketprod1.blob.core.windows.net/automationdscpreview/azuredeploy.json";
67+
public const string TemplateFile = @"https://eus2oaasibizamarketprod1.blob.core.windows.net/automationdscpreview/azuredeployV2.json";
6468

6569
// The metaconfig file
66-
public const string ModulesUrl = @"https://eus2oaasibizamarketprod1.blob.core.windows.net/automationdscpreview/RegistrationMetaConfig.zip";
70+
public const string ModulesUrl = @"https://eus2oaasibizamarketprod1.blob.core.windows.net/automationdscpreview/RegistrationMetaConfigV2.zip";
6771

68-
public const string ConfigurationFunction = @"RegistrationMetaConfig.ps1\RegistrationMetaConfig";
72+
public const string ConfigurationFunction = @"RegistrationMetaConfigV2.ps1\RegistrationMetaConfigV2";
6973

7074

7175
public static class RunbookType

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ Model.Webhook CreateWebhook(
235235
IEnumerable<JobStream> GetJobStream(string resourceGroupName, string automationAccountName, Guid jobId,
236236
DateTimeOffset? time, string streamType, ref string nextLink);
237237

238+
JobStreamRecord GetJobStreamRecord(string resourceGroupName, string automationAccountName, Guid jobId, string jobStreamId);
239+
238240
#endregion
239241

240242
#region Certificates

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using System;
1616
using System.Collections.Generic;
17+
using System.Diagnostics.Eventing;
1718
using System.Linq;
1819
using System.Text;
1920
using System.Threading.Tasks;
@@ -31,6 +32,11 @@ public RequestSettings(IAutomationManagementClient automationClient)
3132
client = ((AutomationManagementClient)automationClient);
3233
client.HttpClient.DefaultRequestHeaders.Remove(Constants.ClientRequestIdHeaderName);
3334
client.HttpClient.DefaultRequestHeaders.Add(Constants.ClientRequestIdHeaderName, Guid.NewGuid().ToString());
35+
36+
client.HttpClient.DefaultRequestHeaders.Remove(Constants.ActivityIdHeaderName);
37+
var activityId = Guid.NewGuid();
38+
EventProvider.SetActivityId(ref activityId);
39+
client.HttpClient.DefaultRequestHeaders.Add(Constants.ActivityIdHeaderName, activityId.ToString());
3440
}
3541

3642
public void Dispose()
@@ -43,6 +49,7 @@ protected virtual void Dispose(bool disposing)
4349
if (disposing)
4450
{
4551
client.HttpClient.DefaultRequestHeaders.Remove(Constants.ClientRequestIdHeaderName);
52+
client.HttpClient.DefaultRequestHeaders.Remove(Constants.ActivityIdHeaderName);
4653
}
4754
}
4855
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public Job(string resourceGroupName, string accountName, Azure.Management.Automa
5050

5151
if (job.Properties == null) return;
5252

53-
this.Id = job.Properties.JobId;
53+
this.JobId = job.Properties.JobId;
5454
this.CreationTime = job.Properties.CreationTime.ToLocalTime();
5555
this.LastModifiedTime = job.Properties.LastModifiedTime.ToLocalTime();
5656
this.StartTime = job.Properties.StartTime.HasValue ? job.Properties.StartTime.Value.ToLocalTime() : (DateTimeOffset?)null;
@@ -105,7 +105,7 @@ public Job()
105105
/// <summary>
106106
/// Gets or sets the job id.
107107
/// </summary>
108-
public Guid Id { get; set; }
108+
public Guid JobId { get; set; }
109109

110110
/// <summary>
111111
/// Gets or sets the tags.

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System;
16+
using System.Collections;
17+
using System.Management.Automation;
1618
using Microsoft.Azure.Commands.Automation.Common;
1719

1820
using AutomationManagement = Microsoft.Azure.Management.Automation;
@@ -45,13 +47,19 @@ public JobStream(AutomationManagement.Models.JobStream jobStream, string resourc
4547
{
4648
Requires.Argument("jobStream", jobStream).NotNull();
4749

48-
this.JobStreamId = jobStream.Properties.JobStreamId;
50+
this.StreamRecordId = jobStream.Properties.JobStreamId;
4951
this.Type = jobStream.Properties.StreamType;
50-
this.Text = jobStream.Properties.Summary;
5152
this.Time = jobStream.Properties.Time;
5253
this.AutomationAccountName = automationAccountName;
5354
this.ResourceGroupName = resourceGroupName;
54-
this.Id = jobId;
55+
this.JobId = jobId;
56+
57+
if (!String.IsNullOrWhiteSpace(jobStream.Properties.Summary))
58+
{
59+
this.Summary = jobStream.Properties.Summary.Length > Constants.JobSummaryLength ?
60+
jobStream.Properties.Summary.Substring(0, Constants.JobSummaryLength) + "..." :
61+
jobStream.Properties.Summary;
62+
}
5563
}
5664

5765
/// <summary>
@@ -74,22 +82,22 @@ public JobStream()
7482
/// <summary>
7583
/// Gets or sets the Job Id.
7684
/// </summary>
77-
public Guid Id { get; set; }
85+
public Guid JobId { get; set; }
7886

7987
/// <summary>
80-
/// Gets or sets the stream id
88+
/// Gets or sets the stream record id
8189
/// </summary>
82-
public string JobStreamId { get; set; }
90+
public string StreamRecordId { get; set; }
8391

8492
/// <summary>
8593
/// Gets or sets the stream time.
8694
/// </summary>
8795
public DateTimeOffset Time { get; set; }
8896

8997
/// <summary>
90-
/// Gets or sets the stream text.
98+
/// Gets or sets the summary.
9199
/// </summary>
92-
public string Text { get; set; }
100+
public string Summary { get; set; }
93101

94102
/// <summary>
95103
/// Gets or sets the stream Type.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections;
17+
using System.Collections.Generic;
18+
using System.Management.Automation;
19+
using Microsoft.Azure.Commands.Automation.Common;
20+
21+
using AutomationManagement = Microsoft.Azure.Management.Automation;
22+
23+
namespace Microsoft.Azure.Commands.Automation.Model
24+
{
25+
/// <summary>
26+
/// The Job Stream Record.
27+
/// </summary>
28+
public class JobStreamRecord : JobStream
29+
{
30+
/// <summary>
31+
/// Initializes a new instance of the <see cref="JobStreamRecord"/> class.
32+
/// </summary>
33+
/// <param name="jobStream">
34+
/// The job stream.
35+
/// </param>
36+
/// <param name="resourceGroupName">
37+
/// The resource group name.
38+
/// </param>
39+
/// <param name="automationAccountName">
40+
/// The automation account name
41+
/// </param>
42+
/// <param name="jobId">
43+
/// The job Id
44+
/// </param>
45+
/// <exception cref="System.ArgumentException">
46+
/// </exception>
47+
public JobStreamRecord(AutomationManagement.Models.JobStream jobStream, string resourceGroupName, string automationAccountName, Guid jobId ) : base (jobStream, resourceGroupName, automationAccountName, jobId)
48+
{
49+
this.Value = new Hashtable();
50+
foreach (var kvp in jobStream.Properties.Value)
51+
{
52+
object paramValue;
53+
try
54+
{
55+
paramValue = ((object)PowerShellJsonConverter.Deserialize(kvp.Value.ToString()));
56+
}
57+
catch (CmdletInvocationException exception)
58+
{
59+
if (!exception.Message.Contains("Invalid JSON primitive"))
60+
throw;
61+
62+
paramValue = kvp.Value;
63+
}
64+
this.Value.Add(kvp.Key, paramValue);
65+
}
66+
}
67+
68+
/// <summary>
69+
/// Initializes a new instance of the <see cref="JobStreamRecord"/> class.
70+
/// </summary>
71+
public JobStreamRecord()
72+
{
73+
}
74+
75+
/// <summary>
76+
/// Gets or sets the stream values.
77+
/// </summary>
78+
public Hashtable Value { get; set; }
79+
}
80+
}

0 commit comments

Comments
 (0)