1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { CustomStyleRulesCallback } from 'common/custom-theme';
7 import { WithStyles } from '@mui/styles';
8 import withStyles from '@mui/styles/withStyles';
9 import { ProcessIcon } from "components/icon/icon";
10 import { Process, ProcessStatus, getProcessStatus, isProcessQueued, isProcessRunning } from "store/processes/process";
11 import { SubprocessPanel } from "views/subprocess-panel/subprocess-panel";
12 import { SubprocessFilterDataProps } from "components/subprocess-filter/subprocess-filter";
13 import { MPVContainer, MPVPanelContent, MPVPanelState } from "components/multi-panel-view/multi-panel-view";
14 import { ProcessDetailsCard } from "./process-details-card";
15 import { ProcessIOCard, ProcessIOCardType, ProcessIOParameter } from "./process-io-card";
16 import { ProcessResourceCard } from "./process-resource-card";
17 import { getProcessPanelLogs, ProcessLogsPanel } from "store/process-logs-panel/process-logs-panel";
18 import { ProcessLogsCard } from "./process-log-card";
19 import { FilterOption } from "views/process-panel/process-log-form";
20 import { getInputCollectionMounts } from "store/processes/processes-actions";
21 import { WorkflowInputsData } from "models/workflow";
22 import { CommandOutputParameter } from "cwlts/mappings/v1.0/CommandOutputParameter";
23 import { AuthState } from "store/auth/auth-reducer";
24 import { ProcessCmdCard } from "./process-cmd-card";
25 import { ContainerRequestResource } from "models/container-request";
26 import { OutputDetails, NodeInstanceType } from "store/process-panel/process-panel";
27 import { NotFoundView } from 'views/not-found-panel/not-found-panel';
28 import { ArvadosTheme } from 'common/custom-theme';
29 import { useAsyncInterval } from "common/use-async-interval";
30 import { WebSocketService } from "websocket/websocket-service";
32 type CssRules = "root";
34 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
40 export interface ProcessPanelRootDataProps {
42 subprocesses: Array<Process>;
43 filters: Array<SubprocessFilterDataProps>;
44 processLogsPanel: ProcessLogsPanel;
46 inputRaw: WorkflowInputsData | null;
47 inputParams: ProcessIOParameter[] | null;
48 outputData: OutputDetails | null;
49 outputDefinitions: CommandOutputParameter[];
50 outputParams: ProcessIOParameter[] | null;
51 nodeInfo: NodeInstanceType | null;
52 usageReport: string | null;
55 export interface ProcessPanelRootActionProps {
56 onContextMenu: (event: React.MouseEvent<HTMLElement>, process: Process) => void;
57 onToggle: (status: string) => void;
58 cancelProcess: (uuid: string) => void;
59 startProcess: (uuid: string) => void;
60 resumeOnHoldWorkflow: (uuid: string) => void;
61 onLogFilterChange: (filter: FilterOption) => void;
62 navigateToLog: (uuid: string) => void;
63 onCopyToClipboard: (uuid: string) => void;
64 loadInputs: (containerRequest: ContainerRequestResource) => void;
65 loadOutputs: (containerRequest: ContainerRequestResource) => void;
66 loadNodeJson: (containerRequest: ContainerRequestResource) => void;
67 loadOutputDefinitions: (containerRequest: ContainerRequestResource) => void;
68 updateOutputParams: () => void;
69 pollProcessLogs: (processUuid: string) => Promise<void>;
70 refreshProcess: (processUuid: string) => Promise<void>;
73 export type ProcessPanelRootProps = ProcessPanelRootDataProps & ProcessPanelRootActionProps & WithStyles<CssRules>;
75 const panelsData: MPVPanelState[] = [
77 { name: "Logs", visible: true },
78 { name: "Subprocesses" },
82 { name: "Resources" },
85 export const ProcessPanelRoot = withStyles(styles)(({
99 loadOutputDefinitions,
104 }: ProcessPanelRootProps) => {
105 const outputUuid = process?.containerRequest.outputUuid;
106 const containerRequest = process?.containerRequest;
107 const inputMounts = getInputCollectionMounts(process?.containerRequest);
108 const webSocketConnected = WebSocketService.getInstance().isActive();
110 React.useEffect(() => {
111 if (containerRequest) {
112 // Load inputs from mounts or props
113 loadInputs(containerRequest);
114 // Fetch raw output (loads from props or keep)
115 loadOutputs(containerRequest);
116 // Loads output definitions from mounts into store
117 loadOutputDefinitions(containerRequest);
118 // load the assigned instance type from node.json in
119 // the log collection
120 loadNodeJson(containerRequest);
122 }, [containerRequest, loadInputs, loadOutputs, loadOutputDefinitions, loadNodeJson]);
124 const maxHeight = "100%";
126 // Trigger processing output params when raw or definitions change
127 React.useEffect(() => {
128 updateOutputParams();
129 }, [outputData, outputDefinitions, updateOutputParams]);
131 // If WebSocket not connected, poll queued/running process for status updates
133 !webSocketConnected &&
135 isProcessQueued(process)
136 || isProcessRunning(process)
137 // Status is unknown if has containerUuid but container resource not loaded
138 || getProcessStatus(process) === ProcessStatus.UNKNOWN
140 useAsyncInterval(async () => {
141 process && await refreshProcess(process.containerRequest.uuid);
142 }, shouldPoll ? 15000 : null);
146 className={props.classes.root}
148 panelStates={panelsData}
149 justifyContent="flex-start"
156 data-cy="process-details">
159 onContextMenu={event => props.onContextMenu(event, process)}
160 cancelProcess={props.cancelProcess}
161 startProcess={props.startProcess}
162 resumeOnHoldWorkflow={props.resumeOnHoldWorkflow}
169 minHeight={maxHeight}
170 maxHeight={maxHeight}
171 data-cy="process-logs">
173 onCopy={props.onCopyToClipboard}
175 lines={getProcessPanelLogs(processLogsPanel)}
177 label: processLogsPanel.selectedFilter,
178 value: processLogsPanel.selectedFilter,
180 filters={processLogsPanel.filters.map(filter => ({ label: filter, value: filter }))}
181 onLogFilterChange={props.onLogFilterChange}
182 navigateToLog={props.navigateToLog}
183 pollProcessLogs={pollProcessLogs}
190 maxHeight={maxHeight}
191 data-cy="process-children">
192 <SubprocessPanel process={process} />
198 maxHeight={maxHeight}
199 data-cy="process-outputs">
201 label={ProcessIOCardType.OUTPUT}
203 params={outputParams}
204 raw={outputData?.raw}
205 failedToLoadOutputCollection={outputData?.failedToLoadOutputCollection}
206 outputUuid={outputUuid || ""}
213 maxHeight={maxHeight}
214 data-cy="process-inputs">
216 label={ProcessIOCardType.INPUT}
228 data-cy="process-cmd">
230 onCopy={props.onCopyToClipboard}
238 data-cy="process-resources">
242 usageReport={usageReport}
249 messages={["Process not found"]}