Skip to content

Commit d60dee3

Browse files
committed
Using AzureMessager in function creation/deploy action
1 parent a2b1429 commit d60dee3

File tree

3 files changed

+49
-18
lines changed

3 files changed

+49
-18
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/resources/com/microsoft/intellij/ui/messages/messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,7 @@ function.create.hint.created=Function app ({0}) created.
13901390
function.create.hint.startCreateFunction=The specified function app does not exist. Creating a new function app...
13911391
function.create.hint.functionCreated=Successfully created function app ({0})
13921392
function.create.error.targetExists=Failed to create function app ({0}), target function app already exists.
1393-
function.create.error.createApplicationInsightsFailed=Failed to create application insights for function app ({0})
1393+
function.create.error.createApplicationInsightsFailed=Skip binding application insights as failed to create insights instance for function app ({0})
13941394
function.create.error.dockerNotSupport=The 'docker' runtime is not supported in current version.
13951395
function.create.error.invalidRuntime=Unsupported runtime {0}
13961396
function.create.dialog.title=Create Function

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/function/action/CreateFunctionAppAction.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@
55

66
package com.microsoft.azure.toolkit.intellij.function.action;
77

8-
import com.intellij.notification.Notification;
9-
import com.intellij.notification.NotificationType;
10-
import com.intellij.notification.Notifications;
118
import com.intellij.openapi.progress.ProgressIndicator;
129
import com.intellij.openapi.progress.ProgressManager;
1310
import com.intellij.openapi.project.Project;
1411
import com.microsoft.azure.management.appservice.FunctionApp;
12+
import com.microsoft.azure.toolkit.intellij.common.messager.IntellijAzureMessager;
1513
import com.microsoft.azure.toolkit.intellij.function.FunctionAppCreationDialog;
1614
import com.microsoft.azure.toolkit.lib.common.exception.AzureExceptionHandler;
1715
import com.microsoft.azure.toolkit.lib.common.exception.AzureExceptionHandler.AzureExceptionAction;
16+
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
1817
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
1918
import com.microsoft.azure.toolkit.lib.common.operation.IAzureOperationTitle;
2019
import com.microsoft.azure.toolkit.lib.common.task.AzureTask;
2120
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
2221
import com.microsoft.azure.toolkit.lib.function.FunctionAppConfig;
2322
import com.microsoft.azure.toolkit.lib.function.FunctionAppService;
2423
import com.microsoft.azuretools.authmanage.AuthMethodManager;
24+
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
2525
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
26-
import com.microsoft.intellij.actions.AzureSignInAction;
2726
import com.microsoft.azuretools.utils.AzureUIRefreshCore;
2827
import com.microsoft.azuretools.utils.AzureUIRefreshEvent;
28+
import com.microsoft.intellij.actions.AzureSignInAction;
2929
import com.microsoft.intellij.util.AzureLoginHelper;
3030
import com.microsoft.tooling.msservices.helpers.Name;
3131
import com.microsoft.tooling.msservices.serviceexplorer.AzureActionEnum;
@@ -92,13 +92,20 @@ private void openDialog(final Project project, @Nullable final FunctionAppConfig
9292
@AzureOperation(name = "function.create_detail", params = {"config.getName()"}, type = AzureOperation.Type.ACTION)
9393
private Single<FunctionApp> createFunctionApp(final FunctionAppConfig config) {
9494
final IAzureOperationTitle title = title("function.create_detail", config.getName());
95+
final IntellijAzureMessager actionMessenger = new IntellijAzureMessager() {
96+
@Override
97+
public void info(@NotNull String message, String title) {
98+
// swallow info notification for action
99+
}
100+
};
95101
final AzureTask<FunctionApp> task = new AzureTask<>(null, title, false, () -> {
102+
AzureMessager.getContext().setMessager(actionMessenger);
96103
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
97104
indicator.setIndeterminate(true);
98105
return functionAppService.createFunctionApp(config);
99106
});
100107
return AzureTaskManager.getInstance().runInModalAsObservable(task).toSingle().doOnSuccess(app -> {
101-
this.notifyCreationSuccess(app);
108+
AzureMessager.getMessager().success(message("function.create.success.title"), message("function.create.success.message", app.name()));
102109
this.refreshAzureExplorer(app);
103110
});
104111
}
@@ -111,11 +118,4 @@ private void refreshAzureExplorer(FunctionApp app) {
111118
}
112119
});
113120
}
114-
115-
private void notifyCreationSuccess(final FunctionApp app) {
116-
final String title = message("function.create.success.title");
117-
final String message = message("function.create.success.message", app.name());
118-
final Notification notification = new Notification(NOTIFICATION_GROUP_ID, title, message, NotificationType.INFORMATION);
119-
Notifications.Bus.notify(notification);
120-
}
121121
}

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/function/runner/deploy/FunctionDeploymentState.java

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55

