Connect running a process
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Tue, 2 Oct 2018 10:32:05 +0000 (12:32 +0200)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Tue, 2 Oct 2018 10:32:05 +0000 (12:32 +0200)
Feature #13863

Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski@contractors.roche.com>

src/store/run-process-panel/run-process-panel-actions.ts
src/store/run-process-panel/run-process-panel-reducer.ts
src/views-components/side-panel-button/side-panel-button.tsx
src/views/run-process-panel/run-process-panel.tsx

index de18e70f53044afb231a97d16c4ea58ed26b1e29..07b0b175ab62a16bc783266a795e7f528f02dfb2 100644 (file)
@@ -6,9 +6,17 @@ import { Dispatch } from 'redux';
 import { unionize, ofType, UnionOf } from "~/common/unionize";
 import { ServiceRepository } from "~/services/services";
 import { RootState } from '~/store/store';
-import { WorkflowResource } from '~/models/workflow';
+import { WorkflowResource, CommandInputParameter } from '~/models/workflow';
+import { getFormValues } from 'redux-form';
+import { RUN_PROCESS_BASIC_FORM, RunProcessBasicFormData } from '~/views/run-process-panel/run-process-basic-form';
+import { RUN_PROCESS_INPUTS_FORM } from '~/views/run-process-panel/run-process-inputs-form';
+import { WorkflowInputsData } from '~/models/workflow';
+import { createWorkflowMounts } from '~/models/process';
+import { ContainerRequestState } from '~/models/container-request';
+import { navigateToProcess } from '../navigation/navigation-action';
 
 export const runProcessPanelActions = unionize({
+    SET_PROCESS_OWNER_UUID: ofType<string>(),
     SET_CURRENT_STEP: ofType<number>(),
     SET_WORKFLOWS: ofType<WorkflowResource[]>(),
     SET_SELECTED_WORKFLOW: ofType<WorkflowResource>(),
@@ -33,9 +41,50 @@ export const loadRunProcessPanel = () =>
         }
     };
 
-export const setWorkflow = (workflow: WorkflowResource) => 
+export const setWorkflow = (workflow: WorkflowResource) =>
     async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
         dispatch(runProcessPanelActions.SET_SELECTED_WORKFLOW(workflow));
     };
 
