Skip to content

Commit 82e58b8

Browse files
authored
Update app properties after active deployment (#4295)
* Update app properties after active deployment * Better naming
1 parent 71719cd commit 82e58b8

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/util/SpringCloudUtils.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public static AppResourceInner activeDeployment(AppResourceInner appResourceInne
4545
DeploymentResourceInner deploymentResourceInner,
4646
SpringCloudDeployConfiguration configuration) throws IOException {
4747
final AppPlatformManager appPlatformManager = getAppPlatformManager(configuration.getSubscriptionId());
48-
final AppResourceProperties appResourceProperties = appResourceInner.properties()
48+
AppResourceProperties appResourceProperties = updateAppResourceProperties(appResourceInner.properties(),
49+
configuration);
50+
appResourceProperties = appResourceProperties
4951
.withActiveDeploymentName(deploymentResourceInner.name())
5052
.withPublicProperty(configuration.isPublic());
5153
return appPlatformManager.apps().inner().update(SpringCloudIdHelper.getResourceGroup(configuration.getClusterId()),
@@ -131,8 +133,13 @@ private static AppResourceProperties updateAppResourceProperties(AppResourceProp
131133
SpringCloudDeployConfiguration configuration) {
132134
// Enable persistent disk with default parameters
133135
appResourceProperties = appResourceProperties == null ? new AppResourceProperties() : appResourceProperties;
134-
if (appResourceProperties.persistentDisk() == null && configuration.isEnablePersistentStorage()) {
136+
final PersistentDisk previousPersistentDisk = appResourceProperties.persistentDisk();
137+
final int preStorageSize = (previousPersistentDisk == null || previousPersistentDisk.sizeInGB() == null) ? 0 :
138+
previousPersistentDisk.sizeInGB();
139+
if (configuration.isEnablePersistentStorage() && preStorageSize <= 0) {
135140
appResourceProperties = appResourceProperties.withPersistentDisk(getDefaultPersistentDisk());
141+
} else if (!configuration.isEnablePersistentStorage() && preStorageSize > 0) {
142+
appResourceProperties = appResourceProperties.withPersistentDisk(getEmptyPersistentDisk());
136143
}
137144
// As we can't set public policy to an app without active deployment
138145
if (StringUtils.isNotEmpty(appResourceProperties.activeDeploymentName())) {
@@ -148,6 +155,13 @@ private static PersistentDisk getDefaultPersistentDisk() {
148155
return persistentDisk;
149156
}
150157

158+
private static PersistentDisk getEmptyPersistentDisk() {
159+
final PersistentDisk persistentDisk = new PersistentDisk();
160+
persistentDisk.withMountPath(null)
161+
.withSizeInGB(0);
162+
return persistentDisk;
163+
}
164+
151165
private static AppPlatformManager getAppPlatformManager(String subscriptionId) throws IOException {
152166
return AuthMethodManager.getInstance().getAzureSpringCloudClient(subscriptionId);
153167
}

0 commit comments

Comments
 (0)