Skip to content

Commit 5313d80

Browse files
committed
Fix the 'can't get cluster' dialog issue
Signed-off-by: Wei Zhang <[email protected]>
1 parent bb9c550 commit 5313d80

File tree

3 files changed

+69
-27
lines changed

3 files changed

+69
-27
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/ui/SparkSubmissionContentPanel.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.microsoft.azure.hdinsight.spark.common.SubmissionTableModel;
4040
import com.microsoft.azure.hdinsight.spark.uihelper.InteractiveRenderer;
4141
import com.microsoft.azure.hdinsight.spark.uihelper.InteractiveTableModel;
42+
import com.microsoft.azuretools.authmanage.AuthMethodManager;
4243
import com.microsoft.azuretools.azurecommons.helpers.StringHelper;
4344
import org.jetbrains.annotations.NotNull;
4445
import org.jetbrains.annotations.Nullable;
@@ -52,6 +53,8 @@
5253
import java.awt.event.*;
5354
import java.beans.PropertyChangeEvent;
5455
import java.beans.PropertyChangeListener;
56+
import java.io.IOException;
57+
import java.util.Optional;
5558
import java.util.concurrent.TimeUnit;
5659

5760
public class SparkSubmissionContentPanel extends JPanel{
@@ -261,7 +264,15 @@ public void propertyChange(PropertyChangeEvent evt) {
261264
GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
262265
new Insets(margin, margin, 0, margin), 0, 0));
263266

264-
errorMessageLabels[ErrorMessageLabelTag.ClusterName.ordinal()] = new JLabel("Cluster Name Should not be null");
267+
boolean isSignedIn = false;
268+
269+
try {
270+
isSignedIn = AuthMethodManager.getInstance().isSignedIn();
271+
} catch (IOException ignored) { }
272+
273+
errorMessageLabels[ErrorMessageLabelTag.ClusterName.ordinal()] = new JLabel( isSignedIn ?
274+
"Cluster Name Should not be null, please choose one for submission" :
275+
"Can't list cluster, please login within Azure Explorer and refresh");
265276
errorMessageLabels[ErrorMessageLabelTag.ClusterName.ordinal()].setForeground(DarkThemeManager.getInstance().getErrorMessageColor());
266277