66
package com.microsoft.azure.toolkit.intellij.function.runner.deploy;
77

8+
import com.intellij.execution.process.ProcessOutputTypes;
89
import com.intellij.openapi.project.Project;
910
import com.intellij.psi.PsiMethod;
11+
import com.microsoft.azure.toolkit.intellij.common.messager.IntellijAzureMessager;
12+
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
1013
import com.microsoft.azure.toolkit.lib.legacy.function.configurations.FunctionConfiguration;
1114
import com.microsoft.azure.management.appservice.AppServicePlan;
1215
import com.microsoft.azure.management.appservice.FunctionApp;
@@ -27,10 +30,12 @@
2730
import com.microsoft.azuretools.utils.AzureUIRefreshCore;
2831
import com.microsoft.azuretools.utils.AzureUIRefreshEvent;
2932
import com.microsoft.intellij.RunProcessHandler;
33+
import lombok.RequiredArgsConstructor;
3034
import org.apache.commons.lang.StringUtils;
3135
import org.jetbrains.annotations.NotNull;
3236
import org.jetbrains.annotations.Nullable;
3337

38+
import javax.annotation.Nonnull;
3439
import java.io.File;
3540
import java.io.IOException;
3641
import java.nio.file.Path;
@@ -57,6 +62,8 @@ public FunctionDeploymentState(Project project, FunctionDeployConfiguration func
5762
@Override
5863
@AzureOperation(name = "function.deploy.state", type = AzureOperation.Type.ACTION)
5964
public WebAppBase executeSteps(@NotNull RunProcessHandler processHandler, @NotNull Operation operation) throws Exception {
65+
final FunctionDeploymentMessenger messenger = new FunctionDeploymentMessenger(processHandler);
66+
AzureMessager.getContext().setMessager(messenger);
6067
// Update run time information by function app
6168
final FunctionApp functionApp;
6269
if (deployModel.isNewResource()) {
@@ -73,11 +80,7 @@ public WebAppBase executeSteps(@NotNull RunProcessHandler processHandler, @NotNu
7380
stagingFolder = FunctionUtils.getTempStagingFolder();
7481
deployModel.setDeploymentStagingDirectoryPath(stagingFolder.getPath());
7582
prepareStagingFolder(stagingFolder, processHandler, operation);
76-
final DeployFunctionHandler deployFunctionHandler = new DeployFunctionHandler(deployModel, message -> {
77-
if (processHandler.isProcessRunning()) {
78-
processHandler.setText(message);
79-
}
80-
}, operation);
83+
final DeployFunctionHandler deployFunctionHandler = new DeployFunctionHandler(deployModel, operation);
8184
return deployFunctionHandler.execute();
8285
}
8386

@@ -151,4 +154,32 @@ protected void onFail(@NotNull Throwable error, @NotNull RunProcessHandler proce
151154
protected Map<String, String> getTelemetryMap() {
152155
return functionDeployConfiguration.getModel().getTelemetryProperties();
153156
}
157+
158+
// todo: create shared run state messenger for all run states
159+
@RequiredArgsConstructor
160+
private static class FunctionDeploymentMessenger extends IntellijAzureMessager {
161+
private final RunProcessHandler processHandler;
162+
163+
@Override
164+
public void info(@Nonnull String message, String title) {
165+
processHandler.setText(message);
166+
}
167+
168+
@Override
169+
public void success(@Nonnull String message, String title) {
170+
processHandler.println(message, ProcessOutputTypes.SYSTEM);
171+
super.success(message, title);
172+
}
173+
174+
@Override
175+
public void error(@Nonnull String message, String title) {
176+
processHandler.println(message, ProcessOutputTypes.STDERR);
177+
super.error(message, title);
178+
}
179+
180+
@Override
181+
public void warning(@Nonnull String message, String title) {
182+
processHandler.setText(message);
183+
}
184+
}
154185
}

0 commit comments

Comments
 (0)