1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { Grid, StyleRulesCallback, withStyles, Typography } from "@material-ui/core";
7 import { Dispatch } from 'redux';
8 import { formatCost, formatDate } from "common/formatters";
9 import { resourceLabel } from "common/labels";
10 import { DetailsAttribute } from "components/details-attribute/details-attribute";
11 import { ResourceKind } from "models/resource";
12 import { CollectionName, ContainerRunTime, ResourceWithName } from "views-components/data-explorer/renderers";
13 import { Process, getProcess, getProcessStatus, ProcessProperties } from "store/processes/process";
14 import { RootState } from "store/store";
15 import { connect } from "react-redux";
16 import { ProcessResource, MOUNT_PATH_CWL_WORKFLOW } from "models/process";
17 import { ContainerResource, ContainerState } from "models/container";
18 import { navigateToOutput, openWorkflow, loadContainerStatus } from "store/process-panel/process-panel-actions";
19 import { ArvadosTheme } from "common/custom-theme";
20 import { ProcessRuntimeStatus } from "views-components/process-runtime-status/process-runtime-status";
21 import { getPropertyChip } from "views-components/resource-properties-form/property-chip";
22 import { ContainerRequestResource, ContainerRequestState } from "models/container-request";
23 import { filterResources } from "store/resources/resources";
24 import { JSONMount } from 'models/mount-types';
25 import { getCollectionUrl } from 'models/collection';
26 import { useAsyncInterval } from 'common/use-async-interval';
27 import { Link } from "react-router-dom";
28 import { getResourceUrl } from "routes/routes";
29 import WarningIcon from '@material-ui/icons/Warning';
31 type CssRules = 'link' | 'propertyTag';
33 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
36 color: theme.palette.primary.main,
42 marginRight: theme.spacing.unit / 2,
43 marginBottom: theme.spacing.unit / 2
47 const mapStateToProps = (state: RootState, props: { request: ProcessResource }) => {
48 const process = getProcess(props.request.uuid)(state.resources);
50 let workflowCollection = "";
51 let workflowPath = "";
52 let schedulingStatus = "";
53 if (process?.containerRequest?.mounts && process.containerRequest.mounts[MOUNT_PATH_CWL_WORKFLOW]) {
54 const wf = process.containerRequest.mounts[MOUNT_PATH_CWL_WORKFLOW] as JSONMount;
56 if (process?.container &&
57 state.processPanel.containerStatus?.uuid === process?.container?.uuid)
59 schedulingStatus = state.processPanel.containerStatus.schedulingStatus;
62 if (wf.content["$graph"] &&
63 wf.content["$graph"].length > 0 &&
64 wf.content["$graph"][0] &&
65 wf.content["$graph"][0]["steps"] &&
66 wf.content["$graph"][0]["steps"][0]) {
68 const REGEX = /keep:([0-9a-f]{32}\+\d+)\/(.*)/;
69 const pdh = wf.content["$graph"][0]["steps"][0].run.match(REGEX);
71 workflowCollection = pdh[1];
72 workflowPath = pdh[2];
78 container: process?.container,
82 subprocesses: filterResources((resource: ContainerRequestResource) =>
83 (resource.kind === ResourceKind.CONTAINER_REQUEST &&
84 resource.requestingContainerUuid === process?.containerRequest.containerUuid)
89 interface ProcessDetailsAttributesActionProps {
90 navigateToOutput: (resource: ContainerRequestResource) => void;
91 openWorkflow: (uuid: string) => void;
92 pollSchedulingStatus: (uuid: string) => void;
95 const mapDispatchToProps = (dispatch: Dispatch): ProcessDetailsAttributesActionProps => ({
96 navigateToOutput: (resource) => dispatch<any>(navigateToOutput(resource)),
97 openWorkflow: (uuid) => dispatch<any>(openWorkflow(uuid)),
98 pollSchedulingStatus: (uuid) => dispatch<any>(loadContainerStatus(uuid)),
101 const isProcessScheduling = (container?: ContainerResource): boolean => (
102 container?.state === ContainerState.QUEUED || container?.state === ContainerState.LOCKED
105 export const ProcessDetailsAttributes = withStyles(styles, { withTheme: true })(
106 connect(mapStateToProps, mapDispatchToProps)(
108 request: ProcessResource,
109 container?: ContainerResource,
110 subprocesses: ContainerRequestResource[],
115 hideProcessPanelRedundantFields?: boolean,
116 pollSchedulingStatus: (processUuid: string) => Promise<void>,
117 classes: Record<CssRules, string>
118 } & ProcessDetailsAttributesActionProps) => {
119 const containerRequest = props.request;
120 const container = props.container;
121 const subprocesses = props.subprocesses;
122 const classes = props.classes;
123 const mdSize = props.twoCol ? 6 : 12;
124 const workflowCollection = props.workflowCollection;
125 const workflowPath = props.workflowPath;
126 const filteredPropertyKeys = Object.keys(containerRequest.properties)
127 .filter(k => (typeof containerRequest.properties[k] !== 'object'));
128 const hasTotalCost = containerRequest && containerRequest.cumulativeCost > 0;
129 const totalCostNotReady = container && container.cost > 0 && container.state === "Running" && containerRequest && containerRequest.cumulativeCost === 0 && subprocesses.length > 0;
130 let schedulingStatus = props.schedulingStatus;
131 const resubmittedUrl = containerRequest && getResourceUrl(containerRequest.properties[ProcessProperties.FAILED_CONTAINER_RESUBMITTED]);
133 useAsyncInterval(() => (
134 props.pollSchedulingStatus(containerRequest.uuid)
135 ), isProcessScheduling(container) ? 5000 : null);
137 if (containerRequest.state == ContainerRequestState.UNCOMMITTED) {
138 schedulingStatus = "In draft state, not ready to run";
141 return <Grid container>
143 <ProcessRuntimeStatus runtimeStatus={container?.runtimeStatus} containerCount={containerRequest.containerCount} schedulingStatus={schedulingStatus} />
145 {!props.hideProcessPanelRedundantFields && <Grid item xs={12} md={mdSize}>
146 <DetailsAttribute label='Type' value={resourceLabel(ResourceKind.PROCESS)} />
148 {resubmittedUrl && <Grid item xs={12}>
151 This process failed but was automatically resubmitted. <Link to={resubmittedUrl}> Click here to go to the resubmitted process.</Link>
154 <Grid item xs={12} md={mdSize}>
155 <DetailsAttribute label='Container request UUID' linkToUuid={containerRequest.uuid} value={containerRequest.uuid} />
157 <Grid item xs={12} md={mdSize}>
158 <DetailsAttribute label='Docker image locator'
159 linkToUuid={containerRequest.containerImage} value={containerRequest.containerImage} />
161 <Grid item xs={12} md={mdSize}>
163 label='Owner' linkToUuid={containerRequest.ownerUuid}
164 uuidEnhancer={(uuid: string) => <ResourceWithName uuid={uuid} />} />
166 <Grid item xs={12} md={mdSize}>
167 <DetailsAttribute label='Container UUID' value={containerRequest.containerUuid} />
169 {!props.hideProcessPanelRedundantFields && <Grid item xs={12} md={mdSize}>
170 <DetailsAttribute label='Status' value={getProcessStatus({ containerRequest, container })} />
172 <Grid item xs={12} md={mdSize}>
173 <DetailsAttribute label='Created at' value={formatDate(containerRequest.createdAt)} />
175 <Grid item xs={12} md={mdSize}>
176 <DetailsAttribute label='Started at' value={container ? formatDate(container.startedAt) : "(none)"} />
178 <Grid item xs={12} md={mdSize}>
179 <DetailsAttribute label='Finished at' value={container ? formatDate(container.finishedAt) : "(none)"} />
181 <Grid item xs={12} md={mdSize}>
182 <DetailsAttribute label='Container run time'>
183 <ContainerRunTime uuid={containerRequest.uuid} />
186 {(containerRequest && containerRequest.modifiedByUserUuid) && <Grid item xs={12} md={mdSize} data-cy="process-details-attributes-modifiedby-user">
188 label='Submitted by' linkToUuid={containerRequest.modifiedByUserUuid}
189 uuidEnhancer={(uuid: string) => <ResourceWithName uuid={uuid} />} />
191 {(container && container.runtimeUserUuid && container.runtimeUserUuid !== containerRequest.modifiedByUserUuid) && <Grid item xs={12} md={mdSize} data-cy="process-details-attributes-runtime-user">
193 label='Run as' linkToUuid={container.runtimeUserUuid}
194 uuidEnhancer={(uuid: string) => <ResourceWithName uuid={uuid} />} />
196 <Grid item xs={12} md={mdSize}>
197 <DetailsAttribute label='Requesting container UUID' value={containerRequest.requestingContainerUuid || "(none)"} />
200 <DetailsAttribute label='Output collection' />
201 {containerRequest.outputUuid && <span onClick={() => props.navigateToOutput(containerRequest!)}>
202 <CollectionName className={classes.link} uuid={containerRequest.outputUuid} />
205 {container && <Grid item xs={12} md={mdSize}>
206 <DetailsAttribute label='Cost' value={
207 `${hasTotalCost ? formatCost(containerRequest.cumulativeCost) + ' total, ' : (totalCostNotReady ? 'total pending completion, ' : '')}${container.cost > 0 ? formatCost(container.cost) : 'not available'} for this container`
210 {container && workflowCollection && <Grid item xs={12} md={mdSize}>
211 <DetailsAttribute label='Workflow code' link={getCollectionUrl(workflowCollection)} value={workflowPath} />
213 {containerRequest.properties.template_uuid &&
214 <Grid item xs={12} md={mdSize}>
215 <span onClick={() => props.openWorkflow(containerRequest.properties.template_uuid)}>
216 <DetailsAttribute classValue={classes.link}
217 label='Workflow' value={containerRequest.properties.workflowName} />
220 <Grid item xs={12} md={mdSize}>
221 <DetailsAttribute label='Priority' value={containerRequest.priority} />
224 NOTE: The property list should be kept at the bottom, because it spans
225 the entire available width, without regards of the twoCol prop.
227 <Grid item xs={12} md={12}>
228 <DetailsAttribute label='Properties' />
229 {filteredPropertyKeys.length > 0
230 ? filteredPropertyKeys.map(k =>
231 Array.isArray(containerRequest.properties[k])
232 ? containerRequest.properties[k].map((v: string) =>
233 getPropertyChip(k, v, undefined, classes.propertyTag))
234 : getPropertyChip(k, containerRequest.properties[k], undefined, classes.propertyTag))
235 : <div>No properties</div>}