-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConfig.java
More file actions
65 lines (57 loc) · 3.3 KB
/
Config.java
File metadata and controls
65 lines (57 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package org.togetherjava.jshellapi;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
@ConfigurationProperties("jshellapi")
public record Config(long regularSessionTimeoutSeconds, long oneTimeSessionTimeoutSeconds,
long evalTimeoutSeconds, long evalTimeoutValidationLeeway, int sysOutCharLimit,
long maxAliveSessions, int dockerMaxRamMegaBytes, double dockerCPUsUsage,
@Nullable String dockerCPUSetCPUs, long schedulerSessionKillScanRateSeconds,
long dockerResponseTimeout, long dockerConnectionTimeout, String jshellWrapperImageName) {
public static final String JSHELL_WRAPPER_IMAGE_NAME_TAG = ":master";
private static boolean checkJShellWrapperImageName(String imageName) {
if (!StringUtils.hasText(imageName)
|| !imageName.endsWith(Config.JSHELL_WRAPPER_IMAGE_NAME_TAG)) {
return false;
}
final String imageNameFirstPart = imageName.split(Config.JSHELL_WRAPPER_IMAGE_NAME_TAG)[0];
return StringUtils.hasText(imageNameFirstPart);
}
public Config {
if (regularSessionTimeoutSeconds <= 0)
throw new IllegalArgumentException(
"Invalid regularSessionTimeoutSeconds " + regularSessionTimeoutSeconds);
if (oneTimeSessionTimeoutSeconds <= 0)
throw new IllegalArgumentException(
"Invalid oneTimeSessionTimeoutSeconds " + oneTimeSessionTimeoutSeconds);
if (evalTimeoutSeconds <= 0)
throw new IllegalArgumentException("Invalid evalTimeoutSeconds " + evalTimeoutSeconds);
if (evalTimeoutValidationLeeway <= 0)
throw new IllegalArgumentException(
"Invalid evalTimeoutValidationLeeway " + evalTimeoutSeconds);
if (sysOutCharLimit <= 0)
throw new IllegalArgumentException("Invalid sysOutCharLimit " + sysOutCharLimit);
if (maxAliveSessions <= 0)
throw new IllegalArgumentException("Invalid maxAliveSessions " + maxAliveSessions);
if (dockerMaxRamMegaBytes <= 0)
throw new IllegalArgumentException(
"Invalid dockerMaxRamMegaBytes " + dockerMaxRamMegaBytes);
if (dockerCPUsUsage <= 0)
throw new IllegalArgumentException("Invalid dockerCPUsUsage " + dockerCPUsUsage);
if (dockerCPUSetCPUs != null && !dockerCPUSetCPUs.matches("[1-9]?\\d([-,]\\d?\\d)?"))
throw new IllegalArgumentException("Invalid dockerCPUSetCPUs " + dockerCPUSetCPUs);
if (schedulerSessionKillScanRateSeconds <= 0)
throw new IllegalArgumentException("Invalid schedulerSessionKillScanRateSeconds "
+ schedulerSessionKillScanRateSeconds);
if (dockerResponseTimeout <= 0)
throw new IllegalArgumentException(
"Invalid dockerResponseTimeout " + dockerResponseTimeout);
if (dockerConnectionTimeout <= 0)
throw new IllegalArgumentException(
"Invalid dockerConnectionTimeout " + dockerConnectionTimeout);
if (!checkJShellWrapperImageName(jshellWrapperImageName)) {
throw new IllegalArgumentException(
"Invalid jshellWrapperImageName " + jshellWrapperImageName);
}
}
}