Skip to content

Commit b9d401d

Browse files
authored
Merge pull request Azure#2325 from robplank/dev
Added Get-AzureRMAutomationHybridRunbookWorkerGroup cmdlet
2 parents a1c152f + f73250c commit b9d401d

10 files changed

+518
-3
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@
103103
<SpecificVersion>False</SpecificVersion>
104104
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
105105
</Reference>
106-
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
106+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
107+
<Private>False</Private>
108+
</Reference>
107109
<Reference Include="Microsoft.WindowsAzure.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
108110
<SpecificVersion>False</SpecificVersion>
109111
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
@@ -190,6 +192,7 @@
190192
<Compile Include="UnitTests\StartAzureAutomationRunbookTest.cs" />
191193
<Compile Include="UnitTests\StopAzureAutomationJobTest.cs" />
192194
<Compile Include="UnitTests\SuspendAzureAutomationJobTest.cs" />
195+
<Compile Include="UnitTests\GetAzureAutomationHybridWorkerGroupTest.cs" />
193196
<Compile Include="UnitTests\UnregisterAzureAutomationScheduledRunbookTest.cs" />
194197
</ItemGroup>
195198
<ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using Microsoft.Azure.Commands.Automation.Cmdlet;
2+
using Microsoft.Azure.Commands.Automation.Common;
3+
using Microsoft.Azure.Commands.Automation.Model;
4+
using Microsoft.VisualStudio.TestTools.UnitTesting;
5+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
6+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
7+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
8+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
9+
using Moq;
10+
using System.Collections.Generic;
11+
using Xunit;
12+
13+
namespace Microsoft.Azure.Commands.ResourceManager.Automation.Test.UnitTests
14+
{
15+
[TestClass]
16+
public class GetAzureAutomationHybridWorkerGroupTest : RMTestBase
17+
{
18+
private Mock<IAutomationClient> mockAutomationClient;
19+
20+
private MockCommandRuntime mockCommandRuntime;
21+
22+
private GetAzureAutomationHybridWorkerGroup cmdlet;
23+
24+
25+
public GetAzureAutomationHybridWorkerGroupTest()
26+
{
27+
this.mockAutomationClient = new Mock<IAutomationClient>();
28+
this.mockCommandRuntime = new MockCommandRuntime();
29+
this.cmdlet = new GetAzureAutomationHybridWorkerGroup
30+
{
31+
AutomationClient = this.mockAutomationClient.Object,
32+
CommandRuntime = this.mockCommandRuntime
33+
};
34+
}
35+
36+
[Fact]
37+
[Trait(Category.AcceptanceType, Category.CheckIn)]
38+
public void GetAzureAutomationHybridWorkerGroupByNameSuccessfull()
39+
{
40+
//Setup
41+
string resourceGroupName = "resourceGroup";
42+
string accountName = "automation";
43+
string hybridRunbookWorkerGroupName = "hybridRunbookWorkerGroup";
44+
45+
this.mockAutomationClient.Setup(f => f.GetHybridRunbookWorkerGroup(resourceGroupName, accountName, hybridRunbookWorkerGroupName));
46+
47+
// Test
48+
this.cmdlet.ResourceGroupName = resourceGroupName;
49+
this.cmdlet.AutomationAccountName = accountName;
50+
this.cmdlet.Name = hybridRunbookWorkerGroupName;
51+
this.cmdlet.SetParameterSet("ByName");
52+
this.cmdlet.ExecuteCmdlet();
53+
54+
// Assert
55+
this.mockAutomationClient.Verify(f => f.GetHybridRunbookWorkerGroup(resourceGroupName, accountName, hybridRunbookWorkerGroupName), Times.Once());
56+
}
57+
58+
[Fact]
59+
[Trait(Category.AcceptanceType, Category.CheckIn)]
60+
public void GetAzureAutomationHybridWorkerGroupByAllSuccessfull()
61+
{
62+
// Setup
63+
string resourceGroupName = "resourceGroup";
64+
string accountName = "automation";
65+
string nextLink = string.Empty;
66+
67+
this.mockAutomationClient.Setup(f => f.ListHybridRunbookWorkerGroups(resourceGroupName, accountName, ref nextLink)).Returns((string a, string b, string c) => new List<HybridRunbookWorkerGroup>()); ;
68+
69+
// Test
70+
this.cmdlet.ResourceGroupName = resourceGroupName;
71+
this.cmdlet.AutomationAccountName = accountName;
72+
this.cmdlet.SetParameterSet("ByAll");
73+
this.cmdlet.ExecuteCmdlet();
74+
75+
//Assert
76+
this.mockAutomationClient.Verify(f => f.ListHybridRunbookWorkerGroups(resourceGroupName, accountName, ref nextLink), Times.Once());
77+
}
78+
}
79+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Management.Automation;
4+
using System.Security.Permissions;
5+
using Microsoft.Azure.Commands.Automation.Model;
6+
using Microsoft.Azure.Commands.Automation.Common;
7+
8+
9+
namespace Microsoft.Azure.Commands.Automation.Cmdlet
10+
{
11+
[Cmdlet(VerbsCommon.Get, "AzureRMAutomationHybridWorkerGroup", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)]
12+
[OutputType(typeof(HybridRunbookWorkerGroup))]
13+
public class GetAzureAutomationHybridWorkerGroup : AzureAutomationBaseCmdlet
14+
{
15+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName,Position = 2, Mandatory = false, ValueFromPipeline = true, HelpMessage = "The Hybrid Runbook Worker Group name")]
16+
[Alias("Group")]
17+
public string Name { get; set; }
18+
19+
protected override void AutomationProcessRecord()
20+
{
21+
if (this.ParameterSetName == AutomationCmdletParameterSets.ByName)
22+
{
23+
IEnumerable<HybridRunbookWorkerGroup> ret = null;
24+
ret = new List<HybridRunbookWorkerGroup> {
25+
26+
this.AutomationClient.GetHybridRunbookWorkerGroup(this.ResourceGroupName, this.AutomationAccountName, this.Name)
27+
};
28+
this.GenerateCmdletOutput(ret);
29+
}
30+
else if(this.ParameterSetName == AutomationCmdletParameterSets.ByAll)
31+
{
32+
var nextLink = string.Empty;
33+
do
34+
{
35+
var results = this.AutomationClient.ListHybridRunbookWorkerGroups(this.ResourceGroupName, this.AutomationAccountName, ref nextLink);
36+
this.GenerateCmdletOutput(results);
37+
}while (!string.IsNullOrEmpty(nextLink));
38+
}
39+
}
40+
}
41+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
</ItemGroup>
125125
<ItemGroup>
126126
<Compile Include="Cmdlet\AzureAutomationBaseCmdlet.cs" />
127+
<Compile Include="Cmdlet\GetAzureAutomationHybridWorkerGroup.cs" />
127128
<Compile Include="Cmdlet\GetAzureAutomationJobOutputRecord.cs" />
128129
<Compile Include="Cmdlet\ImportAzureAutomationDscNodeConfiguration.cs" />
129130
<Compile Include="Cmdlet\ExportAzureAutomationDscConfiguration.cs" />
@@ -227,6 +228,8 @@
227228
<Compile Include="Model\DscNode.cs" />
228229
<Compile Include="Model\DscNodeReport.cs" />
229230
<Compile Include="Model\DscOnboardingMetaconfig.cs" />
231+
<Compile Include="Model\HybridRunbookWorker.cs" />
232+
<Compile Include="Model\HybridRunbookWorkerGroup.cs" />
230233
<Compile Include="Model\Job.cs" />
231234
<Compile Include="Model\JobSchedule.cs" />
232235
<Compile Include="Model\JobStreamRecord.cs" />

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

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
using Runbook = Microsoft.Azure.Commands.Automation.Model.Runbook;
4343
using Schedule = Microsoft.Azure.Commands.Automation.Model.Schedule;
4444
using Variable = Microsoft.Azure.Commands.Automation.Model.Variable;
45+
using HybridRunbookWorkerGroup = Microsoft.Azure.Commands.Automation.Model.HybridRunbookWorkerGroup;
46+
4547

