16602: Test for using advanced settings from workflow
authorPeter Amstutz <peter.amstutz@curii.com>
Thu, 27 Aug 2020 18:12:55 +0000 (14:12 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Thu, 27 Aug 2020 18:12:55 +0000 (14:12 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

src/store/run-process-panel/run-process-panel-actions.test.ts
src/store/run-process-panel/run-process-panel-actions.ts

index e863368dafcfaadc424419a344ce28527e6fa28f..cfdb75ea7aa997a24b12ba1da251aaf8345eef71 100644 (file)
 import { runProcess } from "./run-process-panel-actions";
 
 jest.mock("../navigation/navigation-action", () => ({
-  navigateTo: (link: any) => link,
+    navigateTo: (link: any) => link,
 }));
 
 jest.mock("~/models/process", () => ({
-  createWorkflowMounts: jest.fn(),
+    createWorkflowMounts: jest.fn(),
 }));
 
 jest.mock("redux-form", () => ({
-  reduxForm: () => (c: any) => c,
-  getFormValues: (name: string) => () => {
-    switch (name) {
-      case "runProcessBasicForm":
-        return {
-          name: "basicFormTestName",
-          description: "basicFormTestDescription",
-        };
-      case "runProcessInputsForm":
-        return {};
-      default:
-        return null;
-    }
-  },
+    reduxForm: () => (c: any) => c,
+    getFormValues: (name: string) => () => {
+        switch (name) {
+            case "runProcessBasicForm":
+                return {
+                    name: "basicFormTestName",
+                    description: "basicFormTestDescription",
+                };
+            case "runProcessInputsForm":
+                return {};
+            default:
+                return null;
+        }
+    },
 }));
 
 describe("run-process-panel-actions", () => {
-  describe("runProcess", () => {
-    const newProcessUUID = 'newProcessUUID';
-    let dispatch: any, getState: any, services: any;
+    describe("runProcess", () => {
+        const newProcessUUID = 'newProcessUUID';
+        let dispatch: any, getState: any, services: any;
 
-    beforeEach(() => {
-      dispatch = jest.fn();
-      services = {
-        containerRequestService: {
-          create: jest.fn().mockImplementation(async () => ({
-            uuid: newProcessUUID,
-          })),
-        },
-      };
-    });
+        beforeEach(() => {
+            dispatch = jest.fn();
+            services = {
+                containerRequestService: {
+                    create: jest.fn().mockImplementation(async () => ({
+                        uuid: newProcessUUID,
+                    })),
+                },
+            };
+        });
 
-    it("should return when userUuid is null", async () => {
-      // given
-      getState = () => ({
-        auth: {},
-      });
+        it("should return when userUuid is null", async () => {
+            // given
+            getState = () => ({
+                auth: {},
+            });
 
-      // when
-      await runProcess(dispatch, getState, services);
+            // when
+            await runProcess(dispatch, getState, services);
 
-      // then
-      expect(dispatch).not.toHaveBeenCalled();
-    });
+            // then
+            expect(dispatch).not.toHaveBeenCalled();
+        });
 
-    it("should run workflow with project-uuid", async () => {
-      // given
-      getState = () => ({
-        auth: {
-          user: {
-            email: "test@gmail.com",
-            firstName: "TestFirstName",
-            lastName: "TestLastName",
-            uuid: "ce8i5-tpzed-yid70bw31f51234",
-            ownerUuid: "ce8i5-tpzed-000000000000000",
-            isAdmin: false,
-            isActive: true,
-            username: "testfirstname",
-            prefs: {
-              profile: {},
-            },
-          },
-        },
-        runProcessPanel: {
-          processPathname: "/projects/ce8i5-tpzed-yid70bw31f51234",
-          processOwnerUuid: "ce8i5-tpzed-yid70bw31f51234",
-          selectedWorkflow: {
-            href: "/workflows/ce8i5-7fd4e-2tlnerdkxnl4fjt",
-            kind: "arvados#workflow",
-            etag: "8gh5xlhlgo61yqscyl1spw8tc",
-            uuid: "ce8i5-7fd4e-2tlnerdkxnl4fjt",
-            ownerUuid: "ce8i5-tpzed-o4njwilpp4ov321",
-            createdAt: "2020-07-15T19:40:50.296041000Z",
-            modifiedByClientUuid: "ce8i5-ozdt8-libnr89sc5nq111",
-            modifiedByUserUuid: "ce8i5-tpzed-o4njwilpp4ov321",
-            modifiedAt: "2020-07-15T19:40:50.296376000Z",
-            name: "revsort.cwl",
-            description:
-              "Reverse the lines in a document, then sort those lines.",
-            definition:
-              '{\n    "$graph": [\n        {\n            "class": "Workflow",\n            "doc": "Reverse the lines in a document, then sort those lines.",\n            "id": "#main",\n            "inputs": [\n                {\n                    "default": null,\n                    "doc": "The input file to be processed.",\n                    "id": "#main/input",\n                    "type": "File"\n                },\n                {\n                    "default": true,\n                    "doc": "If true, reverse (decending) sort",\n                    "id": "#main/reverse_sort",\n                    "type": "boolean"\n                }\n            ],\n            "outputs": [\n                {\n                    "doc": "The output with the lines reversed and sorted.",\n                    "id": "#main/output",\n                    "outputSource": "#main/sorted/output",\n                    "type": "File"\n                }\n            ],\n            "steps": [\n                {\n                    "id": "#main/rev",\n                    "in": [\n                        {\n                            "id": "#main/rev/input",\n                            "source": "#main/input"\n                        }\n                    ],\n                    "out": [\n                        "#main/rev/output"\n                    ],\n                    "run": "#revtool.cwl"\n                },\n                {\n                    "id": "#main/sorted",\n                    "in": [\n                        {\n                            "id": "#main/sorted/input",\n                            "source": "#main/rev/output"\n                        },\n                        {\n                            "id": "#main/sorted/reverse",\n                            "source": "#main/reverse_sort"\n                        }\n                    ],\n                    "out": [\n                        "#main/sorted/output"\n                    ],\n                    "run": "#sorttool.cwl"\n                }\n            ]\n        },\n        {\n            "baseCommand": "rev",\n            "class": "CommandLineTool",\n            "doc": "Reverse each line using the `rev` command",\n            "hints": [\n                {\n                    "class": "ResourceRequirement",\n                    "ramMin": 8\n                }\n            ],\n            "id": "#revtool.cwl",\n            "inputs": [\n                {\n                    "id": "#revtool.cwl/input",\n                    "inputBinding": {},\n                    "type": "File"\n                }\n            ],\n            "outputs": [\n                {\n                    "id": "#revtool.cwl/output",\n                    "outputBinding": {\n                        "glob": "output.txt"\n                    },\n                    "type": "File"\n                }\n            ],\n            "stdout": "output.txt"\n        },\n        {\n            "baseCommand": "sort",\n            "class": "CommandLineTool",\n            "doc": "Sort lines using the `sort` command",\n            "hints": [\n                {\n                    "class": "ResourceRequirement",\n                    "ramMin": 8\n                }\n            ],\n            "id": "#sorttool.cwl",\n            "inputs": [\n                {\n                    "id": "#sorttool.cwl/reverse",\n                    "inputBinding": {\n                        "position": 1,\n                        "prefix": "-r"\n                    },\n                    "type": "boolean"\n                },\n                {\n                    "id": "#sorttool.cwl/input",\n                    "inputBinding": {\n                        "position": 2\n                    },\n                    "type": "File"\n                }\n            ],\n            "outputs": [\n                {\n                    "id": "#sorttool.cwl/output",\n                    "outputBinding": {\n                        "glob": "output.txt"\n                    },\n                    "type": "File"\n                }\n            ],\n            "stdout": "output.txt"\n        }\n    ],\n    "cwlVersion": "v1.0"\n}',
-          },
-        },
-      });
+        it("should run workflow with project-uuid", async () => {
+            // given
+            getState = () => ({
+                auth: {
+                    user: {
+                        email: "test@gmail.com",
+                        firstName: "TestFirstName",
+                        lastName: "TestLastName",
+                        uuid: "ce8i5-tpzed-yid70bw31f51234",
+                        ownerUuid: "ce8i5-tpzed-000000000000000",
+                        isAdmin: false,
+                        isActive: true,
+                        username: "testfirstname",
+                        prefs: {
+                            profile: {},
+                        },
+                    },
+                },
+                runProcessPanel: {
+                    processPathname: "/projects/ce8i5-tpzed-yid70bw31f51234",
+                    processOwnerUuid: "ce8i5-tpzed-yid70bw31f51234",
+                    selectedWorkflow: {
+                        href: "/workflows/ce8i5-7fd4e-2tlnerdkxnl4fjt",
+                        kind: "arvados#workflow",
+                        etag: "8gh5xlhlgo61yqscyl1spw8tc",
+                        uuid: "ce8i5-7fd4e-2tlnerdkxnl4fjt",
+                        ownerUuid: "ce8i5-tpzed-o4njwilpp4ov321",
+                        createdAt: "2020-07-15T19:40:50.296041000Z",
+                        modifiedByClientUuid: "ce8i5-ozdt8-libnr89sc5nq111",
+                        modifiedByUserUuid: "ce8i5-tpzed-o4njwilpp4ov321",
+                        modifiedAt: "2020-07-15T19:40:50.296376000Z",
+                        name: "revsort.cwl",
+                        description:
+                            "Reverse the lines in a document, then sort those lines.",
+                        definition:
+                            '{\n    "$graph": [\n        {\n            "class": "Workflow",\n            "doc": "Reverse the lines in a document, then sort those lines.",\n            "id": "#main",\n            "hints":[{"class":"http://arvados.org/cwl#WorkflowRunnerResources","acrContainerImage":"arvados/jobs:2.0.4"}], "inputs": [\n                {\n                    "default": null,\n                    "doc": "The input file to be processed.",\n                    "id": "#main/input",\n                    "type": "File"\n                },\n                {\n                    "default": true,\n                    "doc": "If true, reverse (decending) sort",\n                    "id": "#main/reverse_sort",\n                    "type": "boolean"\n                }\n            ],\n            "outputs": [\n                {\n                    "doc": "The output with the lines reversed and sorted.",\n                    "id": "#main/output",\n                    "outputSource": "#main/sorted/output",\n                    "type": "File"\n                }\n            ],\n            "steps": [\n                {\n                    "id": "#main/rev",\n                    "in": [\n                        {\n                            "id": "#main/rev/input",\n                            "source": "#main/input"\n                        }\n                    ],\n                    "out": [\n                        "#main/rev/output"\n                    ],\n                    "run": "#revtool.cwl"\n                },\n                {\n                    "id": "#main/sorted",\n                    "in": [\n                        {\n                            "id": "#main/sorted/input",\n                            "source": "#main/rev/output"\n                        },\n                        {\n                            "id": "#main/sorted/reverse",\n                            "source": "#main/reverse_sort"\n                        }\n                    ],\n                    "out": [\n                        "#main/sorted/output"\n                    ],\n                    "run": "#sorttool.cwl"\n                }\n            ]\n        },\n        {\n            "baseCommand": "rev",\n            "class": "CommandLineTool",\n            "doc": "Reverse each line using the `rev` command",\n            "hints": [\n                {\n                    "class": "ResourceRequirement",\n                    "ramMin": 8\n                }\n            ],\n            "id": "#revtool.cwl",\n            "inputs": [\n                {\n                    "id": "#revtool.cwl/input",\n                    "inputBinding": {},\n                    "type": "File"\n                }\n            ],\n            "outputs": [\n                {\n                    "id": "#revtool.cwl/output",\n                    "outputBinding": {\n                        "glob": "output.txt"\n                    },\n                    "type": "File"\n                }\n            ],\n            "stdout": "output.txt"\n        },\n        {\n            "baseCommand": "sort",\n            "class": "CommandLineTool",\n            "doc": "Sort lines using the `sort` command",\n            "hints": [\n                {\n                    "class": "ResourceRequirement",\n                    "ramMin": 8\n                }\n            ],\n            "id": "#sorttool.cwl",\n            "inputs": [\n                {\n                    "id": "#sorttool.cwl/reverse",\n                    "inputBinding": {\n                        "position": 1,\n                        "prefix": "-r"\n                    },\n                    "type": "boolean"\n                },\n                {\n                    "id": "#sorttool.cwl/input",\n                    "inputBinding": {\n                        "position": 2\n                    },\n                    "type": "File"\n                }\n            ],\n            "outputs": [\n                {\n                    "id": "#sorttool.cwl/output",\n                    "outputBinding": {\n                        "glob": "output.txt"\n                    },\n                    "type": "File"\n                }\n            ],\n            "stdout": "output.txt"\n        }\n    ],\n    "cwlVersion": "v1.0"\n}',
+                    },
+                },
+            });
 
-      // when
-      await runProcess(dispatch, getState, services);
+            // when
+            await runProcess(dispatch, getState, services);
 
-      // then
-      expect(services.containerRequestService.create).toHaveBeenCalledWith({
-        command: [
-          "arvados-cwl-runner",
-          "--api=containers",
-          "--local",
-          "--project-uuid=ce8i5-tpzed-yid70bw31f51234",
-          "/var/lib/cwl/workflow.json#main",
-          "/var/lib/cwl/cwl.input.json",
-        ],
-        containerImage: "arvados/jobs",
-        cwd: "/var/spool/cwl",
-        description: "basicFormTestDescription",
-        mounts: undefined,
-        name: "basicFormTestName",
-        outputName: undefined,
-        outputPath: "/var/spool/cwl",
-        ownerUuid: "ce8i5-tpzed-yid70bw31f51234",
-        priority: 1,
-        properties: {
-          workflowName: "revsort.cwl",
-          workflowUuid: "ce8i5-7fd4e-2tlnerdkxnl4fjt",
-        },
-        runtimeConstraints: {
-          API: true,
-          api: true,
-          ram: 1073741824,
-          vcpus: 1,
-        },
-        schedulingParameters: { max_run_time: undefined },
-        state: "Committed",
-      });
+            // then
+            expect(services.containerRequestService.create).toHaveBeenCalledWith({
+                command: [
+                    "arvados-cwl-runner",
+                    "--api=containers",
+                    "--local",
+                    "--project-uuid=ce8i5-tpzed-yid70bw31f51234",
+                    "/var/lib/cwl/workflow.json#main",
+                    "/var/lib/cwl/cwl.input.json",
+                ],
+                containerImage: "arvados/jobs:2.0.4",
+                cwd: "/var/spool/cwl",
+                description: "basicFormTestDescription",
+                mounts: undefined,
+                name: "basicFormTestName",
+                outputName: undefined,
+                outputPath: "/var/spool/cwl",
+                ownerUuid: "ce8i5-tpzed-yid70bw31f51234",
+                priority: 1,
+                properties: {
+                    workflowName: "revsort.cwl",
+                    workflowUuid: "ce8i5-7fd4e-2tlnerdkxnl4fjt",
+                },
+                runtimeConstraints: {
+                    API: true,
+                    ram: 1073741824,
+                    vcpus: 1,
+                },
+                schedulingParameters: { max_run_time: undefined },
+                state: "Committed",
+            });
 
-      // and
-      expect(dispatch).toHaveBeenCalledWith(newProcessUUID);
+            // and
+            expect(dispatch).toHaveBeenCalledWith(newProcessUUID);
+        });
     });
-  });
 });
index f925c5c4af2b7d9f79146b8d33a722a122140f53..8a8263963448b00d057d6b1b01c4a4caf1dfe97b 100644 (file)
@@ -76,24 +76,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; }
+            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; }
+        }
+    }
+    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 +142,13 @@ 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;
     if (selectedWorkflow) {
+        const advancedForm = getFormValues(RUN_PROCESS_ADVANCED_FORM)(state) as RunProcessAdvancedFormData || getWorkflowRunnerSettings(selectedWorkflow);
         const newProcessData = {
             ownerUuid: ownerUUid,
             name: basicForm.name,