44 */
55package com .microsoft .azure .toolkit .intellij .appservice ;
66
7+ import com .azure .resourcemanager .resources .fluentcore .arm .ResourceUtils ;
78import com .google .gson .JsonObject ;
89import com .intellij .openapi .project .Project ;
910import 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 ;
1411import com .microsoft .azure .toolkit .lib .Azure ;
1512import com .microsoft .azure .toolkit .lib .appservice .AzureAppService ;
1613import 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 ;
1716import com .microsoft .azure .toolkit .lib .appservice .service .IWebApp ;
1817import com .microsoft .azure .toolkit .lib .appservice .service .IWebAppDeploymentSlot ;
1918import com .microsoft .azure .toolkit .lib .common .exception .AzureToolkitRuntimeException ;
2322import com .microsoft .azure .toolkit .lib .common .task .AzureTask ;
2423import com .microsoft .azure .toolkit .lib .common .task .AzureTaskManager ;
2524import com .microsoft .azuretools .core .mvp .model .AzureMvpModel ;
26- import com .microsoft .azuretools .core .mvp .model .function .AzureFunctionMvpModel ;
2725import com .microsoft .azuretools .sdkmanage .IdentityAzureManager ;
2826import com .microsoft .intellij .util .PluginUtil ;
2927import com .microsoft .tooling .msservices .components .DefaultLoader ;
3028import com .microsoft .tooling .msservices .helpers .azure .sdk .AzureSDKManager ;
31- import hu .akarnokd .rxjava3 .interop .RxJavaInterop ;
3229import org .apache .commons .lang3 .StringUtils ;
33- import reactor .adapter .rxjava .RxJava3Adapter ;
34- import rx .Observable ;
30+ import reactor .core .publisher .Flux ;
3531
3632import java .io .IOException ;
3733import 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
0 commit comments