Skip to content

Commit

Permalink
Fix update dialog pops several times when click ok/cancel button issue
Browse files Browse the repository at this point in the history
  • Loading branch information
t-rufang committed Sep 17, 2018
1 parent 07e9ed7 commit 6dc243b
Showing 1 changed file with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@
import com.microsoft.azure.hdinsight.sdk.rest.azure.serverless.spark.models.SparkItemGroupState;
import com.microsoft.azuretools.azurecommons.helpers.AzureCmdException;
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
import com.microsoft.tooling.msservices.serviceexplorer.AzureRefreshableNode;
import com.microsoft.tooling.msservices.serviceexplorer.Node;
import com.microsoft.tooling.msservices.serviceexplorer.NodeActionEvent;
import com.microsoft.tooling.msservices.serviceexplorer.NodeActionListener;
import com.microsoft.tooling.msservices.serviceexplorer.*;

import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.util.Optional;

public class SparkServerlessClusterNode extends AzureRefreshableNode implements ILogger {
private static final String UPDATE_ACTION_NAME = "Update";
@NotNull
private final String CLUSTER_MODULE_ID;
// TODO: Update icon path
Expand Down Expand Up @@ -67,11 +65,7 @@ public SparkServerlessClusterNode(@NotNull Node parent,
protected void refreshItems() throws AzureCmdException {
try {
cluster.get().toBlocking().singleOrDefault(cluster);
if (Optional.ofNullable(cluster.getMasterState()).orElse("")
.equals(SparkItemGroupState.STABLE.toString())) {
addAction("Update", new SparkServerlessUpdateAction(
this, cluster, SparkServerlessClusterOps.getInstance().getUpdateAction()));
}
getNodeActionByName(UPDATE_ACTION_NAME).setEnabled(isClusterStable());
} catch (Exception ex) {
log().warn(String.format("Can't get the cluster %s details: %s", cluster.getName(), ex));
}
Expand All @@ -90,11 +84,11 @@ protected void loadActions() {
this, cluster, adlAccount, SparkServerlessClusterOps.getInstance().getDestroyAction()));
addAction("View Cluster Status", new SparkServerlessMonitorAction(
this, cluster, SparkServerlessClusterOps.getInstance().getMonitorAction()));
if (Optional.ofNullable(cluster.getMasterState()).orElse("")
.equals(SparkItemGroupState.STABLE.toString())) {
addAction("Update", new SparkServerlessUpdateAction(
this, cluster, SparkServerlessClusterOps.getInstance().getUpdateAction()));
}

NodeAction updateAction = addAction(UPDATE_ACTION_NAME, new SparkServerlessUpdateAction(
this, cluster, SparkServerlessClusterOps.getInstance().getUpdateAction()));
updateAction.setEnabled(isClusterStable());

addAction("Open Spark Master UI", new NodeActionListener() {
@Override
protected void actionPerformed(NodeActionEvent e) throws AzureCmdException {
Expand All @@ -115,6 +109,11 @@ protected void actionPerformed(NodeActionEvent e) throws AzureCmdException {
});
}

private Boolean isClusterStable() {
return Optional.ofNullable(cluster.getMasterState()).orElse("")
.equalsIgnoreCase(SparkItemGroupState.STABLE.toString());
}

@NotNull
public String getClusterName() {
return cluster.getName();
Expand Down

0 comments on commit 6dc243b

Please sign in to comment.