|
14 | 14 | import org.springframework.stereotype.Component; |
15 | 15 | import lombok.extern.slf4j.Slf4j; |
16 | 16 |
|
17 | | - |
18 | | -/** |
19 | | - * Handles operations related to supported python versions for data job deployments. |
20 | | - */ |
| 17 | +/** Handles operations related to supported python versions for data job deployments. */ |
21 | 18 | @Component |
22 | 19 | @RequiredArgsConstructor |
23 | 20 | @Slf4j |
24 | 21 | public class SupportedPythonVersions { |
25 | 22 |
|
26 | | - @Value("#{${datajobs.deployment.supportedPythonVersions}}") |
27 | | - private HashMap<String, HashMap<String, String>> supportedPythonVersions; |
28 | | - |
29 | | - @Value("${datajobs.vdk.image}") |
30 | | - private String vdkImage; |
| 23 | + @Value("#{${datajobs.deployment.supportedPythonVersions}}") |
| 24 | + private HashMap<String, HashMap<String, String>> supportedPythonVersions; |
31 | 25 |
|
32 | | - @Value("${datajobs.deployment.dataJobBaseImage:python:3.9-slim}") |
33 | | - private String deploymentDataJobBaseImage; |
| 26 | + @Value("${datajobs.vdk.image}") |
| 27 | + private String vdkImage; |
34 | 28 |
|
35 | | - private static final String VDK_IMAGE = "vdkImage"; |
| 29 | + @Value("${datajobs.deployment.dataJobBaseImage:python:3.9-slim}") |
| 30 | + private String deploymentDataJobBaseImage; |
36 | 31 |
|
37 | | - private static final String BASE_IMAGE = "baseImage"; |
38 | | - |
39 | | - /** |
40 | | - * Check if the python_version passed by the user is supported by the Control Service. |
41 | | - * @param python_version python version passed by the user. |
42 | | - * @return true if the version is supported, and false otherwise. |
43 | | - */ |
44 | | - public boolean isPythonVersionSupported(String python_version) { |
45 | | - if (!supportedPythonVersions.isEmpty()) { |
46 | | - return supportedPythonVersions.containsKey(python_version); |
47 | | - } else { |
48 | | - return false; |
49 | | - } |
50 | | - } |
| 32 | + private static final String VDK_IMAGE = "vdkImage"; |
51 | 33 |
|
52 | | - /** |
53 | | - * Returns a string of the python versions supported by the Control Service, in the |
54 | | - * format: [3.7, 3.8, ...]. If the supportedPythonVersions configuration is not set, |
55 | | - * the method returns the default python version set in the deploymentDataJobBaseImage |
56 | | - * configuration property. |
57 | | - * @return A string of all python versions supported by the Control Service |
58 | | - */ |
59 | | - public String getSupportedPythonVersions() { |
60 | | - if (!supportedPythonVersions.isEmpty()) { |
61 | | - return supportedPythonVersions.keySet().toString(); |
62 | | - } else { |
63 | | - try { |
64 | | - return "[" + getDefaultPythonVersion() + "]"; |
65 | | - } catch (IllegalArgumentException e) { |
66 | | - throw new IllegalArgumentException(e); |
67 | | - } |
68 | | - } |
69 | | - } |
| 34 | + private static final String BASE_IMAGE = "baseImage"; |
70 | 35 |
|
71 | | - /** |
72 | | - * Returns the name of the data job base image as stored in the docker registry. If |
73 | | - * supportedPythonVersions is set, and the python_version passed by the user is supported |
74 | | - * according to the configuration, the base image corresponding to the python_version is |
75 | | - * returned. Otherwise, the default base image name as set in deploymentDataJobBaseImage |
76 | | - * is returned. |
77 | | - * @param python_version a string indicating the python version passed by the user |
78 | | - * @return a string of the data job base image. |
79 | | - */ |
80 | | - public String getJobBaseImage(String python_version) { |
81 | | - if (!supportedPythonVersions.isEmpty() && isPythonVersionSupported(python_version)) { |
82 | | - return supportedPythonVersions.get(python_version).get(BASE_IMAGE); |
83 | | - } else { |
84 | | - return deploymentDataJobBaseImage; |
85 | | - } |
| 36 | + /** |
| 37 | + * Check if the python_version passed by the user is supported by the Control Service. |
| 38 | + * |
| 39 | + * @param python_version python version passed by the user. |
| 40 | + * @return true if the version is supported, and false otherwise. |
| 41 | + */ |
| 42 | + public boolean isPythonVersionSupported(String python_version) { |
| 43 | + if (!supportedPythonVersions.isEmpty()) { |
| 44 | + return supportedPythonVersions.containsKey(python_version); |
| 45 | + } else { |
| 46 | + return false; |
86 | 47 | } |
87 | | - |
88 | | - public String getDefaultJobBaseImage() { |
89 | | - return deploymentDataJobBaseImage; |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Returns a string of the python versions supported by the Control Service, in the format: [3.7, |
| 52 | + * 3.8, ...]. If the supportedPythonVersions configuration is not set, the method returns the |
| 53 | + * default python version set in the deploymentDataJobBaseImage configuration property. |
| 54 | + * |
| 55 | + * @return A string of all python versions supported by the Control Service |
| 56 | + */ |
| 57 | + public String getSupportedPythonVersions() { |
| 58 | + if (!supportedPythonVersions.isEmpty()) { |
| 59 | + return supportedPythonVersions.keySet().toString(); |
| 60 | + } else { |
| 61 | + try { |
| 62 | + return "[" + getDefaultPythonVersion() + "]"; |
| 63 | + } catch (IllegalArgumentException e) { |
| 64 | + throw new IllegalArgumentException(e); |
| 65 | + } |
90 | 66 | } |
91 | | - |
92 | | - /** |
93 | | - * Returns the name of the vdk image as stored in the docker registry. If |
94 | | - * supportedPythonVersions is set, and the python_version, passed by the user, is supported |
95 | | - * according to the configuration, the vdk image corresponding to the python_version is |
96 | | - * returned. Otherwise, the default vdk image name as set in vdkImage is returned. |
97 | | - * @param python_version a string indicating the python version passed by the user |
98 | | - * @return a string of the data job base image. |
99 | | - */ |
100 | | - public String getVdkImage(String python_version) { |
101 | | - if (!supportedPythonVersions.isEmpty() && isPythonVersionSupported(python_version)) { |
102 | | - return supportedPythonVersions.get(python_version).get(VDK_IMAGE); |
103 | | - } else { |
104 | | - return vdkImage; |
105 | | - } |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Returns the name of the data job base image as stored in the docker registry. If |
| 71 | + * supportedPythonVersions is set, and the python_version passed by the user is supported |
| 72 | + * according to the configuration, the base image corresponding to the python_version is returned. |
| 73 | + * Otherwise, the default base image name as set in deploymentDataJobBaseImage is returned. |
| 74 | + * |
| 75 | + * @param python_version a string indicating the python version passed by the user |
| 76 | + * @return a string of the data job base image. |
| 77 | + */ |
| 78 | + public String getJobBaseImage(String python_version) { |
| 79 | + if (!supportedPythonVersions.isEmpty() && isPythonVersionSupported(python_version)) { |
| 80 | + return supportedPythonVersions.get(python_version).get(BASE_IMAGE); |
| 81 | + } else { |
| 82 | + return deploymentDataJobBaseImage; |
106 | 83 | } |
107 | | - |
108 | | - public String getDefaultVdkImage() { |
109 | | - return vdkImage; |
| 84 | + } |
| 85 | + |
| 86 | + public String getDefaultJobBaseImage() { |
| 87 | + return deploymentDataJobBaseImage; |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Returns the name of the vdk image as stored in the docker registry. If supportedPythonVersions |
| 92 | + * is set, and the python_version, passed by the user, is supported according to the |
| 93 | + * configuration, the vdk image corresponding to the python_version is returned. Otherwise, the |
| 94 | + * default vdk image name as set in vdkImage is returned. |
| 95 | + * |
| 96 | + * @param python_version a string indicating the python version passed by the user |
| 97 | + * @return a string of the data job base image. |
| 98 | + */ |
| 99 | + public String getVdkImage(String python_version) { |
| 100 | + if (!supportedPythonVersions.isEmpty() && isPythonVersionSupported(python_version)) { |
| 101 | + return supportedPythonVersions.get(python_version).get(VDK_IMAGE); |
| 102 | + } else { |
| 103 | + return vdkImage; |
110 | 104 | } |
111 | | - |
112 | | - /** |
113 | | - * Returns the default python version supported by the Control Service. The version number is |
114 | | - * extracted from the datajobs.deployment.dataJobBaseImage application property. The property |
115 | | - * is set as for example, `python:3.9-slim`, and we use a regex to match `3.9` and return it |
116 | | - * to the caller. |
117 | | - * @return a string indicating the default python version supported by the Control Service. |
118 | | - * @throws IllegalArgumentException |
119 | | - */ |
120 | | - public String getDefaultPythonVersion() throws IllegalArgumentException { |
121 | | - Pattern pattern = Pattern.compile("(\\d+\\.\\d+)"); |
122 | | - Matcher matcher = pattern.matcher(deploymentDataJobBaseImage); |
123 | | - if (matcher.find()) { |
124 | | - return matcher.group(1); |
125 | | - } else { |
126 | | - throw new IllegalArgumentException("Could not extract python version number from datajobs.deployment.dataJobBaseImage."); |
127 | | - } |
| 105 | + } |
| 106 | + |
| 107 | + public String getDefaultVdkImage() { |
| 108 | + return vdkImage; |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * Returns the default python version supported by the Control Service. The version number is |
| 113 | + * extracted from the datajobs.deployment.dataJobBaseImage application property. The property is |
| 114 | + * set as for example, `python:3.9-slim`, and we use a regex to match `3.9` and return it to the |
| 115 | + * caller. |
| 116 | + * |
| 117 | + * @return a string indicating the default python version supported by the Control Service. |
| 118 | + * @throws IllegalArgumentException |
| 119 | + */ |
| 120 | + public String getDefaultPythonVersion() throws IllegalArgumentException { |
| 121 | + Pattern pattern = Pattern.compile("(\\d+\\.\\d+)"); |
| 122 | + Matcher matcher = pattern.matcher(deploymentDataJobBaseImage); |
| 123 | + if (matcher.find()) { |
| 124 | + return matcher.group(1); |
| 125 | + } else { |
| 126 | + throw new IllegalArgumentException( |
| 127 | + "Could not extract python version number from datajobs.deployment.dataJobBaseImage."); |
128 | 128 | } |
| 129 | + } |
129 | 130 | } |
0 commit comments