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 @@ -109,6 +109,7 @@ public final class Messages {
public static final String INVALID_SUPPORT_COMPONENTS = "Invalid SUPPORT_COMPONENTS \"{0}\"";
public static final String INCOMPATIBLE_PARAMETERS = "Module \"{0}\" has parameters {1} that will be replaced by \"{2}\" due to inconsistency";
public static final String MODULE_0_DEPENDS_ON_MODULE_1_WHICH_CANNOT_BE_RESOLVED = "Module \"{0}\" depends on module \"{1}\", which is not an application and its state cannot be calculated. This dependency will be ignored during deployment.";
public static final String MODULE_0_WILL_BE_SKIPPED_DURING_DEPLOYMENT = "Module \"{0}\" will be skipped during deployment";

// Info messages
public static final String PLATFORMS_NOT_SPECIFIED = "No platforms are specified in the environment.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public ModulesCloudModelBuilderContentCalculator(Set<String> mtaModulesInArchive
public List<Module> calculateContentForBuilding(List<? extends Module> modulesForDeployment) {
initializeModulesDependencyTypes(modulesForDeployment);
List<Module> calculatedModules = modulesForDeployment.stream()
.filter(module -> shouldDeployModule(module, mtaModulesInArchive,
deployedModules))
.filter(
module -> shouldDeployModule(module, mtaModulesInArchive, deployedModules))
.filter(this::isModuleSpecifiedForDeployment)
.collect(Collectors.toList());
validateCalculatedModules(calculatedModules);
Expand Down Expand Up @@ -71,21 +71,25 @@ private boolean isModuleSpecifiedForDeployment(Module module) {
}

private boolean shouldDeployModule(Module module, Set<String> mtaModulesInArchive, Set<String> deployedModules) {
if (moduleToDeployHelper.shouldSkipDeploy(module)) {
printModuleWarningMessage(Messages.MODULE_0_WILL_BE_SKIPPED_DURING_DEPLOYMENT, module.getName());
return false;
}
if (moduleToDeployHelper.shouldDeployAlways(module) || isDockerModule(module)) {
return true;
}
if (!mtaModulesInArchive.contains(module.getName()) || module.getType() == null) {
if (deployedModules.contains(module.getName())) {
printMTAModuleNotFoundWarning(module.getName());
printModuleWarningMessage(Messages.NOT_DESCRIBED_MODULE, module.getName());
}
return false;
}
return true;
}

private void printMTAModuleNotFoundWarning(String name) {
private void printModuleWarningMessage(String warningMessage, String moduleName) {
if (userMessageLogger != null) {
userMessageLogger.warn(Messages.NOT_DESCRIBED_MODULE, name);
userMessageLogger.warn(warningMessage, moduleName);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.cloudfoundry.multiapps.controller.core.helpers;

import jakarta.inject.Named;

import org.cloudfoundry.multiapps.controller.core.model.SupportedParameters;
import org.cloudfoundry.multiapps.mta.model.Module;

@Named
Expand All @@ -15,4 +15,13 @@ public boolean shouldDeployAlways(Module module) {
return false;
}

public boolean shouldSkipDeploy(Module module) {
Object skipDeployObj = module.getParameters()
.get(SupportedParameters.SKIP_DEPLOY);
if (skipDeployObj != null) {
return Boolean.parseBoolean(skipDeployObj.toString());
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public class SupportedParameters {
public static final String STOP_APP = "stop-app";
public static final String NO_START = "no-start";
public static final String CHECK_DEPLOY_ID = "check-deploy-id";
public static final String SKIP_DEPLOY = "skip-deploy";

public static final String REGISTER_SERVICE_URL = "register-service-url";
public static final String REGISTER_SERVICE_URL_SERVICE_NAME = "service-name";
Expand Down Expand Up @@ -197,8 +198,8 @@ public class SupportedParameters {
SUCCESS_MARKER, FAILURE_MARKER, STOP_APP, CHECK_DEPLOY_ID,
REGISTER_SERVICE_URL, REGISTER_SERVICE_URL_SERVICE_NAME,
REGISTER_SERVICE_URL_SERVICE_URL, MODULE_CONFIG, MANAGED, PATH,
APPS_UPLOAD_TIMEOUT, APPS_TASK_EXECUTION_TIMEOUT,
APPS_START_TIMEOUT, APPS_STAGE_TIMEOUT, DELETE_SERVICE_KEY_AFTER_DEPLOYMENT);
APPS_UPLOAD_TIMEOUT, APPS_TASK_EXECUTION_TIMEOUT, APPS_START_TIMEOUT,
APPS_STAGE_TIMEOUT, DELETE_SERVICE_KEY_AFTER_DEPLOYMENT, SKIP_DEPLOY);

public static final Set<String> RESOURCE_PARAMETERS = Set.of(APPLY_NAMESPACE, SERVICE_CONFIG, SYSLOG_DRAIN_URL, DEFAULT_CONTAINER_NAME,
DEFAULT_SERVICE_NAME, DEFAULT_XS_APP_NAME, SERVICE, SERVICE_KEYS,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.cloudfoundry.multiapps.controller.core.cf.v2;

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

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
Expand All @@ -12,6 +10,7 @@
import java.util.TreeMap;
import java.util.stream.Stream;

import com.sap.cloudfoundry.client.facade.CloudControllerClient;
import org.apache.commons.io.IOUtils;
import org.cloudfoundry.multiapps.common.test.Tester;
import org.cloudfoundry.multiapps.common.test.Tester.Expectation;
Expand Down Expand Up @@ -46,7 +45,7 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mockito;

import com.sap.cloudfoundry.client.facade.CloudControllerClient;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class CloudModelBuilderTest {

Expand Down Expand Up @@ -75,7 +74,7 @@ public class CloudModelBuilderTest {

private static Stream<Arguments> getParameters() {
return Stream.of(
// @formatter:off
// @formatter:off
// (01) Full MTA:
Arguments.of("/mta/javahelloworld/mtad.yaml", "/mta/javahelloworld/config.mtaext",
"/mta/cf-platform.json", null, null, false,
Expand Down Expand Up @@ -426,8 +425,49 @@ private static Stream<Arguments> getParameters() {
new String[] {}, // deployedApps
new Expectation("[]"), // services
new Expectation(Expectation.Type.JSON, "keep-existing-routes/apps-with-nohostname.json") // applications
, DEFAULT_APP_SUFFIX_DETERMINER)
// @formatter:on
, DEFAULT_APP_SUFFIX_DETERMINER),
// (45) Test skip-deploy 1 of 2 modules
Arguments.of("/mta/skip-deploy/mtad-skip-deploy-true.yaml", "config-01.mtaext", "/mta/cf-platform.json",
null, // deployedMtaLocation
null, // namespace
false, // applyNamespace
new String[] { "skip-deploy-app", "foo" }, // mtaArchiveModules
new String[] { "foo" }, // mtaModules
new String[] {}, // deployedApps
new Expectation("[]"), // expectedServices
new Expectation(Expectation.Type.JSON, "/mta/skip-deploy/apps-skip-deploy-true.json"), // expectedApps (should contain only foo)
DEFAULT_APP_SUFFIX_DETERMINER),
// (46) Test skip-deploy module parameter with string "true"
Arguments.of(
"/mta/skip-deploy/mtad-skip-deploy-string-true.yaml",
"config-01.mtaext",
"/mta/cf-platform.json",
null,
null,
false,
new String[] { "skip-deploy-app", "foo" },
new String[] { "foo" },
new String[] {},
new Expectation("[]"),
new Expectation(Expectation.Type.JSON, "/mta/skip-deploy/apps-skip-deploy-true.json"),
DEFAULT_APP_SUFFIX_DETERMINER
),
// (47) Test skip-deploy module parameter with false
Arguments.of(
"/mta/skip-deploy/mtad-skip-deploy-false.yaml",
"config-01.mtaext",
"/mta/cf-platform.json",
null,
null,
false,
new String[] { "skip-deploy-app", "foo" },
new String[] { "skip-deploy-app", "foo" },
new String[] {},
new Expectation("[]"),
new Expectation(Expectation.Type.JSON, "/mta/skip-deploy/apps-skip-deploy-false.json"),
DEFAULT_APP_SUFFIX_DETERMINER
)
// @formatter:on
);
}

Expand All @@ -451,12 +491,11 @@ protected ServicesCloudModelBuilder getServicesCloudModelBuilder(DeploymentDescr
return new ServicesCloudModelBuilder(deploymentDescriptor, namespace);
}

protected ApplicationCloudModelBuilder
getApplicationCloudModelBuilder(DeploymentDescriptor deploymentDescriptor, boolean prettyPrinting, DeployedMta deployedMta,
AppSuffixDeterminer appSuffixDeterminer, boolean incrementalInstancesUpdate) {
deploymentDescriptor = new DescriptorReferenceResolver(deploymentDescriptor,
new ResolverBuilder(),
new ResolverBuilder(),
protected ApplicationCloudModelBuilder getApplicationCloudModelBuilder(DeploymentDescriptor deploymentDescriptor,
boolean prettyPrinting, DeployedMta deployedMta,
AppSuffixDeterminer appSuffixDeterminer,
boolean incrementalInstancesUpdate) {
deploymentDescriptor = new DescriptorReferenceResolver(deploymentDescriptor, new ResolverBuilder(), new ResolverBuilder(),
Collections.emptySet()).resolve();
var client = Mockito.mock(CloudControllerClient.class);
Mockito.when(client.getApplicationRoutes(Mockito.any()))
Expand Down Expand Up @@ -560,24 +599,21 @@ protected void injectSystemParameters(DeploymentDescriptor descriptor, String de
void testGetApplications(String deploymentDescriptorLocation, String extensionDescriptorLocation, String platformsLocation,
String deployedMtaLocation, String namespace, boolean applyNamespace, String[] mtaArchiveModules,
String[] mtaModules, String[] deployedApps, Expectation expectedServices, Expectation expectedApps,
AppSuffixDeterminer appSuffixDeterminer)
throws Exception {
AppSuffixDeterminer appSuffixDeterminer) throws Exception {
initializeParameters(deploymentDescriptorLocation, extensionDescriptorLocation, platformsLocation, deployedMtaLocation, namespace,
applyNamespace, mtaArchiveModules, mtaModules, deployedApps, appSuffixDeterminer, false);
tester.test(() -> modulesCalculator.calculateContentForBuilding(deploymentDescriptor.getModules())
.stream()
.map(module -> appBuilder.build(module, moduleToDeployHelper))
.toList(),
expectedApps);
.toList(), expectedApps);
}

@ParameterizedTest
@MethodSource("getParameters")
void testGetServices(String deploymentDescriptorLocation, String extensionDescriptorLocation, String platformsLocation,
String deployedMtaLocation, String namespace, boolean applyNamespace, String[] mtaArchiveModules,
String[] mtaModules, String[] deployedApps, Expectation expectedServices, Expectation expectedApps,
AppSuffixDeterminer appSuffixDeterminer)
throws Exception {
AppSuffixDeterminer appSuffixDeterminer) throws Exception {
initializeParameters(deploymentDescriptorLocation, extensionDescriptorLocation, platformsLocation, deployedMtaLocation, namespace,
applyNamespace, mtaArchiveModules, mtaModules, deployedApps, appSuffixDeterminer, false);
tester.test(() -> servicesBuilder.build(resourcesCalculator.calculateContentForBuilding(deploymentDescriptor.getResources())),
Expand All @@ -604,8 +640,7 @@ void testGetApplicationsWithIncrementalBlueGreen() throws Exception {
protected void initializeParameters(String deploymentDescriptorLocation, String extensionDescriptorLocation, String platformsLocation,
String deployedMtaLocation, String namespace, boolean applyNamespace, String[] mtaArchiveModules,
String[] mtaModules, String[] deployedApps, AppSuffixDeterminer appSuffixDeterminer,
boolean incrementalInstancesUpdate)
throws Exception {
boolean incrementalInstancesUpdate) throws Exception {
this.deploymentDescriptorLocation = deploymentDescriptorLocation;
this.extensionDescriptorLocation = extensionDescriptorLocation;
this.platformLocation = platformsLocation;
Expand All @@ -632,12 +667,9 @@ protected void initializeParameters(String deploymentDescriptorLocation, String

private ModulesCloudModelBuilderContentCalculator getModulesCalculator(Set<String> mtaArchiveModules, Set<String> mtaModules,
Set<String> deployedApps) {
return new ModulesCloudModelBuilderContentCalculator(mtaArchiveModules,
deployedApps,
null,
getUserMessageLogger(),
return new ModulesCloudModelBuilderContentCalculator(mtaArchiveModules, deployedApps, null, getUserMessageLogger(),
new ModuleToDeployHelper(),
List.of(new UnresolvedModulesContentValidator(mtaModules, deployedApps)));
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.cloudfoundry.multiapps.controller.core.helpers;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;

import org.cloudfoundry.multiapps.controller.core.model.SupportedParameters;
import org.cloudfoundry.multiapps.mta.model.Module;
import org.junit.jupiter.api.BeforeEach;
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 ModuleToDeployHelperTest {

private ModuleToDeployHelper helper;

@BeforeEach
void setUp() {
helper = new ModuleToDeployHelper();
}

static Stream<Arguments> skipDeployParameters() {
// @formatter:off
return Stream.of(Arguments.of(null, false),
Arguments.of(true, true),
Arguments.of(false, false),
Arguments.of("true", true),
Arguments.of("false", false),
Arguments.of("invalid", false));
// @formatter:on
}

@ParameterizedTest
@MethodSource("skipDeployParameters")
void testShouldSkipDeploy(Object skipDeployValue, boolean expected) {
Module module = Module.createV3();
if (skipDeployValue != null) {
Map<String, Object> params = new HashMap<>();
params.put(SupportedParameters.SKIP_DEPLOY, skipDeployValue);
module.setParameters(params);
}
assertEquals(expected, helper.shouldSkipDeploy(module));
}
}
Loading