Skip to content

Commit 6b951a3

Browse files
committed
job stream cmdlet
1 parent acc3cda commit 6b951a3

File tree

8 files changed

+157
-4
lines changed

8 files changed

+157
-4
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.Generic;
17+
using System.Management.Automation;
18+
using System.Security.Permissions;
19+
using Microsoft.Azure.Commands.Automation.Common;
20+
using Microsoft.Azure.Commands.Automation.Model;
21+
22+
namespace Microsoft.Azure.Commands.Automation.Cmdlet
23+
{
24+
/// <summary>
25+
/// Gets azure automation variables for a given account.
26+
/// </summary>
27+
[Cmdlet(VerbsCommon.Get, "AzureAutomationJobOutput")]
28+
[OutputType(typeof(Variable))]
29+
public class GetAzureAutomationJobOutput : AzureAutomationBaseCmdlet
30+
{
31+
/// <summary>
32+
/// Gets or sets the job id
33+
/// </summary>
34+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The job id")]
35+
public Guid Id { get; set; }
36+
37+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The stream type")]
38+
public string Stream { get; set; }
39+
40+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The start time filter for job output")]
41+
public DateTime? StartTime { get; set; }
42+
43+
/// <summary>
44+
/// Execute this cmdlet.
45+
/// </summary>
46+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
47+
protected override void AutomationExecuteCmdlet()
48+
{
49+
var ret = this.AutomationClient.GetJobStream(this.AutomationAccountName, this.Id, this.StartTime, this.Stream );
50+
this.GenerateCmdletOutput(ret);
51+
}
52+
}
53+
}

src/ServiceManagement/Automation/Commands.Automation/Cmdlet/SetAutomationVariable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace Microsoft.Azure.Commands.Automation.Cmdlet
2424
/// <summary>
2525
/// Gets azure automation variables for a given account.
2626
/// </summary>
27-
[Cmdlet(VerbsCommon.Get, "AzureAutomationVariable")]
27+
[Cmdlet(VerbsCommon.Set, "AzureAutomationVariable")]
2828
[OutputType(typeof(Variable))]
2929
public class SetAzureAutomationVariable : AzureAutomationBaseCmdlet
3030
{

src/ServiceManagement/Automation/Commands.Automation/Commands.Automation.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
</ItemGroup>
101101
<ItemGroup>
102102
<Compile Include="Cmdlet\AzureAutomationBaseCmdlet.cs" />
103+
<Compile Include="Cmdlet\GetAzureAutomationJobOutput.cs" />
103104
<Compile Include="Cmdlet\GetAzureAutomationVariable.cs" />
104105
<Compile Include="Cmdlet\GetAzureAutomationRunbook.cs" />
105106
<Compile Include="Cmdlet\GetAzureAutomationSchedule.cs" />
@@ -113,6 +114,7 @@
113114
<Compile Include="DataContract\ErrorResponse.cs" />
114115
<Compile Include="DataContract\OdataError.cs" />
115116
<Compile Include="DataContract\OdataErrorMessage.cs" />
117+
<Compile Include="Model\JobStream.cs" />
116118
<Compile Include="Model\Runbook.cs" />
117119
<Compile Include="Model\Schedule.cs" />
118120
<Compile Include="Model\ScheduleFrequency.cs" />

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,25 @@ public Runbook GetRunbook(string automationAccountName, string name)
8989
return new Runbook(sdkRunbook);
9090
}
9191

