summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-server/src/main/webui/components/topologies/map/RackEnergyFillContainer.js
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-web/opendc-web-server/src/main/webui/components/topologies/map/RackEnergyFillContainer.js')
-rw-r--r--opendc-web/opendc-web-server/src/main/webui/components/topologies/map/RackEnergyFillContainer.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/opendc-web/opendc-web-server/src/main/webui/components/topologies/map/RackEnergyFillContainer.js b/opendc-web/opendc-web-server/src/main/webui/components/topologies/map/RackEnergyFillContainer.js
new file mode 100644
index 00000000..a1ca7426
--- /dev/null
+++ b/opendc-web/opendc-web-server/src/main/webui/components/topologies/map/RackEnergyFillContainer.js
@@ -0,0 +1,36 @@
+import React from 'react'
+import PropTypes from 'prop-types'
+import { useSelector } from 'react-redux'
+import RackFillBar from './elements/RackFillBar'
+
+function RackSpaceFillContainer({ rackId, ...props }) {
+ const fillFraction = useSelector((state) => {
+ const rack = state.topology.racks[rackId]
+ if (!rack) {
+ return 0
+ }
+
+ const { machines, cpus, gpus, memories, storages } = state.topology
+ let energyConsumptionTotal = 0
+
+ for (const machineId of rack.machines) {
+ if (!machineId) {
+ continue
+ }
+ const machine = machines[machineId]
+ machine.cpus.forEach((id) => (energyConsumptionTotal += cpus[id].energyConsumptionW))
+ machine.gpus.forEach((id) => (energyConsumptionTotal += gpus[id].energyConsumptionW))
+ machine.memories.forEach((id) => (energyConsumptionTotal += memories[id].energyConsumptionW))
+ machine.storages.forEach((id) => (energyConsumptionTotal += storages[id].energyConsumptionW))
+ }
+
+ return Math.min(1, energyConsumptionTotal / rack.powerCapacityW)
+ })
+ return <RackFillBar {...props} type="energy" fillFraction={fillFraction} />
+}
+
+RackSpaceFillContainer.propTypes = {
+ rackId: PropTypes.string.isRequired,
+}
+
+export default RackSpaceFillContainer