Skip to content

Commit 6535600

Browse files
wezhangt-rufang
authored andcommitted
Fix HDInsightCluster New API error messages with potential NPE issues
# Conflicts: # Utils/hdinsight-node-common/src/com/microsoft/azure/hdinsight/sdk/cluster/HDInsightNewAPI/ClusterOperationNewAPIImpl.java
1 parent 15268b2 commit 6535600

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828
import com.microsoft.azure.hdinsight.sdk.cluster.ClusterRawInfo;
2929
import com.microsoft.azure.hdinsight.sdk.common.AzureManagementHttpObservable;
3030
import com.microsoft.azure.hdinsight.sdk.common.errorresponse.ForbiddenHttpErrorStatus;
31+
import com.microsoft.azure.hdinsight.sdk.common.errorresponse.GatewayTimeoutErrorStatus;
3132
import com.microsoft.azure.hdinsight.sdk.common.errorresponse.HttpErrorStatus;
3233
import com.microsoft.azure.hdinsight.sdk.common.errorresponse.NotFoundHttpErrorStatus;
34+
import com.microsoft.azuretools.adauth.AuthException;
3335
import com.microsoft.azuretools.authmanage.AuthMethodManager;
3436
import com.microsoft.azuretools.authmanage.models.SubscriptionDetail;
3537
import com.microsoft.azuretools.azurecommons.helpers.AzureCmdException;
3638
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
3739
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
40+
import com.microsoft.azuretools.sdkmanage.AzureManager;
3841
import com.microsoft.azuretools.telemetry.AppInsightsClient;
3942
import org.apache.commons.lang3.exception.ExceptionUtils;
4043
import org.apache.http.entity.StringEntity;
@@ -62,8 +65,18 @@ private AzureManagementHttpObservable getHttp() {
6265
return this.http;
6366
}
6467

68+
private AzureManager getAzureManager() throws IOException {
69+
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
70+
71+
if (azureManager == null) {
72+
throw new AuthException("Not signed in. Can't send out the request.");
73+
}
74+
75+
return azureManager;
76+
}
77+
6578
public Observable<Map> getClusterCoreSiteRequest(@NotNull final String clusterId) throws IOException {
66-
String managementURI = AuthMethodManager.getInstance().getAzureManager().getManagementURI();
79+
String managementURI = getAzureManager().getManagementURI();
6780
String url = URI.create(managementURI)
6881
.resolve(clusterId.replaceAll("/+$", "") + "/configurations/core-site").toString();
6982
return getHttp()
@@ -74,7 +87,7 @@ public Observable<Map> getClusterCoreSiteRequest(@NotNull final String clusterId
7487
private Observable<ClusterConfiguration> getClusterConfigurationRequest(
7588
@NotNull final String clusterId) {
7689
try {
77-
String managementURI = AuthMethodManager.getInstance().getAzureManager().getManagementURI();
90+
String managementURI = getAzureManager().getManagementURI();
7891
String url = URI.create(managementURI)
7992
.resolve(clusterId.replaceAll("/+$", "") + "/configurations").toString();
8093
StringEntity entity = new StringEntity("", StandardCharsets.UTF_8);
@@ -124,10 +137,13 @@ public Observable<Boolean> isProbeGetConfigurationSucceed(final ClusterRawInfo c
124137
} else {
125138
if (err instanceof HttpErrorStatus) {
126139
HDInsightNewApiUnavailableException ex = new HDInsightNewApiUnavailableException(err);
127-
if (!(err instanceof NotFoundHttpErrorStatus)) {
128-
log().error("Error getting cluster configurations with NEW HDInsight API. " + clusterId, ex);
140+
if (!(err instanceof NotFoundHttpErrorStatus
141+
|| err instanceof GatewayTimeoutErrorStatus)) {
142+
log().error(String.format(
143+
"Error getting cluster configurations with NEW HDInsight API: %s, %s",
144+
clusterId,
145+
((HttpErrorStatus) err).getErrorDetails()), ex);
129146
}
130-
log().warn(((HttpErrorStatus) err).getErrorDetails());
131147

132148
final Map<String, String> properties = new HashMap<>();
133149
properties.put("ClusterID", clusterId);

0 commit comments

Comments
 (0)