Repository navigation
[Track2 #2] Migrate nodes in Azure explorer to app service library #4972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f4c7273
291ea59
6d50724
7ef11c7
590f289
97cb2c8
46a266e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
| package com.microsoft.tooling.msservices.serviceexplorer.azure.webapp; | ||
|
|
||
| import com.microsoft.azure.management.appservice.WebApp; | ||
| import com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem; | ||
| import com.microsoft.azure.toolkit.lib.appservice.service.IWebApp; | ||
| import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation; | ||
| import com.microsoft.azuretools.ActionConstants; | ||
| import com.microsoft.azuretools.azurecommons.helpers.Nullable; | ||
|
|
@@ -31,18 +33,21 @@ public class WebAppNode extends WebAppBaseNode implements WebAppNodeView { | |
| public static final String SSH_INTO = "SSH into Web App (Preview)"; | ||
| public static final String PROFILE_FLIGHT_RECORDER = "Profile Flight Recorder"; | ||
|
|
||
| private final WebApp webapp; | ||
| // todo: migrate file service to track2 SDK | ||
| private final WebApp webapp; // Track one client, keep for file service | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we lazy load the webapp since the following statement will cause a network call. |
||
| private final IWebApp webappManager; | ||
|
|
||
| public WebAppNode(WebAppModule parent, String subscriptionId, WebApp delegate) { | ||
| super(delegate.id(), delegate.name(), LABEL, parent, subscriptionId, delegate.defaultHostName(), | ||
| delegate.operatingSystem().toString(), delegate.state()); | ||
| this.webapp = delegate; | ||
| public WebAppNode(WebAppModule parent, String subscriptionId, IWebApp webAppManager) { | ||
| super(webAppManager.id(), webAppManager.name(), LABEL, parent, subscriptionId, webAppManager.hostName(), | ||
| webAppManager.getRuntime().getOperatingSystem().toString(), webAppManager.state()); | ||
| this.webapp = AzureWebAppMvpModel.getInstance().getWebAppById(subscriptionId, webAppManager.id()); | ||
| this.webappManager = webAppManager; | ||
| loadActions(); | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable AzureIconSymbol getIconSymbol() { | ||
| boolean isLinux = OS_LINUX.equalsIgnoreCase(webapp.operatingSystem().toString()); | ||
| boolean isLinux = webappManager.getRuntime().getOperatingSystem() != OperatingSystem.WINDOWS; | ||
| boolean running = WebAppBaseState.RUNNING.equals(state); | ||
| boolean updating = WebAppBaseState.UPDATING.equals(state); | ||
| if (isLinux) { | ||
|
|
@@ -61,7 +66,7 @@ protected void refreshItems() { | |
|
|
||
| @Override | ||
| public void renderSubModules() { | ||
| addChildNode(new DeploymentSlotModule(this, this.subscriptionId, this.webapp)); | ||
| addChildNode(new DeploymentSlotModule(this, this.subscriptionId, this.webappManager)); | ||
| addChildNode(new AppServiceUserFilesRootNode(this, this.subscriptionId, this.webapp)); | ||
| addChildNode(new AppServiceLogFilesRootNode(this, this.subscriptionId, this.webapp)); | ||
| } | ||
|
|
@@ -87,7 +92,7 @@ protected final BasicActionBuilder initActionBuilder(Runnable runnable) { | |
| public Map<String, String> toProperties() { | ||
| final Map<String, String> properties = new HashMap<>(); | ||
| properties.put(AppInsightsConstants.SubscriptionId, this.subscriptionId); | ||
| properties.put(AppInsightsConstants.Region, this.webapp.regionName()); | ||
| properties.put(AppInsightsConstants.Region, this.webappManager.entity().getRegion().getName()); | ||
| return properties; | ||
| } | ||
|
|
||
|
|
@@ -122,25 +127,25 @@ private void delete() { | |
|
|
||
| @AzureOperation(name = ActionConstants.WebApp.START, type = AzureOperation.Type.ACTION) | ||
| private void start() { | ||
| AzureWebAppMvpModel.getInstance().startWebApp(this.subscriptionId, this.webapp.id()); | ||
| this.webappManager.start(); | ||
| this.renderNode(WebAppBaseState.RUNNING); | ||
| } | ||
|
|
||
| @AzureOperation(name = ActionConstants.WebApp.STOP, type = AzureOperation.Type.ACTION) | ||
| private void stop() { | ||
| AzureWebAppMvpModel.getInstance().stopWebApp(this.subscriptionId, this.webapp.id()); | ||
| this.webappManager.stop(); | ||
| this.renderNode(WebAppBaseState.STOPPED); | ||
| } | ||
|
|
||
| @AzureOperation(name = ActionConstants.WebApp.RESTART, type = AzureOperation.Type.ACTION) | ||
| private void restart() { | ||
| AzureWebAppMvpModel.getInstance().restartWebApp(this.subscriptionId, this.webapp.id()); | ||
| this.webappManager.restart(); | ||
| this.renderNode(WebAppBaseState.RUNNING); | ||
| } | ||
|
|
||
| @AzureOperation(name = ActionConstants.WebApp.OPEN_IN_BROWSER, type = AzureOperation.Type.ACTION) | ||
| private void openInBrowser() { | ||
| DefaultLoader.getUIHelper().openInBrowser("http://" + this.hostName); | ||
| DefaultLoader.getUIHelper().openInBrowser("http://" + this.webappManager.hostName()); | ||
| } | ||
|
|
||
| @AzureOperation(name = ActionConstants.WebApp.SHOW_PROPERTIES, type = AzureOperation.Type.ACTION) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,9 +5,9 @@ | |
|
|
||
| package com.microsoft.tooling.msservices.serviceexplorer.azure.webapp.deploymentslot; | ||
|
|
||
| import com.microsoft.azure.management.appservice.DeploymentSlot; | ||
| import com.microsoft.azure.management.appservice.OperatingSystem; | ||
| import com.microsoft.azure.management.appservice.WebApp; | ||
| import com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem; | ||
| import com.microsoft.azure.toolkit.lib.appservice.service.IWebApp; | ||
| import com.microsoft.azure.toolkit.lib.appservice.service.IWebAppDeploymentSlot; | ||
| import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation; | ||
| import com.microsoft.azuretools.azurecommons.helpers.NotNull; | ||
| import com.microsoft.azuretools.azurecommons.helpers.Nullable; | ||
|
|
@@ -25,9 +25,9 @@ public class DeploymentSlotModule extends AzureRefreshableNode implements Deploy | |
| private final DeploymentSlotModulePresenter presenter; | ||
| public static final String MODULE_NAME = "Deployment Slots"; | ||
| protected final String subscriptionId; | ||
| protected final WebApp webapp; | ||
| protected final IWebApp webapp; | ||
|
|
||
| public DeploymentSlotModule(final Node parent, final String subscriptionId, final WebApp webapp) { | ||
| public DeploymentSlotModule(final Node parent, final String subscriptionId, final IWebApp webapp) { | ||
| super(MODULE_ID, MODULE_NAME, parent, ICON_PATH); | ||
| this.subscriptionId = subscriptionId; | ||
| this.webapp = webapp; | ||
|
|
@@ -37,7 +37,7 @@ public DeploymentSlotModule(final Node parent, final String subscriptionId, fina | |
|
|
||
| @Override | ||
| public @Nullable AzureIconSymbol getIconSymbol() { | ||
| boolean isLinux = OperatingSystem.LINUX.name().equalsIgnoreCase(webapp.operatingSystem().toString()); | ||
| boolean isLinux = webapp.getRuntime().getOperatingSystem() != OperatingSystem.WINDOWS; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add isLinux in IWebapp |
||
| return isLinux ? AzureIconSymbol.DeploymentSlot.MODULE_ON_LINUX : AzureIconSymbol.DeploymentSlot.MODULE; | ||
| } | ||
|
|
||
|
|
@@ -55,10 +55,7 @@ protected void refreshItems() { | |
| } | ||
|
|
||
| @Override | ||
| public void renderDeploymentSlots(@NotNull final List<DeploymentSlot> slots) { | ||
| slots.forEach(slot -> addChildNode( | ||
| new DeploymentSlotNode(slot.id(), slot.parent().id(), slot.parent().name(), | ||
| this, slot.name(), slot.state(), slot.operatingSystem().toString(), | ||
| this.subscriptionId, slot.defaultHostName()))); | ||
| public void renderDeploymentSlots(@NotNull final List<IWebAppDeploymentSlot> slots) { | ||
| slots.forEach(slot -> addChildNode(new DeploymentSlotNode(slot, DeploymentSlotModule.this))); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,13 @@ | |
|
|
||
| package com.microsoft.tooling.msservices.serviceexplorer.azure.webapp.deploymentslot; | ||
|
|
||
| import com.microsoft.azure.management.appservice.DeploymentSlot; | ||
| import com.microsoft.azure.management.appservice.WebApp; | ||
| import com.azure.resourcemanager.AzureResourceManager; | ||
| import com.microsoft.azure.toolkit.lib.appservice.service.IWebApp; | ||
| import com.microsoft.azure.toolkit.lib.appservice.service.IWebAppDeploymentSlot; | ||
| import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation; | ||
| import com.microsoft.azuretools.ActionConstants; | ||
| import com.microsoft.azuretools.azurecommons.helpers.Nullable; | ||
| import com.microsoft.azuretools.core.mvp.model.webapp.AzureWebAppMvpModel; | ||
| import com.microsoft.azuretools.sdkmanage.Track2Manager; | ||
| import com.microsoft.tooling.msservices.components.DefaultLoader; | ||
| import com.microsoft.tooling.msservices.serviceexplorer.AzureActionEnum; | ||
| import com.microsoft.tooling.msservices.serviceexplorer.AzureIconSymbol; | ||
|
|
@@ -25,17 +26,15 @@ | |
| public class DeploymentSlotNode extends WebAppBaseNode implements DeploymentSlotNodeView { | ||
| private static final String ACTION_SWAP_WITH_PRODUCTION = "Swap with production"; | ||
| private static final String LABEL = "Slot"; | ||
| protected final String webAppId; | ||
| protected final String webAppName; | ||
| protected final String slotName; | ||
|
|
||
| public DeploymentSlotNode(final String slotId, final String webAppId, final String webAppName, | ||
| final DeploymentSlotModule parent, final String name, final String state, final String os, | ||
| final String subscriptionId, final String hostName) { | ||
| super(slotId, name, LABEL, parent, subscriptionId, hostName, os, state); | ||
| this.webAppId = webAppId; | ||
| this.webAppName = webAppName; | ||
| this.slotName = name; | ||
|
|
||
| private final IWebApp webApp; | ||
| private final IWebAppDeploymentSlot slot; | ||
|
|
||
| public DeploymentSlotNode(final IWebAppDeploymentSlot deploymentSlot, final DeploymentSlotModule parent) { | ||
| super(deploymentSlot.id(), deploymentSlot.name(), LABEL, parent, parent.subscriptionId, deploymentSlot.hostName(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment |
||
| deploymentSlot.getRuntime().getOperatingSystem().toString(), deploymentSlot.state()); | ||
| this.webApp = deploymentSlot.webApp(); | ||
| this.slot = deploymentSlot; | ||
| loadActions(); | ||
| } | ||
|
|
||
|
|
@@ -54,11 +53,11 @@ public DeploymentSlotNode(final String slotId, final String webAppId, final Stri | |
| } | ||
|
|
||
| public String getWebAppId() { | ||
| return this.webAppId; | ||
| return this.webApp.id(); | ||
| } | ||
|
|
||
| public String getWebAppName() { | ||
| return this.webAppName; | ||
| return this.webApp.name(); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -95,26 +94,28 @@ protected void onNodeClick(NodeActionEvent e) { | |
| @Override | ||
| @AzureOperation(name = "webapp|deployment.refresh", params = {"@slotName", "@webAppName"}, type = AzureOperation.Type.ACTION) | ||
| protected void refreshItems() { | ||
| final WebApp app = AzureWebAppMvpModel.getInstance().getWebAppById(subscriptionId, webAppId); | ||
| final DeploymentSlot slot = app.deploymentSlots().getByName(slotName); | ||
| this.renderNode(WebAppBaseState.fromString(slot.state())); | ||
| if (slot.exists()) { | ||
| this.renderNode(WebAppBaseState.fromString(slot.state())); | ||
| } else { | ||
| parent.removeNode(subscriptionId, name, this); | ||
| } | ||
| } | ||
|
|
||
| @AzureOperation(name = ActionConstants.WebApp.DeploymentSlot.START, type = AzureOperation.Type.ACTION) | ||
| private void start() { | ||
| AzureWebAppMvpModel.getInstance().startDeploymentSlot(subscriptionId, webAppId, slotName); | ||
| slot.start(); | ||
| this.renderNode(WebAppBaseState.RUNNING); | ||
| } | ||
|
|
||
| @AzureOperation(name = ActionConstants.WebApp.DeploymentSlot.STOP, type = AzureOperation.Type.ACTION) | ||
| private void stop() { | ||
| AzureWebAppMvpModel.getInstance().stopDeploymentSlot(subscriptionId, webAppId, slotName); | ||
| slot.stop(); | ||
| this.renderNode(WebAppBaseState.STOPPED); | ||
| } | ||
|
|
||
| @AzureOperation(name = ActionConstants.WebApp.DeploymentSlot.RESTART, type = AzureOperation.Type.ACTION) | ||
| private void restart() { | ||
| AzureWebAppMvpModel.getInstance().restartDeploymentSlot(subscriptionId, webAppId, slotName); | ||
| slot.restart(); | ||
| this.renderNode(WebAppBaseState.RUNNING); | ||
| } | ||
|
|
||
|
|
@@ -125,12 +126,14 @@ private void delete() { | |
|
|
||
| @AzureOperation(name = ActionConstants.WebApp.DeploymentSlot.SWAP, type = AzureOperation.Type.ACTION) | ||
| private void swap() { | ||
| AzureWebAppMvpModel.getInstance().swapSlotWithProduction(subscriptionId, webAppId, slotName); | ||
| // todo: add swap method to app service library | ||
| final AzureResourceManager resourceManager = Track2Manager.getAzureResourceManager(subscriptionId); | ||
| resourceManager.webApps().getById(webApp.id()).swap(slot.hostName()); | ||
| } | ||
|
|
||
| @AzureOperation(name = ActionConstants.WebApp.DeploymentSlot.OPEN_IN_BROWSER, type = AzureOperation.Type.ACTION) | ||
| private void openInBrowser() { | ||
| DefaultLoader.getUIHelper().openInBrowser("http://" + this.hostName); | ||
| DefaultLoader.getUIHelper().openInBrowser("http://" + slot.hostName()); | ||
| } | ||
|
|
||
| @AzureOperation(name = ActionConstants.WebApp.DeploymentSlot.SHOW_PROPERTIES, type = AzureOperation.Type.ACTION) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why shall we use AzureWebAppMvpModel, shall we use az.webapp(id)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update codes here after refactor app service library to leverage Account service for authentication