Skip to content

Commit 5c64e09

Browse files
authored
Add warning for SAP Java buildpack 1 deprecation
LMCROSSITXSADEPLOY-3201
1 parent 01c1d56 commit 5c64e09

File tree

3 files changed

+102
-27
lines changed

3 files changed

+102
-27
lines changed

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

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package org.cloudfoundry.multiapps.controller.process.steps;
22

3-
import static java.util.stream.Collectors.toList;
4-
import static java.util.stream.Collectors.toSet;
5-
63
import java.util.ArrayList;
74
import java.util.Collections;
85
import java.util.List;
@@ -11,9 +8,10 @@
118
import java.util.TreeSet;
129
import java.util.stream.Collectors;
1310

11+
import com.sap.cloudfoundry.client.facade.CloudControllerClient;
12+
import com.sap.cloudfoundry.client.facade.domain.CloudServiceKey;
1413
import jakarta.inject.Inject;
1514
import jakarta.inject.Named;
16-
1715
import org.cloudfoundry.multiapps.common.SLException;
1816
import org.cloudfoundry.multiapps.controller.api.model.ProcessType;
1917
import org.cloudfoundry.multiapps.controller.client.lib.domain.CloudServiceInstanceExtended;
@@ -35,6 +33,7 @@
3533
import org.cloudfoundry.multiapps.controller.core.util.CloudModelBuilderUtil;
3634
import org.cloudfoundry.multiapps.controller.core.util.NameUtil;
3735
import org.cloudfoundry.multiapps.controller.process.Messages;
36+
import org.cloudfoundry.multiapps.controller.process.util.DeprecatedBuildpackChecker;
3837
import org.cloudfoundry.multiapps.controller.process.util.ProcessTypeParser;
3938
import org.cloudfoundry.multiapps.controller.process.variables.Variables;
4039
import org.cloudfoundry.multiapps.mta.builders.v2.ParametersChainBuilder;
@@ -51,8 +50,8 @@
5150
import org.springframework.beans.factory.config.BeanDefinition;
5251
import org.springframework.context.annotation.Scope;
5352

54-
import com.sap.cloudfoundry.client.facade.CloudControllerClient;
55-
import com.sap.cloudfoundry.client.facade.domain.CloudServiceKey;
53+
import static java.util.stream.Collectors.toList;
54+
import static java.util.stream.Collectors.toSet;
5655

