Skip to content

Commit e045d04

Browse files
committed
remove idle suffix from bg deploy
fix unit test for win
1 parent 48a10df commit e045d04

File tree

6 files changed

+152
-83
lines changed

6 files changed

+152
-83
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
@@ -179,7 +179,7 @@ public final class Messages {
179179
public static final String THREAD_MONITOR_CACHE_TIMEOUT = "Flowable thread monitor cache timeout: {0} seconds";
180180
public static final String SPACE_DEVELOPERS_CACHE_TIME_IN_SECONDS = "Cache for list of space developers per SpaceGUID: {0} seconds";
181181
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.";
182-
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.";
182+
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.";
183183
public static final String APP_SHUTDOWN_STATUS_MONITOR = "Monitor shutdown status of application with id:\"{0}\", instance id:\"{1}\", instance index:\"{2}\". Status:\"{3}\".";
184184
public static final String CONTROLLER_CLIENT_SSL_HANDSHAKE_TIMEOUT_IN_SECONDS = "Controller client SSL handshake timeout in seconds: {0}";
185185
public static final String CONTROLLER_CLIENT_CONNECT_TIMEOUT_IN_SECONDS = "Controller client connect timeout in seconds: {0}";

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

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
import org.cloudfoundry.multiapps.controller.core.cf.clients.AppBoundServiceInstanceNamesGetter;
2929
import org.cloudfoundry.multiapps.controller.core.cf.clients.WebClientFactory;
3030
import org.cloudfoundry.multiapps.controller.core.helpers.ApplicationFileDigestDetector;
31+
import org.cloudfoundry.multiapps.controller.core.model.BlueGreenApplicationNameSuffix;
3132
import org.cloudfoundry.multiapps.controller.core.security.token.TokenService;
3233
import org.cloudfoundry.multiapps.controller.core.util.ApplicationConfiguration;
34+
import org.cloudfoundry.multiapps.controller.persistence.model.ConfigurationSubscription;
35+
import org.cloudfoundry.multiapps.controller.persistence.services.ConfigurationSubscriptionService;
3336
import org.cloudfoundry.multiapps.controller.persistence.services.FileStorageException;
3437
import org.cloudfoundry.multiapps.controller.process.Messages;
3538
import org.cloudfoundry.multiapps.controller.process.util.ApplicationAttributeUpdater;
@@ -59,6 +62,8 @@ public class CreateOrUpdateAppStep extends SyncFlowableStep {
5962
private WebClientFactory webClientFactory;
6063
@Inject
6164
private ApplicationConfiguration configuration;
65+
@Inject
66+
private ConfigurationSubscriptionService subscriptionService;
6267

6368
@Override
6469
protected StepPhase executeStep(ProcessContext context) throws FileStorageException {
@@ -75,6 +80,7 @@ protected StepPhase executeStep(ProcessContext context) throws FileStorageExcept
7580
flowHandler.injectServiceKeysCredentialsInAppEnv();
7681
flowHandler.handleApplicationAttributes();
7782
flowHandler.handleApplicationServices();
83+
flowHandler.handleApplicationName();
7884
flowHandler.printStepEndMessage();
7985

8086
return StepPhase.DONE;
@@ -95,7 +101,9 @@ protected AppBoundServiceInstanceNamesGetter getAppBoundServiceInstanceNamesGett
95101
return new AppBoundServiceInstanceNamesGetter(configuration, webClientFactory, credentials, correlationId);
96102
}
97103

98-
private StepFlowHandler createStepFlowHandler(ProcessContext context, CloudControllerClient client, CloudApplicationExtended app,
104+
private StepFlowHandler createStepFlowHandler(ProcessContext context,
105+
CloudControllerClient client,
106+
CloudApplicationExtended app,
99107
CloudApplication existingApp) {
100108
if (existingApp == null) {
101109
return new CreateAppFlowHandler(context, client, app);
@@ -149,6 +157,8 @@ private Map<String, String> buildServiceKeysCredentials(CloudControllerClient cl
149157

150158
public abstract void handleApplicationAttributes();
151159

160+
public abstract void handleApplicationName();
161+
152162
public abstract void handleApplicationServices();
153163

154164
public abstract void printStepEndMessage();
@@ -189,6 +199,10 @@ public void handleApplicationServices() {
189199
context.setVariable(Variables.SERVICES_TO_UNBIND_BIND, app.getServices());
190200
}
191201

202+
@Override
203+
public void handleApplicationName() {
204+
}
205+
192206
@Override
193207
public void printStepStartMessage() {
194208
getStepLogger().info(Messages.CREATING_APP_FROM_MODULE, app.getName(), app.getModuleName());
@@ -213,7 +227,9 @@ private class UpdateAppFlowHandler extends StepFlowHandler {
213227

214228
final CloudApplication existingApp;
215229

216-
public UpdateAppFlowHandler(ProcessContext context, CloudControllerClient client, CloudApplicationExtended app,
230+
public UpdateAppFlowHandler(ProcessContext context,
231+
CloudControllerClient client,
232+
CloudApplicationExtended app,
217233
CloudApplication existingApp) {
218234
super(context, client, app);
219235
this.existingApp = existingApp;
@@ -279,6 +295,30 @@ private UpdateStrategy getEnvUpdateStrategy() {
279295
.shouldKeepExistingEnv() ? UpdateStrategy.MERGE : UpdateStrategy.REPLACE;
280296
}
281297

298+
@Override
299+
public void handleApplicationName() {
300+
if (!context.getVariable(Variables.KEEP_ORIGINAL_APP_NAMES_AFTER_DEPLOY)) {
301+
getStepLogger().warn(
302+
Variables.KEEP_ORIGINAL_APP_NAMES_AFTER_DEPLOY + " is set to false. The application name will not be updated.");
303+
return;
304+
}
305+
306+
String oldName = existingApp.getName();
307+
String newName = BlueGreenApplicationNameSuffix.removeSuffix(oldName);
308+
if (oldName.equals(newName)) {
309+
getStepLogger().info(Messages.THE_DETECTED_APPLICATION_HAS_THE_SAME_NAME_AS_THE_NEW_ONE);
310+
return;
311+
}
312+
getStepLogger().warn("Renaming application " + oldName + " to " + newName);
313+
getStepLogger().info(Messages.RENAMING_APPLICATION_0_TO_1, oldName, newName);
314+
client.rename(oldName, newName);
315+
context.setVariable(Variables.APP_TO_PROCESS, ImmutableCloudApplicationExtended.copyOf(app)
316+
.withName(newName));
317+
318+
getStepLogger().warn("Updating application name in configuration subscriptions");
319+
updateConfigurationSubscribers(oldName, newName);
320+
}
321+
282322
@Override
283323
public void handleApplicationServices() {
284324
if (context.getVariable(Variables.SHOULD_SKIP_SERVICE_REBINDING)) {
@@ -298,6 +338,40 @@ public void printStepEndMessage() {
298338
getStepLogger().debug(Messages.APP_UPDATED, app.getName());
299339
}
300340

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected StepPhase executeStep(ProcessContext context) {
2525
int desiredInstances = app.getInstances();
2626
int currentInstances = 1; // default instances when creating an app
2727
if (existingApp != null) {
28-
currentInstances = client.getApplicationProcess(client.getApplicationGuid(existingApp.getName()))
28+
currentInstances = client.getApplicationProcess(client.getApplicationGuid(app.getName()))
2929
.getInstances();
3030
}
3131

0 commit comments

Comments
 (0)