Skip to content

Commit b2a0601

Browse files
committed
Merged changes
1 parent 6a51d54 commit b2a0601

File tree

4 files changed

+35
-34
lines changed

4 files changed

+35
-34
lines changed

src/ResourceManager/HDInsight/Commands.HDInsight/ClusterConfigurationUtils.cs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,34 @@ namespace Microsoft.Azure.Commands.HDInsight.Models
2020
internal class ClusterConfigurationUtils
2121
{
2222
public static string GetResourceGroupFromClusterId(string clusterId)
23-
{
24-
string clusterGroup = null;
23+
{
24+
// Parse resource group from cluster Id
25+
// The code expects Id to be of the format \
26+
// /subscriptions/<subscription ID>/resourceGroups/<Resource Group Id>/providers/Microsoft.HDInsight/clusters/<cluster name>
27+
28+
string resourceGroup = null;
2529
int index = clusterId.IndexOf("resourceGroups", StringComparison.OrdinalIgnoreCase);
2630

2731
if (index >= 0)
2832
{
2933
index += "resourceGroups".Length;
30-
string[] parts = clusterId.Substring(index).Split(new [] { '/' }, StringSplitOptions.RemoveEmptyEntries);
34+
string[] parts = clusterId.Substring(index).Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
3135

3236
if (parts.Length > 0)
3337
{
34-
clusterGroup = parts[0];
38+
resourceGroup = parts[0];
3539
}
36-
}
40+
}
3741

38-
return clusterGroup;
42+
return resourceGroup;
3943
}
4044

4145
public static AzureHDInsightDefaultStorageAccount GetDefaultStorageAccountDetails(
42-
IDictionary<string, string> configuration,
46+
IDictionary<string, string> configuration,
4347
string version)
44-
{
45-
string key = Constants.ClusterConfiguration.DefaultStorageAccountNameKey;
46-
47-
if (version.Equals("2.1"))
48-
{
49-
key = Constants.ClusterConfiguration.DefaultStorageAccountNameKeyOld;
50-
}
48+
{
49+
string key = version.Equals("2.1") ? Constants.ClusterConfiguration.DefaultStorageAccountNameKeyOld
50+
: Constants.ClusterConfiguration.DefaultStorageAccountNameKey;
5151

5252
string accountAndContainerStr;
5353

@@ -68,9 +68,10 @@ public static AzureHDInsightDefaultStorageAccount GetDefaultStorageAccountDetail
6868

6969
public static List<string> GetAdditionStorageAccounts(IDictionary<string, string> configuration, string defaultAccount)
7070
{
71-
return (from key in configuration.Keys
72-
where key.StartsWith(Constants.ClusterConfiguration.StorageAccountKeyPrefix) &&
73-
!key.EndsWith(defaultAccount)
71+
// Parse the storage account names from the key and exclude the default one
72+
return (from key in configuration.Keys
73+
where key.StartsWith(Constants.ClusterConfiguration.StorageAccountKeyPrefix, StringComparison.OrdinalIgnoreCase) &&
74+
!key.EndsWith(defaultAccount, StringComparison.OrdinalIgnoreCase)
7475
select key.Remove(0, Constants.ClusterConfiguration.StorageAccountKeyPrefix.Length)).ToList();
7576
}
7677
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ public class GetAzureHDInsightCommand : HDInsightCmdletBase
4545
protected override void ProcessRecord()
4646
{
4747
var result = HDInsightManagementClient.GetCluster(ResourceGroupName, ClusterName);
48-
48+
4949
var output = result.Select(entry =>
5050
{
51-
var configuration = HDInsightManagementClient.GetClusterConfigurations(entry, "core-site");
52-
return new AzureHDInsightCluster(entry, configuration);
51+
string resourceGroupName = ClusterConfigurationUtils.GetResourceGroupFromClusterId(entry.Id);
52+
var configuration = HDInsightManagementClient.GetClusterConfigurations(resourceGroupName, entry.Name, "core-site");
53+
return new AzureHDInsightCluster(entry, configuration);
5354
}).ToList();
5455

5556
WriteObject(output, true);

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ public AzureHDInsightCluster(Cluster cluster)
3636
HttpEndpoint = httpEndpoint != null ? httpEndpoint.Location : null;
3737

3838
ResourceGroup = ClusterConfigurationUtils.GetResourceGroupFromClusterId(cluster.Id);
39-
4039
}
4140

42-
public AzureHDInsightCluster(Cluster cluster, IDictionary<string, string> clusterConfiguration)
41+
public AzureHDInsightCluster(Cluster cluster, IDictionary<string, string> clusterConfiguration)
4342
: this(cluster)
4443
{
4544
if (clusterConfiguration != null)
@@ -53,19 +52,18 @@ public AzureHDInsightCluster(Cluster cluster, IDictionary<string, string> cluste
5352

5453
AdditionalStorageAccounts = ClusterConfigurationUtils.GetAdditionStorageAccounts(clusterConfiguration, DefaultStorageAccount);
5554
}
56-
5755
}
5856

5957
/// <summary>
6058
/// The name of the resource.
6159
/// </summary>
6260
public string Name { get; set; }
63-
61+
6462
/// <summary>
6563
/// The ID of the resource.
6664
/// </summary>
6765
public string Id { get; set; }
68-
66+
6967
/// <summary>
7068
/// The location of the resource.
7169
/// </summary>
@@ -100,7 +98,7 @@ public AzureHDInsightCluster(Cluster cluster, IDictionary<string, string> cluste
10098
/// The endpoint with which to connect to the cluster.
10199
/// </summary>
102100
public string HttpEndpoint { get; set; }
103-
101+
104102
/// <summary>
105103
/// Default storage account for this cluster.
106104
/// </summary>

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public virtual List<Cluster> GetCluster(string resourceGroupName, string cluster
5959
var getresponse = Get(resourceGroupName, clusterName);
6060
if (getresponse != null)
6161
{
62-
result.Add(getresponse.Cluster);
62+
result.Add(getresponse.Cluster);
6363
}
6464
}
6565
return result;
@@ -72,7 +72,7 @@ public virtual ClusterListResponse ListClusters()
7272

7373
public virtual ClusterListResponse ListClusters(string resourceGroupName)
7474
{
75-
return HdInsightManagementClient.Clusters.ListByResourceGroup(resourceGroupName);
75+
return HdInsightManagementClient.Clusters.ListByResourceGroup(resourceGroupName);
7676
}
7777

7878
public virtual ClusterGetResponse Get(string resourceGroupName, string clusterName)
@@ -110,19 +110,20 @@ public virtual CapabilitiesResponse GetCapabilities(string location)
110110
return HdInsightManagementClient.Clusters.GetCapabilities(location);
111111
}
112112

113-
public virtual IDictionary<string, string> GetClusterConfigurations(Cluster cluster, string configurationName)
113+
public virtual IDictionary<string, string> GetClusterConfigurations(string resourceGroupName, string clusterName, string configurationName)
114114
{
115115
Dictionary<string, string> properties = new Dictionary<string, string>();
116-
117-
if(string.IsNullOrWhiteSpace(configurationName))
116+
117+
if (string.IsNullOrWhiteSpace(resourceGroupName) ||
118+
string.IsNullOrWhiteSpace(clusterName) ||
119+
string.IsNullOrWhiteSpace(configurationName))
118120
{
119121
return properties;
120122
}
121123

122-
string resourceGroupName = ClusterConfigurationUtils.GetResourceGroupFromClusterId(cluster.Id);
123124
return HdInsightManagementClient.Clusters.GetClusterConfigurations(
124-
resourceGroupName,
125-
cluster.Name,
125+
resourceGroupName,
126+
clusterName,
126127
configurationName).Configuration;
127128
}
128129
}

0 commit comments

Comments
 (0)