Skip to content

Commit 9e41603

Browse files
authored
remove idle suffix from bg deploy (#1697)
move the idle application renaming before the restage (in CreateOrUpdateAppStep) - ensuring the new name is applied before the restart/restage remove no longer needed RemoveNewApplicationsSuffixStep
1 parent 0788f77 commit 9e41603

File tree

12 files changed

+182
-246
lines changed

12 files changed

+182
-246
lines changed

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/Messages.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public final class Messages {
178178
public static final String THREAD_MONITOR_CACHE_TIMEOUT = "Flowable thread monitor cache timeout: {0} seconds";
179179
public static final String SPACE_DEVELOPERS_CACHE_TIME_IN_SECONDS = "Cache for list of space developers per SpaceGUID: {0} seconds";
180180
public static final String APP_SHUTDOWN_REQUEST = "Application with id:\"{0}\", instance id:\"{1}\", instance index:\"{2}\", is requested to shutdown. Timeout to wait before shutdown of Flowable job executor:\"{3}\" seconds.";
181-
public static final String APP_SHUTDOWNED = "Application with id:\"{0}\", instance id:\"{1}\", instance index:\"{2}\", is shutdowned. Timeout to wait before shutdown of Flowable job executor:\"{3}\" seconds.";
181+
public static final String APP_SUCCESSFULLY_SHUTDOWN = "Application with id:\"{0}\", instance id:\"{1}\", instance index:\"{2}\", is shutdown. Timeout to wait before shutdown of Flowable job executor:\"{3}\" seconds.";
182182
public static final String APP_SHUTDOWN_STATUS_MONITOR = "Monitor shutdown status of application with id:\"{0}\", instance id:\"{1}\", instance index:\"{2}\". Status:\"{3}\".";
183183
public static final String CONTROLLER_CLIENT_SSL_HANDSHAKE_TIMEOUT_IN_SECONDS = "Controller client SSL handshake timeout in seconds: {0}";
184184
public static final String CONTROLLER_CLIENT_CONNECT_TIMEOUT_IN_SECONDS = "Controller client connect timeout in seconds: {0}";

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/cf/detect/AppSuffixDeterminer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public AppSuffixDeterminer(boolean keepOriginalNamesAfterDeploy, boolean isAfter
1010
this.isAfterResumePhase = isAfterResumePhase;
1111
}
1212

13-
public boolean shouldAppendApplicationSuffix() {
13+
public boolean shouldAppendIdleSuffix() {
1414
return keepOriginalNamesAfterDeploy && isAfterResumePhase;
1515
}
1616
}

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/cf/v2/ApplicationCloudModelBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private DeployedMtaApplication findDeployedApplication(String moduleName, Deploy
152152

153153
private String getApplicationName(Module module) {
154154
String applicationName = NameUtil.getApplicationName(module);
155-
if (appSuffixDeterminer.shouldAppendApplicationSuffix()) {
155+
if (appSuffixDeterminer.shouldAppendIdleSuffix()) {
156156
applicationName += BlueGreenApplicationNameSuffix.IDLE.asSuffix();
157157
}
158158
return applicationName;
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package org.cloudfoundry.multiapps.controller.core.cf.detect;
22

3-
import static org.junit.jupiter.api.Assertions.assertEquals;
4-
53
import java.util.stream.Stream;
64

75
import org.junit.jupiter.params.ParameterizedTest;
86
import org.junit.jupiter.params.provider.Arguments;
97
import org.junit.jupiter.params.provider.MethodSource;
108

9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
1111
class AppSuffixDeterminerTest {
1212

1313
static Stream<Arguments> testAppSuffixDeterminer() {
1414
return Stream.of(
15-
//@formatter:off
1615
// (1) Keep original app names is not set and the process is not after resume phase
1716
Arguments.of(false, false, false),
1817
// (2) Keep original app names is set but the process is not after resume phase
@@ -21,14 +20,13 @@ static Stream<Arguments> testAppSuffixDeterminer() {
2120
Arguments.of(false, true, false),
2221
// (4) Keep original app names is set and the process is after resume phase
2322
Arguments.of(true, true, true)
24-
//@formatter:on
2523
);
2624
}
2725

2826
@ParameterizedTest
2927
@MethodSource
3028
void testAppSuffixDeterminer(boolean keepOriginalNamesAfterDeploy, boolean isAfterResumePhase, boolean shouldAppendApplicationSuffix) {
3129
AppSuffixDeterminer appSuffixDeterminer = new AppSuffixDeterminer(keepOriginalNamesAfterDeploy, isAfterResumePhase);
32-
assertEquals(shouldAppendApplicationSuffix, appSuffixDeterminer.shouldAppendApplicationSuffix());
30+
assertEquals(shouldAppendApplicationSuffix, appSuffixDeterminer.shouldAppendIdleSuffix());
3331
}
3432
}

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/Messages.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ public class Messages {
161161
public static final String ERROR_MONITORING_OPERATIONS_OVER_SERVICES = "Error monitoring operations over services";
162162
public static final String ERROR_DELETING_REMAINING_FILE_PARTS = "Error deleting remaining file parts";
163163
public static final String ERROR_DETECTING_APPLICATIONS_TO_RENAME = "Error detecting applications to rename";
164-
public static final String ERROR_RENAMING_NEW_APPLICATIONS = "Error renaming new applications";
165164
public static final String ERROR_MONITORING_CREATION_OR_UPDATE_OF_SERVICES = "Error monitoring creation or update of services";
166165
public static final String ERROR_MONITORING_DELETION_OF_SERVICES = "Error monitoring deletion of services";
167166
public static final String SERVICE_IS_ALREADY_DELETED = "Service \"{0}\" is already deleted";

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/CreateOrUpdateAppStep.java

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.cloudfoundry.multiapps.controller.client.facade.CloudControllerClient;
1919
import org.cloudfoundry.multiapps.controller.client.facade.CloudCredentials;
2020
import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudApplication;
21+
import org.cloudfoundry.multiapps.controller.client.facade.domain.ImmutableCloudApplication;
2122
import org.cloudfoundry.multiapps.controller.client.facade.domain.ImmutableStaging;
2223
import org.cloudfoundry.multiapps.controller.client.facade.domain.Staging;
2324
import org.cloudfoundry.multiapps.controller.client.facade.dto.ApplicationToCreateDto;
@@ -28,8 +29,11 @@
2829
import org.cloudfoundry.multiapps.controller.core.cf.clients.AppBoundServiceInstanceNamesGetter;
2930
import org.cloudfoundry.multiapps.controller.core.cf.clients.WebClientFactory;
3031
import org.cloudfoundry.multiapps.controller.core.helpers.ApplicationFileDigestDetector;
32+
import org.cloudfoundry.multiapps.controller.core.model.BlueGreenApplicationNameSuffix;
3133
import org.cloudfoundry.multiapps.controller.core.security.token.TokenService;
3234
import org.cloudfoundry.multiapps.controller.core.util.ApplicationConfiguration;
35+
import org.cloudfoundry.multiapps.controller.persistence.model.ConfigurationSubscription;
36+
import org.cloudfoundry.multiapps.controller.persistence.services.ConfigurationSubscriptionService;
3337
import org.cloudfoundry.multiapps.controller.persistence.services.FileStorageException;
3438
import org.cloudfoundry.multiapps.controller.process.Messages;
3539
import org.cloudfoundry.multiapps.controller.process.util.ApplicationAttributeUpdater;
@@ -59,6 +63,8 @@ public class CreateOrUpdateAppStep extends SyncFlowableStep {
5963
private WebClientFactory webClientFactory;
6064
@Inject
6165
private ApplicationConfiguration configuration;
66+
@Inject
67+
private ConfigurationSubscriptionService subscriptionService;
6268

6369
@Override
6470
protected StepPhase executeStep(ProcessContext context) throws FileStorageException {
@@ -94,7 +100,9 @@ protected AppBoundServiceInstanceNamesGetter getAppBoundServiceInstanceNamesGett
94100
return new AppBoundServiceInstanceNamesGetter(configuration, webClientFactory, credentials, correlationId);
95101
}
96102

97-
private StepFlowHandler createStepFlowHandler(ProcessContext context, CloudControllerClient client, CloudApplicationExtended app,
103+
private StepFlowHandler createStepFlowHandler(ProcessContext context,
104+
CloudControllerClient client,
105+
CloudApplicationExtended app,
98106
CloudApplication existingApp) {
99107
if (existingApp == null) {
100108
return new CreateAppFlowHandler(context, client, app);
@@ -212,7 +220,9 @@ private class UpdateAppFlowHandler extends StepFlowHandler {
212220

213221
final CloudApplication existingApp;
214222

215-
public UpdateAppFlowHandler(ProcessContext context, CloudControllerClient client, CloudApplicationExtended app,
223+
public UpdateAppFlowHandler(ProcessContext context,
224+
CloudControllerClient client,
225+
CloudApplicationExtended app,
216226
CloudApplication existingApp) {
217227
super(context, client, app);
218228
this.existingApp = existingApp;
@@ -230,7 +240,9 @@ public void handleApplicationAttributes() {
230240

231241
reportApplicationUpdateStatus(app, arePropertiesChanged);
232242
context.setVariable(Variables.VCAP_APP_PROPERTIES_CHANGED, arePropertiesChanged);
243+
233244
updateApplicationEnvironment();
245+
updateApplicationName();
234246
}
235247

236248
private void updateApplicationEnvironment() {
@@ -278,6 +290,31 @@ private UpdateStrategy getEnvUpdateStrategy() {
278290
.shouldKeepExistingEnv() ? UpdateStrategy.MERGE : UpdateStrategy.REPLACE;
279291
}
280292

293+
public void updateApplicationName() {
294+
boolean processIsBlueGreenWithIdleSuffix = StepsUtil.getAppSuffixDeterminer(context)
295+
.shouldAppendIdleSuffix();
296+
if (!processIsBlueGreenWithIdleSuffix) {
297+
return;
298+
}
299+
300+
String oldName = existingApp.getName();
301+
String newName = BlueGreenApplicationNameSuffix.removeSuffix(oldName);
302+
if (oldName.equals(newName)) {
303+
getStepLogger().info(Messages.THE_DETECTED_APPLICATION_HAS_THE_SAME_NAME_AS_THE_NEW_ONE);
304+
return;
305+
}
306+
307+
getStepLogger().info(Messages.RENAMING_APPLICATION_0_TO_1, oldName, newName);
308+
client.rename(oldName, newName);
309+
310+
context.setVariable(Variables.EXISTING_APP, ImmutableCloudApplication.copyOf(existingApp)
311+
.withName(newName));
312+
context.setVariable(Variables.APP_TO_PROCESS, ImmutableCloudApplicationExtended.copyOf(app)
313+
.withName(newName));
314+
315+
updateConfigurationSubscribers(oldName, newName);
316+
}
317+
281318
@Override
282319
public void handleApplicationServices() {
283320
if (context.getVariable(Variables.SHOULD_SKIP_SERVICE_REBINDING)) {
@@ -297,6 +334,40 @@ public void printStepEndMessage() {
297334
getStepLogger().debug(Messages.APP_UPDATED, app.getName());
298335
}
299336

337+
private void updateConfigurationSubscribers(String oldAppName, String newAppName) {
338+
String mtaId = context.getVariable(Variables.MTA_ID);
339+
String spaceGuid = context.getVariable(Variables.SPACE_GUID);
340+
341+
List<ConfigurationSubscription> subscriptions = subscriptionService.createQuery()
342+
.mtaId(mtaId)
343+
.spaceId(spaceGuid)
344+
.list();
345+
for (ConfigurationSubscription subscription : subscriptions) {
346+
if (oldAppName.equals(subscription.getAppName())) {
347+
getStepLogger().debug(Messages.UPDATING_CONFIGURATION_SUBSCRIPTION_0_WITH_NAME_1, subscription.getAppName(),
348+
newAppName);
349+
updateConfigurationSubscription(subscription, newAppName);
350+
}
351+
}
352+
}
353+
354+
private void updateConfigurationSubscription(ConfigurationSubscription subscription, String newAppName) {
355+
ConfigurationSubscription newSubscription = createNewSubscription(subscription, newAppName);
356+
subscriptionService.update(subscription, newSubscription);
357+
}
358+
359+
private ConfigurationSubscription createNewSubscription(ConfigurationSubscription subscription, String newAppName) {
360+
return new ConfigurationSubscription(subscription.getId(),
361+
subscription.getMtaId(),
362+
subscription.getSpaceId(),
363+
newAppName,
364+
subscription.getFilter(),
365+
subscription.getModuleDto(),
366+
subscription.getResourceDto(),
367+
subscription.getModuleId(),
368+
subscription.getResourceId());
369+
}
370+
300371
private List<String> getMtaAndExistingServices() {
301372
var serviceNamesGetter = getAppBoundServiceInstanceNamesGetter(context);
302373
return Stream.of(app.getServices(), serviceNamesGetter.getServiceInstanceNamesBoundToApp(existingApp.getGuid()))

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/RemoveNewApplicationsSuffixStep.java

Lines changed: 0 additions & 75 deletions
This file was deleted.

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/StepsUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static ApplicationCloudModelBuilder getApplicationCloudModelBuilder(ProcessConte
216216
shouldApplyIncrementalInstancesUpdate(context));
217217
}
218218

219-
static AppSuffixDeterminer getAppSuffixDeterminer(ProcessContext context) {
219+
public static AppSuffixDeterminer getAppSuffixDeterminer(ProcessContext context) {
220220
boolean keepOriginalNamesAfterDeploy = context.getVariable(Variables.KEEP_ORIGINAL_APP_NAMES_AFTER_DEPLOY);
221221
boolean isAfterResumePhase = context.getVariable(Variables.PHASE) == Phase.AFTER_RESUME;
222222
return new AppSuffixDeterminer(keepOriginalNamesAfterDeploy, isAfterResumePhase);

0 commit comments

Comments
 (0)