Skip to content

Commit 2fcb5e9

Browse files
authored
Merge branch 'master' into issue-9490
2 parents 7c4674e + fce8bd7 commit 2fcb5e9

File tree

3 files changed

+106
-29
lines changed

3 files changed

+106
-29
lines changed

src/routes/host/HostList.js

+42-28
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,19 @@ import DiskList from './DiskList'
88
import HostActions from './HostActions'
99
import InstanceManagerComponent from './components/InstanceManagerComponent'
1010
import { nodeStatusColorMap } from '../../utils/status'
11-
import { byteToGi, getStorageProgressStatus } from './helper/index'
11+
import {
12+
byteToGi,
13+
getStorageProgressStatus,
14+
computeTotalAllocated,
15+
computeAllocated,
16+
computeBackingImageAllocated,
17+
computeReplicaAllocated,
18+
computeUsagePercentage,
19+
computeTotalUsed,
20+
computeUsed,
21+
computeSize,
22+
computeReserved
23+
} from './helper/index'
1224
import { formatMib } from '../../utils/formatter'
1325
import { pagination } from '../../utils/page'
1426
import { ModalBlur } from '../../components'
@@ -195,26 +207,6 @@ class List extends React.Component {
195207
deleteHost,
196208
}
197209

198-
const computeTotalAllocated = (record) => {
199-
const max = Object.values(record.disks).reduce((total, item) => total + item.storageMaximum, 0)
200-
const reserved = Object.values(record.disks).reduce((total, item) => total + item.storageReserved, 0)
201-
return ((max - reserved) * storageOverProvisioningPercentage) / 100
202-
}
203-
const computeAllocated = (record) => {
204-
return Object.values(record.disks).reduce((total, item) => total + item.storageScheduled, 0)
205-
}
206-
const coumputeTotalUsed = (record) => {
207-
return Object.values(record.disks).reduce((total, item) => total + item.storageMaximum, 0)
208-
}
209-
const computeUsed = (record) => {
210-
return Object.values(record.disks).reduce((total, item) => total + (item.storageMaximum - item.storageAvailable), 0)
211-
}
212-
const computeSize = (record) => {
213-
return Object.values(record.disks).reduce((total, item) => total + (item.storageMaximum - item.storageReserved), 0)
214-
}
215-
const computeReserved = (record) => {
216-
return Object.values(record.disks).reduce((total, item) => total + item.storageReserved, 0)
217-
}
218210
const columns = [
219211
{
220212
title: <span style={{ display: 'inline-block', padding: '0 0 0 30px' }}>Status</span>,
@@ -289,13 +281,34 @@ class List extends React.Component {
289281
sorter: (a, b) => computeAllocated(a) - computeAllocated(b),
290282
render: (text, record) => {
291283
const allocated = computeAllocated(record)
292-
const total = computeTotalAllocated(record)
293-
const p = total === 0 ? 0 : Math.round((allocated / total) * 100)
284+
const total = computeTotalAllocated(record, storageOverProvisioningPercentage)
285+
const backingImageAllocated = computeBackingImageAllocated(record)
286+
const replicaAllocated = computeReplicaAllocated(record)
287+
const percent = computeUsagePercentage(allocated, total)
288+
const backingImagePercent = computeUsagePercentage(backingImageAllocated, total)
289+
const status = getStorageProgressStatus(minimalSchedulingQuotaWarning, percent)
290+
291+
const renderTooltipContent = () => (
292+
<div className={styles.allocatedTooltip}>
293+
<span>Replica Size: {byteToGi(replicaAllocated)} Gi</span>
294+
<span>Backing Image Size: {byteToGi(backingImageAllocated)} Gi</span>
295+
<span>Total Usage: {percent}%</span>
296+
</div>
297+
)
298+
const tooltipContent = renderTooltipContent()
299+
294300
return (
295301
<div>
296302
<div>
297-
<Tooltip title={`${p}%`}>
298-
<Progress strokeWidth={14} status={getStorageProgressStatus(minimalSchedulingQuotaWarning, p)} percent={p > 100 ? 100 : p} showInfo={false} />
303+
<Tooltip title={tooltipContent}>
304+
<Progress
305+
strokeWidth={14}
306+
status={status}
307+
percent={percent}
308+
successPercent={backingImagePercent}
309+
showInfo={false}
310+
className={styles.progress}
311+
/>
299312
</Tooltip>
300313
</div>
301314
<div className={styles.secondLabel}>
@@ -312,12 +325,13 @@ class List extends React.Component {
312325
sorter: (a, b) => computeUsed(a) - computeUsed(b),
313326
render: (text, record) => {
314327
const used = computeUsed(record)
315-
const total = coumputeTotalUsed(record)
316-
const p = total === 0 ? 0 : Math.round((used / total) * 100)
328+
const total = computeTotalUsed(record)
329+
const p = computeUsagePercentage(used, total)
330+
317331
return (
318332
<div>
319333
<div>
320-
<Tooltip title={`${p}%`}>
334+
<Tooltip title={`Total usage: ${p}%`}>
321335
<Progress strokeWidth={14} status={getStorageProgressStatus(minimalSchedulingQuotaWarning, p)} percent={p > 100 ? 100 : p} showInfo={false} />
322336
</Tooltip>
323337
</div>

src/routes/host/HostList.less

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
color: #27ae60;
33
}
44
.status, .name, .allocated, .replicas, .used, .size {
5-
text-align: center !important;
5+
text-align: center !important;
66
}
77
.allowScheduling {
88
text-align: right !important;
@@ -21,3 +21,15 @@ a {
2121
background-color: #27AE5F !important;
2222
}
2323
}
24+
.allocatedTooltip {
25+
display: flex;
26+
flex-direction: column;
27+
}
28+
29+
.progress {
30+
:global {
31+
.ant-progress-success-bg {
32+
background: #219653; // darken(#27AE5F, 10%)
33+
}
34+
}
35+
}

src/routes/host/helper/index.js

+51
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,54 @@ export function getStorageProgressStatus(minimalSchedulingQuotaWarning, percent)
2525
}
2626
return 'success'
2727
}
28+
29+
export const computeTotalAllocated = (record, storageOverProvisioningPercentage) => {
30+
const max = Object.values(record.disks).reduce((total, item) => total + item.storageMaximum, 0)
31+
const reserved = Object.values(record.disks).reduce((total, item) => total + item.storageReserved, 0)
32+
return ((max - reserved) * storageOverProvisioningPercentage) / 100
33+
}
34+
35+
export const computeAllocated = (record) => {
36+
return Object.values(record.disks).reduce((total, item) => total + item.storageScheduled, 0)
37+
}
38+
39+
export const computeTotalSize = (record, property) => {
40+
if (!record?.disks) return 0
41+
return Object.keys(record.disks).reduce((totalSize, key) => {
42+
const disk = record.disks[key]
43+
44+
if (!disk) return totalSize
45+
if (disk[property]) {
46+
totalSize += Object.values(disk[property]).reduce((acc, size) => acc + size, 0)
47+
}
48+
return totalSize
49+
}, 0)
50+
}
51+
52+
export const computeBackingImageAllocated = (record) => {
53+
return computeTotalSize(record, 'scheduledBackingImage')
54+
}
55+
56+
export const computeReplicaAllocated = (record) => {
57+
return computeTotalSize(record, 'scheduledReplica')
58+
}
59+
60+
export const computeUsagePercentage = (allocated, total) => {
61+
return total > 0 ? Math.round((allocated / total) * 100) : 0
62+
}
63+
64+
export const computeTotalUsed = (record) => {
65+
return Object.values(record.disks).reduce((total, item) => total + item.storageMaximum, 0)
66+
}
67+
68+
export const computeUsed = (record) => {
69+
return Object.values(record.disks).reduce((total, item) => total + (item.storageMaximum - item.storageAvailable), 0)
70+
}
71+
72+
export const computeSize = (record) => {
73+
return Object.values(record.disks).reduce((total, item) => total + (item.storageMaximum - item.storageReserved), 0)
74+
}
75+
76+
export const computeReserved = (record) => {
77+
return Object.values(record.disks).reduce((total, item) => total + item.storageReserved, 0)
78+
}

0 commit comments

Comments
 (0)