Skip to content

Commit

Permalink
Update app properties after active deployment (#4295)
Browse files Browse the repository at this point in the history
* Update app properties after active deployment

* Better naming
  • Loading branch information
Flanker32 authored Apr 13, 2020
1 parent 71719cd commit 82e58b8
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down Expand Up @@ -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())) {
Expand All @@ -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);
}
Expand Down

0 comments on commit 82e58b8

Please sign in to comment.