Skip to content

Commit 0859cc8

Browse files
demo usage(deployment run state) in intellij plugin
1 parent 09c0ff3 commit 0859cc8

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/springcloud/deplolyment/SpringCloudDeploymentConfigurationState.java

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
import com.intellij.openapi.project.Project;
99
import com.microsoft.azure.toolkit.intellij.common.AzureRunProfileState;
10+
import com.microsoft.azure.toolkit.intellij.common.messager.IntellijAzureMessager;
11+
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
12+
import com.microsoft.azure.toolkit.lib.common.messager.IAzureMessager;
13+
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
1014
import com.microsoft.azure.toolkit.lib.springcloud.SpringCloudApp;
1115
import com.microsoft.azure.toolkit.lib.springcloud.SpringCloudCluster;
1216
import com.microsoft.azure.toolkit.lib.springcloud.SpringCloudDeployment;
@@ -17,12 +21,14 @@
1721
import com.microsoft.azuretools.telemetrywrapper.Operation;
1822
import com.microsoft.azuretools.telemetrywrapper.TelemetryManager;
1923
import com.microsoft.intellij.RunProcessHandler;
20-
import com.microsoft.tooling.msservices.components.DefaultLoader;
24+
import lombok.RequiredArgsConstructor;
2125
import org.apache.commons.lang3.StringUtils;
2226
import org.jetbrains.annotations.NotNull;
2327

28+
import javax.annotation.Nonnull;
2429
import java.util.HashMap;
2530
import java.util.Map;
31+
import java.util.function.Consumer;
2632

2733
class SpringCloudDeploymentConfigurationState extends AzureRunProfileState<SpringCloudDeployment> {
2834
private static final int GET_URL_TIMEOUT = 60;
@@ -40,16 +46,18 @@ public SpringCloudDeploymentConfigurationState(Project project, SpringCloudDeplo
4046
}
4147

4248
@Override
49+
@AzureOperation(name = "springcloud|app.create_update", params = {"this.config.getAppConfig().getAppName()"}, type = AzureOperation.Type.ACTION)
4350
public SpringCloudDeployment executeSteps(@NotNull RunProcessHandler processHandler, @NotNull Operation operation) {
44-
// TODO: setup action messager
51+
final MyMessager messager = new MyMessager(msg -> this.setText(processHandler, msg));
52+
AzureMessager.getContext().setMessager(messager);
4553
final SpringCloudAppConfig appConfig = this.config.getAppConfig();
4654
final DeploySpringCloudAppTask task = new DeploySpringCloudAppTask(appConfig);
4755
final SpringCloudDeployment deployment = task.execute();
4856
// TODO: notify azure explorer to refresh
4957
final SpringCloudApp app = deployment.app();
5058
final SpringCloudCluster cluster = app.getCluster();
5159
if (!deployment.waitUntilReady(GET_STATUS_TIMEOUT)) {
52-
DefaultLoader.getUIHelper().showWarningNotification(NOTIFICATION_TITLE, GET_DEPLOYMENT_STATUS_TIMEOUT);
60+
AzureMessager.getDefaultMessager().warning(GET_DEPLOYMENT_STATUS_TIMEOUT, NOTIFICATION_TITLE);
5361
}
5462
printPublicUrl(app, processHandler);
5563
return deployment;
@@ -81,18 +89,41 @@ protected Map<String, String> getTelemetryMap() {
8189
}
8290

8391
private void printPublicUrl(final SpringCloudApp app, @NotNull RunProcessHandler processHandler) {
92+
final IAzureMessager messager = AzureMessager.getMessager();
8493
if (!app.entity().isPublic()) {
8594
return;
8695
}
87-
setText(processHandler, String.format("Getting public url of app(%s)...", app.name()));
96+
messager.info(String.format("Getting public url of app(%s)...", app.name()));
8897
String publicUrl = app.entity().getApplicationUrl();
8998
if (StringUtils.isEmpty(publicUrl)) {
9099
publicUrl = Utils.pollUntil(() -> app.refresh().entity().getApplicationUrl(), StringUtils::isNotBlank, GET_URL_TIMEOUT);
91100
}
92101
if (StringUtils.isEmpty(publicUrl)) {
93-
DefaultLoader.getUIHelper().showWarningNotification(NOTIFICATION_TITLE, "Failed to get application url");
102+
messager.warning("Failed to get application url", NOTIFICATION_TITLE);
94103
} else {
95-
setText(processHandler, String.format("Application url: %s", publicUrl));
104+
messager.info(String.format("Application url: %s", publicUrl));
105+
}
106+
}
107+
108+
@RequiredArgsConstructor
109+
private static class MyMessager extends IntellijAzureMessager {
110+
private final Consumer<String> out;
111+
112+
@Override
113+
public void info(@Nonnull String message, String title) {
114+
out.accept(message);
115+
}
116+
117+
@Override
118+
public void success(@Nonnull String message, String title) {
119+
out.accept(message);
120+
super.success(message, title);
121+
}
122+
123+
@Override
124+
public void error(@Nonnull String message, String title) {
125+
out.accept(message);
126+
super.error(message, title);
96127
}
97128
}
98129
}

0 commit comments

Comments
 (0)