Skip to content

Commit 595f7fb

Browse files
Abhijith Padmakumarprbansa
authored andcommitted
Update New-AzureRmHDInsightCluster cmdlet to support data disks groups for workernode during cluster creation.
1 parent 22d98f3 commit 595f7fb

File tree

4 files changed

+153
-13
lines changed

4 files changed

+153
-13
lines changed

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

Lines changed: 129 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,12 +471,137 @@ public void CanCreateNewHDInsightCluster_LinuxComponentVersion()
471471

472472
[Fact]
473473
[Trait(Category.AcceptanceType, Category.CheckIn)]
474-
public void CanCreateNewHDInsightCluster_Kafka_DataDisks_Linux()
474+
public void CanCreateNewHDInsightCluster_DataDisksGroups()
475475
{
476-
ClusterType = "Kafka";
477-
HdiVersion = "3.6";
476+
var kafkaClusterType = "Kafka";
477+
var hdiVersion = "3.6";
478+
var coresUsed = 24;
479+
var expectedClusterState = "Running";
480+
var dataDisksGroup = new DataDisksGroupProperties()
481+
{
482+
DisksPerNode = 8
483+
};
484+
var workerNodeDataDisksGroups = new List<DataDisksGroupProperties>()
485+
{
486+
dataDisksGroup
487+
};
488+
489+
cmdlet.ClusterName = ClusterName;
490+
cmdlet.ResourceGroupName = ResourceGroupName;
491+
cmdlet.ClusterSizeInNodes = ClusterSize;
492+
cmdlet.Location = Location;
493+
cmdlet.HttpCredential = _httpCred;
494+
cmdlet.DefaultStorageAccountName = StorageName;
495+
cmdlet.DefaultStorageAccountKey = StorageKey;
496+
cmdlet.ClusterType = kafkaClusterType;
497+
cmdlet.SshCredential = _sshCred;
498+
cmdlet.OSType = OSType.Linux;
499+
cmdlet.WorkerNodeDataDisksGroups = workerNodeDataDisksGroups;
500+
501+
var cluster = new Cluster
502+
{
503+
Id = "id",
504+
Name = ClusterName,
505+
Location = Location,
506+
Properties = new ClusterGetProperties
507+
{
508+
ClusterVersion = hdiVersion,
509+
ClusterState = expectedClusterState,
510+
ClusterDefinition = new ClusterDefinition
511+
{
512+
ClusterType = kafkaClusterType
513+
},
514+
QuotaInfo = new QuotaInfo
515+
{
516+
CoresUsed = coresUsed
517+
},
518+
OperatingSystemType = OSType.Linux,
519+
ComputeProfile = new ComputeProfile()
520+
{
521+
Roles = new List<Role>()
522+
}
523+
}
524+
};
525+
526+
cluster.Properties.ComputeProfile.Roles.Add(new Role()
527+
{
528+
Name = "workernode",
529+
DataDisksGroups = workerNodeDataDisksGroups
530+
});
531+
532+
var coreConfigs = new Dictionary<string, string>
533+
{
534+
{"fs.defaultFS", "wasb://giyertestcsmv2@" + StorageName},
535+
{
536+
"fs.azure.account.key." + StorageName,
537+
StorageKey
538+
}
539+
};
540+
var gatewayConfigs = new Dictionary<string, string>
541+
{
542+
{"restAuthCredential.isEnabled", "true"},
543+
{"restAuthCredential.username", _httpCred.UserName},
544+
{"restAuthCredential.password", _httpCred.Password.ConvertToString()}
545+
};
478546

479-
CreateNewHDInsightCluster(workerNodeDataDisks: 8);
547+
var configurations = new Dictionary<string, Dictionary<string, string>>
548+
{
549+
{"core-site", coreConfigs},
550+
{"gateway", gatewayConfigs}
551+
};
552+
var serializedConfig = JsonConvert.SerializeObject(configurations);
553+
cluster.Properties.ClusterDefinition.Configurations = serializedConfig;
554+
555+
var getresponse = new ClusterGetResponse { Cluster = cluster };
556+
557+
hdinsightManagementMock.Setup(c => c.CreateNewCluster(ResourceGroupName, ClusterName, It.Is<ClusterCreateParameters>(
558+
parameters =>
559+
parameters.ClusterSizeInNodes == ClusterSize &&
560+
parameters.DefaultStorageInfo as AzureStorageInfo != null &&
561+
((AzureStorageInfo)parameters.DefaultStorageInfo).StorageAccountName == StorageName &&
562+
((AzureStorageInfo)parameters.DefaultStorageInfo).StorageAccountKey == StorageKey &&
563+
parameters.Location == Location &&
564+
parameters.UserName == _httpCred.UserName &&
565+
parameters.Password == _httpCred.Password.ConvertToString() &&
566+
parameters.ClusterType == kafkaClusterType &&
567+
parameters.OSType == OSType.Linux &&
568+
parameters.SshUserName == _sshCred.UserName &&
569+
parameters.SshPassword == _sshCred.Password.ConvertToString() &&
570+
parameters.WorkerNodeDataDisksGroups.First().DisksPerNode == dataDisksGroup.DisksPerNode)))
571+
.Returns(getresponse)
572+
.Verifiable();
573+
hdinsightManagementMock.Setup(
574+
c => c.CreateNewCluster(ResourceGroupName, ClusterName, It.Is<ClusterCreateParameters>(
575+
parameters =>
576+
parameters.ClusterSizeInNodes == ClusterSize &&
577+
parameters.DefaultStorageInfo as AzureStorageInfo != null &&
578+
((AzureStorageInfo)parameters.DefaultStorageInfo).StorageAccountName == StorageName &&
579+
((AzureStorageInfo)parameters.DefaultStorageInfo).StorageAccountKey == StorageKey &&
580+
parameters.Location == Location &&
581+
parameters.UserName == _httpCred.UserName &&
582+
parameters.Password == _httpCred.Password.ConvertToString() &&
583+
parameters.ClusterType == ClusterType &&
584+
parameters.OSType == OSType.Linux &&
585+
parameters.SshUserName == _sshCred.UserName &&
586+
parameters.SshPassword == _sshCred.Password.ConvertToString())))
587+
.Returns(getresponse)
588+
.Verifiable();
589+
590+
cmdlet.ExecuteCmdlet();
591+
592+
commandRuntimeMock.VerifyAll();
593+
594+
595+
commandRuntimeMock.Verify(f => f.WriteObject(It.Is<AzureHDInsightCluster>(
596+
clusterout =>
597+
clusterout.ClusterState == expectedClusterState &&
598+
clusterout.ClusterType == kafkaClusterType &&
599+
clusterout.ClusterVersion == hdiVersion &&
600+
clusterout.CoresUsed == coresUsed &&
601+
clusterout.Location == Location &&
602+
clusterout.Name == ClusterName &&
603+
clusterout.OperatingSystemType == OSType.Linux)),
604+
Times.Once);
480605
}
481606