4648
namespace Microsoft.Azure.Commands.Automation.Common
4749
{
@@ -54,6 +56,10 @@ public AutomationClient()
5456
{
5557
}
5658

59+
/// <summary>
60+
///
61+
/// </summary>
62+
/// <param name="context"></param>
5763
public AutomationClient(AzureContext context)
5864
: this(context.Subscription,
5965
AzureSession.ClientFactory.CreateClient<AutomationManagement.AutomationManagementClient>(context,
@@ -1359,6 +1365,41 @@ public void DeleteConnection(string resourceGroupName, string automationAccountN
13591365

13601366
#endregion
13611367

1368+
#region HybridRunbookworkers
1369+
1370+
public IEnumerable<HybridRunbookWorkerGroup> ListHybridRunbookWorkerGroups(string resourceGroupName, string automationAccountName, ref string nextLink)
1371+
{
1372+
HybridRunbookWorkerGroupsListResponse response;
1373+
1374+
if (string.IsNullOrEmpty(nextLink))
1375+
{
1376+
response = this.automationManagementClient.HybridRunbookWorkerGroups.List(resourceGroupName, automationAccountName);
1377+
}
1378+
else
1379+
{
1380+
response = this.automationManagementClient.HybridRunbookWorkerGroups.ListNext(nextLink);
1381+
}
1382+
1383+
nextLink = response.NextLink;
1384+
1385+
return response.HybridRunbookWorkerGroups.Select(c => new HybridRunbookWorkerGroup(resourceGroupName, automationAccountName, c));
1386+
}
1387+
1388+
public HybridRunbookWorkerGroup GetHybridRunbookWorkerGroup(string resourceGroupName, string automationAccountName, string name)
1389+
{
1390+
var hybridRunbookWorkerGroupModel = this.TryGetHybridRunbookWorkerModel(resourceGroupName, automationAccountName, name);
1391+
if (hybridRunbookWorkerGroupModel == null)
1392+
{
1393+
throw new ResourceCommonException(typeof(HybridRunbookWorkerGroup),
1394+
string.Format(CultureInfo.CurrentCulture, Resources.HybridRunbookWorkerGroupNotFound, name));
1395+
}
1396+
1397+
return new HybridRunbookWorkerGroup(resourceGroupName, automationAccountName, hybridRunbookWorkerGroupModel);
1398+
1399+
}
1400+
1401+
#endregion
1402+
13621403
#region JobSchedules
13631404

13641405
public JobSchedule GetJobSchedule(string resourceGroupName, string automationAccountName, Guid jobScheduleId)
@@ -1598,7 +1639,30 @@ private Azure.Management.Automation.Models.Runbook TryGetRunbookModel(string res
15981639
return runbook;
15991640
}
16001641

1601-
private Azure.Management.Automation.Models.Certificate TryGetCertificateModel(string resourceGroupName, string automationAccountName,
1642+
1643+
1644+
1645+
private Azure.Management.Automation.Models.HybridRunbookWorkerGroup TryGetHybridRunbookWorkerModel(string resourceGroupName, string automationAccountName, string HybridRunbookWorkerGroupName)
1646+
{
1647+
Azure.Management.Automation.Models.HybridRunbookWorkerGroup hybridRunbookWorkerGroup = null;
1648+
try
1649+
{
1650+
hybridRunbookWorkerGroup = this.automationManagementClient.HybridRunbookWorkerGroups.Get(resourceGroupName, automationAccountName, HybridRunbookWorkerGroupName).HybridRunbookWorkerGroup;
1651+
}
1652+
catch (CloudException e)
1653+
{
1654+
if (e.Response.StatusCode == HttpStatusCode.NotFound)
1655+
{
1656+
hybridRunbookWorkerGroup = null;
1657+
}
1658+
else
1659+
{
1660+
throw;
1661+
}
1662+
}
1663+
return hybridRunbookWorkerGroup;
1664+
}
1665+
private Azure.Management.Automation.Models.Certificate TryGetCertificateModel(string resourceGroupName, string automationAccountName,
16021666
string certificateName)
16031667
{
16041668
Azure.Management.Automation.Models.Certificate certificate = null;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ Model.Webhook CreateWebhook(
207207

208208
#endregion
209209

210+
#region HybridrunbookWorker
211+
HybridRunbookWorkerGroup GetHybridRunbookWorkerGroup(string resourceGroupName, string automationAccountName, string hybridRunbookWorkerGroupName);
212+
213+
IEnumerable<HybridRunbookWorkerGroup> ListHybridRunbookWorkerGroups(string resourceGroupName, string automationAccountName, ref string nextLink);
214+
#endregion
215+
210216
#region Credentials
211217

212218
CredentialInfo CreateCredential(string resourceGroupName, string automationAccountName, string name, string userName, string password, string description);

0 commit comments

Comments
 (0)