Skip to content

Commit 1c561ed

Browse files
committed
Documentation changes and review comments.
1 parent 0e76c41 commit 1c561ed

File tree

7 files changed

+253
-154
lines changed

7 files changed

+253
-154
lines changed

src/ResourceManager/HDInsight/Commands.HDInsight.Test/HDInsightTestBase.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using System;
16+
using System.Collections.Generic;
1517
using System.Management.Automation;
1618
using Hyak.Common;
1719
using Microsoft.Azure.Commands.HDInsight.Models;
1820
using Microsoft.Azure.Management.HDInsight.Models;
19-
using Microsoft.WindowsAzure.Commands.Common;
2021
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
2122
using Moq;
2223

@@ -41,9 +42,51 @@ public virtual void SetupTestsForManagement()
4142

4243
public virtual void SetupTestsForData()
4344
{
45+
hdinsightManagementMock = new Mock<AzureHdInsightManagementClient>();
4446
var cred = new BasicAuthenticationCloudCredentials {Username = "username", Password = "Password1!"};
4547
hdinsightJobManagementMock = new Mock<AzureHdInsightJobManagementClient>(ClusterName, cred);
4648
commandRuntimeMock = new Mock<ICommandRuntime>();
4749
}
50+
51+
public virtual void SetupManagementClientForJobTests()
52+
{
53+
// Update HDInsight Management properties for Job.
54+
var cluster1 = new Cluster
55+
{
56+
Id = "/subscriptions/" + Guid.NewGuid() + "/resourceGroups/" + ResourceGroupName + "/providers/Microsoft.HDInsight/clusters/" + ClusterName,
57+
Name = ClusterName,
58+
Location = Location,
59+
Properties = new ClusterGetProperties
60+
{
61+
ClusterVersion = "3.2",
62+
ClusterState = "Running",
63+
ClusterDefinition = new ClusterDefinition
64+
{
65+
ClusterType = ClusterType
66+
},
67+
QuotaInfo = new QuotaInfo
68+
{
69+
CoresUsed = 24
70+
},
71+
OperatingSystemType = OSType.Windows,
72+
ConnectivityEndpoints = new List<ConnectivityEndpoint> { new ConnectivityEndpoint { Location = ClusterName, Name = "HTTPS" } }
73+
}
74+
};
75+
76+
var listresponse = new ClusterListResponse { Clusters = new[] { cluster1 } };
77+
hdinsightManagementMock.Setup(c => c.ListClusters())
78+
.Returns(listresponse)
79+
.Verifiable();
80+
81+
hdinsightManagementMock.Setup(c => c.GetCluster(It.IsAny<string>(), It.IsAny<string>()))
82+
.Returns(new List<Cluster> { cluster1 })
83+
.Verifiable();
84+
85+
var configurationResponse = new Dictionary<string, string>();
86+
87+
hdinsightManagementMock.Setup(c => c.GetClusterConfigurations(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
88+
.Returns(configurationResponse)
89+
.Verifiable();
90+
}
4891
}
4992
}

src/ResourceManager/HDInsight/Commands.HDInsight.Test/UnitTests/JobTests.cs

Lines changed: 122 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
using System.Collections.Generic;
1616
using System.Management.Automation;
1717
using System.Net;
18+
using System.Linq;
1819
using Microsoft.Azure.Commands.HDInsight.Models;
1920
using Microsoft.Azure.Management.HDInsight.Job.Models;
2021
using Microsoft.WindowsAzure.Commands.Common;
2122
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2223
using Moq;
2324
using Xunit;
25+
using Microsoft.Azure.Management.HDInsight.Models;
2426

2527
namespace Microsoft.Azure.Commands.HDInsight.Test
2628
{
@@ -195,14 +197,93 @@ public void CreateStreamingJob()
195197
job.Reducer == reducer && job.Defines.Count == defines.Count)));
196198
}
197199

