1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
18 } from '@material-ui/core';
19 import { ArvadosTheme } from 'common/custom-theme';
26 } from 'components/icon/icon';
27 import { MPVPanelProps } from 'components/multi-panel-view/multi-panel-view';
28 import { connect } from 'react-redux';
29 import { Process } from 'store/processes/process';
30 import { NodeInstanceType } from 'store/process-panel/process-panel';
31 import { DetailsAttribute } from "components/details-attribute/details-attribute";
32 import { formatFileSize } from "common/formatters";
33 import { MountKind } from 'models/mount-types';
35 interface ProcessResourceCardDataProps {
37 nodeInfo: NodeInstanceType | null;
38 usageReport: string | null;
41 type CssRules = "card" | "header" | "title" | "avatar" | "iconHeader" | "content" | "sectionH3" | "reportButton";
43 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
51 paddingTop: theme.spacing.unit * 0.5
54 paddingTop: theme.spacing.unit * 0.5
58 color: theme.customs.colors.greyL,
62 maxHeight: `calc(100% - ${theme.spacing.unit * 7.5}px)`,
67 color: theme.customs.colors.greyD,
68 fontSize: "0.8125rem",
69 textTransform: "uppercase",
75 type ProcessResourceCardProps = ProcessResourceCardDataProps & WithStyles<CssRules> & MPVPanelProps;
77 export const ProcessResourceCard = withStyles(styles)(connect()(
78 ({ classes, nodeInfo, usageReport, doHidePanel, doMaximizePanel, doUnMaximizePanel, panelMaximized, panelName, process, }: ProcessResourceCardProps) => {
80 if (process.container?.mounts) {
81 for (const mnt in process.container.mounts) {
82 const mp = process.container.mounts[mnt];
83 if (mp.kind === MountKind.TEMPORARY_DIRECTORY) {
84 diskRequest += mp.capacity;
89 return <Card className={classes.card} data-cy="process-resources-card">
91 className={classes.header}
93 content: classes.title,
94 avatar: classes.avatar,
96 avatar={<ResourceIcon className={classes.iconHeader} />}
98 <Typography noWrap variant='h6' color='inherit'>
104 {usageReport && <Link href={usageReport} className={classes.reportButton} target="_blank"><ShowChartIcon /> Resource usage report</Link>}
105 {doUnMaximizePanel && panelMaximized &&
106 <Tooltip title={`Unmaximize ${panelName || 'panel'}`} disableFocusListener>
107 <IconButton onClick={doUnMaximizePanel}><UnMaximizeIcon /></IconButton>
109 {doMaximizePanel && !panelMaximized &&
110 <Tooltip title={`Maximize ${panelName || 'panel'}`} disableFocusListener>
111 <IconButton onClick={doMaximizePanel}><MaximizeIcon /></IconButton>
114 <Tooltip title={`Close ${panelName || 'panel'}`} disableFocusListener>
115 <IconButton disabled={panelMaximized} onClick={doHidePanel}><CloseIcon /></IconButton>
119 <CardContent className={classes.content}>
122 <h3 className={classes.sectionH3}>Requested Resources</h3>
125 <DetailsAttribute label="Cores" value={process.container?.runtimeConstraints.vcpus} />
128 <DetailsAttribute label="RAM*" value={formatFileSize(process.container?.runtimeConstraints.ram)} />
131 <DetailsAttribute label="Disk" value={formatFileSize(diskRequest)} />
134 {process.container?.runtimeConstraints.cuda &&
135 process.container?.runtimeConstraints.cuda.device_count > 0 ?
138 <DetailsAttribute label="CUDA devices" value={process.container?.runtimeConstraints.cuda.device_count} />
141 <DetailsAttribute label="CUDA driver version" value={process.container?.runtimeConstraints.cuda.driver_version} />
144 <DetailsAttribute label="CUDA hardware capability" value={process.container?.runtimeConstraints.cuda.hardware_capability} />
148 {process.container?.runtimeConstraints.keep_cache_ram &&
149 process.container?.runtimeConstraints.keep_cache_ram > 0 ?
151 <DetailsAttribute label="Keep cache (RAM)" value={formatFileSize(process.container?.runtimeConstraints.keep_cache_ram)} />
154 {process.container?.runtimeConstraints.keep_cache_disk &&
155 process.container?.runtimeConstraints.keep_cache_disk > 0 ?
157 <DetailsAttribute label="Keep cache (disk)" value={formatFileSize(process.container?.runtimeConstraints.keep_cache_disk)} />
160 {process.container?.runtimeConstraints.API ? <Grid item xs={12}>
161 <DetailsAttribute label="API access" value={process.container?.runtimeConstraints.API.toString()} />
169 <h3 className={classes.sectionH3}>Assigned Instance Type</h3>
170 {nodeInfo === null ? <Grid item xs={8}>
171 No instance type recorded
176 <DetailsAttribute label="Cores" value={nodeInfo.VCPUs} />
180 <DetailsAttribute label="Provider type" value={nodeInfo.ProviderType} />
184 <DetailsAttribute label="RAM" value={formatFileSize(nodeInfo.RAM)} />
188 <DetailsAttribute label="Price" value={"$" + nodeInfo.Price.toString()} />
192 <DetailsAttribute label="Disk" value={formatFileSize(nodeInfo.IncludedScratch + nodeInfo.AddedScratch)} />
196 <DetailsAttribute label="Preemptible" value={nodeInfo.Preemptible.toString()} />
199 {nodeInfo.CUDA && nodeInfo.CUDA.DeviceCount > 0 &&
202 <DetailsAttribute label="CUDA devices" value={nodeInfo.CUDA.DeviceCount} />
209 <DetailsAttribute label="CUDA driver version" value={nodeInfo.CUDA.DriverVersion} />
216 <DetailsAttribute label="CUDA hardware capability" value={nodeInfo.CUDA.HardwareCapability} />
223 <Typography>* RAM available to the program is limited to Requested RAM, not Instance RAM</Typography>