267278
clustersListComboBox.getComboBox().addItemListener(new ItemListener() {

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/ui/SparkSubmissionContentPanelConfigurable.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@
3333
import com.microsoft.azure.hdinsight.spark.common.SettableControl;
3434
import com.microsoft.azure.hdinsight.spark.common.SparkSubmissionParameter;
3535
import com.microsoft.azure.hdinsight.spark.common.SparkSubmitModel;
36+
import com.microsoft.azuretools.authmanage.AuthMethodManager;
3637
import com.microsoft.tooling.msservices.components.DefaultLoader;
3738
import org.jetbrains.annotations.NotNull;
3839
import org.jetbrains.annotations.Nullable;
3940

4041
import javax.swing.*;
41-
import java.util.Arrays;
42-
import java.util.List;
43-
import java.util.Map;
44-
import java.util.Optional;
42+
import java.io.IOException;
43+
import java.util.*;
4544
import java.util.stream.Collectors;
4645
import java.util.stream.IntStream;
4746

@@ -144,10 +143,18 @@ private void refreshClusterListAsync() {
144143
}
145144

146145
private void resetClusterDetailsToComboBoxModel(SparkSubmitModel destSubmitModel, List<IClusterDetail> cachedClusterDetails) {
147-
destSubmitModel.setCachedClusterDetailsWithTitleMapping(cachedClusterDetails);
146+
List<IClusterDetail> clusterDetails = new ArrayList<>();
147+
148+
try {
149+
if (AuthMethodManager.getInstance().isSignedIn()) {
150+
clusterDetails = cachedClusterDetails;
151+
}
152+
} catch (IOException ignored) { }
153+
154+
destSubmitModel.setCachedClusterDetailsWithTitleMapping(clusterDetails);
148155

149156
destSubmitModel.getClusterComboBoxModel().removeAllElements();
150-
cachedClusterDetails.forEach(clusterDetail -> destSubmitModel.getClusterComboBoxModel().addElement(clusterDetail.getTitle()));
157+
clusterDetails.forEach(clusterDetail -> destSubmitModel.getClusterComboBoxModel().addElement(clusterDetail.getTitle()));
151158

152159
setSelectedClusterByName(destSubmitModel.getSubmissionParameter().getClusterName());
153160
}

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

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,18 @@
2828
import com.microsoft.azure.hdinsight.metadata.ClusterMetaDataService;
2929
import com.microsoft.azure.hdinsight.sdk.cluster.*;
3030
import com.microsoft.azuretools.authmanage.AuthMethodManager;
31+
import com.microsoft.azuretools.authmanage.SubscriptionManager;
3132
import com.microsoft.azuretools.authmanage.models.SubscriptionDetail;
3233
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
3334
import com.microsoft.azuretools.azurecommons.helpers.StringHelper;
35+
import com.microsoft.azuretools.sdkmanage.AzureManager;
3436
import com.microsoft.tooling.msservices.components.DefaultLoader;
3537
import com.microsoft.azure.hdinsight.sdk.common.AggregatedException;
3638
import com.microsoft.azure.hdinsight.sdk.common.AuthenticationErrorHandler;
3739
import com.microsoft.azure.hdinsight.sdk.common.HDIException;
3840
import com.microsoft.azure.hdinsight.sdk.storage.HDStorageAccount;
3941

42+
import java.io.IOException;
4043
import java.util.ArrayList;
4144
import java.util.List;
4245
import java.util.Optional;
@@ -144,9 +147,9 @@ public synchronized ImmutableList<IClusterDetail> getClusterDetails() {
144147
}
145148

146149
isListClusterSuccess = false;
147-
com.microsoft.azuretools.sdkmanage.AzureManager manager;
150+
Optional<AzureManager> manager;
148151
try {
149-
manager = AuthMethodManager.getInstance().getAzureManager();
152+
manager = Optional.ofNullable(AuthMethodManager.getInstance().getAzureManager());
150153
} catch (Exception ex) {
151154
// not authenticated
152155
clusterDetails.addAll(hdinsightAdditionalClusterDetails);
@@ -155,26 +158,47 @@ public synchronized ImmutableList<IClusterDetail> getClusterDetails() {
155158
return ClusterMetaDataService.getInstance().getCachedClusterDetails();
156159
}
157160

158-
List<SubscriptionDetail> subscriptionList = null;
159-
try {
160-
subscriptionList = manager.getSubscriptionManager().getSubscriptionDetails();
161-
clusterDetails = ClusterManager.getInstance().getHDInsightClustersWithSpecificType(subscriptionList, OSTYPE);
162-
163-
// TODO: so far we have not a good way to judge whether it is token expired as we have changed the way to list hdinsight clusters
164-
isListClusterSuccess = clusterDetails.size() != 0;
165-
} catch (AggregatedException aggregateException) {
166-
if (dealWithAggregatedException(aggregateException)) {
167-
DefaultLoader.getUIHelper().showError("Failed to get HDInsight Cluster, Please make sure there's no login problem first","List HDInsight Cluster Error");
168-
}
169-
} catch (Exception ex) {
170-
DefaultLoader.getUIHelper().showError("Failed to get HDInsight Clusters","List HDInsight Cluster Error");
171-
}
161+
Optional<List<SubscriptionDetail>> subscriptionList = manager.map(AzureManager::getSubscriptionManager)
162+
.flatMap(subscriptionManager -> {
163+
try {
164+
return Optional.ofNullable(subscriptionManager.getSubscriptionDetails());
165+
} catch (IOException e) {
166+
DefaultLoader.getUIHelper().showError("Failed to get HDInsight Clusters. " +
167+
"Please check your subscription and login at Azure Explorer.",
168+
"List HDInsight Cluster Error");
169+
170+
return Optional.empty();
171+
}
172+
});
173+
174+
subscriptionList
175+
.flatMap(list -> {
176+
try {
177+
return Optional.of(ClusterManager.getInstance().getHDInsightClustersWithSpecificType(list, OSTYPE));
178+
} catch (AggregatedException aggregateException) {
179+
if (dealWithAggregatedException(aggregateException)) {
180+
DefaultLoader.getUIHelper().showError(
181+
"Failed to get HDInsight Cluster, Please make sure there's no login problem first",
182+
"List HDInsight Cluster Error");
183+
}
184+
185+
return Optional.empty();
186+
}
187+
})
188+
.ifPresent(clusterDetailList -> {
189+
// TODO: so far we have not a good way to judge whether it is token expired as
190+
// we have changed the way to list HDInsight clusters
191+
isListClusterSuccess = clusterDetailList.size() != 0;
192+
193+
clusterDetailList.addAll(hdinsightAdditionalClusterDetails);
194+
clusterDetailList.addAll(emulatorClusterDetails);
195+
ClusterMetaDataService.getInstance().addCachedClusters(clusterDetailList);
196+
197+
});
172198

173-
isSelectedSubscriptionExist = subscriptionList != null && !subscriptionList.isEmpty();
199+
isSelectedSubscriptionExist = subscriptionList.map(list -> list.stream().anyMatch(SubscriptionDetail::isSelected))
200+
.orElse(false);
174201

175-
clusterDetails.addAll(hdinsightAdditionalClusterDetails);
176-
clusterDetails.addAll(emulatorClusterDetails);
177-
ClusterMetaDataService.getInstance().addCachedClusters(clusterDetails);
178202
return ClusterMetaDataService.getInstance().getCachedClusterDetails();
179203
}
180204

0 commit comments

Comments
 (0)