Skip to content

Commit 43917bb

Browse files
Merge pull request #5433 from microsoft/fix-appservice-refresh
Fix refresh issues for app service
2 parents c56ef4b + 62678d2 commit 43917bb

File tree

10 files changed

+43
-10
lines changed

10 files changed

+43
-10
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import com.intellij.ui.SimpleListCellRenderer;
1111
import com.intellij.ui.components.fields.ExtendableTextComponent;
1212
import com.microsoft.azure.toolkit.intellij.common.AzureComboBox;
13+
import com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion;
14+
import com.microsoft.azure.toolkit.lib.appservice.model.Runtime;
15+
import com.microsoft.azure.toolkit.lib.appservice.service.IAppService;
1316
import com.microsoft.azure.toolkit.lib.webapp.WebAppService;
1417
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
1518
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
@@ -19,6 +22,7 @@
1922
import javax.swing.*;
2023
import java.util.List;
2124
import java.util.Objects;
25+
import java.util.Optional;
2226

2327
public abstract class AppServiceComboBox<T extends AppServiceComboBoxModel> extends AzureComboBox<T> {
2428

@@ -71,6 +75,17 @@ protected String getItemText(final Object item) {
7175
}
7276
}
7377

78+
protected boolean isJavaAppService(IAppService appService) {
79+
try {
80+
return Optional.ofNullable(appService.getRuntime()).map(Runtime::getJavaVersion)
81+
.map(javaVersion -> !Objects.equals(javaVersion, JavaVersion.OFF))
82+
.orElse(false);
83+
} catch (final RuntimeException e) {
84+
// app service may have been removed while parsing, return false in this case
85+
return false;
86+
}
87+
}
88+
7489
protected abstract void createResource();
7590

