1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { ContainerRequestResource, ContainerRequestState } from '../../models/container-request';
6 import { ContainerResource, ContainerState } from '../../models/container';
7 import { ResourcesState, getResource } from '~/store/resources/resources';
8 import { filterResources } from '../resources/resources';
9 import { ResourceKind, Resource, extractUuidKind } from '~/models/resource';
10 import { getTimeDiff } from '~/common/formatters';
11 import { ArvadosTheme } from '~/common/custom-theme';
13 export interface Process {
14 containerRequest: ContainerRequestResource;
15 container?: ContainerResource;
18 export enum ProcessStatus {
19 CANCELLED = 'Cancelled',
20 COMPLETED = 'Completed',
29 export const getProcess = (uuid: string) => (resources: ResourcesState): Process | undefined => {
30 if (extractUuidKind(uuid) === ResourceKind.CONTAINER_REQUEST) {
31 const containerRequest = getResource<ContainerRequestResource>(uuid)(resources);
32 if (containerRequest) {
33 if (containerRequest.containerUuid) {
34 const container = getResource<ContainerResource>(containerRequest.containerUuid)(resources);
36 return { containerRequest, container };
39 return { containerRequest };
45 export const getSubprocesses = (uuid: string) => (resources: ResourcesState) => {
46 const process = getProcess(uuid)(resources);
47 if (process && process.container) {
48 const containerRequests = filterResources(isSubprocess(process.container.uuid))(resources) as ContainerRequestResource[];
49 return containerRequests.reduce((subprocesses, { uuid }) => {
50 const process = getProcess(uuid)(resources);
52 ? [...subprocesses, process]
59 export const getProcessRuntime = ({ container }: Process) =>
61 ? getTimeDiff(container.finishedAt || '', container.startedAt || '')
64 export const getProcessStatusColor = (status: string, { customs, palette }: ArvadosTheme) => {
66 case ProcessStatus.RUNNING:
67 return customs.colors.blue500;
68 case ProcessStatus.COMPLETED:
69 return customs.colors.green700;
70 case ProcessStatus.CANCELLED:
71 case ProcessStatus.FAILED:
72 return customs.colors.red900;
74 return palette.grey["500"];
78 export const getProcessStatus = ({ containerRequest, container }: Process): ProcessStatus => {
80 case containerRequest.state === ContainerRequestState.UNCOMMITTED:
81 return ProcessStatus.DRAFT;
83 case containerRequest.priority === 0:
84 case container && container.state === ContainerState.CANCELLED:
85 return ProcessStatus.CANCELLED;
87 case container && container.state === ContainerState.QUEUED:
88 return ProcessStatus.QUEUED;
90 case container && container.state === ContainerState.LOCKED:
91 return ProcessStatus.LOCKED;
93 case container && container.state === ContainerState.RUNNING:
94 return ProcessStatus.RUNNING;
96 case container && container.state === ContainerState.COMPLETE && container.exitCode === 0:
97 return ProcessStatus.COMPLETED;
99 case container && container.state === ContainerState.COMPLETE && container.exitCode !== 0:
100 return ProcessStatus.FAILED;
103 return ProcessStatus.UNKNOWN;
107 const isSubprocess = (containerUuid: string) => (resource: Resource) =>
108 resource.kind === ResourceKind.CONTAINER_REQUEST
109 && (resource as ContainerRequestResource).requestingContainerUuid === containerUuid;