Skip to content

Commit 411ff5c

Browse files
Merge pull request #5428 from microsoft/fix-function
Migrate to use cache in library for app service
2 parents b906bc9 + 4283af1 commit 411ff5c

File tree

9 files changed

+14
-50
lines changed

9 files changed

+14
-50
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/webapp/WebAppComboBox.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77

88
import com.intellij.openapi.project.Project;
99
import com.microsoft.azure.toolkit.intellij.appservice.AppServiceComboBox;
10+
import com.microsoft.azure.toolkit.lib.Azure;
11+
import com.microsoft.azure.toolkit.lib.appservice.AzureAppService;
1012
import com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion;
1113
import com.microsoft.azure.toolkit.lib.appservice.service.IWebApp;
1214
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
1315
import com.microsoft.azure.toolkit.lib.webapp.WebAppService;
1416
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
15-
import com.microsoft.azuretools.core.mvp.model.webapp.AzureWebAppMvpModel;
1617
import com.microsoft.tooling.msservices.components.DefaultLoader;
1718

1819
import java.util.List;
@@ -47,7 +48,7 @@ protected void createResource() {
4748
type = AzureOperation.Type.SERVICE
4849
)
4950
protected List<WebAppComboBoxModel> loadAppServiceModels() {
50-
final List<IWebApp> webApps = AzureWebAppMvpModel.getInstance().listAzureWebApps(false);
51+
final List<IWebApp> webApps = Azure.az(AzureAppService.class).webapps(false);
5152
return webApps.stream()
5253
.filter(webApp -> webApp.getRuntime().getJavaVersion() != null && webApp.getRuntime().getJavaVersion() != JavaVersion.OFF)
5354
.sorted((a, b) -> a.name().compareToIgnoreCase(b.name()))

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/webapp/docker/webapponlinux/WebAppOnLinuxDeployState.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,9 @@ protected Operation createOperation() {
123123
type = AzureOperation.Type.TASK
124124
)
125125
protected void onSuccess(IAppService result, @NotNull RunProcessHandler processHandler) {
126-
processHandler.setText("Updating cache ... ");
127-
AzureWebAppMvpModel.getInstance().listAzureWebApps(true); // todo: replace with cache framework
128-
processHandler.setText("Job done");
129126
processHandler.notifyComplete();
130127
if (deployModel.isCreatingNewWebAppOnLinux() && AzureUIRefreshCore.listeners != null) {
131-
AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH, null));
128+
AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH, result));
132129
}
133130
}
134131

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected Operation createOperation() {
115115
@AzureOperation(name = "webapp.complete_starting.state", type = AzureOperation.Type.ACTION)
116116
protected void onSuccess(IAppService result, @NotNull RunProcessHandler processHandler) {
117117
if (webAppSettingModel.isCreatingNew() && AzureUIRefreshCore.listeners != null) {
118-
AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH, null));
118+
AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH, result));
119119
}
120120
updateConfigurationDataModel(result);
121121
int indexOfDot = webAppSettingModel.getTargetName().lastIndexOf(".");

Utils/azure-explorer-common/src/com/microsoft/tooling/msservices/serviceexplorer/azure/container/WebAppOnLinuxDeployPresenter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import com.microsoft.azure.toolkit.lib.appservice.service.IWebApp;
1313
import com.microsoft.azure.toolkit.lib.auth.AzureAccount;
1414
import com.microsoft.azuretools.core.mvp.model.AzureMvpModel;
15-
import com.microsoft.azuretools.core.mvp.model.webapp.AzureWebAppMvpModel;
1615
import com.microsoft.azuretools.core.mvp.ui.base.MvpPresenter;
1716
import com.microsoft.tooling.msservices.components.DefaultLoader;
1817
import reactor.core.publisher.Flux;
@@ -34,7 +33,7 @@ public class WebAppOnLinuxDeployPresenter<V extends WebAppOnLinuxDeployView> ext
3433
private static final String CANNOT_LIST_APP_SERVICE_PLAN = "Failed to list app service plan.";
3534

3635
private List<IWebApp> retrieveListOfWebAppOnLinux(boolean force) {
37-
return AzureWebAppMvpModel.getInstance().listAzureWebApps(force).stream()
36+
return Azure.az(AzureAppService.class).webapps(force).stream()
3837
.filter(iWebApp -> iWebApp.getRuntime().getOperatingSystem() != OperatingSystem.WINDOWS) // docker and linux
3938
.collect(Collectors.toList());
4039
}

Utils/azure-explorer-common/src/com/microsoft/tooling/msservices/serviceexplorer/azure/function/FunctionAppNode.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
package com.microsoft.tooling.msservices.serviceexplorer.azure.function;
77

