Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix update dialog pops several times when click ok/cancel button issue #2013

Merged
merged 7 commits into from
Sep 18, 2018
Merged
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