Skip to content

Commit 3b6a31c

Browse files
committed
Fix auth warning issue of linking a HIB cluster
1 parent b1ae11f commit 3b6a31c

File tree

6 files changed

+25
-15
lines changed

6 files changed

+25
-15
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/common/classifiedexception/SparkToolException.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import com.microsoft.azure.datalake.store.ADLException
2626
import com.microsoft.azure.hdinsight.sdk.common.livy.interactive.exceptions.SessionNotStartException
2727
import com.microsoft.azure.hdinsight.spark.common.SparkJobException
2828
import com.microsoft.azure.hdinsight.spark.common.YarnDiagnosticsException
29+
import com.microsoft.azuretools.adauth.AuthException
2930
import com.microsoft.azuretools.telemetrywrapper.ErrorType
3031
import com.microsoft.intellij.forms.ErrorMessageForm
3132
import org.apache.commons.lang.exception.ExceptionUtils
@@ -57,6 +58,7 @@ object SparkToolExceptionFactory : ClassifiedExceptionFactory() {
5758
&& exp !is SparkJobException
5859
&& exp !is FileNotFoundException
5960
&& exp !is ADLException
61+
&& exp !is AuthException
6062
&& stackTrace.contains(ToolPackageSuffix)) {
6163
SparkToolException(exp)
6264
} else null

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/common/classifiedexception/SparkUserException.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ object SparkUserExceptionFactory : ClassifiedExceptionFactory() {
4747
} else if (exp is ADLException && exp.httpResponseCode == 403) {
4848
val hintMsg = "\nPlease make sure user has RWX permissions for the storage account"
4949
SparkUserException(ADLException("${exp.remoteExceptionMessage}$hintMsg"))
50-
} else if (exp is AuthException && exp.error.equals("invalid_grant")) {
51-
val hintMsg = String.format("\nPlease check whether have enough permission to access the cluster")
52-
SparkUserException(AuthException("${exp.errorMessage}$hintMsg"))
50+
} else if (exp is AuthException) {
51+
val cause = if (exp.error == "invalid_grant") {
52+
val hintMsg = String.format("\nPlease check whether have enough permission to access the cluster")
53+
AuthException("${exp.errorMessage}$hintMsg")
54+
} else exp
55+
56+
SparkUserException(cause)
5357
} else null
5458
}
5559
}

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@
2222
package com.microsoft.azure.hdinsight.sdk.cluster;
2323

2424
import com.microsoft.azure.hdinsight.common.logger.ILogger;
25-
import com.microsoft.azure.hdinsight.sdk.storage.ADLSGen2StorageAccount;
2625
import com.microsoft.azure.hdinsight.sdk.storage.StoragePathInfo;
27-
import com.microsoft.azure.hdinsight.sdk.storage.adlsgen2.ADLSGen2FSOperation;
2826
import com.microsoft.azure.hdinsight.spark.common.SparkSubmitStorageTypeOptionsForCluster;
29-
import com.microsoft.azuretools.authmanage.AuthMethodManager;
3027
import com.microsoft.azuretools.authmanage.models.SubscriptionDetail;
28+
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
3129

32-
import java.net.URI;
3330
import java.util.regex.Pattern;
3431

3532
public class MfaClusterDetail extends ClusterDetail implements MfaEspCluster, ILogger {
@@ -38,29 +35,35 @@ public MfaClusterDetail(SubscriptionDetail paramSubscription, ClusterRawInfo par
3835
super(paramSubscription, paramClusterRawInfo, clusterOperation);
3936
}
4037

38+
@Nullable
4139
@Override
4240
public String getDefaultStorageRootPath() {
4341
String storageRootPath = super.getDefaultStorageRootPath();
4442

43+
if (storageRootPath == null) {
44+
return null;
45+
}
46+
4547
// check login status and get the login user name
4648
try {
4749
if (Pattern.compile(StoragePathInfo.AdlsGen2PathPattern).matcher(storageRootPath).matches()) {
4850
storageRootPath = String.format("%s/%s", storageRootPath, getUserPath());
4951
}
5052

5153
return storageRootPath;
52-
} catch (Exception ignore) {
53-
log().warn(String.format("Get default storage root path for mfa cluster encounter %s", ignore));
54+
} catch (Exception ex) {
55+
log().warn(String.format("Get default storage root path for mfa cluster encounter %s", ex));
5456
}
5557

56-
return "";
58+
return null;
5759
}
5860

5961
@Override
6062
public SparkSubmitStorageTypeOptionsForCluster getStorageOptionsType() {
6163
return SparkSubmitStorageTypeOptionsForCluster.MfaHdiCluster;
6264
}
6365

66+
@Nullable
6467
@Override
6568
public String getTenantId() {
6669
return getSubscription().getTenantId();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public MfaHdiAdditionalClusterDetail(String clusterName, String userName, String
4141
@Nullable
4242
@Override
4343
public synchronized String getTenantId(){
44-
if(tenantId != null){
44+
if(this.tenantId != null){
4545
return this.tenantId;
4646
}
4747

@@ -53,8 +53,8 @@ public synchronized String getTenantId(){
5353
this.tenantId = m.group("tenantId");
5454
}
5555
}
56-
} catch (IOException ignore) {
57-
log().warn(String.format("Encounter expection when negotiating request for linked mfa cluster %s", ignore));
56+
} catch (IOException ex) {
57+
log().warn(String.format("Encounter exception when negotiating request for linked mfa cluster %s", ex));
5858
}
5959

6060
return this.tenantId;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public AzureManager getAzureManager() {
134134
try {
135135
return AuthMethodManager.getInstance().getAzureManager();
136136
} catch (IOException e) {
137-
log().info("Can't get Azure manager now. error: " + e);
137+
log().info("Can't get Azure manager now, please sign in. error: " + e);
138138

139139
return null;
140140
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ public Observable<String> deploy(@NotNull File src) {
7979
.onErrorReturn(err -> {
8080
if (err.getMessage()!= null && (err.getMessage().contains(String.valueOf(HttpStatus.SC_FORBIDDEN))
8181
|| err.getMessage().contains(String.valueOf(HttpStatus.SC_NOT_FOUND)))) {
82-
throw new IllegalArgumentException("Failed to upload Spark application artifacts. ADLS Gen2 root path does not match with access key.");
82+
throw new IllegalArgumentException("Failed to create folder " + dirPath +
83+
" when uploading Spark application artifacts with error: " + err.getMessage());
8384
} else {
8485
throw Exceptions.propagate(err);
8586
}

0 commit comments

Comments
 (0)