198-
[Fact(Skip = "Test requires setting env variable, TODO remove that constraint")]
200+
[Fact]
201+
[Trait(Category.AcceptanceType, Category.CheckIn)]
202+
public void GetJobWithIdProvided()
203+
{
204+
// Update HDInsight Management properties for Job.
205+
SetupManagementClientForJobTests();
206+
207+
var jobId = "jobid_1984120_001";
208+
var cmdlet = GetJobCommandDefinition();
209+
cmdlet.JobId = jobId;
210+
211+
// Setup Job Management mocks
212+
var jobResponse = new JobGetResponse
213+
{
214+
JobDetail = new JobDetailRootJsonObject { Id = jobId, Status = new Status(), Userargs = new Userargs() }
215+
};
216+
217+
hdinsightJobManagementMock.Setup(c => c.GetJob(It.IsAny<string>()))
218+
.Returns(jobResponse)
219+
.Verifiable();
220+
221+
cmdlet.ExecuteCmdlet();
222+
commandRuntimeMock.VerifyAll();
223+
commandRuntimeMock.Verify(
224+
f =>
225+
f.WriteObject(It.Is<AzureHDInsightJob>(job => job.JobId.Equals(jobId))));
226+
}
227+
228+
[Fact]
229+
[Trait(Category.AcceptanceType, Category.CheckIn)]
230+
public void ListJobs()
231+
{
232+
// Update HDInsight Management properties for Job.
233+
SetupManagementClientForJobTests();
234+
235+
var cmdlet = GetJobCommandDefinition();
236+
237+
// Setup Job Management mocks
238+
var jobListResponse = GetJobListResponse();
239+
240+
hdinsightJobManagementMock.Setup(c => c.ListJobs())
241+
.Returns(jobListResponse)
242+
.Verifiable();
243+
244+
cmdlet.ExecuteCmdlet();
245+
commandRuntimeMock.VerifyAll();
246+
commandRuntimeMock.Verify(
247+
f =>
248+
f.WriteObject(It.Is<IEnumerable<string>>(job => job.ElementAt(0).Equals(jobListResponse.ElementAt(0).Detail.Id) && job.ElementAt(1).Equals(jobListResponse.ElementAt(1).Detail.Id)), true));
249+
}
250+
251+
[Fact]
252+
[Trait(Category.AcceptanceType, Category.CheckIn)]
253+
public void ListJobsAfterJobId()
254+
{
255+
// Update HDInsight Management properties for Job.
256+
SetupManagementClientForJobTests();
257+
258+
var cmdlet = GetJobCommandDefinition();
259+
cmdlet.NumOfJobs = 2;
260+
261+
// Setup Job Management mocks
262+
var jobListResponse = GetJobListResponse();
263+
264+
hdinsightJobManagementMock.Setup(c => c.ListJobsAfterJobId(It.IsAny<string>(), It.IsAny<int>()))
265+
.Returns(jobListResponse)
266+
.Verifiable();
267+
268+
cmdlet.ExecuteCmdlet();
269+
commandRuntimeMock.VerifyAll();
270+
commandRuntimeMock.Verify(
271+
f =>
272+
f.WriteObject(It.Is<IEnumerable<AzureHDInsightJob>>(job => job.ElementAt(0).JobId.Equals(jobListResponse.ElementAt(0).Detail.Id) && job.ElementAt(1).JobId.Equals(jobListResponse.ElementAt(1).Detail.Id)), true));
273+
}
274+
275+
[Fact]
199276
[Trait(Category.AcceptanceType, Category.CheckIn)]
200277
public void StartJob()
201278
{
279+
// Update HDInsight Management properties for Job.
280+
SetupManagementClientForJobTests();
281+
202282
var cmdlet = new StartAzureHDInsightJobCommand
203283
{
204284
CommandRuntime = commandRuntimeMock.Object,
205285
HDInsightJobClient = hdinsightJobManagementMock.Object,
286+
HDInsightManagementClient = hdinsightManagementMock.Object,
206287
HttpCredential = new PSCredential("httpuser", string.Format("Password1!").ConvertToSecureString()),
207288
ClusterName = ClusterName
208289
};
@@ -246,7 +327,9 @@ public void StartJob()
246327
{
247328
Completed = "false",
248329
User = cmdlet.HttpCredential.UserName,
249-
Id = jobid
330+
Id = jobid,
331+
Status = new Status(),
332+
Userargs = new Userargs()
250333
}
251334
};
252335
hdinsightJobManagementMock.Setup(c => c.GetJob(jobsub.JobSubmissionJsonResponse.Id)).Returns(getresponse).Verifiable();
@@ -259,5 +342,42 @@ public void StartJob()
259342
It.Is<AzureHDInsightJob>(
260343
job => job.Cluster == ClusterName && job.JobId == jobid && job.Completed == "false")));
261344
}
345+
346+
public JobListResponse GetJobListResponse()
347+
{
348+
var jobListobject1 = new JobListJsonObject
349+
{
350+
Detail = new JobDetailRootJsonObject { Id = "jobid_1984120_001", Status = new Status(), Userargs = new Userargs() },
351+
Id = "jobid_1984120_001"
352+
};
353+
354+
var jobListobject2 = new JobListJsonObject
355+
{
356+
Detail = new JobDetailRootJsonObject { Id = "jobid_1984120_002", Status = new Status(), Userargs = new Userargs() },
357+
Id = "jobid_1984120_002"
358+
};
359+
360+
var jobListResponse = new JobListResponse
361+
{
362+
JobList = new List<JobListJsonObject> { jobListobject1, jobListobject2 },
363+
StatusCode = HttpStatusCode.OK
364+
};
365+
366+
return jobListResponse;
367+
}
368+
369+
public GetAzureHDInsightJobCommand GetJobCommandDefinition()
370+
{
371+
var cmdlet = new GetAzureHDInsightJobCommand
372+
{
373+
CommandRuntime = commandRuntimeMock.Object,
374+
HDInsightJobClient = hdinsightJobManagementMock.Object,
375+
HDInsightManagementClient = hdinsightManagementMock.Object,
376+
HttpCredential = new PSCredential("httpuser", string.Format("Password1!").ConvertToSecureString()),
377+
ClusterName = ClusterName
378+
};
379+
380+
return cmdlet;
381+
}
262382
}
263383
}

