Skip to content

Commit bc34d52

Browse files
authored
Merge pull request #5256 from microsoft/feature-track2-function
Migrate app service log streaming to service library
2 parents 99ddf8f + 048b3bf commit bc34d52

File tree

4 files changed

+35
-36
lines changed

4 files changed

+35
-36
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/appservice/AppServiceStreamingLogConsoleView.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import com.intellij.execution.ui.ConsoleViewContentType;
99
import com.intellij.openapi.project.Project;
1010
import org.jetbrains.annotations.NotNull;
11-
import rx.Observable;
12-
import rx.Subscription;
13-
import rx.schedulers.Schedulers;
11+
import reactor.core.Disposable;
12+
import reactor.core.publisher.Flux;
13+
import reactor.core.scheduler.Schedulers;
1414

1515
import static com.intellij.execution.ui.ConsoleViewContentType.NORMAL_OUTPUT;
1616
import static com.intellij.execution.ui.ConsoleViewContentType.SYSTEM_OUTPUT;
@@ -22,32 +22,32 @@ public class AppServiceStreamingLogConsoleView extends ConsoleViewImpl {
2222

2323
private boolean isDisposed;
2424
private String resourceId;
25-
private Subscription subscription;
25+
private Disposable subscription;
2626

2727
public AppServiceStreamingLogConsoleView(@NotNull Project project, String resourceId) {
2828
super(project, true);
2929
this.isDisposed = false;
3030
this.resourceId = resourceId;
3131
}
3232

33-
public void startStreamingLog(Observable<String> logStreaming) {
33+
public void startStreamingLog(Flux<String> logStreaming) {
3434
if (!isActive()) {
3535
printlnToConsole(message("appService.logStreaming.hint.connect"), SYSTEM_OUTPUT);
36-
subscription = logStreaming.subscribeOn(Schedulers.io())
36+
subscription = logStreaming.subscribeOn(Schedulers.boundedElastic())
3737
.doAfterTerminate(() -> printlnToConsole(message("appService.logStreaming.hint.disconnected"), SYSTEM_OUTPUT))
3838
.subscribe((log) -> printlnToConsole(log, NORMAL_OUTPUT));
3939
}
4040
}
4141

4242
public void closeStreamingLog() {
4343
if (isActive()) {
44-
subscription.unsubscribe();
44+
subscription.dispose();
4545
printlnToConsole(message("appService.logStreaming.hint.disconnected"), SYSTEM_OUTPUT);
4646
}
4747
}
4848

4949
public boolean isActive() {
50-
return subscription != null && !subscription.isUnsubscribed();
50+
return subscription != null && !subscription.isDisposed();
5151
}
5252

5353
public boolean isDisposed() {

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/appservice/AppServiceStreamingLogManager.java

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
*/
55
package com.microsoft.azure.toolkit.intellij.appservice;
66

7+
import com.azure.resourcemanager.resources.fluentcore.arm.ResourceUtils;
78
import com.google.gson.JsonObject;
89
import com.intellij.openapi.project.Project;
910
import com.microsoft.azure.management.applicationinsights.v2015_05_01.ApplicationInsightsComponent;
10-
import com.microsoft.azure.management.appservice.AppSetting;
11-
import com.microsoft.azure.management.appservice.FunctionApp;
12-
import com.microsoft.azure.management.appservice.OperatingSystem;
13-
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils;
1411
import com.microsoft.azure.toolkit.lib.Azure;
1512
import com.microsoft.azure.toolkit.lib.appservice.AzureAppService;
1613
import com.microsoft.azure.toolkit.lib.appservice.model.DiagnosticConfig;
14+
import com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem;
15+
import com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp;
1716
import com.microsoft.azure.toolkit.lib.appservice.service.IWebApp;
1817
import com.microsoft.azure.toolkit.lib.appservice.service.IWebAppDeploymentSlot;
1918
import com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException;
@@ -23,15 +22,12 @@
2322
import com.microsoft.azure.toolkit.lib.common.task.AzureTask;
2423
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
2524
import com.microsoft.azuretools.core.mvp.model.AzureMvpModel;
26-
import com.microsoft.azuretools.core.mvp.model.function.AzureFunctionMvpModel;
2725
import com.microsoft.azuretools.sdkmanage.IdentityAzureManager;
2826
import com.microsoft.intellij.util.PluginUtil;
2927
import com.microsoft.tooling.msservices.components.DefaultLoader;
3028
import com.microsoft.tooling.msservices.helpers.azure.sdk.AzureSDKManager;
31-
import hu.akarnokd.rxjava3.interop.RxJavaInterop;
3229
import org.apache.commons.lang3.StringUtils;
33-
import reactor.adapter.rxjava.RxJava3Adapter;
34-
import rx.Observable;
30+
import reactor.core.publisher.Flux;
3531

3632
import java.io.IOException;
3733
import java.net.URLEncoder;
@@ -107,7 +103,7 @@ private void showAppServiceStreamingLog(Project project, String resourceId, ILog
107103
return;
108104
}
109105
}
110-
final Observable<String> log = logStreaming.getStreamingLogContent();
106+
final Flux<String> log = logStreaming.getStreamingLogContent();
111107
if (log == null) {
112108
return;
113109
}
@@ -137,7 +133,7 @@ default boolean isLogStreamingSupported() {
137133

138134
String getTitle() throws IOException;
139135

140-
Observable<String> getStreamingLogContent() throws IOException;
136+
Flux<String> getStreamingLogContent() throws IOException;
141137
}
142138

143139
static class FunctionLogStreaming implements ILogStreaming {
@@ -147,20 +143,23 @@ static class FunctionLogStreaming implements ILogStreaming {
147143
private static final String MUST_CONFIGURE_APPLICATION_INSIGHTS = message("appService.logStreaming.error.noApplicationInsights");
148144

149145
private final String resourceId;
150-
private FunctionApp functionApp;
146+
private IFunctionApp functionApp;
151147

152148
FunctionLogStreaming(final String resourceId) {
153149
this.resourceId = resourceId;
154150
}
155151

156152
@Override
157153
public boolean isLogStreamingEnabled() {
158-
return getFunctionApp().operatingSystem() == OperatingSystem.LINUX || AzureFunctionMvpModel.isApplicationLogEnabled(getFunctionApp());
154+
return getFunctionApp().getRuntime().getOperatingSystem() == OperatingSystem.LINUX ||
155+
getFunctionApp().getDiagnosticConfig().isEnableApplicationLog();
159156
}
160157

161158
@Override
162159
public void enableLogStreaming() {
163-
AzureFunctionMvpModel.enableApplicationLog(getFunctionApp());
160+
final DiagnosticConfig diagnosticConfig = getFunctionApp().getDiagnosticConfig();
161+
diagnosticConfig.setEnableApplicationLog(true);
162+
getFunctionApp().update().withDiagnosticConfig(diagnosticConfig).commit();
164163
}
165164

166165
@Override
@@ -169,8 +168,8 @@ public String getTitle() {
169168
}
170169

171170
@Override
172-
public Observable<String> getStreamingLogContent() throws IOException {
173-
if (getFunctionApp().operatingSystem() == OperatingSystem.LINUX) {
171+
public Flux<String> getStreamingLogContent() throws IOException {
172+
if (getFunctionApp().getRuntime().getOperatingSystem() == OperatingSystem.LINUX) {
174173
// For linux function, we will just open the "Live Metrics Stream" view in the portal
175174
openLiveMetricsStream();
176175
return null;
@@ -181,11 +180,10 @@ public Observable<String> getStreamingLogContent() throws IOException {
181180
// Refers https://github.com/microsoft/vscode-azurefunctions/blob/v0.22.0/src/
182181
// commands/logstream/startStreamingLogs.ts#L53
183182
private void openLiveMetricsStream() throws IOException {
184-
final AppSetting aiAppSettings = functionApp.getAppSettings().get(APPINSIGHTS_INSTRUMENTATIONKEY);
185-
if (aiAppSettings == null) {
183+
final String aiKey = functionApp.entity().getAppSettings().get(APPINSIGHTS_INSTRUMENTATIONKEY);
184+
if (StringUtils.isEmpty(aiKey)) {
186185
throw new IOException(MUST_CONFIGURE_APPLICATION_INSIGHTS);
187186
}
188-
final String aiKey = aiAppSettings.value();
189187
final String subscriptionId = AzureMvpModel.getSegment(resourceId, SUBSCRIPTIONS);
190188
final List<ApplicationInsightsComponent> insightsResources =
191189
subscriptionId == null ? Collections.EMPTY_LIST : AzureSDKManager.getInsightsResources(subscriptionId);
@@ -208,9 +206,9 @@ private String getApplicationInsightLiveMetricsUrl(ApplicationInsightsComponent
208206
return String.format(APPLICATION_INSIGHT_PATTERN, portalUrl, componentId, aiResourceId);
209207
}
210208

211-
private FunctionApp getFunctionApp() {
209+
private IFunctionApp getFunctionApp() {
212210
if (functionApp == null) {
213-
functionApp = AzureFunctionMvpModel.getInstance().getFunctionById(AzureMvpModel.getSegment(resourceId, SUBSCRIPTIONS), resourceId);
211+
functionApp = Azure.az(AzureAppService.class).functionApp(resourceId);
214212
}
215213
return functionApp;
216214
}
@@ -240,8 +238,8 @@ public String getTitle() {
240238
}
241239

242240
@Override
243-
public Observable<String> getStreamingLogContent() {
244-
return RxJavaInterop.toV1Observable(RxJava3Adapter.fluxToFlowable(webApp.streamAllLogsAsync()));
241+
public Flux<String> getStreamingLogContent() {
242+
return webApp.streamAllLogsAsync();
245243
}
246244
}
247245

@@ -269,8 +267,8 @@ public String getTitle() {
269267
}
270268

271269
@Override
272-
public Observable<String> getStreamingLogContent() {
273-
return RxJavaInterop.toV1Observable(RxJava3Adapter.fluxToFlowable(deploymentSlot.streamAllLogsAsync()));
270+
public Flux<String> getStreamingLogContent() {
271+
return deploymentSlot.streamAllLogsAsync();
274272
}
275273
}
276274

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/webapp/runner/webappconfig/WebAppRunState.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.intellij.execution.process.ProcessOutputTypes;
99
import com.intellij.openapi.project.Project;
1010
import com.intellij.openapi.util.Comparing;
11+
import com.microsoft.azure.toolkit.lib.appservice.service.IWebAppBase;
1112
import com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException;
1213
import com.microsoft.azure.toolkit.intellij.common.AzureArtifact;
1314
import com.microsoft.azure.toolkit.intellij.common.AzureArtifactManager;
@@ -69,7 +70,7 @@ public IAppService executeSteps(@NotNull RunProcessHandler processHandler, @NotN
6970
throw new FileNotFoundException(message("webapp.deploy.error.noTargetFile", file.getAbsolutePath()));
7071
}
7172
webAppConfiguration.setTargetName(file.getName());
72-
final IAppService deployTarget = getOrCreateDeployTargetFromAppSettingModel(processHandler);
73+
final IWebAppBase deployTarget = getOrCreateDeployTargetFromAppSettingModel(processHandler);
7374
updateApplicationSettings(deployTarget, processHandler);
7475
AzureWebAppMvpModel.getInstance().deployArtifactsToWebApp(deployTarget, file, webAppSettingModel.isDeployToRoot(), processHandler);
7576
return deployTarget;
@@ -138,7 +139,7 @@ protected Map<String, String> getTelemetryMap() {
138139
}
139140

140141
@NotNull
141-
private IAppService getOrCreateDeployTargetFromAppSettingModel(@NotNull RunProcessHandler processHandler) throws Exception {
142+
private IWebAppBase getOrCreateDeployTargetFromAppSettingModel(@NotNull RunProcessHandler processHandler) throws Exception {
142143
final AzureAppService azureAppService = AzureWebAppMvpModel.getInstance().getAzureAppServiceClient(webAppSettingModel.getSubscriptionId());
143144
final IWebApp webApp = getOrCreateWebappFromAppSettingModel(azureAppService, processHandler);
144145
if (!isDeployToSlot()) {

Utils/azuretools-core/src/com/microsoft/azuretools/core/mvp/model/webapp/AzureWebAppMvpModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
import com.microsoft.azure.toolkit.lib.appservice.model.DiagnosticConfig;
3232
import com.microsoft.azure.toolkit.lib.appservice.model.DockerConfiguration;
3333
import com.microsoft.azure.toolkit.lib.appservice.model.Runtime;
34-
import com.microsoft.azure.toolkit.lib.appservice.service.IAppService;
3534
import com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan;
3635
import com.microsoft.azure.toolkit.lib.appservice.service.IWebApp;
36+
import com.microsoft.azure.toolkit.lib.appservice.service.IWebAppBase;
3737
import com.microsoft.azure.toolkit.lib.appservice.service.IWebAppDeploymentSlot;
3838
import com.microsoft.azure.toolkit.lib.appservice.service.impl.WebAppDeploymentSlot;
3939
import com.microsoft.azure.toolkit.lib.auth.AzureAccount;
@@ -1081,7 +1081,7 @@ public AzureAppService getAzureAppServiceClient(String subscriptionId) {
10811081
params = {"file.getName()", "deployTarget.name()"},
10821082
type = AzureOperation.Type.SERVICE
10831083
)
1084-
public void deployArtifactsToWebApp(@NotNull final IAppService deployTarget, @NotNull final File file,
1084+
public void deployArtifactsToWebApp(@NotNull final IWebAppBase deployTarget, @NotNull final File file,
10851085
boolean isDeployToRoot, @NotNull final IProgressIndicator progressIndicator) {
10861086
if (!(deployTarget instanceof IWebApp || deployTarget instanceof IWebAppDeploymentSlot)) {
10871087
final String error = "the deployment target is not a valid (deployment slot of) Web App";

0 commit comments

Comments
 (0)