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';
11 export interface Process {
12 containerRequest: ContainerRequestResource;
13 container?: ContainerResource;
16 export const getProcess = (uuid: string) => (resources: ResourcesState): Process | undefined => {
17 const containerRequest = getResource<ContainerRequestResource>(uuid)(resources);
18 if (containerRequest) {
19 if (containerRequest.containerUuid) {
20 const container = getResource<ContainerResource>(containerRequest.containerUuid)(resources);
22 return { containerRequest, container };
25 return { containerRequest };
30 export const getSubprocesses = (uuid: string) => (resources: ResourcesState) => {
31 const containerRequests = filterResources(isSubprocess(uuid))(resources) as ContainerRequestResource[];
32 return containerRequests.reduce((subprocesses, { uuid }) => {
33 const process = getProcess(uuid)(resources);
35 ? [...subprocesses, process]
40 export const getProcessStatus = (process: Process) =>
42 ? process.container.state
43 : process.containerRequest.state;
45 const isSubprocess = (uuid: string) => (resource: Resource) =>
46 resource.kind === ResourceKind.CONTAINER_REQUEST
47 && (resource as ContainerRequestResource).requestingContainerUuid === uuid;