1313import com .microsoft .azure .toolkit .lib .Azure ;
1414import com .microsoft .azure .toolkit .lib .applicationinsights .ApplicationInsight ;
1515import com .microsoft .azure .toolkit .lib .applicationinsights .AzureApplicationInsights ;
16- import com .microsoft .azure .toolkit .lib .appservice .function .AzureFunctions ;
17- import com .microsoft .azure .toolkit .lib .appservice .function .FunctionApp ;
16+ import com .microsoft .azure .toolkit .lib .appservice .function .FunctionAppBase ;
17+ import com .microsoft .azure .toolkit .lib .appservice .function .FunctionAppDeploymentSlotDraft ;
1818import com .microsoft .azure .toolkit .lib .appservice .function .FunctionAppDraft ;
1919import com .microsoft .azure .toolkit .lib .appservice .model .DiagnosticConfig ;
2020import com .microsoft .azure .toolkit .lib .appservice .model .OperatingSystem ;
3333import com .microsoft .azure .toolkit .lib .common .operation .OperationBundle ;
3434import com .microsoft .azure .toolkit .lib .common .task .AzureTask ;
3535import com .microsoft .azure .toolkit .lib .common .task .AzureTaskManager ;
36+ import lombok .Getter ;
3637import org .apache .commons .lang3 .StringUtils ;
3738import reactor .core .publisher .Flux ;
3839
@@ -70,8 +71,12 @@ public void showWebAppStreamingLog(Project project, String webAppId) {
7071 showAppServiceStreamingLog (project , webAppId , new WebAppLogStreaming (webAppId ));
7172 }
7273
73- public void showFunctionStreamingLog (Project project , String functionId ) {
74- showAppServiceStreamingLog (project , functionId , new FunctionLogStreaming (functionId ));
74+ public void showFunctionStreamingLog (Project project , FunctionAppBase <?,?,?> app ) {
75+ showAppServiceStreamingLog (project , app .getId (), new FunctionLogStreaming (app ));
76+ }
77+
78+ public void showFunctionDeploymentSlotStreamingLog (Project project , FunctionAppBase <?,?,?> app ) {
79+ showAppServiceStreamingLog (project , app .getId (), new FunctionDeploymentSlotLogStreaming (app ));
7580 }
7681
7782 @ AzureOperation (name = "appservice.close_log_stream.app" , params = {"nameFromResourceId(appId)" }, type = AzureOperation .Type .SERVICE )
@@ -95,11 +100,6 @@ private void showAppServiceStreamingLog(Project project, String resourceId, ILog
95100 final String name = logStreaming .getTitle ();
96101 final AppServiceStreamingLogConsoleView consoleView = getOrCreateConsoleView (project , resourceId );
97102 if (!consoleView .isActive ()) {
98- if (!logStreaming .isLogStreamingSupported ()) {
99- AzureTaskManager .getInstance ().runLater (() -> AzureMessager .getMessager ()
100- .error (message ("appService.logStreaming.hint.notSupport" , name ), NOT_SUPPORTED ));
101- return ;
102- }
103103 if (!logStreaming .isLogStreamingEnabled ()) {
104104 // Enable Log Streaming if log streaming of target is not enabled
105105 final boolean userInput = AzureMessager .getMessager ()
@@ -130,10 +130,6 @@ private AppServiceStreamingLogConsoleView getOrCreateConsoleView(Project project
130130 }
131131
132132 interface ILogStreaming {
133- default boolean isLogStreamingSupported () {
134- return true ;
135- }
136-
137133 boolean isLogStreamingEnabled ();
138134
139135 void enableLogStreaming ();
@@ -144,16 +140,17 @@ default boolean isLogStreamingSupported() {
144140 Flux <String > getStreamingLogContent ();
145141 }
146142
147- static class FunctionLogStreaming implements ILogStreaming {
143+ static abstract class AbstractFunctionLogStreaming implements ILogStreaming {
148144
149145 private static final String APPINSIGHTS_INSTRUMENTATIONKEY = "APPINSIGHTS_INSTRUMENTATIONKEY" ;
150146 private static final String APPLICATION_INSIGHT_PATTERN = "%s/#blade/AppInsightsExtension/QuickPulseBladeV2/ComponentId/%s/ResourceId/%s" ;
151147 private static final String MUST_CONFIGURE_APPLICATION_INSIGHTS = message ("appService.logStreaming.error.noApplicationInsights" );
152148
153- private final FunctionApp functionApp ;
149+ @ Getter
150+ protected final FunctionAppBase <?, ?, ?> functionApp ;
154151
155- FunctionLogStreaming (final String resourceId ) {
156- this .functionApp = Azure . az ( AzureFunctions . class ). functionApp ( resourceId ) ;
152+ AbstractFunctionLogStreaming (final FunctionAppBase <?,?,?> functionApp ) {
153+ this .functionApp = functionApp ;
157154 }
158155
159156 @ Override
@@ -164,15 +161,6 @@ public boolean isLogStreamingEnabled() {
164161 return operatingSystem == OperatingSystem .LINUX || isEnableApplicationLog ;
165162 }
166163
167- @ Override
168- public void enableLogStreaming () {
169- final DiagnosticConfig diagnosticConfig = Optional .ofNullable (functionApp .getDiagnosticConfig ()).orElseGet (DiagnosticConfig ::new );
170- diagnosticConfig .setEnableApplicationLog (true );
171- final FunctionAppDraft draft = (FunctionAppDraft ) functionApp .update ();
172- draft .setDiagnosticConfig (diagnosticConfig );
173- draft .commit ();
174- }
175-
176164 @ Override
177165 public String getTitle () {
178166 return functionApp .getName ();
@@ -218,6 +206,38 @@ private String getApplicationInsightLiveMetricsUrl(ApplicationInsight target, St
218206 }
219207 }
220208
209+ static class FunctionLogStreaming extends AbstractFunctionLogStreaming {
210+
211+ FunctionLogStreaming (FunctionAppBase <?, ?, ?> functionApp ) {
212+ super (functionApp );
213+ }
214+
215+ @ Override
216+ public void enableLogStreaming () {
217+ final DiagnosticConfig diagnosticConfig = Optional .ofNullable (getFunctionApp ().getDiagnosticConfig ()).orElseGet (DiagnosticConfig ::new );
218+ diagnosticConfig .setEnableApplicationLog (true );
219+ final FunctionAppDraft draft = (FunctionAppDraft ) getFunctionApp ().update ();
220+ draft .setDiagnosticConfig (diagnosticConfig );
221+ draft .commit ();
222+ }
223+ }
224+
225+ static class FunctionDeploymentSlotLogStreaming extends AbstractFunctionLogStreaming {
226+
227+ FunctionDeploymentSlotLogStreaming (FunctionAppBase <?,?,?> functionApp ) {
228+ super (functionApp );
229+ }
230+
231+ @ Override
232+ public void enableLogStreaming () {
233+ final DiagnosticConfig diagnosticConfig = Optional .ofNullable (getFunctionApp ().getDiagnosticConfig ()).orElseGet (DiagnosticConfig ::new );
234+ diagnosticConfig .setEnableApplicationLog (true );
235+ final FunctionAppDeploymentSlotDraft draft = (FunctionAppDeploymentSlotDraft ) getFunctionApp ().update ();
236+ draft .setDiagnosticConfig (diagnosticConfig );
237+ draft .commit ();
238+ }
239+ }
240+
221241 static class WebAppLogStreaming implements ILogStreaming {
222242 private final WebApp webApp ;
223243
0 commit comments