15407: Fixes handling of runtime constraints and scheduling params.
[arvados-workbench2.git] / src / views / run-process-panel / run-process-advanced-form.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { ExpansionPanel, ExpansionPanelDetails, ExpansionPanelSummary } from '@material-ui/core';
7 import { reduxForm, Field } from 'redux-form';
8 import { Grid } from '@material-ui/core';
9 import { TextField } from '~/components/text-field/text-field';
10 import { ExpandIcon } from '~/components/icon/icon';
11 import * as IntInput from './inputs/int-input';
12 import { require } from '~/validators/require';
13 import { min } from '~/validators/min';
14 import { optional } from '~/validators/optional';
15 import { SwitchField } from '~/components/switch-field/switch-field';
16
17 export const RUN_PROCESS_ADVANCED_FORM = 'runProcessAdvancedForm';
18
19 export const OUTPUT_FIELD = 'output';
20 export const RUNTIME_FIELD = 'runtime';
21 export const RAM_FIELD = 'ram';
22 export const VCPUS_FIELD = 'vcpus';
23 export const KEEP_CACHE_RAM_FIELD = 'keep_cache_ram';
24 export const API_FIELD = 'api';
25
26 export interface RunProcessAdvancedFormData {
27     [OUTPUT_FIELD]?: string;
28     [RUNTIME_FIELD]?: number;
29     [RAM_FIELD]: number;
30     [VCPUS_FIELD]: number;
31     [KEEP_CACHE_RAM_FIELD]?: number;
32     [API_FIELD]?: boolean;
33 }
34
35 export const RunProcessAdvancedForm =
36     reduxForm<RunProcessAdvancedFormData>({
37         form: RUN_PROCESS_ADVANCED_FORM,
38     })(() =>
39         <form>
40             <ExpansionPanel elevation={0}>
41                 <ExpansionPanelSummary style={{ padding: 0 }} expandIcon={<ExpandIcon />}>
42                     Advanced
43                 </ExpansionPanelSummary>
44                 <ExpansionPanelDetails style={{ padding: 0 }}>
45                     <Grid container spacing={32}>
46                         <Grid item xs={12} md={6}>
47                             <Field
48                                 name={OUTPUT_FIELD}
49                                 component={TextField}
50                                 label="Output name" />
51                         </Grid>
52                         <Grid item xs={12} md={6}>
53                             <Field
54                                 name={RUNTIME_FIELD}
55                                 component={TextField}
56                                 helperText="Maximum running time (in seconds) that this container will be allowed to run before being cancelled."
57                                 label="Runtime limit"
58                                 parse={IntInput.parse}
59                                 format={IntInput.format}
60                                 type='number'
61                                 validate={runtimeValidation} />
62                         </Grid>
63                         <Grid item xs={12} md={6}>
64                             <Field
65                                 name={RAM_FIELD}
66                                 component={TextField}
67                                 label="RAM"
68                                 helperText="Number of ram bytes to be used to run this process."
69                                 parse={IntInput.parse}
70                                 format={IntInput.format}
71                                 type='number'
72                                 required
73                                 validate={ramValidation} />
74                         </Grid>
75                         <Grid item xs={12} md={6}>
76                             <Field
77                                 name={VCPUS_FIELD}
78                                 component={TextField}
79                                 label="VCPUs"
80                                 helperText="Number of cores to be used to run this process."
81                                 parse={IntInput.parse}
82                                 format={IntInput.format}
83                                 type='number'
84                                 required
85                                 validate={vcpusValidation} />
86                         </Grid>
87                         <Grid item xs={12} md={6}>
88                             <Field
89                                 name={KEEP_CACHE_RAM_FIELD}
90                                 component={TextField}
91                                 label="Keep cache RAM"
92                                 helperText="Number of keep cache bytes to be used to run this process."
93                                 parse={IntInput.parse}
94                                 format={IntInput.format}
95                                 type='number'
96                                 validate={keepCacheRamValidation} />
97                         </Grid>
98                         <Grid item xs={12} md={6}>
99                             <Field
100                                 name={API_FIELD}
101                                 component={SwitchField}
102                                 switchProps={{
103                                     color: 'primary'
104                                 }}
105                                 label='API'
106                                 helperText='When set, ARVADOS_API_HOST and ARVADOS_API_TOKEN will be set, and process will have networking enabled to access the Arvados API server.' />
107                         </Grid>
108                     </Grid>
109                 </ExpansionPanelDetails>
110             </ExpansionPanel>
111         </form >);
112
113 const ramValidation = [min(0)];
114 const vcpusValidation = [min(1)];
115 const keepCacheRamValidation = [optional(min(0))];
116 const runtimeValidation = [optional(min(1))];