1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch } from 'redux';
6 import { unionize, ofType, UnionOf } from "~/common/unionize";
7 import { ServiceRepository } from "~/services/services";
8 import { RootState } from '~/store/store';
9 import { WorkflowResource, CommandInputParameter } from '~/models/workflow';
10 import { getFormValues } from 'redux-form';
11 import { RUN_PROCESS_BASIC_FORM, RunProcessBasicFormData } from '~/views/run-process-panel/run-process-basic-form';
12 import { RUN_PROCESS_INPUTS_FORM } from '~/views/run-process-panel/run-process-inputs-form';
13 import { WorkflowInputsData } from '~/models/workflow';
14 import { createWorkflowMounts } from '~/models/process';
15 import { ContainerRequestState } from '~/models/container-request';
16 import { navigateToProcess } from '../navigation/navigation-action';
18 export const runProcessPanelActions = unionize({
19 SET_PROCESS_OWNER_UUID: ofType<string>(),
20 SET_CURRENT_STEP: ofType<number>(),
21 SET_WORKFLOWS: ofType<WorkflowResource[]>(),
22 SET_SELECTED_WORKFLOW: ofType<WorkflowResource>(),
25 export interface RunProcessSecondStepDataFormProps {
30 export const RUN_PROCESS_SECOND_STEP_FORM_NAME = 'runProcessSecondStepFormName';
32 export type RunProcessPanelAction = UnionOf<typeof runProcessPanelActions>;
34 export const loadRunProcessPanel = () =>
35 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
37 const response = await services.workflowService.list();
38 dispatch(runProcessPanelActions.SET_WORKFLOWS(response.items));
44 export const setWorkflow = (workflow: WorkflowResource) =>
45 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
46 dispatch(runProcessPanelActions.SET_SELECTED_WORKFLOW(workflow));
49 export const goToStep = (step: number) => runProcessPanelActions.SET_CURRENT_STEP(step);
51 export const runProcess = async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
52 const state = getState();
53 const basicForm = getFormValues(RUN_PROCESS_BASIC_FORM)(state) as RunProcessBasicFormData;
54 const inputsForm = getFormValues(RUN_PROCESS_INPUTS_FORM)(state) as WorkflowInputsData;
55 const { processOwnerUuid, selectedWorkflow } = state.runProcessPanel;
56 if (selectedWorkflow) {
57 const newProcessData = {
58 ownerUuid: processOwnerUuid,
60 description: basicForm.description,
61 state: ContainerRequestState.COMMITTED,
62 mounts: createWorkflowMounts(selectedWorkflow, normalizeInputKeys(inputsForm)),
68 containerImage: 'arvados/jobs:1.1.4.20180618144723',
69 cwd: '/var/spool/cwl',
74 `--project-uuid=${processOwnerUuid}`,
75 '/var/lib/cwl/workflow.json#main',
76 '/var/lib/cwl/cwl.input.json'
78 outputPath: '/var/spool/cwl',
81 const newProcess = await services.containerRequestService.create(newProcessData);
82 dispatch(navigateToProcess(newProcess.uuid));
86 const normalizeInputKeys = (inputs: WorkflowInputsData): WorkflowInputsData =>
87 Object.keys(inputs).reduce((normalizedInputs, key) => ({
89 [key.split('/').slice(1).join('/')]: inputs[key],