1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { unionize, ofType, UnionOf } from "common/unionize";
6 import { getInputs, getOutputParameters, getRawInputs, getRawOutputs, loadProcess } from 'store/processes/processes-actions';
7 import { Dispatch } from 'redux';
8 import { ProcessStatus } from 'store/processes/process';
9 import { RootState } from 'store/store';
10 import { ServiceRepository } from "services/services";
11 import { navigateTo, navigateToWorkflows } from 'store/navigation/navigation-action';
12 import { snackbarActions } from 'store/snackbar/snackbar-actions';
13 import { SnackbarKind } from '../snackbar/snackbar-actions';
14 import { showWorkflowDetails } from 'store/workflow-panel/workflow-panel-actions';
15 import { loadSubprocessPanel } from "../subprocess-panel/subprocess-panel-actions";
16 import { initProcessLogsPanel, processLogsPanelActions } from "store/process-logs-panel/process-logs-panel-actions";
17 import { CollectionFile } from "models/collection-file";
18 import { ContainerRequestResource } from "models/container-request";
19 import { CommandOutputParameter } from 'cwlts/mappings/v1.0/CommandOutputParameter';
20 import { CommandInputParameter, getIOParamId, WorkflowInputsData } from 'models/workflow';
21 import { getIOParamDisplayValue, ProcessIOParameter } from "views/process-panel/process-io-card";
22 import { OutputDetails, NodeInstanceType, NodeInfo } from "./process-panel";
23 import { AuthState } from "store/auth/auth-reducer";
24 import { CommonService } from "services/common-service/common-service";
25 import { camelCase } from "lodash";
27 export const processPanelActions = unionize({
28 RESET_PROCESS_PANEL: ofType<{}>(),
29 SET_PROCESS_PANEL_CONTAINER_REQUEST_UUID: ofType<string>(),
30 SET_PROCESS_PANEL_FILTERS: ofType<string[]>(),
31 TOGGLE_PROCESS_PANEL_FILTER: ofType<string>(),
32 SET_INPUT_RAW: ofType<WorkflowInputsData | null>(),
33 SET_INPUT_PARAMS: ofType<ProcessIOParameter[] | null>(),
34 SET_OUTPUT_RAW: ofType<OutputDetails | null>(),
35 SET_OUTPUT_DEFINITIONS: ofType<CommandOutputParameter[]>(),
36 SET_OUTPUT_PARAMS: ofType<ProcessIOParameter[] | null>(),
37 SET_NODE_INFO: ofType<NodeInfo>(),
40 export type ProcessPanelAction = UnionOf<typeof processPanelActions>;
42 export const toggleProcessPanelFilter = processPanelActions.TOGGLE_PROCESS_PANEL_FILTER;
44 export const loadProcessPanel = (uuid: string) =>
45 async (dispatch: Dispatch) => {
46 dispatch(processPanelActions.RESET_PROCESS_PANEL());
47 dispatch(processLogsPanelActions.RESET_PROCESS_LOGS_PANEL());
48 dispatch<ProcessPanelAction>(processPanelActions.SET_PROCESS_PANEL_CONTAINER_REQUEST_UUID(uuid));
49 await dispatch<any>(loadProcess(uuid));
50 dispatch(initProcessPanelFilters);
51 dispatch<any>(initProcessLogsPanel(uuid));
52 dispatch<any>(loadSubprocessPanel());
55 export const navigateToOutput = (uuid: string) =>
56 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
58 await services.collectionService.get(uuid);
59 dispatch<any>(navigateTo(uuid));
61 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'This collection does not exists!', hideDuration: 2000, kind: SnackbarKind.ERROR }));
65 export const loadInputs = (containerRequest: ContainerRequestResource) =>
66 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
67 dispatch<ProcessPanelAction>(processPanelActions.SET_INPUT_RAW(getRawInputs(containerRequest)));
68 dispatch<ProcessPanelAction>(processPanelActions.SET_INPUT_PARAMS(formatInputData(getInputs(containerRequest), getState().auth)));
71 export const loadOutputs = (containerRequest: ContainerRequestResource) =>
72 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
73 const noOutputs = { rawOutputs: {} };
74 if (!containerRequest.outputUuid) {
75 dispatch<ProcessPanelAction>(processPanelActions.SET_OUTPUT_RAW(noOutputs));
79 const propsOutputs = getRawOutputs(containerRequest);
80 const filesPromise = services.collectionService.files(containerRequest.outputUuid);
81 const collectionPromise = services.collectionService.get(containerRequest.outputUuid);
82 const [files, collection] = await Promise.all([filesPromise, collectionPromise]);
84 // If has propsOutput, skip fetching cwl.output.json
85 if (propsOutputs !== undefined) {
86 dispatch<ProcessPanelAction>(processPanelActions.SET_OUTPUT_RAW({
87 rawOutputs: propsOutputs,
88 pdh: collection.portableDataHash
91 // Fetch outputs from keep
92 const outputFile = files.find((file) => file.name === 'cwl.output.json') as CollectionFile | undefined;
93 let outputData = outputFile ? await services.collectionService.getFileContents(outputFile) : undefined;
94 if (outputData && (outputData = JSON.parse(outputData)) && collection.portableDataHash) {
95 dispatch<ProcessPanelAction>(processPanelActions.SET_OUTPUT_RAW({
96 rawOutputs: outputData,
97 pdh: collection.portableDataHash,
100 dispatch<ProcessPanelAction>(processPanelActions.SET_OUTPUT_RAW(noOutputs));
104 dispatch<ProcessPanelAction>(processPanelActions.SET_OUTPUT_RAW(noOutputs));
109 export const loadNodeJson = (containerRequest: ContainerRequestResource) =>
110 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
111 const noLog = { nodeInfo: null };
112 if (!containerRequest.logUuid) {
113 dispatch<ProcessPanelAction>(processPanelActions.SET_NODE_INFO(noLog));
117 const filesPromise = services.collectionService.files(containerRequest.logUuid);
118 const collectionPromise = services.collectionService.get(containerRequest.logUuid);
119 const [files, collection] = await Promise.all([filesPromise, collectionPromise]);
121 // Fetch node.json from keep
122 const nodeFile = files.find((file) => file.name === 'node.json') as CollectionFile | undefined;
123 let nodeData = nodeFile ? await services.collectionService.getFileContents(nodeFile) : undefined;
124 if (nodeData && (nodeData = JSON.parse(nodeData))) {
125 dispatch<ProcessPanelAction>(processPanelActions.SET_NODE_INFO({
126 nodeInfo: nodeData as NodeInstanceType
129 dispatch<ProcessPanelAction>(processPanelActions.SET_NODE_INFO(noLog));
132 dispatch<ProcessPanelAction>(processPanelActions.SET_NODE_INFO(noLog));
136 export const loadOutputDefinitions = (containerRequest: ContainerRequestResource) =>
137 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
138 if (containerRequest && containerRequest.mounts) {
139 dispatch<ProcessPanelAction>(processPanelActions.SET_OUTPUT_DEFINITIONS(getOutputParameters(containerRequest)));
143 export const updateOutputParams = () =>
144 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
145 const outputDefinitions = getState().processPanel.outputDefinitions;
146 const outputRaw = getState().processPanel.outputRaw;
148 if (outputRaw !== null && outputRaw.rawOutputs) {
149 dispatch<ProcessPanelAction>(processPanelActions.SET_OUTPUT_PARAMS(formatOutputData(outputDefinitions, outputRaw.rawOutputs, outputRaw.pdh, getState().auth)));
153 export const openWorkflow = (uuid: string) =>
154 (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
155 dispatch<any>(navigateToWorkflows);
156 dispatch<any>(showWorkflowDetails(uuid));
159 export const initProcessPanelFilters = processPanelActions.SET_PROCESS_PANEL_FILTERS([
160 ProcessStatus.QUEUED,
161 ProcessStatus.COMPLETED,
162 ProcessStatus.FAILED,
163 ProcessStatus.RUNNING,
164 ProcessStatus.ONHOLD,
165 ProcessStatus.FAILING,
166 ProcessStatus.WARNING,
167 ProcessStatus.CANCELLED
170 const formatInputData = (inputs: CommandInputParameter[], auth: AuthState): ProcessIOParameter[] => {
171 return inputs.map(input => {
173 id: getIOParamId(input),
174 label: input.label || "",
175 value: getIOParamDisplayValue(auth, input)
180 const formatOutputData = (definitions: CommandOutputParameter[], values: any, pdh: string | undefined, auth: AuthState): ProcessIOParameter[] => {
181 return definitions.map(output => {
183 id: getIOParamId(output),
184 label: output.label || "",
185 value: getIOParamDisplayValue(auth, Object.assign(output, { value: values[getIOParamId(output)] || [] }), pdh)