Skip to content

Commit 23b4589

Browse files
authored
Merge pull request #10306 from aim-for-better/FixResource404WhenCreateCluster
[HDInsight] Fix Error Operation returned an invalid status code 'NotFound' when using New-AzHDInsightCluster with ADLS
2 parents a833c07 + 74b084a commit 23b4589

10 files changed

+121
-22
lines changed

src/HDInsight/HDInsight.Test/DataLakeStoreDefaultFilesystemTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class DataLakeStoreDefaultFilesystemTests : HDInsightTestBase
3232
private const string StorageName = "dummystorage.azuredatalakestore.net";
3333
private const int ClusterSize = 4;
3434
private Guid ObjectId = new Guid("11111111-1111-1111-1111-111111111111");
35+
private Guid ApplicationId = new Guid("11111111-1111-1111-1111-111111111111");
3536
private Guid AadTenantId = new Guid("11111111-1111-1111-1111-111111111111");
3637
private string Certificate = "";
3738
private string CertificatePassword = "";
@@ -61,6 +62,7 @@ public void CanCreateClusterConfigWithDataLakeStoreParameters()
6162
CommandRuntime = commandRuntimeMock.Object,
6263
HDInsightManagementClient = hdinsightManagementMock.Object,
6364
ObjectId = ObjectId,
65+
ApplicationId = ApplicationId,
6466
CertificateFilePath = Certificate,
6567
AadTenantId = AadTenantId,
6668
CertificatePassword = CertificatePassword,
@@ -76,6 +78,7 @@ public void CanCreateClusterConfigWithDataLakeStoreParameters()
7678
c.AADTenantId == AadTenantId &&
7779
c.CertificatePassword == CertificatePassword &&
7880
c.ObjectId == ObjectId &&
81+
c.ApplicationId == ApplicationId &&
7982
c.CertificateFilePath == Certificate &&
8083
c.DefaultStorageAccountName == StorageName
8184
)),
@@ -91,6 +94,7 @@ public void CanCreateDataLakeClusterWithCertificateFileContents()
9194
CommandRuntime = commandRuntimeMock.Object,
9295
HDInsightManagementClient = hdinsightManagementMock.Object,
9396
ObjectId = ObjectId,
97+
ApplicationId = ApplicationId,
9498
CertificateFileContents = CertificateFileContents,
9599
AadTenantId = AadTenantId,
96100
CertificatePassword = CertificatePassword,
@@ -106,6 +110,7 @@ public void CanCreateDataLakeClusterWithCertificateFileContents()
106110
c.AADTenantId == AadTenantId &&
107111
c.CertificatePassword == CertificatePassword &&
108112
c.ObjectId == ObjectId &&
113+
c.ApplicationId == ApplicationId &&
109114
c.CertificateFileContents == CertificateFileContents &&
110115
c.DefaultStorageAccountName == StorageName
111116
)),
@@ -121,6 +126,7 @@ public void ShouldThrowIfCertificateOptionsAreNotPassed()
121126
CommandRuntime = commandRuntimeMock.Object,
122127
HDInsightManagementClient = hdinsightManagementMock.Object,
123128
ObjectId = ObjectId,
129+
ApplicationId = ApplicationId,
124130
AadTenantId = AadTenantId,
125131
CertificatePassword = CertificatePassword
126132
};
@@ -137,6 +143,7 @@ public void ShouldThrowIfBothCertificateOptionsArePassed()
137143
CommandRuntime = commandRuntimeMock.Object,
138144
HDInsightManagementClient = hdinsightManagementMock.Object,
139145
ObjectId = ObjectId,
146+
ApplicationId = ApplicationId,
140147
AadTenantId = AadTenantId,
141148
CertificatePassword = CertificatePassword,
142149
CertificateFileContents = CertificateFileContents,

