-
Notifications
You must be signed in to change notification settings - Fork 42
Add support for cnb (#1629) - LMCROSSITXSADEPLOY-2993 #1630
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it better to validate fields of parsed object that includes proper values?
| @Test | ||
| void testValidateLifecycleWithDockerAndValidDockerInfo() { | ||
| parametersList.add(getDockerParams()); | ||
| assertDoesNotThrow(() -> parser.parse(parametersList)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment
| @Test | ||
| void testValidateLifecycleWithBuildpackAndNoBuildpacks() { | ||
| parametersList.add(Collections.singletonMap("lifecycle", "buildpack")); | ||
| assertDoesNotThrow(() -> parser.parse(parametersList)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment
| } catch (IllegalArgumentException e) { | ||
| throw new SLException("Unsupported lifecycle value: " + lifecycleValue); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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'."); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract the error messages
| } 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract repeated strings like "buildpack-1", "command1", "stack1" and others into constants
theghost5800
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use the method LifecycleType::from ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussed
c978648
|



Add support for CNB
Original PR: #1560