Skip to content

Commit 860c8b1

Browse files
committed
Using Azure Messager in Function handlers
1 parent 3bdf893 commit 860c8b1

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/function/runner/library/function/CreateFunctionHandler.java

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

88
import com.google.common.base.Preconditions;
99
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
10+
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
1011
import com.microsoft.azure.toolkit.lib.legacy.appservice.OperatingSystemEnum;
1112
import com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException;
1213
import com.microsoft.azure.toolkit.lib.legacy.function.configurations.ElasticPremiumPricingTier;
@@ -16,7 +17,6 @@
1617
import com.microsoft.azure.toolkit.lib.legacy.function.handlers.runtime.LinuxFunctionRuntimeHandler;
1718
import com.microsoft.azure.toolkit.lib.legacy.function.handlers.runtime.WindowsFunctionRuntimeHandler;
1819
import com.microsoft.azure.toolkit.lib.legacy.function.utils.FunctionUtils;
19-
import com.microsoft.azure.toolkit.lib.common.logging.Log;
2020
import com.microsoft.azure.toolkit.lib.legacy.appservice.AppServiceUtils;
2121
import com.microsoft.azure.management.applicationinsights.v2015_05_01.ApplicationInsightsComponent;
2222
import com.microsoft.azure.management.appservice.FunctionApp;
@@ -77,7 +77,7 @@ public FunctionApp execute() {
7777
type = AzureOperation.Type.SERVICE
7878
)
7979
private FunctionApp createFunctionApp() {
80-
Log.prompt(message("function.create.hint.startCreateFunction"));
80+
AzureMessager.getMessager().info(message("function.create.hint.startCreateFunction"));
8181
final WithCreate withCreate;
8282
try {
8383
final FunctionRuntimeHandler runtimeHandler = getFunctionRuntimeHandler();
@@ -95,7 +95,7 @@ private FunctionApp createFunctionApp() {
9595

9696
FunctionApp result = withCreate.create();
9797
operation.trackProperty("pricingTier", ctx.getPricingTier());
98-
Log.prompt(message("function.create.hint.functionCreated", ctx.getAppName()));
98+
AzureMessager.getMessager().info(message("function.create.hint.functionCreated", ctx.getAppName()));
9999
return result;
100100
}
101101

@@ -129,7 +129,7 @@ private Map<String, String> bindingApplicationInsights() {
129129
instrumentationKey = insights.instrumentationKey();
130130
} catch (final IOException | RuntimeException e) {
131131
// swallow exception for application insights, which should not block function creation
132-
Log.prompt(message("function.create.error.createApplicationInsightsFailed", ctx.getAppName()));
132+
AzureMessager.getMessager().warning(message("function.create.error.createApplicationInsightsFailed", ctx.getAppName()));
133133
}
134134
}
135135
return Collections.singletonMap(APP_INSIGHTS_INSTRUMENTATION_KEY, instrumentationKey);
@@ -175,7 +175,7 @@ private void setDefaultAppSetting(Map result, String settingName, String setting
175175

176176
final String setting = (String) result.get(settingName);
177177
if (StringUtils.isEmpty(setting)) {
178-
Log.prompt(settingIsEmptyMessage);
178+
AzureMessager.getMessager().info(settingIsEmptyMessage);
179179
result.put(settingName, settingValue);
180180
}
181181
}
@@ -185,9 +185,9 @@ private void overrideDefaultAppSetting(Map result, String settingName, String se
185185

186186
final String setting = (String) result.get(settingName);
187187
if (StringUtils.isEmpty(setting)) {
188-
Log.prompt(settingIsEmptyMessage);
188+
AzureMessager.getMessager().info(settingIsEmptyMessage);
189189
} else if (!setting.equals(settingValue)) {
190-
Log.warn(String.format(changeSettingMessage, setting));
190+
AzureMessager.getMessager().warning(String.format(changeSettingMessage, setting));
191191
}
192192
result.put(settingName, settingValue);
193193
}

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/function/runner/library/function/DeployFunctionHandler.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.microsoft.azure.toolkit.intellij.function.runner.library.IPrompter;
1313
import com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException;
1414
import com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException;
15+
import com.microsoft.azure.toolkit.lib.common.messager.AzureMessager;
1516
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
1617
import com.microsoft.azure.toolkit.lib.legacy.appservice.AppServiceUtils;
1718
import com.microsoft.azure.toolkit.lib.legacy.appservice.DeployTarget;
@@ -72,20 +73,20 @@ public FunctionApp execute() throws Exception {
7273
final FunctionApp app = getFunctionApp();
7374
updateFunctionAppSettings(app);
7475
final DeployTarget deployTarget = new DeployTarget(app, DeployTargetType.FUNCTION);
75-
prompt(message("function.deploy.hint.startDeployFunction"));
76+
AzureMessager.getMessager().info(message("function.deploy.hint.startDeployFunction"));
7677
getArtifactHandler().publish(deployTarget);
77-
prompt(message("function.deploy.hint.deployDone", model.getAppName()));
78+
AzureMessager.getMessager().info(message("function.deploy.hint.deployDone", model.getAppName()));
7879
listHTTPTriggerUrls();
7980
return (FunctionApp) deployTarget.getApp();
8081
}
8182

8283
private void updateFunctionAppSettings(final FunctionApp app) throws AzureExecutionException {
83-
prompt(message("function.deploy.hint.updateFunctionApp"));
84+
AzureMessager.getMessager().info(message("function.deploy.hint.updateFunctionApp"));
8485
// Work around of https://github.com/Azure/azure-sdk-for-java/issues/1755
8586
final Update update = app.update();
8687
configureAppSettings(update::withAppSettings, getAppSettingsWithDefaultValue());
8788
update.apply();
88-
prompt(message("function.deploy.hint.updateDone", model.getAppName()));
89+
AzureMessager.getMessager().info(message("function.deploy.hint.updateDone", model.getAppName()));
8990
}
9091

9192
private void configureAppSettings(final Consumer<Map> withAppSettings, final Map appSettings) {
@@ -113,13 +114,13 @@ private void listHTTPTriggerUrls() {
113114
AuthorizationLevel.ANONYMOUS.toString()))
114115
.collect(Collectors.toList());
115116
if (CollectionUtils.isEmpty(httpFunction) || CollectionUtils.isEmpty(anonymousTriggers)) {
116-
prompt(message("function.deploy.hint.noAnonymousHttpTrigger"));
117+
AzureMessager.getMessager().info(message("function.deploy.hint.noAnonymousHttpTrigger"));
117118
return;
118119
}
119-
prompt(message("function.deploy.hint.httpTriggerUrls"));
120-
anonymousTriggers.forEach(trigger -> prompt(String.format("\t %s : %s", trigger.getName(), trigger.getTriggerUrl())));
120+
AzureMessager.getMessager().info(message("function.deploy.hint.httpTriggerUrls"));
121+
anonymousTriggers.forEach(trigger -> AzureMessager.getMessager().info(String.format("\t %s : %s", trigger.getName(), trigger.getTriggerUrl())));
121122
if (anonymousTriggers.size() < httpFunction.size()) {
122-
prompt(message("function.deploy.error.listHttpTriggerFailed"));
123+
AzureMessager.getMessager().info(message("function.deploy.error.listHttpTriggerFailed"));
123124
}
124125
}
125126