482607
[Fact]

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ var storageAccount in
158158
{
159159
result.ComponentVersion.Add(component.Key, component.Value);
160160
}
161-
161+
foreach (var dataDisksGroups in parameters.WorkerNodeDataDisksGroups.Where(d => d.DisksPerNode > 0))
162+
{
163+
result.DataDisksGroupProperties.Add(dataDisksGroups);
164+
}
162165
return result;
163166
}
164167
set
@@ -210,6 +213,10 @@ var storageAccount in
210213
{
211214
parameters.ComponentVersion.Add(component.Key, component.Value);
212215
}
216+
foreach (var dataDisksGroups in value.DataDisksGroupProperties.Where(d => d.DisksPerNode > 0))
217+
{
218+
this.parameters.WorkerNodeDataDisksGroups.Add(dataDisksGroups);
219+
}
213220
}
214221
}
215222

@@ -287,6 +294,13 @@ public Dictionary<string, string> ComponentVersion
287294
set { parameters.ComponentVersion = value; }
288295
}
289296

297+
[Parameter(HelpMessage = "Gets or sets the data disks groups for worker node role in the cluster.")]
298+
public List<DataDisksGroupProperties> WorkerNodeDataDisksGroups
299+
{
300+
get { return parameters.WorkerNodeDataDisksGroups; }
301+
set { parameters.WorkerNodeDataDisksGroups = value; }
302+
}
303+
290304
[Parameter(HelpMessage = "Gets or sets the virtual network guid for this HDInsight cluster.")]
291305
public string VirtualNetworkId
292306
{
@@ -463,13 +477,14 @@ var storageAccount in
463477
};
464478
}
465479

466-
if (DisksPerWorkerNode > 0)
480+
if (WorkerNodeDataDisksGroups != null)
467481
{
468-
parameters.WorkerNodeDataDisksGroups = new List<DataDisksGroupProperties>()
482+
var dataDisksGroups = WorkerNodeDataDisksGroups;
483+
this.parameters.WorkerNodeDataDisksGroups = new List<DataDisksGroupProperties>()
469484
{
470485
new DataDisksGroupProperties()
471486
{
472-
DisksPerNode = DisksPerWorkerNode
487+
DisksPerNode = dataDisksGroups.First().DisksPerNode
473488
}
474489
};
475490
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ public AzureHDInsightCluster(Cluster cluster)
4848
WorkerNodeDataDisksGroups = new List<DataDisksGroupProperties>();
4949
if (cluster.Properties.ComputeProfile != null && cluster.Properties.ComputeProfile.Roles.Any())
5050
{
51-
var rolesWithDataDisksGroups = cluster.Properties.ComputeProfile.Roles.Where(x => x.DataDisksGroups != null);
52-
foreach (var role in rolesWithDataDisksGroups)
51+
foreach (var role in cluster.Properties.ComputeProfile.Roles)
5352
{
5453
WorkerNodeDataDisksGroups.AddRange(role.DataDisksGroups);
5554
}
@@ -189,7 +188,7 @@ public AzureHDInsightCluster(Cluster cluster, IDictionary<string, string> cluste
189188
public List<string> ComponentVersion { get; set; }
190189

191190
/// <summary>
192-
/// Data Disks Group Properties for the Worker Role.
191+
/// Data Disks Properties for the worker role.
193192
/// </summary>
194193
public List<DataDisksGroupProperties> WorkerNodeDataDisksGroups { get; set; }
195194

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ public class AzureHDInsightConfig
131131
public AzureHDInsightSecurityProfile SecurityProfile { get; set; }
132132

133133
/// <summary>
134-
/// Gets or sets the number of disks for worker node role for the cluster.
134+
/// Gets or sets the data disks groups properties for the cluster.
135135
/// </summary>
136-
public int DisksPerWorkerNode { get; set; }
136+
public List<DataDisksGroupProperties> DataDisksGroupProperties { get; set; }
137137

138138
public AzureHDInsightConfig()
139139
{
@@ -142,6 +142,7 @@ public AzureHDInsightConfig()
142142
Configurations = new Dictionary<string, Hashtable>();
143143
ScriptActions = new Dictionary<ClusterNodeType, List<AzureHDInsightScriptAction>>();
144144
ComponentVersion = new Dictionary<string, string>();
145+
DataDisksGroupProperties = new List<DataDisksGroupProperties>();
145146
}
146147
}
147148
}

0 commit comments

Comments
 (0)