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 { Grid, Typography } from "@mui/material";
8 import withStyles from '@mui/styles/withStyles';
9 import { Dispatch } from 'redux';
10 import { formatCost, formatDate } from "common/formatters";
11 import { resourceLabel } from "common/labels";
12 import { DetailsAttribute } from "components/details-attribute/details-attribute";
13 import { ResourceKind } from "models/resource";
14 import { CollectionName, ContainerRunTime, ResourceWithName } from "views-components/data-explorer/renderers";
15 import { getProcess, getProcessStatus, ProcessProperties } from "store/processes/process";
16 import { RootState } from "store/store";
17 import { connect } from "react-redux";
18 import { ProcessResource, MOUNT_PATH_CWL_WORKFLOW } from "models/process";
19 import { ContainerResource, ContainerState } from "models/container";
20 import { navigateToOutput, openWorkflow } from "store/process-panel/process-panel-actions";
21 import { ArvadosTheme } from "common/custom-theme";
22 import { ProcessRuntimeStatus } from "views-components/process-runtime-status/process-runtime-status";
23 import { getPropertyChip } from "views-components/resource-properties-form/property-chip";
24 import { ContainerRequestResource, ContainerRequestState } from "models/container-request";
25 import { filterResources } from "store/resources/resources";
26 import { JSONMount } from 'models/mount-types';
27 import { getCollectionUrl } from 'models/collection';
28 import { useAsyncInterval } from 'common/use-async-interval';
29 import { Link } from "react-router-dom";
30 import { getResourceUrl } from "routes/routes";
31 import WarningIcon from '@mui/icons-material/Warning';
33 type CssRules = 'link' | 'propertyTag';
35 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
38 color: theme.palette.primary.main,
44 marginRight: theme.spacing(0.5),
45 marginBottom: theme.spacing(0.5)
49 const mapStateToProps = (state: RootState, props: { request: ProcessResource, container?: ContainerResource }) => {
50 const process = getProcess(props.request.uuid)(state.resources);
52 let workflowCollection = "";
53 let workflowPath = "";
54 if (process?.containerRequest?.mounts && process.containerRequest.mounts[MOUNT_PATH_CWL_WORKFLOW]) {
55 const wf = process.containerRequest.mounts[MOUNT_PATH_CWL_WORKFLOW] as JSONMount;
57 if (wf.content["$graph"] &&
58 wf.content["$graph"].length > 0 &&
59 wf.content["$graph"][0] &&
60 wf.content["$graph"][0]["steps"] &&
61 wf.content["$graph"][0]["steps"][0]) {
63 const REGEX = /keep:([0-9a-f]{32}\+\d+)\/(.*)/;
64 const pdh = wf.content["$graph"][0]["steps"][0].run.match(REGEX);
66 workflowCollection = pdh[1];
67 workflowPath = pdh[2];
73 container: process?.container,
76 subprocesses: filterResources((resource: ContainerRequestResource) =>
77 (resource.kind === ResourceKind.CONTAINER_REQUEST &&
78 resource.requestingContainerUuid === process?.containerRequest.containerUuid)
83 interface ProcessDetailsAttributesActionProps {
84 navigateToOutput: (resource: ContainerRequestResource) => void;
85 openWorkflow: (uuid: string) => void;
88 const mapDispatchToProps = (dispatch: Dispatch): ProcessDetailsAttributesActionProps => ({
89 navigateToOutput: (resource) => dispatch<any>(navigateToOutput(resource)),
90 openWorkflow: (uuid) => dispatch<any>(openWorkflow(uuid)),
93 export const ProcessDetailsAttributes = withStyles(styles, { withTheme: true })(
94 connect(mapStateToProps, mapDispatchToProps)(
96 request: ProcessResource,
97 container?: ContainerResource,
98 subprocesses: ContainerRequestResource[],
102 hideProcessPanelRedundantFields?: boolean,
103 classes: Record<CssRules, string>
104 } & ProcessDetailsAttributesActionProps) => {
105 const containerRequest = props.request;
106 const container = props.container;
107 const subprocesses = props.subprocesses;
108 const classes = props.classes;
109 const mdSize = props.twoCol ? 6 : 12;
110 const workflowCollection = props.workflowCollection;
111 const workflowPath = props.workflowPath;
112 const filteredPropertyKeys = Object.keys(containerRequest.properties)
113 .filter(k => (typeof containerRequest.properties[k] !== 'object'));
114 const hasTotalCost = containerRequest && containerRequest.cumulativeCost > 0;
115 const totalCostNotReady = container && container.cost > 0 && container.state === "Running" && containerRequest && containerRequest.cumulativeCost === 0 && subprocesses.length > 0;
116 const resubmittedUrl = containerRequest && getResourceUrl(containerRequest.properties[ProcessProperties.FAILED_CONTAINER_RESUBMITTED]);
118 return <Grid container>
120 <ProcessRuntimeStatus runtimeStatus={container?.runtimeStatus} containerCount={containerRequest.containerCount} />
122 {!props.hideProcessPanelRedundantFields && <Grid item xs={12} md={mdSize}>
123 <DetailsAttribute label='Type' value={resourceLabel(ResourceKind.PROCESS)} />
125 {resubmittedUrl && <Grid item xs={12}>
128 This process failed but was automatically resubmitted. <Link to={resubmittedUrl}> Click here to go to the resubmitted process.</Link>
131 <Grid item xs={12} md={mdSize}>
132 <DetailsAttribute label='Container request UUID' linkToUuid={containerRequest.uuid} value={containerRequest.uuid} />
134 <Grid item xs={12} md={mdSize}>
135 <DetailsAttribute label='Docker image locator'
136 linkToUuid={containerRequest.containerImage} value={containerRequest.containerImage} />
138 <Grid item xs={12} md={mdSize}>
140 label='Owner' linkToUuid={containerRequest.ownerUuid}
141 uuidEnhancer={(uuid: string) => <ResourceWithName uuid={uuid} />} />
143 <Grid item xs={12} md={mdSize}>
144 <DetailsAttribute label='Container UUID' value={containerRequest.containerUuid} />
146 {!props.hideProcessPanelRedundantFields && <Grid item xs={12} md={mdSize}>
147 <DetailsAttribute label='Status' value={getProcessStatus({ containerRequest, container })} />
149 <Grid item xs={12} md={mdSize}>
150 <DetailsAttribute label='Created at' value={formatDate(containerRequest.createdAt)} />
152 <Grid item xs={12} md={mdSize}>
153 <DetailsAttribute label='Started at' value={container ? formatDate(container.startedAt) : "(none)"} />
155 <Grid item xs={12} md={mdSize}>
156 <DetailsAttribute label='Finished at' value={container ? formatDate(container.finishedAt) : "(none)"} />
158 <Grid item xs={12} md={mdSize}>
159 <DetailsAttribute label='Container run time'>
160 <ContainerRunTime uuid={containerRequest.uuid} />
163 {(containerRequest && containerRequest.modifiedByUserUuid) && <Grid item xs={12} md={mdSize} data-cy="process-details-attributes-modifiedby-user">
165 label='Submitted by' linkToUuid={containerRequest.modifiedByUserUuid}
166 uuidEnhancer={(uuid: string) => <ResourceWithName uuid={uuid} />} />
168 {(container && container.runtimeUserUuid && container.runtimeUserUuid !== containerRequest.modifiedByUserUuid) && <Grid item xs={12} md={mdSize} data-cy="process-details-attributes-runtime-user">
170 label='Run as' linkToUuid={container.runtimeUserUuid}
171 uuidEnhancer={(uuid: string) => <ResourceWithName uuid={uuid} />} />
173 <Grid item xs={12} md={mdSize}>
174 <DetailsAttribute label='Requesting container UUID' value={containerRequest.requestingContainerUuid || "(none)"} />
177 <DetailsAttribute label='Output collection' />
178 {containerRequest.outputUuid && <span onClick={() => props.navigateToOutput(containerRequest!)}>
179 <CollectionName className={classes.link} uuid={containerRequest.outputUuid} />
182 {container && <Grid item xs={12} md={mdSize}>
183 <DetailsAttribute label='Cost' value={
184 `${hasTotalCost ? formatCost(containerRequest.cumulativeCost) + ' total, ' : (totalCostNotReady ? 'total pending completion, ' : '')}${container.cost > 0 ? formatCost(container.cost) : 'not available'} for this container`
187 {container && workflowCollection && <Grid item xs={12} md={mdSize}>
188 <DetailsAttribute label='Workflow code' link={getCollectionUrl(workflowCollection)} value={workflowPath} />
190 {containerRequest.properties.template_uuid &&
191 <Grid item xs={12} md={mdSize}>
192 <span onClick={() => props.openWorkflow(containerRequest.properties.template_uuid)}>
193 <DetailsAttribute classValue={classes.link}
194 label='Workflow' value={containerRequest.properties.workflowName} />
197 <Grid item xs={12} md={mdSize}>
198 <DetailsAttribute label='Priority' value={containerRequest.priority} />
201 NOTE: The property list should be kept at the bottom, because it spans
202 the entire available width, without regards of the twoCol prop.
204 <Grid item xs={12} md={12}>
205 <DetailsAttribute label='Properties' />
206 {filteredPropertyKeys.length > 0
207 ? filteredPropertyKeys.map(k =>
208 Array.isArray(containerRequest.properties[k])
209 ? containerRequest.properties[k].map((v: string) =>
210 getPropertyChip(k, v, undefined, classes.propertyTag))
211 : getPropertyChip(k, containerRequest.properties[k], undefined, classes.propertyTag))
212 : <div>No properties</div>}