8-
import com.microsoft.azure.toolkit.lib.Azure;
9-
import com.microsoft.azure.toolkit.lib.appservice.AzureAppService;
108
import com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp;
119
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
1210
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
@@ -29,7 +27,7 @@ public class FunctionAppNode extends WebAppBaseNode {
2927

3028
private static final String FUNCTION_LABEL = "Function";
3129

32-
private IFunctionApp functionApp;
30+
private final IFunctionApp functionApp;
3331

3432
public FunctionAppNode(@Nonnull AzureRefreshableNode parent, @Nonnull IFunctionApp functionApp) {
3533
super(parent, FUNCTION_LABEL, functionApp);

Utils/azure-explorer-common/src/com/microsoft/tooling/msservices/serviceexplorer/azure/function/FunctionModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void removeNode(String sid, String id, Node node) {
4444
@Override
4545
@AzureOperation(name = "function.reload_all", type = AzureOperation.Type.ACTION)
4646
protected void refreshItems() {
47-
Azure.az(AzureAppService.class).functionApps()
47+
Azure.az(AzureAppService.class).functionApps(true)
4848
.stream().map(functionApp -> new FunctionAppNode(FunctionModule.this, functionApp))
4949
.forEach(this::addChildNode);
5050
}

Utils/azure-explorer-common/src/com/microsoft/tooling/msservices/serviceexplorer/azure/webapp/WebAppModule.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
1010
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
1111
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
12-
import com.microsoft.azuretools.core.mvp.model.webapp.AzureWebAppMvpModel;
1312
import com.microsoft.azuretools.utils.AzureUIRefreshCore;
1413
import com.microsoft.azuretools.utils.AzureUIRefreshEvent;
1514
import com.microsoft.azuretools.utils.AzureUIRefreshListener;
16-
import com.microsoft.azuretools.utils.WebAppUtils;
17-
import com.microsoft.tooling.msservices.components.DefaultLoader;
1815
import com.microsoft.tooling.msservices.serviceexplorer.AzureIconSymbol;
1916
import com.microsoft.tooling.msservices.serviceexplorer.AzureRefreshableNode;
2017
import com.microsoft.tooling.msservices.serviceexplorer.Node;
@@ -68,12 +65,12 @@ public void run() {
6865
if (event.opsType == AzureUIRefreshEvent.EventType.SIGNIN || event.opsType == AzureUIRefreshEvent
6966
.EventType.SIGNOUT) {
7067
removeAllChildNodes();
71-
} else if (event.object == null && (event.opsType == AzureUIRefreshEvent.EventType.UPDATE || event
68+
} else if (event.object instanceof IWebApp && (event.opsType == AzureUIRefreshEvent.EventType.UPDATE || event
7269
.opsType == AzureUIRefreshEvent.EventType.REMOVE)) {
7370
if (hasChildNodes()) {
7471
load(true);
7572
}
76-
} else if (event.object == null && event.opsType == AzureUIRefreshEvent.EventType.REFRESH) {
73+
} else if (event.object instanceof IWebApp && event.opsType == AzureUIRefreshEvent.EventType.REFRESH) {
7774
load(true);
7875
}
7976
}
@@ -88,4 +85,5 @@ public void renderChildren(@NotNull final List<IWebApp> resourceExes) {
8885
.map(webApp -> new WebAppNode(this, webApp))
8986
.forEach(this::addChildNode);
9087
}
88+
9189
}

Utils/azure-explorer-common/src/com/microsoft/tooling/msservices/serviceexplorer/azure/webapp/WebAppModulePresenter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package com.microsoft.tooling.msservices.serviceexplorer.azure.webapp;
77

8+
import com.microsoft.azure.toolkit.lib.Azure;
9+
import com.microsoft.azure.toolkit.lib.appservice.AzureAppService;
810
import com.microsoft.azuretools.core.mvp.model.webapp.AzureWebAppMvpModel;
911
import com.microsoft.azuretools.core.mvp.ui.base.MvpPresenter;
1012

@@ -15,7 +17,7 @@ public class WebAppModulePresenter<V extends WebAppModuleView> extends MvpPresen
1517
public void onModuleRefresh() {
1618
final WebAppModuleView view = getMvpView();
1719
if (view != null) {
18-
view.renderChildren(AzureWebAppMvpModel.getInstance().listAzureWebApps(true));
20+
view.renderChildren(Azure.az(AzureAppService.class).webapps(true));
1921
}
2022
}
2123

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

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import com.microsoft.azure.toolkit.lib.appservice.service.IWebAppBase;
2020
import com.microsoft.azure.toolkit.lib.appservice.service.IWebAppDeploymentSlot;
2121
import com.microsoft.azure.toolkit.lib.appservice.service.impl.WebAppDeploymentSlot;
22-
import com.microsoft.azure.toolkit.lib.auth.AzureAccount;
23-
import com.microsoft.azure.toolkit.lib.common.cache.Cacheable;
2422
import com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException;
2523
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
2624
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
@@ -30,11 +28,7 @@
3028
import org.apache.commons.lang3.StringUtils;
3129

3230
import java.io.File;
33-
import java.util.List;
3431
import java.util.Map;
35-
import java.util.stream.Collectors;
36-
37-
import static com.microsoft.azure.toolkit.lib.Azure.az;
3832

3933
// todo: Refactor to tasks in app service library
4034
@Deprecated
@@ -128,31 +122,6 @@ public IWebApp updateWebAppOnDocker(String webAppId, ImageSetting imageSetting)
128122
return app;
129123
}
130124

131-
/**
132-
* List all the Web Apps in selected subscriptions.
133-
* todo: move to app service library
134-
*/
135-
@AzureOperation(
136-
name = "webapp.list.subscription|selected",
137-
type = AzureOperation.Type.SERVICE
138-
)
139-
public List<IWebApp> listAzureWebApps(final boolean force) {
140-
return az(AzureAccount.class).account().getSelectedSubscriptions().stream()
141-
.flatMap(sub -> listAzureWebAppsBySubscription(sub.getId(), force).stream())
142-
.collect(Collectors.toList());
143-
}
144-
145-
@NotNull
146-
@AzureOperation(
147-
name = "webapp.list.subscription",
148-
params = {"subscriptionId"},
149-
type = AzureOperation.Type.SERVICE
150-
)
151-
@Cacheable(cacheName = "subscription-webapps-track2", key = "$subscriptionId", condition = "!(force&&force[0])")
152-
public List<IWebApp> listAzureWebAppsBySubscription(final String subscriptionId, final boolean... force) {
153-
return com.microsoft.azure.toolkit.lib.Azure.az(AzureAppService.class).subscription(subscriptionId).webapps();
154-
}
155-
156125
/**
157126
* API to create new Web App by setting model.
158127
*/

0 commit comments

Comments
 (0)