1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { ContainerRequestResource } from '../../models/container-request';
6 import { ContainerResource } from '../../models/container';
7 import { ResourcesState, getResource } from '~/store/resources/resources';
8 import { filterResources } from '../resources/resources';
9 import { ResourceKind, Resource } from '~/models/resource';
10 import { getTimeDiff } from '~/common/formatters';
11 import { SubprocessesStatus } from '~/views/process-panel/process-subprocesses-card';
12 import { ArvadosTheme } from '~/common/custom-theme';
14 export interface Process {
15 containerRequest: ContainerRequestResource;
16 container?: ContainerResource;
19 export const getProcess = (uuid: string) => (resources: ResourcesState): Process | undefined => {
20 const containerRequest = getResource<ContainerRequestResource>(uuid)(resources);
21 if (containerRequest) {
22 if (containerRequest.containerUuid) {
23 const container = getResource<ContainerResource>(containerRequest.containerUuid)(resources);
25 return { containerRequest, container };
28 return { containerRequest };
33 export const getSubprocesses = (uuid: string) => (resources: ResourcesState) => {
34 const process = getProcess(uuid)(resources);
35 if (process && process.container) {
36 const containerRequests = filterResources(isSubprocess(process.container.uuid))(resources) as ContainerRequestResource[];
37 return containerRequests.reduce((subprocesses, { uuid }) => {
38 const process = getProcess(uuid)(resources);
40 ? [...subprocesses, process]
47 export const getProcessRuntime = ({ container }: Process) =>
49 ? getTimeDiff(container.finishedAt || '', container.startedAt || '')
52 export const getProcessStatusColor = (status: string, { customs }: ArvadosTheme) => {
54 case SubprocessesStatus.COMPLETED:
55 return customs.colors.green700;
56 case SubprocessesStatus.CANCELED:
57 return customs.colors.red900;
58 case SubprocessesStatus.QUEUED:
59 return customs.colors.grey500;
60 case SubprocessesStatus.FAILED:
61 return customs.colors.red900;
62 case SubprocessesStatus.ACTIVE:
63 return customs.colors.blue500;
65 return customs.colors.grey500;
69 export const getProcessStatus = (process: Process) =>
71 ? process.container.state
72 : process.containerRequest.state;
74 const isSubprocess = (containerUuid: string) => (resource: Resource) =>
75 resource.kind === ResourceKind.CONTAINER_REQUEST
76 && (resource as ContainerRequestResource).requestingContainerUuid === containerUuid;