Skip to content

Commit 10354c8

Browse files
author
Abhijith Padmakumar
committed
Update New-AzureRmHDInsightCluster cmdlet to support data disks groups for workernode during cluster creation.
1 parent cb572aa commit 10354c8

File tree

5 files changed

+185
-1
lines changed

5 files changed

+185
-1
lines changed

src/ResourceManager/HDInsight/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Added support for Data Disks property in cluster creation
22+
- Added parameter 'WorkerNodeDataDisksGroups' to the New-AzureHDInsightCluster cmdlet
2123

2224
## Version 3.3.1
2325

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

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Moq;
2121
using Newtonsoft.Json;
2222
using System.Collections.Generic;
23+
using System.Linq;
2324
using System.Management.Automation;
2425
using Xunit;
2526

@@ -438,6 +439,141 @@ public void CanCreateNewHDInsightCluster_LinuxComponentVersion()
438439
Times.Once);
439440
}
440441

442+
[Fact]
443+
[Trait(Category.AcceptanceType, Category.CheckIn)]
444+
public void CanCreateNewHDInsightCluster_DataDisksGroups()
445+
{
446+
var kafkaClusterType = "Kafka";
447+
var hdiVersion = "3.6";
448+
var coresUsed = 24;
449+
var expectedClusterState = "Running";
450+
var dataDisksGroup = new DataDisksGroupProperties()
451+
{
452+
DisksPerNode = 8
453+
};
454+
var workerNodeDataDisksGroups = new List<DataDisksGroupProperties>()
455+
{
456+
dataDisksGroup
457+
};
458+
459+
cmdlet.ClusterName = ClusterName;
460+
cmdlet.ResourceGroupName = ResourceGroupName;
461+
cmdlet.ClusterSizeInNodes = ClusterSize;
462+
cmdlet.Location = Location;
463+
cmdlet.HttpCredential = _httpCred;
464+
cmdlet.DefaultStorageAccountName = StorageName;
465+
cmdlet.DefaultStorageAccountKey = StorageKey;
466+
cmdlet.ClusterType = kafkaClusterType;
467+
cmdlet.SshCredential = _sshCred;
468+
cmdlet.OSType = OSType.Linux;
469+
cmdlet.WorkerNodeDataDisksGroups = workerNodeDataDisksGroups;
470+
471+
var cluster = new Cluster
472+
{
473+
Id = "id",
474+
Name = ClusterName,
475+
Location = Location,
476+
Properties = new ClusterGetProperties
477+
{
478+
ClusterVersion = hdiVersion,
479+
ClusterState = expectedClusterState,
480+
ClusterDefinition = new ClusterDefinition
481+
{
482+
ClusterType = kafkaClusterType
483+
},
484+
QuotaInfo = new QuotaInfo
485+
{
486+
CoresUsed = coresUsed
487+
},
488+
OperatingSystemType = OSType.Linux,
489+
ComputeProfile = new ComputeProfile()
490+
{
491+
Roles = new List<Role>()
492+
}
493+
}
494+
};
495+
496+
cluster.Properties.ComputeProfile.Roles.Add(new Role()
497+
{
498+
Name = "workernode",
499+
DataDisksGroups = workerNodeDataDisksGroups
500+
});
501+
502+
var coreConfigs = new Dictionary<string, string>
503+
{
504+
{"fs.defaultFS", "wasb://giyertestcsmv2@" + StorageName},
505+
{
506+
"fs.azure.account.key." + StorageName,
507+
StorageKey
508+
}
509+
};
510+
var gatewayConfigs = new Dictionary<string, string>
511+
{
512+
{"restAuthCredential.isEnabled", "true"},
513+
{"restAuthCredential.username", _httpCred.UserName},
514+
{"restAuthCredential.password", _httpCred.Password.ConvertToString()}
515+
};
516+
517+
var configurations = new Dictionary<string, Dictionary<string, string>>
518+
{
519+
{"core-site", coreConfigs},
520+
{"gateway", gatewayConfigs}
521+
};
522+
var serializedConfig = JsonConvert.SerializeObject(configurations);
523+
cluster.Properties.ClusterDefinition.Configurations = serializedConfig;
524+
525+
var getresponse = new ClusterGetResponse { Cluster = cluster };
526+
527+
hdinsightManagementMock.Setup(c => c.CreateNewCluster(ResourceGroupName, ClusterName, It.Is<ClusterCreateParameters>(
528+
parameters =>
529+
parameters.ClusterSizeInNodes == ClusterSize &&
530+
parameters.DefaultStorageInfo as AzureStorageInfo != null &&
531+
((AzureStorageInfo)parameters.DefaultStorageInfo).StorageAccountName == StorageName &&
532+
((AzureStorageInfo)parameters.DefaultStorageInfo).StorageAccountKey == StorageKey &&
533+
parameters.Location == Location &&
534+
parameters.UserName == _httpCred.UserName &&
535+
parameters.Password == _httpCred.Password.ConvertToString() &&
536+
parameters.ClusterType == kafkaClusterType &&
537+
parameters.OSType == OSType.Linux &&
538+
parameters.SshUserName == _sshCred.UserName &&
539+
parameters.SshPassword == _sshCred.Password.ConvertToString() &&
540+
parameters.WorkerNodeDataDisksGroups.First().DisksPerNode == dataDisksGroup.DisksPerNode)))
541+
.Returns(getresponse)
542+
.Verifiable();
543+
hdinsightManagementMock.Setup(
544+
c => c.CreateNewCluster(ResourceGroupName, ClusterName, It.Is<ClusterCreateParameters>(
545+
parameters =>
546+
parameters.ClusterSizeInNodes == ClusterSize &&
547+
parameters.DefaultStorageInfo as AzureStorageInfo != null &&
548+
((AzureStorageInfo)parameters.DefaultStorageInfo).StorageAccountName == StorageName &&
549+
((AzureStorageInfo)parameters.DefaultStorageInfo).StorageAccountKey == StorageKey &&
550+
parameters.Location == Location &&
551+
parameters.UserName == _httpCred.UserName &&
552+
parameters.Password == _httpCred.Password.ConvertToString() &&
553+
parameters.ClusterType == ClusterType &&
554+
parameters.OSType == OSType.Linux &&
555+
parameters.SshUserName == _sshCred.UserName &&
556+
parameters.SshPassword == _sshCred.Password.ConvertToString())))
557+
.Returns(getresponse)
558+
.Verifiable();
559+
560+
cmdlet.ExecuteCmdlet();
561+
562+
commandRuntimeMock.VerifyAll();
563+
564+
565+
commandRuntimeMock.Verify(f => f.WriteObject(It.Is<AzureHDInsightCluster>(
566+
clusterout =>
567+
clusterout.ClusterState == expectedClusterState &&
568+
clusterout.ClusterType == kafkaClusterType &&
569+
clusterout.ClusterVersion == hdiVersion &&
570+
clusterout.CoresUsed == coresUsed &&
571+
clusterout.Location == Location &&
572+
clusterout.Name == ClusterName &&
573+
clusterout.OperatingSystemType == OSType.Linux)),
574+
Times.Once);
575+
}
576+
441577
[Fact]
442578
[Trait(Category.AcceptanceType, Category.CheckIn)]
443579
public void TestStorageAccountTypeDefaultsToAzureStorage()

