From 82e58b8aa45ed4eeac8f280160142c02dd896e69 Mon Sep 17 00:00:00 2001 From: Hanxiao Liu Date: Mon, 13 Apr 2020 16:25:09 +0800 Subject: [PATCH] Update app properties after active deployment (#4295) * Update app properties after active deployment * Better naming --- .../intellij/util/SpringCloudUtils.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/util/SpringCloudUtils.java b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/util/SpringCloudUtils.java index fe23642b7a..aa26b0eb48 100644 --- a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/util/SpringCloudUtils.java +++ b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/util/SpringCloudUtils.java @@ -45,7 +45,9 @@ public static AppResourceInner activeDeployment(AppResourceInner appResourceInne DeploymentResourceInner deploymentResourceInner, SpringCloudDeployConfiguration configuration) throws IOException { final AppPlatformManager appPlatformManager = getAppPlatformManager(configuration.getSubscriptionId()); - final AppResourceProperties appResourceProperties = appResourceInner.properties() + AppResourceProperties appResourceProperties = updateAppResourceProperties(appResourceInner.properties(), + configuration); + appResourceProperties = appResourceProperties .withActiveDeploymentName(deploymentResourceInner.name()) .withPublicProperty(configuration.isPublic()); return appPlatformManager.apps().inner().update(SpringCloudIdHelper.getResourceGroup(configuration.getClusterId()), @@ -131,8 +133,13 @@ private static AppResourceProperties updateAppResourceProperties(AppResourceProp SpringCloudDeployConfiguration configuration) { // Enable persistent disk with default parameters appResourceProperties = appResourceProperties == null ? new AppResourceProperties() : appResourceProperties; - if (appResourceProperties.persistentDisk() == null && configuration.isEnablePersistentStorage()) { + final PersistentDisk previousPersistentDisk = appResourceProperties.persistentDisk(); + final int preStorageSize = (previousPersistentDisk == null || previousPersistentDisk.sizeInGB() == null) ? 0 : + previousPersistentDisk.sizeInGB(); + if (configuration.isEnablePersistentStorage() && preStorageSize <= 0) { appResourceProperties = appResourceProperties.withPersistentDisk(getDefaultPersistentDisk()); + } else if (!configuration.isEnablePersistentStorage() && preStorageSize > 0) { + appResourceProperties = appResourceProperties.withPersistentDisk(getEmptyPersistentDisk()); } // As we can't set public policy to an app without active deployment if (StringUtils.isNotEmpty(appResourceProperties.activeDeploymentName())) { @@ -148,6 +155,13 @@ private static PersistentDisk getDefaultPersistentDisk() { return persistentDisk; } + private static PersistentDisk getEmptyPersistentDisk() { + final PersistentDisk persistentDisk = new PersistentDisk(); + persistentDisk.withMountPath(null) + .withSizeInGB(0); + return persistentDisk; + } + private static AppPlatformManager getAppPlatformManager(String subscriptionId) throws IOException { return AuthMethodManager.getInstance().getAzureSpringCloudClient(subscriptionId); }