src/HDInsight/HDInsight.Test/UnitTests/DataLakeStoreTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class DataLakeStoreTests : HDInsightTestBase
3030
{
3131
private NewAzureHDInsightClusterCommand cmdlet;
3232
private Guid ObjectId = new Guid("11111111-1111-1111-1111-111111111111");
33+
private Guid ApplicationId = new Guid("11111111-1111-1111-1111-111111111111");
3334
private Guid AadTenantId = new Guid("11111111-1111-1111-1111-111111111111");
3435
private string Certificate = "";
3536
private string CertificatePassword = "";
@@ -59,6 +60,7 @@ public void CanCreateClusterConfigWithDataLakeStoreParameters()
5960
CommandRuntime = commandRuntimeMock.Object,
6061
HDInsightManagementClient = hdinsightManagementMock.Object,
6162
ObjectId = ObjectId,
63+
ApplicationId = ApplicationId,
6264
CertificateFilePath = Certificate,
6365
AadTenantId = AadTenantId,
6466
CertificatePassword = CertificatePassword
@@ -73,6 +75,7 @@ public void CanCreateClusterConfigWithDataLakeStoreParameters()
7375
c.AADTenantId == AadTenantId &&
7476
c.CertificatePassword == CertificatePassword &&
7577
c.ObjectId == ObjectId &&
78+
c.ApplicationId == ApplicationId &&
7679
c.CertificateFilePath == Certificate
7780
)),
7881
Times.Once);
@@ -87,6 +90,7 @@ public void CanCreateDataLakeClusterWithCertificationFileContents()
8790
CommandRuntime = commandRuntimeMock.Object,
8891
HDInsightManagementClient = hdinsightManagementMock.Object,
8992
ObjectId = ObjectId,
93+
ApplicationId = ApplicationId,
9094
CertificateFileContents = CertificateFileContents,
9195
AadTenantId = AadTenantId,
9296
CertificatePassword = CertificatePassword
@@ -101,6 +105,7 @@ public void CanCreateDataLakeClusterWithCertificationFileContents()
101105
c.AADTenantId == AadTenantId &&
102106
c.CertificatePassword == CertificatePassword &&
103107
c.ObjectId == ObjectId &&
108+
c.ApplicationId == ApplicationId &&
104109
c.CertificateFileContents == CertificateFileContents
105110
)),
106111
Times.Once);
@@ -115,6 +120,7 @@ public void ShouldThrowIfCertificateOptionsAreNotPassed()
115120
CommandRuntime = commandRuntimeMock.Object,
116121
HDInsightManagementClient = hdinsightManagementMock.Object,
117122
ObjectId = ObjectId,
123+
ApplicationId = ApplicationId,
118124
AadTenantId = AadTenantId,
119125
CertificatePassword = CertificatePassword
120126
};
@@ -131,6 +137,7 @@ public void ShouldThrowIfBothCertificateOptionsArePassed()
131137
CommandRuntime = commandRuntimeMock.Object,
132138
HDInsightManagementClient = hdinsightManagementMock.Object,
133139
ObjectId = ObjectId,
140+
ApplicationId = ApplicationId,
134141
AadTenantId = AadTenantId,
135142
CertificatePassword = CertificatePassword,
136143
CertificateFileContents = CertificateFileContents,

src/HDInsight/HDInsight/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020
## Upcoming Release
2121
* Fixed the bug that customer will get "Not a valid Base-64 string" error when using Get-AzHDInsightCluster to get the cluster with ADLSGen1 storage.
22+
* Add a parameter named "ApplicationId" to three cmdlets Add-AzHDInsightClusterIdentity, New-AzHDInsightClusterConfig and New-AzHDInsightCluster so that customer can provide the service principal application id for accessing Azure Data Lake.
2223

2324
## Version 2.0.2
2425
* Call out breaking changes

src/HDInsight/HDInsight/ManagementCommands/AddAzureHDInsightClusterIdentity.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public class AddAzureHDInsightClusterIdentity : HDInsightCmdletBase
6161
HelpMessage = "The Service Principal AAD Tenant Id for accessing Azure Data Lake.")]
6262
public Guid AadTenantId { get; set; }
6363

64+
[Parameter(Position = 5,
65+
Mandatory = false,
66+
HelpMessage = "The Service Principal Application Id for accessing Azure Data Lake.")]
67+
public Guid ApplicationId { get; set; }
68+
6469
#endregion
6570

6671
public override void ExecuteCmdlet()
@@ -82,6 +87,7 @@ public override void ExecuteCmdlet()
8287
}
8388

8489
Config.ObjectId = ObjectId;
90+
Config.ApplicationId = ApplicationId;
8591
Config.AADTenantId = AadTenantId;
8692
Config.CertificatePassword = CertificatePassword;
8793

