Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

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

import com.microsoft.azure.management.appservice.WebApp;
import com.microsoft.azure.common.Utils;
import com.microsoft.azure.management.resources.fluentcore.arm.ResourceId;
import com.microsoft.azure.toolkit.lib.appservice.service.IWebApp;
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
import com.microsoft.azuretools.core.mvp.model.ResourceEx;
import com.microsoft.azuretools.core.mvp.model.webapp.AzureWebAppMvpModel;
import com.microsoft.azuretools.utils.AzureUIRefreshCore;
import com.microsoft.azuretools.utils.AzureUIRefreshEvent;
import com.microsoft.azuretools.utils.AzureUIRefreshListener;
Expand Down Expand Up @@ -80,10 +81,13 @@ public void run() {
WebAppUtils.WebAppDetails webAppDetails = (WebAppUtils.WebAppDetails) event.object;
switch (event.opsType) {
case ADD:
final IWebApp newWebApp = AzureWebAppMvpModel.getInstance()

Copy link
Copy Markdown
Contributor

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)?

Copy link
Copy Markdown
Member Author

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

.getAzureAppServiceClient(webAppDetails.subscriptionDetail.getSubscriptionId())
.webapp(webAppDetails.webApp.id());
DefaultLoader.getIdeHelper().invokeLater(() -> {
addChildNode(new WebAppNode(WebAppModule.this,
ResourceId.fromString(webAppDetails.webApp.id()).subscriptionId(),
webAppDetails.webApp));
newWebApp));
});
break;
case UPDATE:
Expand All @@ -98,11 +102,10 @@ public void run() {
}

@Override
public void renderChildren(@NotNull final List<ResourceEx<WebApp>> resourceExes) {
for (final ResourceEx<WebApp> resourceEx : resourceExes) {
final WebApp app = resourceEx.getResource();
final String sId = resourceEx.getSubscriptionId();
final WebAppNode node = new WebAppNode(this, sId, app);
public void renderChildren(@NotNull final List<IWebApp> resourceExes) {
for (final IWebApp webApp : resourceExes) {
final String subscriptionId = Utils.getSubscriptionId(webApp.id());
final WebAppNode node = new WebAppNode(this, subscriptionId, webApp);

addChildNode(node);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public class WebAppModulePresenter<V extends WebAppModuleView> extends MvpPresen
public void onModuleRefresh() {
final WebAppModuleView view = getMvpView();
if (view != null) {
view.renderChildren(AzureWebAppMvpModel.getInstance().listAllWebApps(true));
view.renderChildren(AzureWebAppMvpModel.getInstance().listAzureWebApps(true));
}
}

public void onDeleteWebApp(String sid, String id) {
AzureWebAppMvpModel.getInstance().deleteWebApp(sid, id);
AzureWebAppMvpModel.getInstance().getAzureAppServiceClient(sid).webapp(id).delete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

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

import java.util.List;

import com.microsoft.azure.management.appservice.WebApp;
import com.microsoft.azuretools.core.mvp.model.ResourceEx;
import com.microsoft.azure.toolkit.lib.appservice.service.IWebApp;
import com.microsoft.azuretools.core.mvp.ui.base.MvpView;

import java.util.List;

public interface WebAppModuleView extends MvpView {
void renderChildren(List<ResourceEx<WebApp>> resourceExes);
void renderChildren(List<IWebApp> resourceExes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

AzureWebAppMvpModel.getInstance().getWebAppById(subscriptionId, webAppManager.id());

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) {
Expand All @@ -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));
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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;
}

Expand All @@ -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
Expand Up @@ -12,12 +12,12 @@ public class DeploymentSlotModulePresenter<V extends DeploymentSlotModuleView> e
public void onRefreshDeploymentSlotModule(final String subscriptionId, final String webAppId) {
final DeploymentSlotModuleView view = getMvpView();
if (view != null) {
view.renderDeploymentSlots(AzureWebAppMvpModel.getInstance().getDeploymentSlots(subscriptionId, webAppId));
view.renderDeploymentSlots(AzureWebAppMvpModel.getInstance().getAzureAppServiceClient(subscriptionId).webapp(webAppId).deploymentSlots());
}
}

public void onDeleteDeploymentSlot(final String subscriptionId, final String webAppId,
final String slotName) {
AzureWebAppMvpModel.getInstance().deleteDeploymentSlotNode(subscriptionId, webAppId, slotName);
AzureWebAppMvpModel.getInstance().getAzureAppServiceClient(subscriptionId).webapp(webAppId).deploymentSlot(slotName).delete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

package com.microsoft.tooling.msservices.serviceexplorer.azure.webapp.deploymentslot;

import com.microsoft.azure.management.appservice.DeploymentSlot;
import com.microsoft.azure.toolkit.lib.appservice.service.IWebAppDeploymentSlot;
import com.microsoft.azuretools.core.mvp.ui.base.MvpView;

import java.util.List;

public interface DeploymentSlotModuleView extends MvpView {
void renderDeploymentSlots(final List<DeploymentSlot>slots);
void renderDeploymentSlots(final List<IWebAppDeploymentSlot> slots);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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();
}

Expand All @@ -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
Expand Down Expand Up @@ -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);
}

Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions Utils/azuretools-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@
</resources>
</build>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-toolkit-appservice-lib</artifactId>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-queue</artifactId>
Expand Down
Loading