92+
public IEnumerable<JobStream> GetJobStream(string automationAccountName, Guid jobId, DateTime? time, string streamType)
93+
{
94+
var listParams = new AutomationManagement.Models.JobStreamListParameters();
95+
96+
if (time.HasValue)
97+
{
98+
listParams.Time = time.Value.ToUniversalTime().ToString();
99+
}
100+
101+
if (streamType != null)
102+
{
103+
listParams.StreamType = streamType;
104+
}
105+
106+
var jobStreams = this.automationManagementClient.JobStreams.List(automationAccountName, jobId, listParams).JobStreams;
107+
108+
return jobStreams.Select(this.CreateJobStreamFromJobStreamModel);
109+
}
110+
92111
public Variable SetVariable(string automationAccountName, Variable variable)
93112
{
94113
bool variableExists = true;
@@ -248,6 +267,12 @@ public IEnumerable<Runbook> ListRunbooks(string automationAccountName)
248267
#endregion
249268

250269
#region Private Methods
270+
private JobStream CreateJobStreamFromJobStreamModel(AutomationManagement.Models.JobStream jobStream)
271+
{
272+
Requires.Argument("jobStream", jobStream).NotNull();
273+
return new JobStream(jobStream);
274+
}
275+
251276
private Variable CreateVariableFromVariableModel(AutomationManagement.Models.Variable variable)
252277
{
253278
Requires.Argument("variable", variable).NotNull();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public interface IAutomationClient
2424
{
2525
AzureSubscription Subscription { get; }
2626

27+
IEnumerable<JobStream> GetJobStream(string automationAccountname, Guid jobId, DateTime? time, string streamType);
28+
2729
Variable GetVariable(string automationAccountName, string variableName);
2830

2931
IEnumerable<Variable> ListVariables(string automationAccountName);
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 Microsoft.Azure.Commands.Automation.Common;
17+
18+
namespace Microsoft.Azure.Commands.Automation.Model
19+
{
20+
using AutomationManagement = Management.Automation;
21+
22+
/// <summary>
23+
/// The Job Stream.
24+
/// </summary>
25+
public class JobStream
26+
{
27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="JobStream"/> class.
29+
/// </summary>
30+
/// <param name="jobStream">
31+
/// The job stream.
32+
/// </param>
33+
/// <exception cref="System.ArgumentException">
34+
/// </exception>
35+
public JobStream(AutomationManagement.Models.JobStream jobStream)
36+
{
37+
Requires.Argument("jobStream", jobStream).NotNull();
38+
39+
this.StreamId = jobStream.Properties.StreamId;
40+
this.StreamType = jobStream.Properties.StreamType;
41+
this.Summary = jobStream.Properties.Summary;
42+
this.Time = jobStream.Properties.Time.ToLocalTime();
43+
}
44+
45+
/// <summary>
46+
/// Initializes a new instance of the <see cref="JobStream"/> class.
47+
/// </summary>
48+
public JobStream()
49+
{
50+
}
51+
52+
/// <summary>
53+
/// Gets or sets the stream id
54+
/// </summary>
55+
public string StreamId { get; set; }
56+
57+
/// <summary>
58+
/// Gets or sets the stream time.
59+
/// </summary>
60+
public DateTimeOffset Time { get; set; }
61+
62+
/// <summary>
63+
/// Gets or sets the stream summary.
64+
/// </summary>
65+
public string Summary { get; set; }
66+
67+
/// <summary>
68+
/// Gets or sets the stream Type.
69+
/// </summary>
70+
public string StreamType { get; set; }
71+
}
72+
}

src/ServiceManagement/Automation/Commands.Automation/Model/Variable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class Variable
2828
/// Initializes a new instance of the <see cref="Variable"/> class.
2929
/// </summary>
3030
/// <param name="variable">
31-
/// The runbook.
31+
/// The varaiable.
3232
/// </param>
3333
/// <exception cref="System.ArgumentException">
3434
/// </exception>
@@ -48,7 +48,7 @@ public Variable(AutomationManagement.Models.Variable variable)
4848
/// Initializes a new instance of the <see cref="Variable"/> class.
4949
/// </summary>
5050
/// <param name="variable">
51-
/// The runbook.
51+
/// The variable.
5252
/// </param>
5353
/// <exception cref="System.ArgumentException">
5454
/// </exception>

src/ServiceManagement/Automation/Commands.Automation/packages.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.Azure.Management.Automation" version="2.0.0-preview" targetFramework="net45" />
43
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
54
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
65
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />

0 commit comments

Comments
 (0)