diff --git a/projects/control-service/projects/pipelines_control_service/src/main/java/com/vmware/taurus/service/deploy/JobImageDeployer.java b/projects/control-service/projects/pipelines_control_service/src/main/java/com/vmware/taurus/service/deploy/JobImageDeployer.java index 5dc400db3d..8c96765f37 100644 --- a/projects/control-service/projects/pipelines_control_service/src/main/java/com/vmware/taurus/service/deploy/JobImageDeployer.java +++ b/projects/control-service/projects/pipelines_control_service/src/main/java/com/vmware/taurus/service/deploy/JobImageDeployer.java @@ -47,7 +47,6 @@ public class JobImageDeployer { @Value("${datajobs.deployment.readOnlyRootFilesystem:}") private boolean readOnlyRootFilesystem; - private static final String VOLUME_NAME = "vdk"; private static final String VOLUME_MOUNT_PATH = "/vdk"; private static final String EPHEMERAL_VOLUME_NAME = "tmpfs"; diff --git a/projects/control-service/projects/pipelines_control_service/src/main/java/com/vmware/taurus/service/deploy/SupportedPythonVersions.java b/projects/control-service/projects/pipelines_control_service/src/main/java/com/vmware/taurus/service/deploy/SupportedPythonVersions.java index defcc65e7f..8b1727e82e 100644 --- a/projects/control-service/projects/pipelines_control_service/src/main/java/com/vmware/taurus/service/deploy/SupportedPythonVersions.java +++ b/projects/control-service/projects/pipelines_control_service/src/main/java/com/vmware/taurus/service/deploy/SupportedPythonVersions.java @@ -14,116 +14,117 @@ import org.springframework.stereotype.Component; import lombok.extern.slf4j.Slf4j; - -/** - * Handles operations related to supported python versions for data job deployments. - */ +/** Handles operations related to supported python versions for data job deployments. */ @Component @RequiredArgsConstructor @Slf4j public class SupportedPythonVersions { - @Value("#{${datajobs.deployment.supportedPythonVersions}}") - private HashMap> supportedPythonVersions; - - @Value("${datajobs.vdk.image}") - private String vdkImage; + @Value("#{${datajobs.deployment.supportedPythonVersions}}") + private HashMap> supportedPythonVersions; - @Value("${datajobs.deployment.dataJobBaseImage:python:3.9-slim}") - private String deploymentDataJobBaseImage; + @Value("${datajobs.vdk.image}") + private String vdkImage; - private static final String VDK_IMAGE = "vdkImage"; + @Value("${datajobs.deployment.dataJobBaseImage:python:3.9-slim}") + private String deploymentDataJobBaseImage; - private static final String BASE_IMAGE = "baseImage"; - - /** - * Check if the python_version passed by the user is supported by the Control Service. - * @param python_version python version passed by the user. - * @return true if the version is supported, and false otherwise. - */ - public boolean isPythonVersionSupported(String python_version) { - if (!supportedPythonVersions.isEmpty()) { - return supportedPythonVersions.containsKey(python_version); - } else { - return false; - } - } + private static final String VDK_IMAGE = "vdkImage"; - /** - * Returns a string of the python versions supported by the Control Service, in the - * format: [3.7, 3.8, ...]. If the supportedPythonVersions configuration is not set, - * the method returns the default python version set in the deploymentDataJobBaseImage - * configuration property. - * @return A string of all python versions supported by the Control Service - */ - public String getSupportedPythonVersions() { - if (!supportedPythonVersions.isEmpty()) { - return supportedPythonVersions.keySet().toString(); - } else { - try { - return "[" + getDefaultPythonVersion() + "]"; - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException(e); - } - } - } + private static final String BASE_IMAGE = "baseImage"; - /** - * Returns the name of the data job base image as stored in the docker registry. If - * supportedPythonVersions is set, and the python_version passed by the user is supported - * according to the configuration, the base image corresponding to the python_version is - * returned. Otherwise, the default base image name as set in deploymentDataJobBaseImage - * is returned. - * @param python_version a string indicating the python version passed by the user - * @return a string of the data job base image. - */ - public String getJobBaseImage(String python_version) { - if (!supportedPythonVersions.isEmpty() && isPythonVersionSupported(python_version)) { - return supportedPythonVersions.get(python_version).get(BASE_IMAGE); - } else { - return deploymentDataJobBaseImage; - } + /** + * Check if the python_version passed by the user is supported by the Control Service. + * + * @param python_version python version passed by the user. + * @return true if the version is supported, and false otherwise. + */ + public boolean isPythonVersionSupported(String python_version) { + if (!supportedPythonVersions.isEmpty()) { + return supportedPythonVersions.containsKey(python_version); + } else { + return false; } - - public String getDefaultJobBaseImage() { - return deploymentDataJobBaseImage; + } + + /** + * Returns a string of the python versions supported by the Control Service, in the format: [3.7, + * 3.8, ...]. If the supportedPythonVersions configuration is not set, the method returns the + * default python version set in the deploymentDataJobBaseImage configuration property. + * + * @return A string of all python versions supported by the Control Service + */ + public String getSupportedPythonVersions() { + if (!supportedPythonVersions.isEmpty()) { + return supportedPythonVersions.keySet().toString(); + } else { + try { + return "[" + getDefaultPythonVersion() + "]"; + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException(e); + } } - - /** - * Returns the name of the vdk image as stored in the docker registry. If - * supportedPythonVersions is set, and the python_version, passed by the user, is supported - * according to the configuration, the vdk image corresponding to the python_version is - * returned. Otherwise, the default vdk image name as set in vdkImage is returned. - * @param python_version a string indicating the python version passed by the user - * @return a string of the data job base image. - */ - public String getVdkImage(String python_version) { - if (!supportedPythonVersions.isEmpty() && isPythonVersionSupported(python_version)) { - return supportedPythonVersions.get(python_version).get(VDK_IMAGE); - } else { - return vdkImage; - } + } + + /** + * Returns the name of the data job base image as stored in the docker registry. If + * supportedPythonVersions is set, and the python_version passed by the user is supported + * according to the configuration, the base image corresponding to the python_version is returned. + * Otherwise, the default base image name as set in deploymentDataJobBaseImage is returned. + * + * @param python_version a string indicating the python version passed by the user + * @return a string of the data job base image. + */ + public String getJobBaseImage(String python_version) { + if (!supportedPythonVersions.isEmpty() && isPythonVersionSupported(python_version)) { + return supportedPythonVersions.get(python_version).get(BASE_IMAGE); + } else { + return deploymentDataJobBaseImage; } - - public String getDefaultVdkImage() { - return vdkImage; + } + + public String getDefaultJobBaseImage() { + return deploymentDataJobBaseImage; + } + + /** + * Returns the name of the vdk image as stored in the docker registry. If supportedPythonVersions + * is set, and the python_version, passed by the user, is supported according to the + * configuration, the vdk image corresponding to the python_version is returned. Otherwise, the + * default vdk image name as set in vdkImage is returned. + * + * @param python_version a string indicating the python version passed by the user + * @return a string of the data job base image. + */ + public String getVdkImage(String python_version) { + if (!supportedPythonVersions.isEmpty() && isPythonVersionSupported(python_version)) { + return supportedPythonVersions.get(python_version).get(VDK_IMAGE); + } else { + return vdkImage; } - - /** - * Returns the default python version supported by the Control Service. The version number is - * extracted from the datajobs.deployment.dataJobBaseImage application property. The property - * is set as for example, `python:3.9-slim`, and we use a regex to match `3.9` and return it - * to the caller. - * @return a string indicating the default python version supported by the Control Service. - * @throws IllegalArgumentException - */ - public String getDefaultPythonVersion() throws IllegalArgumentException { - Pattern pattern = Pattern.compile("(\\d+\\.\\d+)"); - Matcher matcher = pattern.matcher(deploymentDataJobBaseImage); - if (matcher.find()) { - return matcher.group(1); - } else { - throw new IllegalArgumentException("Could not extract python version number from datajobs.deployment.dataJobBaseImage."); - } + } + + public String getDefaultVdkImage() { + return vdkImage; + } + + /** + * Returns the default python version supported by the Control Service. The version number is + * extracted from the datajobs.deployment.dataJobBaseImage application property. The property is + * set as for example, `python:3.9-slim`, and we use a regex to match `3.9` and return it to the + * caller. + * + * @return a string indicating the default python version supported by the Control Service. + * @throws IllegalArgumentException + */ + public String getDefaultPythonVersion() throws IllegalArgumentException { + Pattern pattern = Pattern.compile("(\\d+\\.\\d+)"); + Matcher matcher = pattern.matcher(deploymentDataJobBaseImage); + if (matcher.find()) { + return matcher.group(1); + } else { + throw new IllegalArgumentException( + "Could not extract python version number from datajobs.deployment.dataJobBaseImage."); } + } } diff --git a/projects/control-service/projects/pipelines_control_service/src/test/java/com/vmware/taurus/service/deploy/SupportedPythonVersionsTest.java b/projects/control-service/projects/pipelines_control_service/src/test/java/com/vmware/taurus/service/deploy/SupportedPythonVersionsTest.java index 3e11edcd58..4d4edabaaa 100644 --- a/projects/control-service/projects/pipelines_control_service/src/test/java/com/vmware/taurus/service/deploy/SupportedPythonVersionsTest.java +++ b/projects/control-service/projects/pipelines_control_service/src/test/java/com/vmware/taurus/service/deploy/SupportedPythonVersionsTest.java @@ -17,131 +17,150 @@ @ExtendWith(MockitoExtension.class) public class SupportedPythonVersionsTest { - private static final String VDK_IMAGE = "vdkImage"; - private static final String BASE_IMAGE = "baseImage"; - - - @InjectMocks private SupportedPythonVersions supportedPythonVersions; - - @BeforeEach - public void setUp() { - ReflectionTestUtils.setField(supportedPythonVersions, "vdkImage", "test-vdk-image"); - ReflectionTestUtils.setField(supportedPythonVersions, "deploymentDataJobBaseImage", "python:3.7-slim"); - } - - @Test - public void isPythonVersionSupported_noSupportedVersions() { - ReflectionTestUtils.setField(supportedPythonVersions, "supportedPythonVersions", new HashMap<>()); - - Assertions.assertFalse(supportedPythonVersions.isPythonVersionSupported("3.7")); - } - - @Test - public void isPythonVersionSupported_versionSupported() { - var supportedVersions = new HashMap>(); - supportedVersions.put("3.7", new HashMap(){ - { - put(BASE_IMAGE, "python:3.7-slim"); - put(VDK_IMAGE, "test_vdk_image"); - } + private static final String VDK_IMAGE = "vdkImage"; + private static final String BASE_IMAGE = "baseImage"; + + @InjectMocks private SupportedPythonVersions supportedPythonVersions; + + @BeforeEach + public void setUp() { + ReflectionTestUtils.setField(supportedPythonVersions, "vdkImage", "test-vdk-image"); + ReflectionTestUtils.setField( + supportedPythonVersions, "deploymentDataJobBaseImage", "python:3.7-slim"); + } + + @Test + public void isPythonVersionSupported_noSupportedVersions() { + ReflectionTestUtils.setField( + supportedPythonVersions, "supportedPythonVersions", new HashMap<>()); + + Assertions.assertFalse(supportedPythonVersions.isPythonVersionSupported("3.7")); + } + + @Test + public void isPythonVersionSupported_versionSupported() { + var supportedVersions = new HashMap>(); + supportedVersions.put( + "3.7", + new HashMap() { + { + put(BASE_IMAGE, "python:3.7-slim"); + put(VDK_IMAGE, "test_vdk_image"); + } }); - ReflectionTestUtils.setField(supportedPythonVersions, "supportedPythonVersions", supportedVersions); - - Assertions.assertTrue(supportedPythonVersions.isPythonVersionSupported("3.7")); - } - - @Test - public void isPythonVersionSupported_versionNotInSupported() { - var supportedVersions = new HashMap>(); - supportedVersions.put("3.8", new HashMap(){ - { - put(BASE_IMAGE, "python:3.8-slim"); - put(VDK_IMAGE, "test_vdk_image"); - } + ReflectionTestUtils.setField( + supportedPythonVersions, "supportedPythonVersions", supportedVersions); + + Assertions.assertTrue(supportedPythonVersions.isPythonVersionSupported("3.7")); + } + + @Test + public void isPythonVersionSupported_versionNotInSupported() { + var supportedVersions = new HashMap>(); + supportedVersions.put( + "3.8", + new HashMap() { + { + put(BASE_IMAGE, "python:3.8-slim"); + put(VDK_IMAGE, "test_vdk_image"); + } }); - ReflectionTestUtils.setField(supportedPythonVersions, "supportedPythonVersions", supportedVersions); + ReflectionTestUtils.setField( + supportedPythonVersions, "supportedPythonVersions", supportedVersions); - Assertions.assertFalse(supportedPythonVersions.isPythonVersionSupported("3.7")); - } + Assertions.assertFalse(supportedPythonVersions.isPythonVersionSupported("3.7")); + } - @Test - public void getSupportedPythonVersions_multipleSupportedVersions() { - var supportedVersions = generateSupportedPythonVersionsConf(); + @Test + public void getSupportedPythonVersions_multipleSupportedVersions() { + var supportedVersions = generateSupportedPythonVersionsConf(); - final String resultStr = "[3.7, 3.8, 3.9]"; + final String resultStr = "[3.7, 3.8, 3.9]"; - ReflectionTestUtils.setField(supportedPythonVersions, "supportedPythonVersions", supportedVersions); + ReflectionTestUtils.setField( + supportedPythonVersions, "supportedPythonVersions", supportedVersions); - Assertions.assertEquals(resultStr, supportedPythonVersions.getSupportedPythonVersions()); - } + Assertions.assertEquals(resultStr, supportedPythonVersions.getSupportedPythonVersions()); + } - @Test - public void getSupportedPythonVersions_getDefaultVersion() { - ReflectionTestUtils.setField(supportedPythonVersions, "supportedPythonVersions", new HashMap<>()); - final String resultStr = "[3.7]"; + @Test + public void getSupportedPythonVersions_getDefaultVersion() { + ReflectionTestUtils.setField( + supportedPythonVersions, "supportedPythonVersions", new HashMap<>()); + final String resultStr = "[3.7]"; - Assertions.assertEquals(resultStr, supportedPythonVersions.getSupportedPythonVersions()); - } + Assertions.assertEquals(resultStr, supportedPythonVersions.getSupportedPythonVersions()); + } - @Test - public void getJobBaseImage_defaultImage() { - ReflectionTestUtils.setField(supportedPythonVersions, "supportedPythonVersions", new HashMap<>()); - final String defaultBaseImage = "python:3.7-slim"; + @Test + public void getJobBaseImage_defaultImage() { + ReflectionTestUtils.setField( + supportedPythonVersions, "supportedPythonVersions", new HashMap<>()); + final String defaultBaseImage = "python:3.7-slim"; - Assertions.assertEquals(defaultBaseImage, supportedPythonVersions.getJobBaseImage("3.8")); - } + Assertions.assertEquals(defaultBaseImage, supportedPythonVersions.getJobBaseImage("3.8")); + } - @Test - public void getJobBaseImage_multipleSupportedVersions() { - var supportedVersions = generateSupportedPythonVersionsConf(); + @Test + public void getJobBaseImage_multipleSupportedVersions() { + var supportedVersions = generateSupportedPythonVersionsConf(); - final String resultBaseImg = "python:3.8-slim"; - ReflectionTestUtils.setField(supportedPythonVersions, "supportedPythonVersions", supportedVersions); + final String resultBaseImg = "python:3.8-slim"; + ReflectionTestUtils.setField( + supportedPythonVersions, "supportedPythonVersions", supportedVersions); - Assertions.assertEquals(resultBaseImg, supportedPythonVersions.getJobBaseImage("3.8")); - } + Assertions.assertEquals(resultBaseImg, supportedPythonVersions.getJobBaseImage("3.8")); + } - @Test - public void getVdkImage_defaultImage() { - ReflectionTestUtils.setField(supportedPythonVersions, "supportedPythonVersions", new HashMap<>()); - final String defaultVdkImage = "test-vdk-image"; + @Test + public void getVdkImage_defaultImage() { + ReflectionTestUtils.setField( + supportedPythonVersions, "supportedPythonVersions", new HashMap<>()); + final String defaultVdkImage = "test-vdk-image"; - Assertions.assertEquals(defaultVdkImage, supportedPythonVersions.getVdkImage("3.8")); - } + Assertions.assertEquals(defaultVdkImage, supportedPythonVersions.getVdkImage("3.8")); + } - @Test - public void getVdkImage_multipleSupportedVersions() { - var supportedVersions = generateSupportedPythonVersionsConf(); + @Test + public void getVdkImage_multipleSupportedVersions() { + var supportedVersions = generateSupportedPythonVersionsConf(); - final String resultVdkImg = "test_vdk_image_3.8"; - ReflectionTestUtils.setField(supportedPythonVersions, "supportedPythonVersions", supportedVersions); + final String resultVdkImg = "test_vdk_image_3.8"; + ReflectionTestUtils.setField( + supportedPythonVersions, "supportedPythonVersions", supportedVersions); - Assertions.assertEquals(resultVdkImg, supportedPythonVersions.getVdkImage("3.8")); - } + Assertions.assertEquals(resultVdkImg, supportedPythonVersions.getVdkImage("3.8")); + } - private static HashMap> generateSupportedPythonVersionsConf() { - var supportedVersions = new HashMap>(); - supportedVersions.put("3.7", new HashMap(){ - { - put(BASE_IMAGE, "python:3.7-slim"); - put(VDK_IMAGE, "test_vdk_image_3.7"); - } + private static HashMap> generateSupportedPythonVersionsConf() { + var supportedVersions = new HashMap>(); + supportedVersions.put( + "3.7", + new HashMap() { + { + put(BASE_IMAGE, "python:3.7-slim"); + put(VDK_IMAGE, "test_vdk_image_3.7"); + } }); - supportedVersions.put("3.8", new HashMap(){ - { - put(BASE_IMAGE, "python:3.8-slim"); - put(VDK_IMAGE, "test_vdk_image_3.8"); - } + supportedVersions.put( + "3.8", + new HashMap() { + { + put(BASE_IMAGE, "python:3.8-slim"); + put(VDK_IMAGE, "test_vdk_image_3.8"); + } }); - supportedVersions.put("3.9", new HashMap(){ - { - put(BASE_IMAGE, "python:3.9-slim"); - put(VDK_IMAGE, "test_vdk_image_3.9"); - } + supportedVersions.put( + "3.9", + new HashMap() { + { + put(BASE_IMAGE, "python:3.9-slim"); + put(VDK_IMAGE, "test_vdk_image_3.9"); + } }); - return supportedVersions; - } + return supportedVersions; + } }