src/HDInsight/HDInsight/ManagementCommands/NewAzureHDInsightClusterCommand.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public AzureHDInsightConfig Config
130130
HiveMetastore = HiveMetastore,
131131
OozieMetastore = OozieMetastore,
132132
ObjectId = ObjectId,
133+
ApplicationId = ApplicationId,
133134
AADTenantId = AadTenantId,
134135
CertificateFileContents = CertificateFileContents,
135136
CertificateFilePath = CertificateFilePath,
@@ -185,6 +186,7 @@ var storageAccount in
185186
CertificateFilePath = value.CertificateFilePath;
186187
AadTenantId = value.AADTenantId;
187188
ObjectId = value.ObjectId;
189+
ApplicationId = value.ApplicationId;
188190
CertificatePassword = value.CertificatePassword;
189191
SecurityProfile = value.SecurityProfile;
190192
DisksPerWorkerNode = value.DisksPerWorkerNode;
@@ -332,6 +334,9 @@ public DateTime RdpAccessExpiry
332334
[Parameter(HelpMessage = "Gets or sets the Service Principal Object Id for accessing Azure Data Lake.")]
333335
public Guid ObjectId { get; set; }
334336

337+
[Parameter(HelpMessage = "Gets or sets the Service Principal Application Id for accessing Azure Data Lake.")]
338+
public Guid ApplicationId { get; set; }
339+
335340
[Parameter(HelpMessage = "Gets or sets the Service Principal Certificate file path for accessing Azure Data Lake.",
336341
ParameterSetName = CertificateFilePathSet)]
337342
public string CertificateFilePath { get; set; }
@@ -434,7 +439,7 @@ var storageAccount in
434439
CertificateFileContents = File.ReadAllBytes(CertificateFilePath);
435440
}
436441
var servicePrincipal = new Management.HDInsight.Models.ServicePrincipal(
437-
GetApplicationId(), GetTenantId(AadTenantId), CertificateFileContents,
442+
GetApplicationId(ApplicationId), GetTenantId(AadTenantId), CertificateFileContents,
438443
CertificatePassword);
439444

440445
parameters.Principal = servicePrincipal;
@@ -504,20 +509,34 @@ private Guid GetTenantId(Guid tenantId)
504509
return new Guid(tenantIdStr);
505510
}
506511

507-
//Get ApplicationId for the given ObjectId.
508-
private Guid GetApplicationId()
512+
//Get ApplicationId of Service Principal if user doesn't provide this parameter
513+
private Guid GetApplicationId(Guid applicationId)
509514
{
515+
if (applicationId != Guid.Empty)
516+
{
517+
return applicationId;
518+
}
519+
510520
GraphRbacManagementClient graphClient = AzureSession.Instance.ClientFactory.CreateArmClient<GraphRbacManagementClient>(
511521
DefaultProfile.DefaultContext, AzureEnvironment.Endpoint.Graph);
512522

513523
graphClient.TenantID = DefaultProfile.DefaultContext.Tenant.Id.ToString();
514524

515-
Microsoft.Azure.Graph.RBAC.Version1_6.Models.ServicePrincipal sp = graphClient.ServicePrincipals.Get(ObjectId.ToString());
525+
Microsoft.Azure.Graph.RBAC.Version1_6.Models.ServicePrincipal sp=null;
526+
try
527+
{
528+
sp = graphClient.ServicePrincipals.Get(ObjectId.ToString());
529+
}
530+
catch(Microsoft.Azure.Graph.RBAC.Version1_6.Models.GraphErrorException e)
531+
{
532+
string errorMessage = e.Message + ". Please specify Application Id explicitly by providing ApplicationId parameter and retry.";
533+
throw new Microsoft.Azure.Graph.RBAC.Version1_6.Models.GraphErrorException(errorMessage);
534+
}
516535

517-
var applicationId = Guid.Empty;
518-
Guid.TryParse(sp.AppId, out applicationId);
519-
Debug.Assert(applicationId != Guid.Empty);
520-
return applicationId;
536+
var spApplicationId = Guid.Empty;
537+
Guid.TryParse(sp.AppId, out spApplicationId);
538+
Debug.Assert(spApplicationId != Guid.Empty);
539+
return spApplicationId;
521540
}
522541
}
523542
}

src/HDInsight/HDInsight/ManagementCommands/NewAzureHDInsightClusterConfigCommand.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ public Guid ObjectId
113113
set { _config.ObjectId = value; }
114114
}
115115

