1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch } from "redux";
6 import { RootState } from 'store/store';
7 import { ServiceRepository } from 'services/services';
8 import { updateResources } from 'store/resources/resources-actions';
9 import { Process } from './process';
10 import { dialogActions } from 'store/dialog/dialog-actions';
11 import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
12 import { projectPanelActions } from 'store/project-panel/project-panel-action';
13 import { navigateToRunProcess } from 'store/navigation/navigation-action';
14 import { goToStep, runProcessPanelActions } from 'store/run-process-panel/run-process-panel-actions';
15 import { getResource } from 'store/resources/resources';
16 import { initialize } from "redux-form";
17 import { RUN_PROCESS_BASIC_FORM, RunProcessBasicFormData } from "views/run-process-panel/run-process-basic-form";
18 import { RunProcessAdvancedFormData, RUN_PROCESS_ADVANCED_FORM } from "views/run-process-panel/run-process-advanced-form";
19 import { MOUNT_PATH_CWL_WORKFLOW, MOUNT_PATH_CWL_INPUT } from 'models/process';
20 import { CommandInputParameter, getWorkflow, getWorkflowInputs } from "models/workflow";
21 import { ProjectResource } from "models/project";
22 import { UserResource } from "models/user";
24 export const loadProcess = (containerRequestUuid: string) =>
25 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<Process> => {
26 const containerRequest = await services.containerRequestService.get(containerRequestUuid);
27 dispatch<any>(updateResources([containerRequest]));
29 if (containerRequest.containerUuid) {
30 const container = await services.containerService.get(containerRequest.containerUuid);
31 dispatch<any>(updateResources([container]));
32 return { containerRequest, container };
34 return { containerRequest };
37 export const loadContainers = (filters: string) =>
38 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
39 const { items } = await services.containerService.list({ filters });
40 dispatch<any>(updateResources(items));
44 export const cancelRunningWorkflow = (uuid: string) =>
45 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
47 const process = await services.containerRequestService.update(uuid, { priority: 0 });
50 throw new Error('Could not cancel the process.');
54 export const reRunProcess = (processUuid: string, workflowUuid: string) =>
55 (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
56 const process = getResource<any>(processUuid)(getState().resources);
57 const workflows = getState().runProcessPanel.searchWorkflows;
58 const workflow = workflows.find(workflow => workflow.uuid === workflowUuid);
59 if (workflow && process) {
60 const mainWf = getWorkflow(process.mounts[MOUNT_PATH_CWL_WORKFLOW]);
61 if (mainWf) { mainWf.inputs = getInputs(process); }
62 const stringifiedDefinition = JSON.stringify(process.mounts[MOUNT_PATH_CWL_WORKFLOW].content);
63 const newWorkflow = { ...workflow, definition: stringifiedDefinition };
65 const owner = getResource<ProjectResource | UserResource>(workflow.ownerUuid)(getState().resources);
66 const basicInitialData: RunProcessBasicFormData = { name: `Copy of: ${process.name}`, description: process.description, owner };
67 dispatch<any>(initialize(RUN_PROCESS_BASIC_FORM, basicInitialData));
69 const advancedInitialData: RunProcessAdvancedFormData = {
70 output: process.outputName,
71 runtime: process.schedulingParameters.max_run_time,
72 ram: process.runtimeConstraints.ram,
73 vcpus: process.runtimeConstraints.vcpus,
74 keep_cache_ram: process.runtimeConstraints.keep_cache_ram,
75 acr_container_image: process.containerImage
77 dispatch<any>(initialize(RUN_PROCESS_ADVANCED_FORM, advancedInitialData));
79 dispatch<any>(navigateToRunProcess);
80 dispatch<any>(goToStep(1));
81 dispatch(runProcessPanelActions.SET_STEP_CHANGED(true));
82 dispatch(runProcessPanelActions.SET_SELECTED_WORKFLOW(newWorkflow));
84 dispatch<any>(snackbarActions.OPEN_SNACKBAR({ message: `You can't re-run this process`, kind: SnackbarKind.ERROR }));
88 export const getInputs = (data: any): CommandInputParameter[] => {
89 if (!data || !data.mounts || !data.mounts[MOUNT_PATH_CWL_WORKFLOW]) { return []; }
90 const inputs = getWorkflowInputs(data.mounts[MOUNT_PATH_CWL_WORKFLOW].content);
91 return inputs ? inputs.map(
97 default: data.mounts[MOUNT_PATH_CWL_INPUT].content[it.id],
98 value: data.mounts[MOUNT_PATH_CWL_INPUT].content[it.id.split('/').pop()] || [],
105 export const openRemoveProcessDialog = (uuid: string) =>
106 (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
107 dispatch(dialogActions.OPEN_DIALOG({
108 id: REMOVE_PROCESS_DIALOG,
110 title: 'Remove process permanently',
111 text: 'Are you sure you want to remove this process?',
112 confirmButtonLabel: 'Remove',
118 export const REMOVE_PROCESS_DIALOG = 'removeProcessDialog';
120 export const removeProcessPermanently = (uuid: string) =>
121 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
122 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing ...', kind: SnackbarKind.INFO }));
123 await services.containerRequestService.delete(uuid);
124 dispatch(projectPanelActions.REQUEST_ITEMS());
125 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removed.', hideDuration: 2000, kind: SnackbarKind.SUCCESS }));