Skip to content

Handle backup applications when switch from old to new blue green #1589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2025
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 @@ -25,11 +25,25 @@ public static boolean isSuffixContainedIn(String name) {
.anyMatch(name::endsWith);
}

public static boolean isLiveIdleSuffixContainedIn(String name) {
return Stream.of(LIVE, IDLE)
.map(BlueGreenApplicationNameSuffix::asSuffix)
.anyMatch(name::endsWith);
}

public static String removeSuffix(String name) {
if (isSuffixContainedIn(name)) {
return name.substring(0, name.lastIndexOf('-'));
}
return name;
}

public static String removeDoubleSuffixes(String name) {
String newName = name;
while (isSuffixContainedIn(newName)) {
newName = newName.substring(0, newName.lastIndexOf('-'));
}
return newName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.util.Set;
import java.util.stream.Collectors;

import jakarta.inject.Named;

import org.apache.commons.collections4.CollectionUtils;
import org.cloudfoundry.multiapps.controller.core.model.BlueGreenApplicationNameSuffix;
import org.cloudfoundry.multiapps.controller.core.model.DeployedMta;
Expand All @@ -23,6 +21,8 @@
import com.sap.cloudfoundry.client.facade.CloudControllerClient;
import com.sap.cloudfoundry.client.facade.domain.CloudApplication;

import jakarta.inject.Named;

@Named("detectApplicationsToRenameStep")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class DetectApplicationsToRenameStep extends SyncFlowableStep {
Expand Down Expand Up @@ -54,7 +54,7 @@ protected StepPhase executeStep(ProcessContext context) {
private List<String> computeOldAppsToRename(DeployedMta deployedMta, List<String> selectedModules) {
return deployedMta.getApplications()
.stream()
.filter(app -> !BlueGreenApplicationNameSuffix.isSuffixContainedIn(app.getName()))
.filter(app -> !BlueGreenApplicationNameSuffix.isLiveIdleSuffixContainedIn(app.getName()))
.filter(app -> isModuleSelectedForDeployment(app.getModuleName(), selectedModules))
.map(DeployedMtaApplication::getName)
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected StepPhase executeStep(ProcessContext context) throws Exception {
String mtaUserNamespaceWithSystemNamespace = NameUtil.computeUserNamespaceWithSystemNamespace(Constants.MTA_BACKUP_NAMESPACE,
mtaNamespace);

String newApplicationName = BlueGreenApplicationNameSuffix.removeSuffix(cloudApplication.getName());
String newApplicationName = BlueGreenApplicationNameSuffix.removeDoubleSuffixes(cloudApplication.getName());
newApplicationName = NameUtil.computeValidApplicationName(newApplicationName, Constants.MTA_BACKUP_NAMESPACE, true, false);

getStepLogger().info(Messages.RENAMING_APPLICATION_0_TO_1_TO_BE_USED_FOR_ROLLBACK, cloudApplication.getName(), newApplicationName);
Expand Down