src/ResourceManager/HDInsight/Commands.HDInsight/HDInsightCmdletBase.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Microsoft.Azure.Commands.HDInsight.Models;
1919
using Microsoft.Azure.Commands.ResourceManager.Common;
2020
using Microsoft.WindowsAzure.Commands.Utilities.Common;
21+
using Microsoft.Azure.Management.HDInsight;
2122

2223
namespace Microsoft.Azure.Commands.HDInsight.Commands
2324
{
@@ -99,5 +100,28 @@ protected string GetResourceGroupByAccountName(string clusterName)
99100
}
100101
}
101102

103+
protected AzureHDInsightDefaultStorageAccount GetDefaultStorageAccount(string resourceGroupName, string clusterName)
104+
{
105+
var result = HDInsightManagementClient.GetCluster(resourceGroupName, clusterName);
106+
107+
if (result == null || result.Count == 0)
108+
{
109+
throw new CloudException(string.Format("Couldn't find cluster {0}", clusterName));
110+
}
111+
112+
var cluster = result.FirstOrDefault();
113+
var configuration = HDInsightManagementClient.GetClusterConfigurations(resourceGroupName, cluster.Name, ConfigurationKey.CoreSite);
114+
115+
var DefaultStorageAccount = ClusterConfigurationUtils.GetDefaultStorageAccountDetails(
116+
configuration,
117+
cluster.Properties.ClusterVersion);
118+
119+
if (DefaultStorageAccount == null)
120+
{
121+
throw new CloudException(string.Format("Couldn't find storage information for cluster {0}", clusterName));
122+
}
123+
124+
return DefaultStorageAccount;
125+
}
102126
}
103127
}

src/ResourceManager/HDInsight/Commands.HDInsight/JobCommands/GetAzureHDInsightJobOutputCommand.cs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -133,34 +133,11 @@ private static string Convert(Stream stream)
133133
return text;
134134
}
135135

136-
internal IStorageAccess GetDefaultStorageAccess(string ResourceGroupName, string clusterName)
136+
internal IStorageAccess GetDefaultStorageAccess(string resourceGroupName, string clusterName)
137137
{
138138
if (DefaultContainer == null && DefaultStorageAccountName == null && DefaultStorageAccountKey == null)
139139
{
140-
var result = HDInsightManagementClient.GetCluster(ResourceGroupName, clusterName);
141-
142-
if (result == null || result.Count == 0)
143-
{
144-
throw new CloudException(string.Format("Couldn't find cluster {0}", clusterName));
145-
}
146-
147-
var cluster = result.FirstOrDefault();
148-
string resourceGroupName = ClusterConfigurationUtils.GetResourceGroupFromClusterId(cluster.Id);
149-
var configuration = HDInsightManagementClient.GetClusterConfigurations(resourceGroupName, cluster.Name, "core-site");
150-
151-
if (configuration == null)
152-
{
153-
throw new CloudException(string.Format("Couldn't find storage information for cluster {0}", clusterName));
154-
}
155-
156-
var DefaultStorageAccount = ClusterConfigurationUtils.GetDefaultStorageAccountDetails(
157-
configuration,
158-
cluster.Properties.ClusterVersion);
159-
160-
if (DefaultStorageAccount == null)
161-
{
162-
throw new CloudException(string.Format("Couldn't find storage information for cluster {0}", clusterName));
163-
}
140+
var DefaultStorageAccount = GetDefaultStorageAccount(resourceGroupName, clusterName);
164141

165142
DefaultContainer = DefaultStorageAccount.StorageContainerName;
166143
DefaultStorageAccountName = DefaultStorageAccount.StorageAccountName;

src/ResourceManager/HDInsight/Commands.HDInsight/JobCommands/NewAzureHDInsightSqoopJobDefinitionCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public string Command
5555
set { job.Command = value; }
5656
}
5757

58-
[Parameter(HelpMessage = "The output location to use for the job.")]
58+
[Parameter(HelpMessage = "The directory where the libjar can be found for the Sqoop job.")]
5959
public string LibDir
6060
{
6161
get { return job.LibDir; }

0 commit comments

Comments
 (0)