src/ResourceManager/HDInsight/Commands.HDInsight/ManagementCommands/NewAzureHDInsightClusterCommand.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ var storageAccount in
157157
{
158158
result.ComponentVersion.Add(component.Key, component.Value);
159159
}
160+
foreach (var dataDisksGroups in parameters.WorkerNodeDataDisksGroups.Where(d => d.DisksPerNode > 0))
161+
{
162+
result.DataDisksGroupProperties.Add(dataDisksGroups);
163+
}
160164
return result;
161165
}
162166
set
@@ -207,6 +211,10 @@ var storageAccount in
207211
{
208212
parameters.ComponentVersion.Add(component.Key, component.Value);
209213
}
214+
foreach (var dataDisksGroups in value.DataDisksGroupProperties.Where(d => d.DisksPerNode > 0))
215+
{
216+
this.parameters.WorkerNodeDataDisksGroups.Add(dataDisksGroups);
217+
}
210218
}
211219
}
212220

@@ -284,6 +292,13 @@ public Dictionary<string, string> ComponentVersion
284292
set { parameters.ComponentVersion = value; }
285293
}
286294

295+
[Parameter(HelpMessage = "Gets or sets the data disks groups for worker node role in the cluster.")]
296+
public List<DataDisksGroupProperties> WorkerNodeDataDisksGroups
297+
{
298+
get { return parameters.WorkerNodeDataDisksGroups; }
299+
set { parameters.WorkerNodeDataDisksGroups = value; }
300+
}
301+
287302
[Parameter(HelpMessage = "Gets or sets the virtual network guid for this HDInsight cluster.")]
288303
public string VirtualNetworkId
289304
{
@@ -456,7 +471,19 @@ var storageAccount in
456471
ClusterUsersGroupDNs = SecurityProfile.ClusterUsersGroupDNs
457472
};
458473
}
459-
474+
475+
if (WorkerNodeDataDisksGroups != null)
476+
{
477+
var dataDisksGroups = WorkerNodeDataDisksGroups;
478+
this.parameters.WorkerNodeDataDisksGroups = new List<DataDisksGroupProperties>()
479+
{
480+
new DataDisksGroupProperties()
481+
{
482+
DisksPerNode = dataDisksGroups.First().DisksPerNode
483+
}
484+
};
485+
}
486+
460487
var cluster = HDInsightManagementClient.CreateNewCluster(ResourceGroupName, ClusterName, parameters);
461488