7691
public static class AppComboBoxRender extends SimpleListCellRenderer {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public void setSubscription(Subscription subscription) {
5555
this.clear();
5656
return;
5757
}
58+
// force refresh service plan when switch subscription
59+
Azure.az(AzureAppService.class).subscription(subscription.getId()).appServicePlans(true);
5860
this.refreshItems();
5961
}
6062

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/function/FunctionAppComboBox.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.microsoft.azure.toolkit.intellij.appservice.AppServiceComboBox;
1010
import com.microsoft.azure.toolkit.lib.Azure;
1111
import com.microsoft.azure.toolkit.lib.appservice.AzureAppService;
12-
import com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion;
1312
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
1413
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
1514
import com.microsoft.tooling.msservices.components.DefaultLoader;
@@ -44,7 +43,7 @@ protected void createResource() {
4443
)
4544
protected List<FunctionAppComboBoxModel> loadAppServiceModels() {
4645
return Azure.az(AzureAppService.class).functionApps().parallelStream()
47-
.filter(functionApp -> functionApp.getRuntime().getJavaVersion() != JavaVersion.OFF)
46+
.filter(this::isJavaAppService)
4847
.map(FunctionAppComboBoxModel::new)
4948
.sorted((app1, app2) -> app1.getAppName().compareToIgnoreCase(app2.getAppName()))
5049
.collect(Collectors.toList());

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ protected void createResource() {
4949
)
5050
protected List<WebAppComboBoxModel> loadAppServiceModels() {
5151
final List<IWebApp> webApps = Azure.az(AzureAppService.class).webapps(false);
52-
return webApps.stream()
53-
.filter(webApp -> webApp.getRuntime().getJavaVersion() != null && webApp.getRuntime().getJavaVersion() != JavaVersion.OFF)
54-
.sorted((a, b) -> a.name().compareToIgnoreCase(b.name()))
55-
.map(WebAppComboBoxModel::new)
56-
.collect(Collectors.toList());
52+
return webApps.stream().parallel()
53+
.filter(this::isJavaAppService)
54+
.sorted((a, b) -> a.name().compareToIgnoreCase(b.name()))
55+
.map(WebAppComboBoxModel::new)
56+
.collect(Collectors.toList());
5757
}
5858
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public FunctionAppNode(@Nonnull AzureRefreshableNode parent, @Nonnull IFunctionA
4444

4545
@Override
4646
protected void refreshItems() {
47+
super.refreshItems();
4748
this.renderSubModules();
4849
}
4950

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
@@ -45,7 +45,7 @@ public void removeNode(String sid, String id, Node node) {
4545
@AzureOperation(name = "function.reload_all", type = AzureOperation.Type.ACTION)
4646
protected void refreshItems() {
4747
Azure.az(AzureAppService.class).functionApps(true)
48-
.stream().map(functionApp -> new FunctionAppNode(FunctionModule.this, functionApp))
48+
.stream().parallel().map(functionApp -> new FunctionAppNode(FunctionModule.this, functionApp))
4949
.forEach(this::addChildNode);
5050
}
5151

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public void run() {
8181
@Override
8282
public void renderChildren(@NotNull final List<IWebApp> resourceExes) {
8383
resourceExes.stream()
84+
.parallel()
8485
.filter(webApp -> StringUtils.isNotEmpty(webApp.id()))
8586
.map(webApp -> new WebAppNode(this, webApp))
8687
.forEach(this::addChildNode);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public IWebApp getWebappManager() {
5959
@Override
6060
@AzureOperation(name = "webapp.refresh", type = AzureOperation.Type.ACTION)
6161
protected void refreshItems() {
62+
super.refreshItems();
6263
this.renderSubModules();
6364
}
6465

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.microsoft.azure.toolkit.lib.appservice.service.IAppService;
1111
import com.microsoft.azuretools.telemetry.AppInsightsConstants;
1212
import com.microsoft.azuretools.telemetry.TelemetryProperties;
13+
import com.microsoft.tooling.msservices.components.DefaultLoader;
14+
import com.microsoft.tooling.msservices.serviceexplorer.AzureIconSymbol;
1315
import com.microsoft.tooling.msservices.serviceexplorer.AzureRefreshableNode;
1416
import com.microsoft.tooling.msservices.serviceexplorer.NodeAction;
1517
import com.microsoft.tooling.msservices.serviceexplorer.RefreshableNode;
@@ -38,7 +40,8 @@ public WebAppBaseNode(final AzureRefreshableNode parent, final String label, fin
3840
this.appService = appService;
3941
this.subscriptionId = ResourceId.fromString(appService.id()).subscriptionId();
4042

41-
renderNode(WebAppBaseState.fromString(appService.state()));
43+
renderNode(WebAppBaseState.UPDATING);
44+
DefaultLoader.getIdeHelper().executeOnPooledThread(() -> refreshItems());
4245
}
4346

4447
protected String getAppServiceIconPath(final WebAppBaseState state) {
@@ -47,6 +50,13 @@ protected String getAppServiceIconPath(final WebAppBaseState state) {
4750
+ label + (state == WebAppBaseState.RUNNING ? ICON_RUNNING_POSTFIX : ICON_STOPPED_POSTFIX);
4851
}
4952

53+
@Override
54+
protected void refreshItems() {
55+
renderNode(WebAppBaseState.UPDATING);
56+
appService.refresh();
57+
renderNode(WebAppBaseState.fromString(appService.state()));
58+
}
59+
5060
@Override
5161
public List<NodeAction> getNodeActions() {
5262
boolean running = this.state == WebAppBaseState.RUNNING;
@@ -58,12 +68,15 @@ public List<NodeAction> getNodeActions() {
5868
}
5969

6070
public void renderNode(@Nonnull WebAppBaseState state) {
71+
this.state = state;
6172
switch (state) {
6273
case RUNNING:
6374
case STOPPED:
64-
this.state = state;
6575
this.setIconPath(getAppServiceIconPath(state));
6676
break;
77+
case UPDATING:
78+
this.setIconPath(AzureIconSymbol.Common.REFRESH.getPath());
79+
break;
6780
default:
6881
break;
6982
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ protected void onNodeClick(NodeActionEvent e) {
9595
@Override
9696
@AzureOperation(name = "webapp|deployment.refresh", params = {"this.slot.name()", "this.webApp.name()"}, type = AzureOperation.Type.ACTION)
9797
protected void refreshItems() {
98+
super.refreshItems();
9899
if (slot.exists()) {
99100
this.renderNode(WebAppBaseState.fromString(slot.state()));
100101
} else {

0 commit comments

Comments
 (0)