-export const goToStep = (step: number) => runProcessPanelActions.SET_CURRENT_STEP(step);
\ No newline at end of file
+export const goToStep = (step: number) => runProcessPanelActions.SET_CURRENT_STEP(step);
+
+export const runProcess = async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
+    const state = getState();
+    const basicForm = getFormValues(RUN_PROCESS_BASIC_FORM)(state) as RunProcessBasicFormData;
+    const inputsForm = getFormValues(RUN_PROCESS_INPUTS_FORM)(state) as WorkflowInputsData;
+    const { processOwnerUuid, selectedWorkflow } = state.runProcessPanel;
+    if (selectedWorkflow) {
+        const newProcessData = {
+            ownerUuid: processOwnerUuid,
+            name: basicForm.name,
+            description: basicForm.description,
+            state: ContainerRequestState.COMMITTED,
+            mounts: createWorkflowMounts(selectedWorkflow, normalizeInputKeys(inputsForm)),
+            runtimeConstraints: {
+                API: true,
+                vcpus: 1,
+                ram: 1073741824,
+            },
+            containerImage: 'arvados/jobs:1.1.4.20180618144723',
+            cwd: '/var/spool/cwl',
+            command: [
+                'arvados-cwl-runner',
+                '--local',
+                '--api=containers',
+                `--project-uuid=${processOwnerUuid}`,
+                '/var/lib/cwl/workflow.json#main',
+                '/var/lib/cwl/cwl.input.json'
+            ],
+            outputPath: '/var/spool/cwl',
+            priority: 1,
+        };
+        const newProcess = await services.containerRequestService.create(newProcessData);
+        dispatch(navigateToProcess(newProcess.uuid));
+    }
+};
+
+const normalizeInputKeys = (inputs: WorkflowInputsData): WorkflowInputsData =>
+    Object.keys(inputs).reduce((normalizedInputs, key) => ({
+        ...normalizedInputs,
+        [key.split('/').slice(1).join('/')]: inputs[key],
+    }), {});
\ No newline at end of file
index f91039b3424324ad895368ff6830ac7091758a46..2470de1436e30605356dfbbdb83cdb764859eb11 100644 (file)
@@ -6,6 +6,7 @@ import { RunProcessPanelAction, runProcessPanelActions } from '~/store/run-proce
 import { WorkflowResource, CommandInputParameter, getWorkflowInputs, parseWorkflowDefinition } from '~/models/workflow';
 
 interface RunProcessPanel {
+    processOwnerUuid: string;
     currentStep: number;
     workflows: WorkflowResource[];
     selectedWorkflow: WorkflowResource | undefined;
@@ -13,6 +14,7 @@ interface RunProcessPanel {
 }
 
 const initialState: RunProcessPanel = {
+    processOwnerUuid: '',
     currentStep: 0,
     workflows: [],
     selectedWorkflow: undefined,
@@ -21,6 +23,7 @@ const initialState: RunProcessPanel = {
 
 export const runProcessPanelReducer = (state = initialState, action: RunProcessPanelAction): RunProcessPanel =>
     runProcessPanelActions.match(action, {
+        SET_PROCESS_OWNER_UUID: processOwnerUuid => ({ ...state, processOwnerUuid }),
         SET_CURRENT_STEP: currentStep => ({ ...state, currentStep }),
         SET_WORKFLOWS: workflows => ({ ...state, workflows }),
         SET_SELECTED_WORKFLOW: selectedWorkflow => ({
index 2e8433a9ddb074dedb405ba205abbadddb078803..9ba23267dd3a1025a6f2f96fec956c86e2090a9f 100644 (file)
@@ -15,6 +15,7 @@ import { openProjectCreateDialog } from '~/store/projects/project-create-actions
 import { openCollectionCreateDialog } from '~/store/collections/collection-create-actions';
 import { matchProjectRoute } from '~/routes/routes';
 import { navigateToRunProcess } from '~/store/navigation/navigation-action';
+import { runProcessPanelActions } from '~/store/run-process-panel/run-process-panel-actions';
 
 type CssRules = 'button' | 'menuItem' | 'icon';
 
@@ -67,10 +68,10 @@ export const SidePanelButton = withStyles(styles)(
             };
 
             render() {
-                const { classes, buttonVisible  } = this.props;
+                const { classes, buttonVisible } = this.props;
                 const { anchorEl } = this.state;
                 return <Toolbar>
-                    {buttonVisible  && <Grid container>
+                    {buttonVisible && <Grid container>
                         <Grid container item xs alignItems="center" justify="flex-start">
                             <Button variant="contained" color="primary" size="small" className={classes.button}
                                 aria-owns={anchorEl ? 'aside-menu-list' : undefined}
@@ -97,7 +98,7 @@ export const SidePanelButton = withStyles(styles)(
                                 </MenuItem>
                             </Menu>
                         </Grid>
-                    </Grid> }
+                    </Grid>}
                 </Toolbar>;
             }
 
@@ -106,6 +107,7 @@ export const SidePanelButton = withStyles(styles)(
             }
 
             handleRunProcessClick = () => {
+                this.props.dispatch(runProcessPanelActions.SET_PROCESS_OWNER_UUID(this.props.currentItemId));
                 this.props.dispatch<any>(navigateToRunProcess);
             }
 
index dd7b08509e2bbf8ab2a252e8cc1d5860730b2dff..68917c2cf94ae108383be387488e475fae0d249a 100644 (file)
@@ -6,7 +6,7 @@ import { Dispatch } from 'redux';
 import { connect } from 'react-redux';
 import { RootState } from '~/store/store';
 import { RunProcessPanelRootDataProps, RunProcessPanelRootActionProps, RunProcessPanelRoot } from '~/views/run-process-panel/run-process-panel-root';
-import { goToStep, setWorkflow } from '~/store/run-process-panel/run-process-panel-actions';
+import { goToStep, setWorkflow, runProcess } from '~/store/run-process-panel/run-process-panel-actions';
 import { WorkflowResource } from '~/models/workflow';
 
 const mapStateToProps = ({ runProcessPanel }: RootState): RunProcessPanelRootDataProps => {
@@ -25,7 +25,7 @@ const mapDispatchToProps = (dispatch: Dispatch): RunProcessPanelRootActionProps
         dispatch<any>(setWorkflow(workflow));
     },
     runProcess: () => {
-        console.log('run process!');
+        dispatch<any>(runProcess);
     }
 });