462489
if (cluster != null)

src/ResourceManager/HDInsight/Commands.HDInsight/Models/Management/AzureHDInsightCluster.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ public AzureHDInsightCluster(Cluster cluster)
4545
{
4646
ComponentVersion.Add(componentVersion.ToString());
4747
}
48+
WorkerNodeDataDisksGroups = new List<DataDisksGroupProperties>();
49+
if (cluster.Properties.ComputeProfile != null && cluster.Properties.ComputeProfile.Roles.Any())
50+
{
51+
foreach (var role in cluster.Properties.ComputeProfile.Roles)
52+
{
53+
WorkerNodeDataDisksGroups.AddRange(role.DataDisksGroups);
54+
}
55+
}
4856
var clusterSecurityProfile = cluster.Properties.SecurityProfile;
4957
SecurityProfile = clusterSecurityProfile != null ? new AzureHDInsightSecurityProfile()
5058
{
@@ -178,6 +186,11 @@ public AzureHDInsightCluster(Cluster cluster, IDictionary<string, string> cluste
178186
/// Version of a component service in the cluster
179187
/// </summary>
180188
public List<string> ComponentVersion { get; set; }
189+
190+
/// <summary>
191+
/// Data Disks Properties for the worker role.
192+
/// </summary>
193+
public List<DataDisksGroupProperties> WorkerNodeDataDisksGroups { get; set; }
181194

182195
/// Gets or sets the security profile.
183196
/// </summary>

src/ResourceManager/HDInsight/Commands.HDInsight/Models/Management/AzureHDInsightConfig.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,19 @@ public class AzureHDInsightConfig
130130
/// </value>
131131
public AzureHDInsightSecurityProfile SecurityProfile { get; set; }
132132

133+
/// <summary>
134+
/// Gets or sets the data disks groups properties for the cluster.
135+
/// </summary>
136+
public List<DataDisksGroupProperties> DataDisksGroupProperties { get; set; }
137+
133138
public AzureHDInsightConfig()
134139
{
135140
ClusterType = Constants.Hadoop;
136141
AdditionalStorageAccounts = new Dictionary<string, string>();
137142
Configurations = new Dictionary<string, Hashtable>();
138143
ScriptActions = new Dictionary<ClusterNodeType, List<AzureHDInsightScriptAction>>();
139144
ComponentVersion = new Dictionary<string, string>();
145+
DataDisksGroupProperties = new List<DataDisksGroupProperties>();
140146
}
141147
}
142148
}

0 commit comments

Comments
 (0)