Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions public/static/locales/en/tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@
"maxCPUCoresLbl": "Maximum CPU Cores",
"memoryLimit": "Memory Limit",
"memoryLimitLabel": "Memory Limit (bytes)",
"maxGPUs": "Max GPUs",
"maxGPUsLbl": "Maximum GPUs",
"minCPUCores": "Min CPU Cores",
"minCPUCoresLbl": "Minimum CPU Cores",
"minDiskSpace": "Min Disk Space",
"minDiskSpaceLbl": "Minimum Disk Space (bytes)",
"minMemoryLimit": "Min Memory Limit",
"minMemoryLimitLbl": "Minimum Memory",
"minGPUs": "Min GPUs",
"minGPUsLbl": "Minimum GPUs",
"myTools": "Only my tools",
"name": "Name",
"namePrefix": "Name Prefix",
Expand Down Expand Up @@ -141,8 +145,10 @@
"useToolInApp": "Use in app",
"validationErrMaxCPUsLessThanMin": "Must be greater than Min CPU Cores",
"validationErrMaxRAMLessThanMin": "Must be greater than Min Memory",
"validationErrMaxGPUsLessThanMin": "Must be greater than Min GPUs",
"validationErrMinCPUsGreaterThanMax": "Must be less than Max CPU Cores",
"validationErrMinRAMGreaterThanMax": "Must be less than Max Memory",
"validationErrMinGPUsGreaterThanMax": "Must be less than Max GPUs",
"validationErrMustBePositive": "Must be at least 0",
"versionLbl": "Version",
"viewFilter": "View Filter",
Expand Down
6 changes: 6 additions & 0 deletions src/components/tools/details/ToolDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ export default function ToolDetails(props) {
<GridLabelValue label={t("minDiskSpaceLbl")}>
{tool.container.min_disk_space}
</GridLabelValue>
<GridLabelValue label={t("minGPUsLbl")}>
{tool.container.min_gpus}
</GridLabelValue>
<GridLabelValue label={t("maxGPUsLbl")}>
{tool.container.max_gpus}
</GridLabelValue>
<Grid item xs={12}>
<Typography variant="h6">{t("restrictionsLabel")}</Typography>
</Grid>
Expand Down
4 changes: 4 additions & 0 deletions src/components/tools/edit/EditTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function EditToolDialog(props) {
const maxCPUCore = resourceConfigs?.max_cpu_limit;
const maxMemory = resourceConfigs?.max_memory_limit;
const maxDiskSpace = resourceConfigs?.max_disk_limit;
const maxGPU = resourceConfigs?.max_gpu_limit;

// Get QueryClient from the context
const queryClient = useQueryClient();
Expand Down Expand Up @@ -313,6 +314,7 @@ function EditToolDialog(props) {
maxCPUCore={maxCPUCore}
maxMemory={maxMemory}
maxDiskSpace={maxDiskSpace}
maxGPU={maxGPU}
values={values}
/>
)}
Expand Down Expand Up @@ -428,6 +430,7 @@ function EditToolForm(props) {
maxCPUCore,
maxMemory,
maxDiskSpace,
maxGPU,
classes,
values,
} = props;
Expand Down Expand Up @@ -628,6 +631,7 @@ function EditToolForm(props) {
maxDiskSpace={maxDiskSpace}
maxCPUCore={maxCPUCore}
maxMemory={maxMemory}
maxGPU={maxGPU}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be destructred from props at the top of this EditToolForm component.

If this were a Typescript file, it probably would have been caught at compile-time 😖

component={Restrictions}
/>
</>
Expand Down
54 changes: 54 additions & 0 deletions src/components/tools/edit/ToolRestrictions.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function Restrictions(props) {
maxCPUCore,
maxMemory,
maxDiskSpace,
maxGPU,
form: { values },
} = props;

Expand All @@ -57,6 +58,7 @@ function Restrictions(props) {
globalConstants.ONE_GiB,
maxDiskSpace
);
const gpuLimitList = maxGPU === 0 ? [0] : buildLimitList(1, maxGPU ?? 8);

const validateMinCPUs = (value) => {
if (value && value < 0) {
Expand Down Expand Up @@ -102,6 +104,28 @@ function Restrictions(props) {
}
};

const validateMinGpus = (value) => {
if (value && value < 0) {
return t("validationErrMustBePositive");
}

const gpu_limit = getIn(values, "container.max_gpus");
if (gpu_limit > 0 && value > gpu_limit) {
return t("validationErrMinGpusGreaterThanMax");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This i18n message needs to be added to public/static/locales/en/tools.json.

}
};

const validateMaxGpus = (value) => {
if (value && value < 0) {
return t("validationErrMustBePositive");
}

const min_gpu_limit = getIn(values, "container.min_gpus");
if (0 < value && value < min_gpu_limit) {
return t("validationErrMaxGpusLessThanMin");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This i18n message needs to be added to public/static/locales/en/tools.json.

}
};

return (
<SimpleExpansionPanel header={t("restrictions")} parentId={parentId}>
{isAdmin && (
Expand Down Expand Up @@ -173,6 +197,36 @@ function Restrictions(props) {
</MenuItem>
))}
</Field>
{isAdmin && (
<Field
name="container.min_gpus"
label={t("minGPUs")}
id={buildID(parentId, ids.EDIT_TOOL_DLG.MIN_GPUS)}
component={FormNumberField}
validate={validateMinGpus}
/>
)}
<Field
name="container.max_gpus"
label={t("maxGPUs")}
id={buildID(parentId, ids.EDIT_TOOL_DLG.MAX_GPUS)}
component={FormSelectField}
validate={validateMaxGpus}
>
{gpuLimitList.map((size, index) => (
<MenuItem
key={index}
value={size}
id={buildID(
parentId,
ids.EDIT_TOOL_DLG.GPU_LIMIT,
size
)}
>
{size}
</MenuItem>
))}
</Field>
{isAdmin && (
<Field
name="container.cpu_shares"
Expand Down
2 changes: 2 additions & 0 deletions src/components/tools/ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const ids = {
CONTAINER_UID: "uid",
MAX_CPU_CORES: "maxCPUCores",
MEMORY_LIMIT: "memoryLimit",
MAX_GPUS: "maxGPUS",
MIN_DISK_SPACE: "minDiskSpace",
CONTAINER_PORTS: "containerPorts",
PIDS_LIMIT: "pidsLimit",
Expand All @@ -40,6 +41,7 @@ const ids = {
INTERACTIVE: "interactive",
CONTAINER_NAME: "containerName",
MIN_MEMORY_LIMIT: "minMemoryLimit",
MIN_GPUS: "minGPUs",
CPU_SHARES: "cpuShares",
MIN_CPU_CORES: "minCPUCores",
SKIP_TMP_MOUNT: "skipTmpMount",
Expand Down