116+
[Parameter(HelpMessage = "Gets or sets the Service Principal Application Id for accessing Azure Data Lake.")]
117+
public Guid ApplicationId
118+
{
119+
get { return _config.ApplicationId; }
120+
set { _config.ApplicationId = value; }
121+
}
122+
116123
[Parameter(HelpMessage = "Gets or sets the Service Principal Certificate file contents for accessing Azure Data Lake.")]
117124
public byte[] CertificateFileContents
118125
{

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ public class AzureHDInsightConfig
9292
/// </summary>
9393
public Guid ObjectId { get; set; }
9494

95+
/// <summary>
96+
/// Gets Application id of the service principal.
97+
/// </summary>
98+
public Guid ApplicationId { get; set; }
99+
95100
/// <summary>
96101
/// Gets the file path of the client certificate file contents associated with the service principal.
97102
/// </summary>

src/HDInsight/HDInsight/help/Add-AzHDInsightClusterIdentity.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---
1+
---
22
external help file: Microsoft.Azure.PowerShell.Cmdlets.HDInsight.dll-Help.xml
33
Module Name: Az.HDInsight
44
ms.assetid: A40AB6AB-D3CB-4A6C-B614-0B22085759DA
@@ -17,14 +17,14 @@ Adds a cluster identity to a cluster configuration object.
1717
```
1818
Add-AzHDInsightClusterIdentity [-Config] <AzureHDInsightConfig> [-ObjectId] <Guid>
1919
[-CertificateFilePath] <String> [-CertificatePassword] <String> [[-AadTenantId] <Guid>]
20-
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
20+
[-ApplicationId <Guid>] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
2121
```
2222

2323
### CertificateFileContents
2424
```
2525
Add-AzHDInsightClusterIdentity [-Config] <AzureHDInsightConfig> [-ObjectId] <Guid>
2626
[-CertificateFileContents] <Byte[]> [-CertificatePassword] <String> [[-AadTenantId] <Guid>]
27-
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
27+
[-ApplicationId <Guid>] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
2828
```
2929

3030
## DESCRIPTION
@@ -52,6 +52,7 @@ PS C:\> $clusterCreds = Get-Credential
5252
# Cluster Identity values
5353
PS C:\> $tenantId = (Get-AzContext).Tenant.TenantId
5454
PS C:\> $objectId = "<Azure AD Service Principal Object ID>"
55+
PS C:\> $applicationId = "<Azure AD Service Principal Application ID>"
5556
PS C:\> $certificateFilePath = "<Path to Azure AD Service Principal Certificate>"
5657
PS C:\> $certificatePassword = "<Password for Azure AD Service Principal Certificate>"
5758
@@ -60,11 +61,12 @@ PS C:\> New-AzHDInsightClusterConfig `
6061
| Add-AzHDInsightClusterIdentity `
6162
-AadTenantId $tenantId `
6263
-ObjectId $objectId `
64+
-Application $applicationId
6365
-CertificateFilePath $certificateFilePath `
6466
-CertificatePassword $certificatePassword `
6567
| New-AzHDInsightCluster `
6668
-ClusterType Hadoop `
67-
-OSType Windows `
69+
-OSType Linux `
6870
-ClusterSizeInNodes 4 `
6971
-ResourceGroupName $clusterResourceGroupName `
7072
-ClusterName $clusterName `
@@ -94,6 +96,21 @@ Accept pipeline input: False
9496
Accept wildcard characters: False
9597
```
9698
99+
### -ApplicationId
100+
The Service Principal Application Id for accessing Azure Data Lake.
101+
102+
```yaml
103+
Type: System.Guid
104+
Parameter Sets: (All)
105+
Aliases:
106+
107+
Required: False
108+
Position: Named
109+
Default value: None
110+
Accept pipeline input: False
111+
Accept wildcard characters: False
112+
```
113+
97114
### -CertificateFileContents
98115
Specifies file contents of the certificate that will be used when accessing Azure Data Lake Store.
99116
@@ -189,7 +206,7 @@ Accept wildcard characters: False
189206
```
190207
191208
### CommonParameters
192-
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
209+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
193210
194211
## INPUTS
195212

src/HDInsight/HDInsight/help/New-AzHDInsightCluster.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---
1+
---
22
external help file: Microsoft.Azure.PowerShell.Cmdlets.HDInsight.dll-Help.xml
33
Module Name: Az.HDInsight
44
ms.assetid: 691AC991-3249-487C-A0DF-C579ED7D00E7
@@ -29,8 +29,8 @@ New-AzHDInsightCluster [-Location] <String> [-ResourceGroupName] <String> [-Clus
2929
[-ComponentVersion <System.Collections.Generic.Dictionary`2[System.String,System.String]>]
3030
[-VirtualNetworkId <String>] [-SubnetName <String>] [-OSType <OSType>] [-ClusterTier <Tier>]
3131
[-SshCredential <PSCredential>] [-SshPublicKey <String>] [-RdpCredential <PSCredential>]
32-
[-RdpAccessExpiry <DateTime>] [-ObjectId <Guid>] [-CertificatePassword <String>] [-AadTenantId <Guid>]
33-
[-SecurityProfile <AzureHDInsightSecurityProfile>] [-DisksPerWorkerNode <Int32>]
32+
[-RdpAccessExpiry <DateTime>] [-ObjectId <Guid>] [-ApplicationId <Guid>] [-CertificatePassword <String>]
33+
[-AadTenantId <Guid>] [-SecurityProfile <AzureHDInsightSecurityProfile>] [-DisksPerWorkerNode <Int32>]
3434
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
3535
```
3636

@@ -50,7 +50,7 @@ New-AzHDInsightCluster [-Location] <String> [-ResourceGroupName] <String> [-Clus
5050
[-ComponentVersion <System.Collections.Generic.Dictionary`2[System.String,System.String]>]
5151
[-VirtualNetworkId <String>] [-SubnetName <String>] [-OSType <OSType>] [-ClusterTier <Tier>]
5252
[-SshCredential <PSCredential>] [-SshPublicKey <String>] [-RdpCredential <PSCredential>]
53-
[-RdpAccessExpiry <DateTime>] [-ObjectId <Guid>] [-CertificateFilePath <String>]
53+
[-RdpAccessExpiry <DateTime>] [-ObjectId <Guid>] [-ApplicationId <Guid>] [-CertificateFilePath <String>]
5454
[-CertificatePassword <String>] [-AadTenantId <Guid>] [-SecurityProfile <AzureHDInsightSecurityProfile>]
5555
[-DisksPerWorkerNode <Int32>] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
5656
```
@@ -71,7 +71,7 @@ New-AzHDInsightCluster [-Location] <String> [-ResourceGroupName] <String> [-Clus
7171
[-ComponentVersion <System.Collections.Generic.Dictionary`2[System.String,System.String]>]
7272
[-VirtualNetworkId <String>] [-SubnetName <String>] [-OSType <OSType>] [-ClusterTier <Tier>]
7373
[-SshCredential <PSCredential>] [-SshPublicKey <String>] [-RdpCredential <PSCredential>]
74-
[-RdpAccessExpiry <DateTime>] [-ObjectId <Guid>] [-CertificateFileContents <Byte[]>]
74+
[-RdpAccessExpiry <DateTime>] [-ObjectId <Guid>] [-ApplicationId <Guid>] [-CertificateFileContents <Byte[]>]
7575
[-CertificatePassword <String>] [-AadTenantId <Guid>] [-SecurityProfile <AzureHDInsightSecurityProfile>]
7676
[-DisksPerWorkerNode <Int32>] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
7777
```
@@ -149,6 +149,21 @@ Accept pipeline input: False
149149
Accept wildcard characters: False
150150
```
151151
152+
### -ApplicationId
153+
Gets or sets the Service Principal Application Id for accessing Azure Data Lake.
154+
155+
```yaml
156+
Type: System.Guid
157+
Parameter Sets: (All)
158+
Aliases:
159+
160+
Required: False
161+
Position: Named
162+
Default value: None
163+
Accept pipeline input: False
164+
Accept wildcard characters: False
165+
```
166+
152167
### -CertificateFileContents
153168
Specifies file contents of the certificate that will be used when accessing Azure Data Lake Store.
154169
@@ -730,7 +745,7 @@ Accept wildcard characters: False
730745
```
731746
732747
### CommonParameters
733-
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
748+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
734749
735750
## INPUTS
736751

0 commit comments

Comments
 (0)