@@ -141,7 +142,7 @@ private List<FunctionResource> listFunctions() {
141142
for (int i = 0; i < LIST_TRIGGERS_MAX_RETRY; i++) {
142143
try {
143144
Thread.sleep(LIST_TRIGGERS_RETRY_PERIOD_IN_SECONDS * 1000);
144-
prompt(String.format(message("function.deploy.hint.syncTriggers"), i + 1, LIST_TRIGGERS_MAX_RETRY));
145+
AzureMessager.getMessager().info(String.format(message("function.deploy.hint.syncTriggers"), i + 1, LIST_TRIGGERS_MAX_RETRY));
145146
functionApp.syncTriggers();
146147
final List<FunctionResource> triggers =
147148
model.getAzureClient().appServices().functionApps()
@@ -209,7 +210,7 @@ private void setDefaultAppSetting(Map result, String settingName, String setting
209210

210211
final String setting = (String) result.get(settingName);
211212
if (StringUtils.isEmpty(setting)) {
212-
prompt(settingIsEmptyMessage);
213+
AzureMessager.getMessager().info(settingIsEmptyMessage);
213214
result.put(settingName, settingValue);
214215
}
215216
}
@@ -219,9 +220,9 @@ private void overrideDefaultAppSetting(Map result, String settingName, String se
219220

220221
final String setting = (String) result.get(settingName);
221222
if (StringUtils.isEmpty(setting)) {
222-
prompt(settingIsEmptyMessage);
223+
AzureMessager.getMessager().info(settingIsEmptyMessage);
223224
} else if (!setting.equals(settingValue)) {
224-
prompt(String.format(changeSettingMessage, setting));
225+
AzureMessager.getMessager().info(String.format(changeSettingMessage, setting));
225226
}
226227
result.put(settingName, settingValue);
227228
}
@@ -258,7 +259,4 @@ private ArtifactHandler getArtifactHandler() throws AzureExecutionException {
258259
.build();
259260
}
260261

261-
private void prompt(String promptMessage) {
262-
prompter.prompt(promptMessage);
263-
}
264262
}

0 commit comments

Comments
 (0)