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 } from "store/navigation/navigation-action";
12 import { snackbarActions } from "store/snackbar/snackbar-actions";
13 import { SnackbarKind } from "../snackbar/snackbar-actions";
14 import { loadSubprocessPanel, subprocessPanelActions } from "../subprocess-panel/subprocess-panel-actions";
15 import { initProcessLogsPanel, processLogsPanelActions } from "store/process-logs-panel/process-logs-panel-actions";
16 import { CollectionFile } from "models/collection-file";
17 import { ContainerRequestResource } from "models/container-request";
18 import { CommandOutputParameter } from "cwlts/mappings/v1.0/CommandOutputParameter";
19 import { CommandInputParameter, getIOParamId, WorkflowInputsData } from "models/workflow";
20 import { getIOParamDisplayValue, ProcessIOParameter } from "views/process-panel/process-io-card";
21 import { OutputDetails, NodeInstanceType, NodeInfo } from "./process-panel";
22 import { AuthState } from "store/auth/auth-reducer";
24 export const processPanelActions = unionize({
25 RESET_PROCESS_PANEL: ofType<{}>(),
26 SET_PROCESS_PANEL_CONTAINER_REQUEST_UUID: ofType<string>(),
27 SET_PROCESS_PANEL_FILTERS: ofType<string[]>(),
28 TOGGLE_PROCESS_PANEL_FILTER: ofType<string>(),
29 SET_INPUT_RAW: ofType<WorkflowInputsData | null>(),
30 SET_INPUT_PARAMS: ofType<ProcessIOParameter[] | null>(),
31 SET_OUTPUT_RAW: ofType<OutputDetails | null>(),
32 SET_OUTPUT_DEFINITIONS: ofType<CommandOutputParameter[]>(),
33 SET_OUTPUT_PARAMS: ofType<ProcessIOParameter[] | null>(),
34 SET_NODE_INFO: ofType<NodeInfo>(),
37 export type ProcessPanelAction = UnionOf<typeof processPanelActions>;
39 export const toggleProcessPanelFilter = processPanelActions.TOGGLE_PROCESS_PANEL_FILTER;
41 export const loadProcessPanel = (uuid: string) => async (dispatch: Dispatch, getState: () => RootState) => {
42 // Reset subprocess data explorer if navigating to new process
43 // Avoids resetting pagination when refreshing same process
44 if (getState().processPanel.containerRequestUuid !== uuid) {
45 dispatch(subprocessPanelActions.CLEAR());
47 dispatch(processPanelActions.RESET_PROCESS_PANEL());
48 dispatch(processLogsPanelActions.RESET_PROCESS_LOGS_PANEL());
49 dispatch<ProcessPanelAction>(processPanelActions.SET_PROCESS_PANEL_CONTAINER_REQUEST_UUID(uuid));
50 await dispatch<any>(loadProcess(uuid));
51 dispatch(initProcessPanelFilters);
52 dispatch<any>(initProcessLogsPanel(uuid));
53 dispatch<any>(loadSubprocessPanel());
56 export const navigateToOutput = (uuid: string) => 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: "Output collection was trashed or deleted.", hideDuration: 4000, kind: SnackbarKind.WARNING }));
65 export const loadInputs =
66 (containerRequest: ContainerRequestResource) => 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 =
72 (containerRequest: ContainerRequestResource) => async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
73 const noOutputs = { rawOutputs: {} };
75 if (!containerRequest.outputUuid) {
76 dispatch<ProcessPanelAction>(processPanelActions.SET_OUTPUT_RAW({ uuid: containerRequest.uuid, outputRaw: noOutputs }));
80 const propsOutputs = getRawOutputs(containerRequest);
81 const filesPromise = services.collectionService.files(containerRequest.outputUuid);
82 const collectionPromise = services.collectionService.get(containerRequest.outputUuid);
83 const [files, collection] = await Promise.all([filesPromise, collectionPromise]);
85 // If has propsOutput, skip fetching cwl.output.json
86 if (propsOutputs !== undefined) {
87 dispatch<ProcessPanelAction>(
88 processPanelActions.SET_OUTPUT_RAW({
89 rawOutputs: propsOutputs,
90 pdh: collection.portableDataHash,
94 // Fetch outputs from keep
95 const outputFile = files.find(file => file.name === "cwl.output.json") as CollectionFile | undefined;
96 let outputData = outputFile ? await services.collectionService.getFileContents(outputFile) : undefined;
97 if (outputData && (outputData = JSON.parse(outputData)) && collection.portableDataHash) {
98 dispatch<ProcessPanelAction>(
99 processPanelActions.SET_OUTPUT_RAW({
100 uuid: containerRequest.uuid,
101 outputRaw: { rawOutputs: outputData, pdh: collection.portableDataHash },
105 dispatch<ProcessPanelAction>(processPanelActions.SET_OUTPUT_RAW({ uuid: containerRequest.uuid, outputRaw: noOutputs }));
109 dispatch<ProcessPanelAction>(processPanelActions.SET_OUTPUT_RAW({ uuid: containerRequest.uuid, outputRaw: noOutputs }));
113 export const loadNodeJson =
114 (containerRequest: ContainerRequestResource) => async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
115 const noLog = { nodeInfo: null };
116 if (!containerRequest.logUuid) {
117 dispatch<ProcessPanelAction>(processPanelActions.SET_NODE_INFO(noLog));
121 const filesPromise = services.collectionService.files(containerRequest.logUuid);
122 const collectionPromise = services.collectionService.get(containerRequest.logUuid);
123 const [files] = await Promise.all([filesPromise, collectionPromise]);
125 // Fetch node.json from keep
126 const nodeFile = files.find(file => file.name === "node.json") as CollectionFile | undefined;
127 let nodeData = nodeFile ? await services.collectionService.getFileContents(nodeFile) : undefined;
128 if (nodeData && (nodeData = JSON.parse(nodeData))) {
129 dispatch<ProcessPanelAction>(
130 processPanelActions.SET_NODE_INFO({
131 nodeInfo: nodeData as NodeInstanceType,
135 dispatch<ProcessPanelAction>(processPanelActions.SET_NODE_INFO(noLog));
138 dispatch<ProcessPanelAction>(processPanelActions.SET_NODE_INFO(noLog));
142 export const loadOutputDefinitions =
143 (containerRequest: ContainerRequestResource) => async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
144 if (containerRequest && containerRequest.mounts) {
145 dispatch<ProcessPanelAction>(processPanelActions.SET_OUTPUT_DEFINITIONS(getOutputParameters(containerRequest)));
149 export const updateOutputParams = () => async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
150 const outputDefinitions = getState().processPanel.outputDefinitions;
151 const outputRaw = getState().processPanel.outputRaw;
153 if (outputRaw && outputRaw.rawOutputs) {
154 dispatch<ProcessPanelAction>(
155 processPanelActions.SET_OUTPUT_PARAMS(formatOutputData(outputDefinitions, outputRaw.rawOutputs, outputRaw.pdh, getState().auth))
160 export const openWorkflow = (uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
161 dispatch<any>(navigateTo(uuid));
164 export const initProcessPanelFilters = processPanelActions.SET_PROCESS_PANEL_FILTERS([
165 ProcessStatus.QUEUED,
166 ProcessStatus.COMPLETED,
167 ProcessStatus.FAILED,
168 ProcessStatus.RUNNING,
169 ProcessStatus.ONHOLD,
170 ProcessStatus.FAILING,
171 ProcessStatus.WARNING,
172 ProcessStatus.CANCELLED,
175 export const formatInputData = (inputs: CommandInputParameter[], auth: AuthState): ProcessIOParameter[] => {
176 return inputs.map(input => {
178 id: getIOParamId(input),
179 label: input.label || "",
180 value: getIOParamDisplayValue(auth, input),
185 export const formatOutputData = (
186 definitions: CommandOutputParameter[],
188 pdh: string | undefined,
190 ): ProcessIOParameter[] => {
191 return definitions.map(output => {
193 id: getIOParamId(output),
194 label: output.label || "",
195 value: getIOParamDisplayValue(auth, Object.assign(output, { value: values[getIOParamId(output)] || [] }), pdh),