Merge branch '16159-logout-request-with-token'
[arvados-workbench2.git] / src / store / run-process-panel / run-process-panel-actions.ts
index f925c5c4af2b7d9f79146b8d33a722a122140f53..d9686feb4b2b7dcbe28681a6977b75cb7fd59518 100644 (file)
@@ -21,7 +21,6 @@ import {
 } from '~/views/run-process-panel/run-process-advanced-form';
 import { dialogActions } from '~/store/dialog/dialog-actions';
 import { setBreadcrumbs } from '~/store/breadcrumbs/breadcrumbs-actions';
-import { matchProjectRoute } from '~/routes/routes';
 
 export const runProcessPanelActions = unionize({
     SET_PROCESS_PATHNAME: ofType<string>(),
@@ -76,24 +75,29 @@ export const openSetWorkflowDialog = (workflow: WorkflowResource) =>
         }
     };
 
+export const getWorkflowRunnerSettings = (workflow: WorkflowResource) => {
+    const advancedFormValues = {};
+    Object.assign(advancedFormValues, DEFAULT_ADVANCED_FORM_VALUES);
+
+    const wf = getWorkflow(parseWorkflowDefinition(workflow));
+    const hints = wf ? wf.hints : undefined;
+    if (hints) {
+        const resc = hints.find(item => item.class === 'http://arvados.org/cwl#WorkflowRunnerResources') as WorkflowRunnerResources | undefined;
+        if (resc) {
+            if (resc.ramMin) { advancedFormValues[RAM_FIELD] = resc.ramMin * (1024 * 1024); }
+            if (resc.coresMin) { advancedFormValues[VCPUS_FIELD] = resc.coresMin; }
+            if (resc.keep_cache) { advancedFormValues[KEEP_CACHE_RAM_FIELD] = resc.keep_cache * (1024 * 1024); }
+            if (resc.acrContainerImage) { advancedFormValues[RUNNER_IMAGE_FIELD] = resc.acrContainerImage; }
+        }
+    }
+    return advancedFormValues;
+};
+
 export const setWorkflow = (workflow: WorkflowResource, isWorkflowChanged = true) =>
     (dispatch: Dispatch<any>, getState: () => RootState) => {
         const isStepChanged = getState().runProcessPanel.isStepChanged;
 
-        const advancedFormValues = {};
-        Object.assign(advancedFormValues, DEFAULT_ADVANCED_FORM_VALUES);
-
-        const wf = getWorkflow(parseWorkflowDefinition(workflow));
-        const hints = wf ? wf.hints : undefined;
-        if (hints) {
-            const resc = hints.find(item => item.class === 'http://arvados.org/cwl#WorkflowRunnerResources') as WorkflowRunnerResources | undefined;
-            if (resc) {
-                if (resc.ramMin) { advancedFormValues[RAM_FIELD] = resc.ramMin; }
-                if (resc.coresMin) { advancedFormValues[VCPUS_FIELD] = resc.coresMin; }
-                if (resc.keep_cache) { advancedFormValues[KEEP_CACHE_RAM_FIELD] = resc.keep_cache; }
-                if (resc.acrContainerImage) { advancedFormValues[RUNNER_IMAGE_FIELD] = resc.acrContainerImage; }
-            }
-        }
+        const advancedFormValues = getWorkflowRunnerSettings(workflow);
 
         if (isStepChanged && isWorkflowChanged) {
             dispatch(runProcessPanelActions.SET_STEP_CHANGED(false));
@@ -137,13 +141,12 @@ export const runProcess = async (dispatch: Dispatch<any>, getState: () => RootSt
     const state = getState();
     const basicForm = getFormValues(RUN_PROCESS_BASIC_FORM)(state) as RunProcessBasicFormData;
     const inputsForm = getFormValues(RUN_PROCESS_INPUTS_FORM)(state) as WorkflowInputsData;
-    const advancedForm = getFormValues(RUN_PROCESS_ADVANCED_FORM)(state) as RunProcessAdvancedFormData || DEFAULT_ADVANCED_FORM_VALUES;
     const userUuid = getUserUuid(getState());
     if (!userUuid) { return; }
-    const pathname = getState().runProcessPanel.processPathname;
     const { processOwnerUuid, selectedWorkflow } = state.runProcessPanel;
-    const ownerUUid = !matchProjectRoute(pathname) ? userUuid : processOwnerUuid;
+    const ownerUUid = processOwnerUuid ? processOwnerUuid : userUuid;
     if (selectedWorkflow) {
+        const advancedForm = getFormValues(RUN_PROCESS_ADVANCED_FORM)(state) as RunProcessAdvancedFormData || getWorkflowRunnerSettings(selectedWorkflow);
         const newProcessData = {
             ownerUuid: ownerUUid,
             name: basicForm.name,
@@ -153,7 +156,7 @@ export const runProcess = async (dispatch: Dispatch<any>, getState: () => RootSt
             runtimeConstraints: {
                 API: true,
                 vcpus: advancedForm[VCPUS_FIELD],
-                ram: advancedForm[RAM_FIELD],
+                ram: (advancedForm[KEEP_CACHE_RAM_FIELD] + advancedForm[RAM_FIELD]),
             },
             schedulingParameters: {
                 max_run_time: advancedForm[RUNTIME_FIELD]
@@ -181,9 +184,10 @@ export const runProcess = async (dispatch: Dispatch<any>, getState: () => RootSt
     }
 };
 
-export const DEFAULT_ADVANCED_FORM_VALUES: Partial<RunProcessAdvancedFormData> = {
+const DEFAULT_ADVANCED_FORM_VALUES: Partial<RunProcessAdvancedFormData> = {
     [VCPUS_FIELD]: 1,
     [RAM_FIELD]: 1073741824,
+    [KEEP_CACHE_RAM_FIELD]: 268435456,
     [RUNNER_IMAGE_FIELD]: "arvados/jobs"
 };