Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public final class Messages {
public static final String THREAD_MONITOR_CACHE_TIMEOUT = "Flowable thread monitor cache timeout: {0} seconds";
public static final String SPACE_DEVELOPERS_CACHE_TIME_IN_SECONDS = "Cache for list of space developers per SpaceGUID: {0} seconds";
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.";
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.";
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.";
public static final String APP_SHUTDOWN_STATUS_MONITOR = "Monitor shutdown status of application with id:\"{0}\", instance id:\"{1}\", instance index:\"{2}\". Status:\"{3}\".";
public static final String CONTROLLER_CLIENT_SSL_HANDSHAKE_TIMEOUT_IN_SECONDS = "Controller client SSL handshake timeout in seconds: {0}";
public static final String CONTROLLER_CLIENT_CONNECT_TIMEOUT_IN_SECONDS = "Controller client connect timeout in seconds: {0}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public AppSuffixDeterminer(boolean keepOriginalNamesAfterDeploy, boolean isAfter
this.isAfterResumePhase = isAfterResumePhase;
}

public boolean shouldAppendApplicationSuffix() {
public boolean shouldAppendIdleSuffix() {
return keepOriginalNamesAfterDeploy && isAfterResumePhase;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private DeployedMtaApplication findDeployedApplication(String moduleName, Deploy

private String getApplicationName(Module module) {
String applicationName = NameUtil.getApplicationName(module);
if (appSuffixDeterminer.shouldAppendApplicationSuffix()) {
if (appSuffixDeterminer.shouldAppendIdleSuffix()) {
applicationName += BlueGreenApplicationNameSuffix.IDLE.asSuffix();
}
return applicationName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package org.cloudfoundry.multiapps.controller.core.cf.detect;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.stream.Stream;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import static org.junit.jupiter.api.Assertions.assertEquals;

class AppSuffixDeterminerTest {

static Stream<Arguments> testAppSuffixDeterminer() {
return Stream.of(
//@formatter:off
// (1) Keep original app names is not set and the process is not after resume phase
Arguments.of(false, false, false),
// (2) Keep original app names is set but the process is not after resume phase
Expand All @@ -21,14 +20,13 @@ static Stream<Arguments> testAppSuffixDeterminer() {
Arguments.of(false, true, false),
// (4) Keep original app names is set and the process is after resume phase
Arguments.of(true, true, true)
//@formatter:on
);
}

@ParameterizedTest
@MethodSource
void testAppSuffixDeterminer(boolean keepOriginalNamesAfterDeploy, boolean isAfterResumePhase, boolean shouldAppendApplicationSuffix) {
AppSuffixDeterminer appSuffixDeterminer = new AppSuffixDeterminer(keepOriginalNamesAfterDeploy, isAfterResumePhase);
assertEquals(shouldAppendApplicationSuffix, appSuffixDeterminer.shouldAppendApplicationSuffix());
assertEquals(shouldAppendApplicationSuffix, appSuffixDeterminer.shouldAppendIdleSuffix());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ public class Messages {
public static final String ERROR_MONITORING_OPERATIONS_OVER_SERVICES = "Error monitoring operations over services";
public static final String ERROR_DELETING_REMAINING_FILE_PARTS = "Error deleting remaining file parts";
public static final String ERROR_DETECTING_APPLICATIONS_TO_RENAME = "Error detecting applications to rename";
public static final String ERROR_RENAMING_NEW_APPLICATIONS = "Error renaming new applications";
public static final String ERROR_MONITORING_CREATION_OR_UPDATE_OF_SERVICES = "Error monitoring creation or update of services";
public static final String ERROR_MONITORING_DELETION_OF_SERVICES = "Error monitoring deletion of services";
public static final String SERVICE_IS_ALREADY_DELETED = "Service \"{0}\" is already deleted";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.cloudfoundry.multiapps.controller.client.facade.CloudControllerClient;
import org.cloudfoundry.multiapps.controller.client.facade.CloudCredentials;
import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudApplication;
import org.cloudfoundry.multiapps.controller.client.facade.domain.ImmutableCloudApplication;
import org.cloudfoundry.multiapps.controller.client.facade.domain.ImmutableStaging;
import org.cloudfoundry.multiapps.controller.client.facade.domain.Staging;
import org.cloudfoundry.multiapps.controller.client.facade.dto.ApplicationToCreateDto;
Expand All @@ -28,8 +29,11 @@
import org.cloudfoundry.multiapps.controller.core.cf.clients.AppBoundServiceInstanceNamesGetter;
import org.cloudfoundry.multiapps.controller.core.cf.clients.WebClientFactory;
import org.cloudfoundry.multiapps.controller.core.helpers.ApplicationFileDigestDetector;
import org.cloudfoundry.multiapps.controller.core.model.BlueGreenApplicationNameSuffix;
import org.cloudfoundry.multiapps.controller.core.security.token.TokenService;
import org.cloudfoundry.multiapps.controller.core.util.ApplicationConfiguration;
import org.cloudfoundry.multiapps.controller.persistence.model.ConfigurationSubscription;
import org.cloudfoundry.multiapps.controller.persistence.services.ConfigurationSubscriptionService;
import org.cloudfoundry.multiapps.controller.persistence.services.FileStorageException;
import org.cloudfoundry.multiapps.controller.process.Messages;
import org.cloudfoundry.multiapps.controller.process.util.ApplicationAttributeUpdater;
Expand Down Expand Up @@ -59,6 +63,8 @@ public class CreateOrUpdateAppStep extends SyncFlowableStep {
private WebClientFactory webClientFactory;
@Inject
private ApplicationConfiguration configuration;
@Inject
private ConfigurationSubscriptionService subscriptionService;

@Override
protected StepPhase executeStep(ProcessContext context) throws FileStorageException {
Expand Down Expand Up @@ -94,7 +100,9 @@ protected AppBoundServiceInstanceNamesGetter getAppBoundServiceInstanceNamesGett
return new AppBoundServiceInstanceNamesGetter(configuration, webClientFactory, credentials, correlationId);
}

private StepFlowHandler createStepFlowHandler(ProcessContext context, CloudControllerClient client, CloudApplicationExtended app,
private StepFlowHandler createStepFlowHandler(ProcessContext context,
CloudControllerClient client,
CloudApplicationExtended app,
CloudApplication existingApp) {
if (existingApp == null) {
return new CreateAppFlowHandler(context, client, app);
Expand Down Expand Up @@ -212,7 +220,9 @@ private class UpdateAppFlowHandler extends StepFlowHandler {

final CloudApplication existingApp;

public UpdateAppFlowHandler(ProcessContext context, CloudControllerClient client, CloudApplicationExtended app,
public UpdateAppFlowHandler(ProcessContext context,
CloudControllerClient client,
CloudApplicationExtended app,
CloudApplication existingApp) {
super(context, client, app);
this.existingApp = existingApp;
Expand All @@ -230,7 +240,9 @@ public void handleApplicationAttributes() {

reportApplicationUpdateStatus(app, arePropertiesChanged);
context.setVariable(Variables.VCAP_APP_PROPERTIES_CHANGED, arePropertiesChanged);

updateApplicationEnvironment();
updateApplicationName();
}

private void updateApplicationEnvironment() {
Expand Down Expand Up @@ -278,6 +290,31 @@ private UpdateStrategy getEnvUpdateStrategy() {
.shouldKeepExistingEnv() ? UpdateStrategy.MERGE : UpdateStrategy.REPLACE;
}

public void updateApplicationName() {
boolean processIsBlueGreenWithIdleSuffix = StepsUtil.getAppSuffixDeterminer(context)
.shouldAppendIdleSuffix();
if (!processIsBlueGreenWithIdleSuffix) {
return;
}

String oldName = existingApp.getName();
String newName = BlueGreenApplicationNameSuffix.removeSuffix(oldName);
if (oldName.equals(newName)) {
getStepLogger().info(Messages.THE_DETECTED_APPLICATION_HAS_THE_SAME_NAME_AS_THE_NEW_ONE);
return;
}

getStepLogger().info(Messages.RENAMING_APPLICATION_0_TO_1, oldName, newName);
client.rename(oldName, newName);

context.setVariable(Variables.EXISTING_APP, ImmutableCloudApplication.copyOf(existingApp)
.withName(newName));
context.setVariable(Variables.APP_TO_PROCESS, ImmutableCloudApplicationExtended.copyOf(app)
.withName(newName));

updateConfigurationSubscribers(oldName, newName);
}

@Override
public void handleApplicationServices() {
if (context.getVariable(Variables.SHOULD_SKIP_SERVICE_REBINDING)) {
Expand All @@ -297,6 +334,40 @@ public void printStepEndMessage() {
getStepLogger().debug(Messages.APP_UPDATED, app.getName());
}

private void updateConfigurationSubscribers(String oldAppName, String newAppName) {
String mtaId = context.getVariable(Variables.MTA_ID);
String spaceGuid = context.getVariable(Variables.SPACE_GUID);

List<ConfigurationSubscription> subscriptions = subscriptionService.createQuery()
.mtaId(mtaId)
.spaceId(spaceGuid)
.list();
for (ConfigurationSubscription subscription : subscriptions) {
if (oldAppName.equals(subscription.getAppName())) {
getStepLogger().debug(Messages.UPDATING_CONFIGURATION_SUBSCRIPTION_0_WITH_NAME_1, subscription.getAppName(),
newAppName);
updateConfigurationSubscription(subscription, newAppName);
}
}
}

private void updateConfigurationSubscription(ConfigurationSubscription subscription, String newAppName) {
ConfigurationSubscription newSubscription = createNewSubscription(subscription, newAppName);
subscriptionService.update(subscription, newSubscription);
}

private ConfigurationSubscription createNewSubscription(ConfigurationSubscription subscription, String newAppName) {
return new ConfigurationSubscription(subscription.getId(),
subscription.getMtaId(),
subscription.getSpaceId(),
newAppName,
subscription.getFilter(),
subscription.getModuleDto(),
subscription.getResourceDto(),
subscription.getModuleId(),
subscription.getResourceId());
}

private List<String> getMtaAndExistingServices() {
var serviceNamesGetter = getAppBoundServiceInstanceNamesGetter(context);
return Stream.of(app.getServices(), serviceNamesGetter.getServiceInstanceNamesBoundToApp(existingApp.getGuid()))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ static ApplicationCloudModelBuilder getApplicationCloudModelBuilder(ProcessConte
shouldApplyIncrementalInstancesUpdate(context));
}

static AppSuffixDeterminer getAppSuffixDeterminer(ProcessContext context) {
public static AppSuffixDeterminer getAppSuffixDeterminer(ProcessContext context) {
boolean keepOriginalNamesAfterDeploy = context.getVariable(Variables.KEEP_ORIGINAL_APP_NAMES_AFTER_DEPLOY);
boolean isAfterResumePhase = context.getVariable(Variables.PHASE) == Phase.AFTER_RESUME;
return new AppSuffixDeterminer(keepOriginalNamesAfterDeploy, isAfterResumePhase);
Expand Down
Loading
Loading