-
Notifications
You must be signed in to change notification settings - Fork 64
Control Service: Add supported python version configuration #1761
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e0e2bff
Control Service: Add supported python version configuration
doks5 ee0262e
Google Java Format
13eab40
Remove unnecessary new line.
doks5 d55171a
Addressed feedback.
doks5 bf52d8f
Google Java Format
025cba0
Update.
doks5 6c0127d
Google Java Format
8c756e1
Remove unnecessary code.
doks5 07acdf9
Google Java Format
0129fb8
Latest feedback.
doks5 4d1ddd5
Google Java Format
7333d6a
Addressed more feedback.
doks5 9f13e08
Addressed more feedback.
doks5 e5ce9ca
Google Java Format
1eed034
Reverted changes.
doks5 e47b81b
Google Java Format
17a099c
Google Java Format
18ff736
Merge branch 'main' into person/andonova/impl-pyver-spec
doks5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...ntrol_service/src/main/java/com/vmware/taurus/service/deploy/SupportedPythonVersions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /* | ||
| * Copyright 2023-2023 VMware, Inc. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package com.vmware.taurus.service.deploy; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Value; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Component; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| /** | ||
| * Handles operations related to supported python versions for data job deployments. The class | ||
| * contains utility methods which provide functionality to read the configuration related to the | ||
| * python versions supported by the Control Service. These utility methods are meant to be used in | ||
| * other components, as needed. | ||
| */ | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| @Slf4j | ||
| public class SupportedPythonVersions { | ||
|
|
||
| private static String BASE_IMAGE = "baseImage"; | ||
|
|
||
| private static String VDK_IMAGE = "vdkImage"; | ||
|
|
||
| @Value("#{${datajobs.deployment.supportedPythonVersions:{}}}") | ||
| private Map<String, Map<String, String>> supportedPythonVersions; | ||
|
|
||
| @Value("${datajobs.deployment.defaultPythonVersion}") | ||
| private String defaultPythonVersion; | ||
|
|
||
| /** | ||
| * Check if the pythonVersion passed by the user is supported by the Control Service. | ||
| * | ||
| * @param pythonVersion python version passed by the user. | ||
| * @return true if the version is supported, and false otherwise. | ||
| */ | ||
| public boolean isPythonVersionSupported(String pythonVersion) { | ||
| return !supportedPythonVersions.isEmpty() && supportedPythonVersions.containsKey(pythonVersion); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a set 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 an empty | ||
| * set. | ||
| * | ||
| * @return A set of all python versions supported by the Control Service. | ||
| */ | ||
| public Set<String> getSupportedPythonVersions() { | ||
| return Optional.ofNullable(supportedPythonVersions) | ||
doks5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .map(Map::keySet) | ||
| .orElse(Collections.emptySet()); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the name of the data job base image as stored in the docker registry. If | ||
| * supportedPythonVersions is set, and the pythonVersion passed by the user is supported according | ||
| * to the configuration, the base image corresponding to the pythonVersion is returned. Otherwise, | ||
| * the default base image is returned. | ||
| * | ||
| * @param pythonVersion a string indicating the python version passed by the user | ||
| * @return a string of the data job base image. | ||
| */ | ||
| public String getJobBaseImage(String pythonVersion) { | ||
| if (isPythonVersionSupported(pythonVersion)) { | ||
| return supportedPythonVersions.get(pythonVersion).get(BASE_IMAGE); | ||
| } else { | ||
| log.warn( | ||
| "An issue with the passed pythonVersion or supportedPythonVersions configuration has" | ||
| + " occurred. Returning default job base image"); | ||
| return getDefaultJobBaseImage(); | ||
| } | ||
| } | ||
|
|
||
| public String getDefaultJobBaseImage() { | ||
| return supportedPythonVersions.get(defaultPythonVersion).get(BASE_IMAGE); | ||
doks5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * Returns the name of the vdk image as stored in the docker registry. If supportedPythonVersions | ||
| * is set, and the pythonVersion, passed by the user, is supported according to the configuration, | ||
| * the vdk image corresponding to the pythonVersion is returned. Otherwise, the default vdk image | ||
| * is returned. | ||
| * | ||
| * @param pythonVersion a string indicating the python version passed by the user | ||
| * @return a string of the vdk image. | ||
| */ | ||
| public String getVdkImage(String pythonVersion) { | ||
| if (isPythonVersionSupported(pythonVersion)) { | ||
| return supportedPythonVersions.get(pythonVersion).get(VDK_IMAGE); | ||
| } else { | ||
| log.warn( | ||
| "An issue with the passed pythonVersion or supportedPythonVersions configuration has" | ||
| + " occurred. Returning default vdk image"); | ||
| return getDefaultVdkImage(); | ||
| } | ||
| } | ||
|
|
||
| public String getDefaultVdkImage() { | ||
| return supportedPythonVersions.get(defaultPythonVersion).get(VDK_IMAGE); | ||
doks5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * Returns the default python version supported by the Control Service. The version number is read | ||
| * from the datajobs.deployment.defaultPythonVersion application property. | ||
| * | ||
| * @return a string indicating the default python version supported by the Control Service. | ||
| */ | ||
| public String getDefaultPythonVersion() { | ||
| return defaultPythonVersion; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
...l_service/src/test/java/com/vmware/taurus/service/deploy/SupportedPythonVersionsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| /* | ||
| * Copyright 2023-2023 VMware, Inc. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package com.vmware.taurus.service.deploy; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
| import org.springframework.test.util.ReflectionTestUtils; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| public class SupportedPythonVersionsTest { | ||
| private static final String SUPPORTED_PYTHON_VERSIONS = "supportedPythonVersions"; | ||
| private static final String BASE_IMAGE = "baseImage"; | ||
| private static final String VDK_IMAGE = "vdkImage"; | ||
| private static final String DEFAULT_PYTHON_VERSION = "defaultPythonVersion"; | ||
|
|
||
| @InjectMocks private SupportedPythonVersions supportedPythonVersions; | ||
|
|
||
| @Test | ||
| public void isPythonVersionSupported_noSupportedVersions() { | ||
| ReflectionTestUtils.setField(supportedPythonVersions, SUPPORTED_PYTHON_VERSIONS, Map.of()); | ||
|
|
||
| Assertions.assertFalse(supportedPythonVersions.isPythonVersionSupported("3.7")); | ||
| } | ||
|
|
||
| @Test | ||
| public void isPythonVersionSupported_versionSupported() { | ||
| Map<String, Map<String, String>> supportedVersions = | ||
| Map.of("3.7", Map.of(BASE_IMAGE, "python:3.7-slim", VDK_IMAGE, "test_vdk_image")); | ||
|
|
||
| ReflectionTestUtils.setField( | ||
| supportedPythonVersions, SUPPORTED_PYTHON_VERSIONS, supportedVersions); | ||
|
|
||
| Assertions.assertTrue(supportedPythonVersions.isPythonVersionSupported("3.7")); | ||
| } | ||
|
|
||
| @Test | ||
| public void isPythonVersionSupported_versionNotInSupported() { | ||
| Map<String, Map<String, String>> supportedVersions = | ||
| Map.of("3.8", Map.of(BASE_IMAGE, "python:3.8-slim", VDK_IMAGE, "test_vdk_image")); | ||
|
|
||
| ReflectionTestUtils.setField( | ||
| supportedPythonVersions, SUPPORTED_PYTHON_VERSIONS, supportedVersions); | ||
|
|
||
| Assertions.assertFalse(supportedPythonVersions.isPythonVersionSupported("3.7")); | ||
| } | ||
|
|
||
| @Test | ||
| public void getSupportedPythonVersions_multipleSupportedVersions() { | ||
| var supportedVersions = generateSupportedPythonVersionsConf(); | ||
|
|
||
| var res = Set.of("3.7", "3.8", "3.9"); | ||
|
|
||
| ReflectionTestUtils.setField( | ||
| supportedPythonVersions, SUPPORTED_PYTHON_VERSIONS, supportedVersions); | ||
|
|
||
| Assertions.assertEquals(res, supportedPythonVersions.getSupportedPythonVersions()); | ||
| } | ||
|
|
||
| @Test | ||
| public void getDefaultPythonVersion() { | ||
| ReflectionTestUtils.setField(supportedPythonVersions, DEFAULT_PYTHON_VERSION, "3.7"); | ||
| var res = "3.7"; | ||
|
|
||
| Assertions.assertEquals(res, supportedPythonVersions.getDefaultPythonVersion()); | ||
| } | ||
|
|
||
| @Test | ||
| public void getJobBaseImage_defaultImage() { | ||
| var supportedVersions = generateSupportedPythonVersionsConf(); | ||
| ReflectionTestUtils.setField( | ||
| supportedPythonVersions, SUPPORTED_PYTHON_VERSIONS, supportedVersions); | ||
| ReflectionTestUtils.setField(supportedPythonVersions, DEFAULT_PYTHON_VERSION, "3.7"); | ||
| final String defaultBaseImage = "python:3.7-slim"; | ||
|
|
||
| Assertions.assertEquals(defaultBaseImage, supportedPythonVersions.getJobBaseImage("3.11")); | ||
| } | ||
|
|
||
| @Test | ||
| public void getJobBaseImage_multipleSupportedVersions() { | ||
| var supportedVersions = generateSupportedPythonVersionsConf(); | ||
|
|
||
| final String resultBaseImg = "python:3.8-slim"; | ||
| ReflectionTestUtils.setField( | ||
| supportedPythonVersions, SUPPORTED_PYTHON_VERSIONS, supportedVersions); | ||
|
|
||
| Assertions.assertEquals(resultBaseImg, supportedPythonVersions.getJobBaseImage("3.8")); | ||
| } | ||
|
|
||
| @Test | ||
| public void getVdkImage_defaultImage() { | ||
| var supportedVersions = generateSupportedPythonVersionsConf(); | ||
| ReflectionTestUtils.setField( | ||
| supportedPythonVersions, SUPPORTED_PYTHON_VERSIONS, supportedVersions); | ||
| ReflectionTestUtils.setField(supportedPythonVersions, DEFAULT_PYTHON_VERSION, "3.7"); | ||
|
|
||
| final String defaultVdkImage = "test_vdk_image_3.7"; | ||
|
|
||
| Assertions.assertEquals(defaultVdkImage, supportedPythonVersions.getVdkImage("3.11")); | ||
| } | ||
|
|
||
| @Test | ||
| public void getVdkImage_multipleSupportedVersions() { | ||
| var supportedVersions = generateSupportedPythonVersionsConf(); | ||
|
|
||
| final String resultVdkImg = "test_vdk_image_3.8"; | ||
| ReflectionTestUtils.setField( | ||
| supportedPythonVersions, SUPPORTED_PYTHON_VERSIONS, supportedVersions); | ||
|
|
||
| Assertions.assertEquals(resultVdkImg, supportedPythonVersions.getVdkImage("3.8")); | ||
| } | ||
|
|
||
| private static Map<String, Map<String, String>> generateSupportedPythonVersionsConf() { | ||
| return Map.of( | ||
| "3.7", Map.of(BASE_IMAGE, "python:3.7-slim", VDK_IMAGE, "test_vdk_image_3.7"), | ||
| "3.8", Map.of(BASE_IMAGE, "python:3.8-slim", VDK_IMAGE, "test_vdk_image_3.8"), | ||
| "3.9", Map.of(BASE_IMAGE, "python:3.9-slim", VDK_IMAGE, "test_vdk_image_3.9")); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.