Skip to content

Commit 38244f0

Browse files
authored
handle invalid key exp (#2927)
1 parent a4d843c commit 38244f0

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/run/SparkBatchJobRunner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ public ISparkBatchJob buildSparkBatchJob(@NotNull SparkSubmitModel submitModel,
173173
throw new ExecutionException("Cannot get valid storage account");
174174
}
175175

176-
httpObservable = new SharedKeyHttpObservable(storageAccount.getName(), accessKey);
177176
if (StringUtils.isBlank(accessKey)) {
178-
throw new ExecutionException("Invalid access key input.");
177+
throw new ExecutionException("Invalid access key input");
179178
}
180179

180+
httpObservable = new SharedKeyHttpObservable(storageAccount.getName(), accessKey);
181181
jobDeploy = new ADLSGen2Deploy(clusterDetail, httpObservable);
182182
break;
183183
case WEBHDFS:

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/ui/SparkSubmissionJobUploadStorageAzureBlobCard.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package com.microsoft.azure.hdinsight.spark.ui
2424

2525
import com.intellij.ui.ComboboxWithBrowseButton
26+
import com.intellij.ui.components.fields.ExpandableTextField
2627
import com.intellij.uiDesigner.core.GridConstraints.*
2728
import com.microsoft.azure.hdinsight.common.StreamUtil
2829
import com.microsoft.azure.hdinsight.spark.common.SparkSubmitStorageType
@@ -38,7 +39,7 @@ class SparkSubmissionJobUploadStorageAzureBlobCard: SparkSubmissionJobUploadStor
3839
private val storageAccountLabel = JLabel("Storage Account").apply { toolTipText = storageAccountTip }
3940
val storageAccountField = JTextField().apply { toolTipText = storageAccountTip }
4041
private val storageKeyLabel = JLabel("Storage Key").apply { toolTipText = storageKeyTip }
41-
val storageKeyField = JTextArea().apply { toolTipText = storageKeyTip }
42+
val storageKeyField = ExpandableTextField().apply { toolTipText = storageKeyTip }
4243
private val storageContainerLabel = JLabel("Storage Container")
4344
val storageContainerUI = ComboboxWithBrowseButton().apply {
4445
button.toolTipText = "Refresh"

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/ui/SparkSubmissionJobUploadStorageGen2Card.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package com.microsoft.azure.hdinsight.spark.ui
2424

2525
import com.intellij.ui.ComboboxWithBrowseButton
26+
import com.intellij.ui.components.fields.ExpandableTextField
2627
import com.intellij.uiDesigner.core.GridConstraints
2728
import com.intellij.uiDesigner.core.GridConstraints.*
2829
import com.microsoft.azure.hdinsight.common.StreamUtil
@@ -36,7 +37,7 @@ class SparkSubmissionJobUploadStorageGen2Card : SparkSubmissionJobUploadStorageB
3637
private val refreshButtonIconPath = "/icons/refresh.png"
3738
private val storageKeyTip = "The access key of the default storage account, which can be found from HDInsight cluster storage accounts of Azure portal."
3839
private val storageKeyLabel = JLabel("Access Key").apply { toolTipText = storageKeyTip }
39-
val storageKeyField = JTextArea().apply { toolTipText = storageKeyTip }
40+
val storageKeyField = ExpandableTextField().apply { toolTipText = storageKeyTip }
4041
val gen2AccountField = JTextArea().apply { isVisible = false }
4142

4243
init {

Utils/hdinsight-node-common/src/com/microsoft/azure/hdinsight/sdk/common/SharedKeyHttpObservable.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ public SharedKeyHttpObservable(String accountName, String accessKey) {
5252
setDefaultHeaderGroup(defaultHeaders);
5353
try {
5454
this.cred = new SharedKeyCredential(accountName, accessKey);
55-
} catch (InvalidKeyException e) {
56-
throw new IllegalArgumentException("Cannot init shared key credential");
55+
} catch (IllegalArgumentException ex) {
56+
log().warn("Create shared key credential encounter exception", ex);
57+
throw new IllegalArgumentException("Can't create shared key credential.Please check access key");
5758
}
5859
}
5960

Utils/hdinsight-node-common/src/com/microsoft/azure/hdinsight/sdk/storage/adlsgen2/SharedKeyCredential.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ public final class SharedKeyCredential {
4343
private final String accountName;
4444
private final byte[] accountKey;
4545

46-
public SharedKeyCredential(String accountName, String accountKey) throws InvalidKeyException {
46+
public SharedKeyCredential(String accountName, String accountKey) {
4747
this.accountName = accountName;
4848
this.accountKey = Base64.getDecoder().decode(accountKey);
49-
StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(accountName, accountKey);
5049
}
5150

5251
private String buildStringToSign(HttpRequestBase request, HeaderGroup httpHeaders, List<NameValuePair> pairs) {

Utils/hdinsight-node-common/src/com/microsoft/azure/hdinsight/spark/common/ADLSGen2Deploy.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,18 @@
3333
import com.microsoft.azure.hdinsight.sdk.common.SharedKeyHttpObservable;
3434
import com.microsoft.azure.hdinsight.sdk.storage.HDStorageAccount;
3535
import com.microsoft.azure.hdinsight.sdk.storage.adlsgen2.ADLSGen2FSOperation;
36-
import com.microsoft.azure.hdinsight.sdk.storage.adlsgen2.ADLSGen2ParamsBuilder;
3736
import com.microsoft.azure.hdinsight.spark.jobs.JobUtils;
3837
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
3938
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
4039
import org.apache.commons.lang3.StringUtils;
41-
import org.apache.http.NameValuePair;
40+
import org.apache.http.HttpStatus;
4241
import org.apache.http.client.methods.HttpPut;
4342
import rx.Observable;
43+
import rx.exceptions.Exceptions;
4444

4545
import java.io.File;
4646
import java.net.URI;
4747
import java.net.URISyntaxException;
48-
import java.util.List;
4948

5049
public class ADLSGen2Deploy implements Deployable, ILogger {
5150
@NotNull
@@ -84,6 +83,13 @@ public Observable<String> deploy(@NotNull File src, @NotNull URI destURI) {
8483
HttpPut req = new HttpPut(dirPath);
8584
ADLSGen2FSOperation op = new ADLSGen2FSOperation((SharedKeyHttpObservable) this.http);
8685
return op.createDir(dirPath)
86+
.onErrorReturn(err -> {
87+
if (err.getMessage().contains(String.valueOf(HttpStatus.SC_FORBIDDEN))) {
88+
throw new IllegalArgumentException("Failed to upload Spark application artifacts.The access key is invalid.");
89+
} else {
90+
throw Exceptions.propagate(err);
91+
}
92+
})
8793
.flatMap(ignore -> op.createFile(filePath))
8894
.flatMap(ignore -> op.uploadData(filePath, src))
8995
.map(ignored -> {

0 commit comments

Comments
 (0)