-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor out the common sum aggregator used in the topology controller
- Loading branch information
1 parent
2cf4b5d
commit 0d920ae
Showing
1 changed file
with
7 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ import { computed, action } from '@ember/object'; | |
import classic from 'ember-classic-decorator'; | ||
import { reduceToLargestUnit } from 'nomad-ui/helpers/format-bytes'; | ||
|
||
const sumAggregator = (sum, value) => sum + (value || 0); | ||
|
||
@classic | ||
export default class TopologyControllers extends Controller { | ||
@computed('[email protected]') | ||
|
@@ -17,9 +19,7 @@ export default class TopologyControllers extends Controller { | |
|
||
@computed('[email protected]') | ||
get totalMemory() { | ||
const mibs = this.model.nodes | ||
.mapBy('resources.memory') | ||
.reduce((sum, memory) => sum + (memory || 0), 0); | ||
const mibs = this.model.nodes.mapBy('resources.memory').reduce(sumAggregator, 0); | ||
return mibs * 1024 * 1024; | ||
} | ||
|
||
|
@@ -40,17 +40,13 @@ export default class TopologyControllers extends Controller { | |
|
||
@computed('[email protected]') | ||
get totalReservedMemory() { | ||
const mibs = this.model.allocations | ||
.mapBy('allocatedResources.memory') | ||
.reduce((sum, memory) => sum + (memory || 0), 0); | ||
const mibs = this.model.allocations.mapBy('allocatedResources.memory').reduce(sumAggregator, 0); | ||
return mibs * 1024 * 1024; | ||
} | ||
|
||
@computed('[email protected]') | ||
get totalReservedCPU() { | ||
return this.model.allocations | ||
.mapBy('allocatedResources.cpu') | ||
.reduce((sum, cpu) => sum + (cpu || 0), 0); | ||
return this.model.allocations.mapBy('allocatedResources.cpu').reduce(sumAggregator, 0); | ||
} | ||
|
||
@computed('totalMemory', 'totalReservedMemory') | ||
|
@@ -80,12 +76,8 @@ export default class TopologyControllers extends Controller { | |
get nodeUtilization() { | ||
const node = this.activeNode; | ||
const [formattedMemory, memoryUnits] = reduceToLargestUnit(node.memory * 1024 * 1024); | ||
const totalReservedMemory = node.allocations | ||
.mapBy('memory') | ||
.reduce((sum, memory) => sum + (memory || 0), 0); | ||
const totalReservedCPU = node.allocations | ||
.mapBy('cpu') | ||
.reduce((sum, cpu) => sum + (cpu || 0), 0); | ||
const totalReservedMemory = node.allocations.mapBy('memory').reduce(sumAggregator, 0); | ||
const totalReservedCPU = node.allocations.mapBy('cpu').reduce(sumAggregator, 0); | ||
|
||
return { | ||
totalMemoryFormatted: formattedMemory.toFixed(2), | ||
|