Add support for cnb (#1629) - LMCROSSITXSADEPLOY-2993#1630
Conversation
* add CNB type * add validation for cnb * add validation and tests * update lifecycle to be nullable * refactoring * add tests * update validation
e86c145 to
629713f
Compare
| try { | ||
| return LifecycleType.valueOf(lifecycleValue.toUpperCase()); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new SLException("Unsupported lifecycle value: " + lifecycleValue); |
There was a problem hiding this comment.
Extract message into constant and avoid string concatenation, just pass lifecycleValue as second argument to SLException constructor. Actually this type of issue is related with user content, it's not error from our side, so this can be org.cloudfoundry.multiapps.common.ContentException instead SLException.
| } | ||
|
|
||
| private void validateLifecycleType(LifecycleType lifecycleType, List<String> buildpacks, DockerInfo dockerInfo) { | ||
| if (lifecycleType == LifecycleType.CNB && (buildpacks == null || buildpacks.isEmpty())) { |
There was a problem hiding this comment.
Just use CollectionUtils to check for empty/null list.
| throw new SLException("Buildpacks must be provided when lifecycle is set to 'cnb'."); | ||
| } | ||
| // Validate Docker-specific conditions | ||
| if (lifecycleType == LifecycleType.DOCKER) { | ||
| if (dockerInfo == null) { | ||
| throw new SLException("Docker information must be provided when lifecycle is set to 'docker'."); | ||
| } | ||
| if (buildpacks != null && !buildpacks.isEmpty()) { | ||
| throw new SLException("Buildpacks must not be provided when lifecycle is set to 'docker'."); | ||
| } | ||
| } else if (dockerInfo != null && lifecycleType != null) { | ||
| throw new SLException("Docker information must not be provided when lifecycle is set to " + lifecycleType + "'."); | ||
| } |
There was a problem hiding this comment.
- Extract string messages into Messages class.
- Replace throwing SLException with ContentException, this should avoid automatic retry from multiapps cli plugin when error is related with content of mta descriptor.
- Try to avoid nested if blocks by extracting logic into new methods.
| void testValidateLifecycleWithCnbAndValidBuildpacks() { | ||
| parametersList.add(Collections.singletonMap("lifecycle", "cnb")); | ||
| parametersList.add(Collections.singletonMap("buildpacks", List.of("custom-buildpack-url"))); | ||
| assertDoesNotThrow(() -> parser.parse(parametersList)); |
There was a problem hiding this comment.
Isn't it better to validate fields of parsed object that includes proper values?
| @Test | ||
| void testValidateLifecycleWithDockerAndValidDockerInfo() { | ||
| parametersList.add(getDockerParams()); | ||
| assertDoesNotThrow(() -> parser.parse(parametersList)); |
| @Test | ||
| void testValidateLifecycleWithBuildpackAndNoBuildpacks() { | ||
| parametersList.add(Collections.singletonMap("lifecycle", "buildpack")); | ||
| assertDoesNotThrow(() -> parser.parse(parametersList)); |
| } catch (IllegalArgumentException e) { | ||
| throw new SLException("Unsupported lifecycle value: " + lifecycleValue); | ||
| } |
There was a problem hiding this comment.
Extract the error message as a constant and use MessageFormat.format instead of string concatenation
| if (dockerInfo == null) { | ||
| throw new SLException("Docker information must be provided when lifecycle is set to 'docker'."); | ||
| } | ||
| if (buildpacks != null && !buildpacks.isEmpty()) { | ||
| throw new SLException("Buildpacks must not be provided when lifecycle is set to 'docker'."); | ||
| } |
| } else if (dockerInfo != null && lifecycleType != null) { | ||
| throw new SLException("Docker information must not be provided when lifecycle is set to " + lifecycleType + "'."); |
There was a problem hiding this comment.
Same here, extract message and use MessageFormat.format
| assertEquals("Buildpacks must be provided when lifecycle is set to 'cnb'.", exception.getMessage()); | ||
| } |
There was a problem hiding this comment.
Extract the expected error message
| assertEquals("Buildpacks must not be provided when lifecycle is set to 'docker'.", exception.getMessage()); | ||
| } |
There was a problem hiding this comment.
same here, extract the expected error message
| @Test | ||
| void testValidateLifecycleWithCnbAndValidBuildpacks() { | ||
| parametersList.add(Collections.singletonMap("lifecycle", "cnb")); | ||
| parametersList.add(Collections.singletonMap("buildpacks", List.of("custom-buildpack-url"))); | ||
| assertDoesNotThrow(() -> parser.parse(parametersList)); |
There was a problem hiding this comment.
extract strings like "buildpacks", "lifecycle" and "cnb" as constants to avoid duplication
| Arguments.of(ImmutableStaging.builder().addBuildpack("buildpack-1").command("command1").build(), | ||
| ImmutableStaging.builder().addBuildpack("buildpack-1").command("command2").build(), true), | ||
| ImmutableStaging.builder().addBuildpack("buildpack-1").command("command2").build(), true, LifecycleType.BUILDPACK), | ||
| Arguments.of(ImmutableStaging.builder().addBuildpack("buildpack-1").build(), | ||
| ImmutableStaging.builder().addBuildpack("buildpack-1").build(), false), | ||
| ImmutableStaging.builder().addBuildpack("buildpack-1").build(), false, LifecycleType.BUILDPACK), | ||
| Arguments.of( | ||
| ImmutableStaging.builder().addBuildpack("buildpack-1").command("command1").stackName("stack1") | ||
| .healthCheckTimeout(5).healthCheckType("process").isSshEnabled(false).build(), | ||
| ImmutableStaging.builder().addBuildpack("buildpack-2").command("command2").stackName("stack2") |
There was a problem hiding this comment.
extract repeated strings like "buildpack-1", "command1", "stack1" and others into constants
theghost5800
left a comment
There was a problem hiding this comment.
Before merge adopt released version of cf-java-client-sap and squash commits into one
| return null; | ||
| } | ||
| try { | ||
| return LifecycleType.valueOf(lifecycleValue.toUpperCase()); |
There was a problem hiding this comment.
can you use the method LifecycleType::from ?
c978648
|



Add support for CNB
Original PR: #1560