5756
@Named("buildCloudDeployModelStep")
5857
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@@ -62,6 +61,8 @@ public class BuildCloudDeployModelStep extends SyncFlowableStep {
6261
private ModuleToDeployHelper moduleToDeployHelper;
6362
@Inject
6463
private ProcessTypeParser processTypeParser;
64+
@Inject
65+
private DeprecatedBuildpackChecker buildpackChecker;
6566

6667
@Override
6768
protected StepPhase executeStep(ProcessContext context) {
@@ -89,6 +90,10 @@ protected StepPhase executeStep(ProcessContext context) {
8990
List<Module> modulesCalculatedForDeployment = calculateModulesForDeployment(context, deploymentDescriptor, mtaDescriptorModules,
9091
mtaManifestModulesNames, deployedModuleNames,
9192
mtaModulesForDeployment);
93+
94+
buildpackChecker.warnForDeprecatedBuildpacks(modulesCalculatedForDeployment, deploymentDescriptor, getStepLogger(),
95+
moduleToDeployHelper);
96+
9297
List<String> moduleJsons = modulesCalculatedForDeployment.stream()
9398
.map(SecureSerialization::toJson)
9499
.collect(toList());
@@ -179,7 +184,7 @@ private List<String> getAppNames(List<Module> modulesCalculatedForDeployment) {
179184
.map(NameUtil::getApplicationName)
180185
.collect(toList());
181186
}
182-
187+
183188
private List<CloudServiceInstanceExtended> buildServicesForBindings(ServicesCloudModelBuilder servicesCloudModelBuilder,
184189
DeploymentDescriptor deploymentDescriptor,
185190
List<Module> modulesCalculatedForDeployment) {
@@ -191,11 +196,13 @@ private List<CloudServiceInstanceExtended> buildServicesForBindings(ServicesClou
191196
private List<CloudServiceInstanceExtended> buildFilteredServices(DeploymentDescriptor deploymentDescriptor,
192197
List<String> filteredResourceNames,
193198
ServicesCloudModelBuilder servicesCloudModelBuilder) {
194-
CloudModelBuilderContentCalculator<Resource> resourcesCloudModelBuilderContentCalculator = new ResourcesCloudModelBuilderContentCalculator(filteredResourceNames,
195-
getStepLogger(),
196-
false);
199+
CloudModelBuilderContentCalculator<Resource> resourcesCloudModelBuilderContentCalculator = new ResourcesCloudModelBuilderContentCalculator(
200+
filteredResourceNames,
201+
getStepLogger(),
202+
false);
197203
// this always filters the 'isActive', 'isResourceSpecifiedForDeployment' and 'isService' resources
198-
List<Resource> calculatedFilteredResources = resourcesCloudModelBuilderContentCalculator.calculateContentForBuilding(deploymentDescriptor.getResources());
204+
List<Resource> calculatedFilteredResources = resourcesCloudModelBuilderContentCalculator.calculateContentForBuilding(
205+
deploymentDescriptor.getResources());
199206

200207
return servicesCloudModelBuilder.build(calculatedFilteredResources);
201208
}
@@ -235,9 +242,10 @@ private List<Module> calculateModulesForDeployment(ProcessContext context, Deplo
235242

236243
private List<Resource> calculateResourcesForDeployment(ProcessContext context, DeploymentDescriptor deploymentDescriptor) {
237244
List<String> resourcesSpecifiedForDeployment = context.getVariable(Variables.RESOURCES_FOR_DEPLOYMENT);
238-
CloudModelBuilderContentCalculator<Resource> resourcesCloudModelBuilderContentCalculator = new ResourcesCloudModelBuilderContentCalculator(resourcesSpecifiedForDeployment,
239-
getStepLogger(),
240-
shouldProcessOnlyUserProvidedServices(context));
245+
CloudModelBuilderContentCalculator<Resource> resourcesCloudModelBuilderContentCalculator = new ResourcesCloudModelBuilderContentCalculator(
246+
resourcesSpecifiedForDeployment,
247+
getStepLogger(),
248+
shouldProcessOnlyUserProvidedServices(context));
241249
return resourcesCloudModelBuilderContentCalculator.calculateContentForBuilding(deploymentDescriptor.getResources());
242250
}
243251

@@ -247,8 +255,8 @@ private boolean shouldProcessOnlyUserProvidedServices(ProcessContext context) {
247255
}
248256

249257
protected ModulesCloudModelBuilderContentCalculator
250-
getModulesContentCalculator(ProcessContext context, List<Module> mtaDescriptorModules, Set<String> mtaManifestModuleNames,
251-
Set<String> deployedModuleNames, Set<String> mtaModuleNamesForDeployment) {
258+
getModulesContentCalculator(ProcessContext context, List<Module> mtaDescriptorModules, Set<String> mtaManifestModuleNames,
259+
Set<String> deployedModuleNames, Set<String> mtaModuleNamesForDeployment) {
252260
List<ModulesContentValidator> modulesValidators = getModuleContentValidators(context.getControllerClient(), mtaDescriptorModules,
253261
mtaModuleNamesForDeployment, deployedModuleNames);
254262
return new ModulesCloudModelBuilderContentCalculator(mtaManifestModuleNames,
@@ -306,7 +314,8 @@ private List<String> getDomainsFromApps(ProcessContext context, DeploymentDescri
306314
if (!moduleToDeployHelper.isApplication(module)) {
307315
continue;
308316
}
309-
ParametersChainBuilder parametersChainBuilder = new ParametersChainBuilder(context.getVariable(Variables.COMPLETE_DEPLOYMENT_DESCRIPTOR));
317+
ParametersChainBuilder parametersChainBuilder = new ParametersChainBuilder(
318+
context.getVariable(Variables.COMPLETE_DEPLOYMENT_DESCRIPTOR));
310319
List<Map<String, Object>> parametersList = parametersChainBuilder.buildModuleChain(module.getName());
311320

312321
boolean noRoute = (Boolean) PropertiesUtil.getPropertyValue(parametersList, SupportedParameters.NO_ROUTE, false);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.cloudfoundry.multiapps.controller.process.util;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
import jakarta.inject.Named;
7+
import org.cloudfoundry.multiapps.controller.core.helpers.ModuleToDeployHelper;
8+
import org.cloudfoundry.multiapps.controller.core.model.SupportedParameters;
9+
import org.cloudfoundry.multiapps.mta.builders.v2.ParametersChainBuilder;
10+
import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor;
11+
import org.cloudfoundry.multiapps.mta.model.Module;
12+
import org.cloudfoundry.multiapps.mta.util.PropertiesUtil;
13+
14+
@Named
15+
public class DeprecatedBuildpackChecker {
16+
17+
private static final String DEPRECATION_MESSAGE = "SAP Java Buildpack 1 has been deprecated and is going to be removed from SAP BTP, Cloud Foundry environment after June, 2025!";
18+
private static final String DEFAULT_BUILDPACK_MESSAGE_1 = "If no buildpack is specified, sap_java_buildpack is currently applied by default for certain module types (java.tomee, java.tomcat, java).";
19+
private static final String DEFAULT_BUILDPACK_MESSAGE_2 = "This default will change after June - we strongly recommend that you manually migrate to the supported buildpack in advance to avoid deployment issues.";
20+
private static final String DEPRECATION_LINK = "https://help.sap.com/whats-new/cf0cb2cb149647329b5d02aa96303f56?Component=SAP+Java+Buildpack&Valid_as_Of=2025-04-01:2025-04-10&locale=en-US";
21+
22+
private static final String DEPRECATED_BUILDPACK = "sap_java_buildpack";
23+
24+
public void warnForDeprecatedBuildpacks(List<Module> modulesCalculatedForDeployment,
25+
DeploymentDescriptor deploymentDescriptor, StepLogger stepLogger,
26+
ModuleToDeployHelper moduleToDeployHelper) {
27+
List<String> appsWithDeprecatedBuildpacks = modulesCalculatedForDeployment.stream()
28+
.filter(moduleToDeployHelper::isApplication)
29+
.filter(module -> hasDeprecatedBuildpack(module,
30+
deploymentDescriptor
31+
))
32+
.map(Module::getName)
33+
.toList();
34+
35+
if (!appsWithDeprecatedBuildpacks.isEmpty()) {
36+
logDeprecationNotice(stepLogger, appsWithDeprecatedBuildpacks);
37+
}
38+
}
39+
40+
private boolean hasDeprecatedBuildpack(Module module, DeploymentDescriptor deploymentDescriptor) {
41+
List<Map<String, Object>> parametersList = new ParametersChainBuilder(deploymentDescriptor)
42+
.buildModuleChain(module.getName());
43+
44+
List<String> buildpacks = PropertiesUtil.getPluralOrSingular(
45+
parametersList, SupportedParameters.BUILDPACKS, SupportedParameters.BUILDPACK);
46+
47+
return buildpacks.contains(DEPRECATED_BUILDPACK);
48+
}
49+
50+
private void logDeprecationNotice(StepLogger stepLogger, List<String> appsWithDeprecatedBuildpacks) {
51+
String separator = "=".repeat(80);
52+
53+
stepLogger.warn("== ATTENTION: ==");
54+
stepLogger.warn(separator);
55+
stepLogger.warn(DEPRECATION_MESSAGE);
56+
stepLogger.warn(DEFAULT_BUILDPACK_MESSAGE_1);
57+
stepLogger.warn(DEFAULT_BUILDPACK_MESSAGE_2);
58+
stepLogger.warn("Affected modules: " + appsWithDeprecatedBuildpacks);
59+
stepLogger.warn("For more information, see: " + DEPRECATION_LINK);
60+
stepLogger.warn(separator);
61+
}
62+
63+
}

multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/BuildCloudDeployModelStepTest.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package org.cloudfoundry.multiapps.controller.process.steps;
22

3-
import static org.junit.jupiter.api.Assertions.assertEquals;
4-
import static org.junit.jupiter.api.Assertions.assertFalse;
5-
import static org.mockito.ArgumentMatchers.any;
6-
import static org.mockito.Mockito.when;
7-
83
import java.util.Collections;
94
import java.util.List;
105
import java.util.Map;
116
import java.util.Set;
127
import java.util.stream.Stream;
138

9+
import com.fasterxml.jackson.core.type.TypeReference;
10+
import com.sap.cloudfoundry.client.facade.domain.CloudServiceKey;
1411
import org.cloudfoundry.multiapps.common.test.TestUtil;
1512
import org.cloudfoundry.multiapps.common.test.Tester.Expectation;
1613
import org.cloudfoundry.multiapps.common.util.JsonUtil;
@@ -20,6 +17,7 @@
2017
import org.cloudfoundry.multiapps.controller.core.helpers.ModuleToDeployHelper;
2118
import org.cloudfoundry.multiapps.controller.core.model.DeployedMta;
2219
import org.cloudfoundry.multiapps.controller.core.test.DescriptorTestUtil;
20+
import org.cloudfoundry.multiapps.controller.process.util.DeprecatedBuildpackChecker;
2321
import org.cloudfoundry.multiapps.controller.process.util.ProcessTypeParser;
2422
import org.cloudfoundry.multiapps.controller.process.variables.Variables;
2523
import org.cloudfoundry.multiapps.mta.model.DeploymentDescriptor;
@@ -29,8 +27,10 @@
2927
import org.junit.jupiter.params.provider.MethodSource;
3028
import org.mockito.Mock;
3129

32-
import com.fasterxml.jackson.core.type.TypeReference;
33-
import com.sap.cloudfoundry.client.facade.domain.CloudServiceKey;
30+
import static org.junit.jupiter.api.Assertions.assertEquals;
31+
import static org.junit.jupiter.api.Assertions.assertFalse;
32+
import static org.mockito.ArgumentMatchers.any;
33+
import static org.mockito.Mockito.when;
3434

3535
class BuildCloudDeployModelStepTest extends SyncFlowableStepTest<BuildCloudDeployModelStep> {
3636

@@ -54,9 +54,12 @@ class BuildCloudDeployModelStepTest extends SyncFlowableStepTest<BuildCloudDeplo
5454
@Mock
5555
private ProcessTypeParser processTypeParser;
5656

57+
@Mock
58+
private DeprecatedBuildpackChecker deprecatedBuildpackChecker;
59+
5760
public static Stream<Arguments> testExecute() {
5861
return Stream.of(
59-
// @formatter:off
62+
// @formatter:off
6063
Arguments.of(new StepInput("modules-to-deploy-01.json", "services-to-create-01.json", "service-keys-01.json", List.of("api.cf.neo.ondemand.com"), "deployed-mta-12.json")),
6164
Arguments.of(new StepInput("modules-to-deploy-01.json", "services-to-create-01.json", "service-keys-01.json", List.of("api.cf.neo.ondemand.com"), null))
6265
// @formatter:on
@@ -141,8 +144,8 @@ protected ApplicationCloudModelBuilder getApplicationCloudModelBuilder(ProcessCo
141144

142145
@Override
143146
protected ModulesCloudModelBuilderContentCalculator
144-
getModulesContentCalculator(ProcessContext context, List<Module> mtaDescriptorModules, Set<String> mtaManifestModuleNames,
145-
Set<String> deployedModuleNames, Set<String> allMtaModuleNames) {
147+
getModulesContentCalculator(ProcessContext context, List<Module> mtaDescriptorModules, Set<String> mtaManifestModuleNames,
148+
Set<String> deployedModuleNames, Set<String> allMtaModuleNames) {
146149
return modulesCloudModelBuilderContentCalculator;
147150
}
148151

0 commit comments

Comments
 (0)