Skip to content

Commit

Permalink
Google Java Format
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions authored and doks5 committed Mar 21, 2023
1 parent e7943ed commit cdc3d20
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, HashMap<String, String>> supportedPythonVersions;

@Value("${datajobs.vdk.image}")
private String vdkImage;
@Value("#{${datajobs.deployment.supportedPythonVersions}}")
private HashMap<String, HashMap<String, String>> 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.");
}
}
}
Loading

0 comments on commit cdc3d20

Please sign in to comment.