2020-09-11 06:29:07 +00:00
|
|
|
import Controller from '@ember/controller';
|
2020-09-11 06:59:58 +00:00
|
|
|
import { computed, action } from '@ember/object';
|
2020-11-05 03:22:59 +00:00
|
|
|
import { alias } from '@ember/object/computed';
|
|
|
|
import { inject as service } from '@ember/service';
|
2021-01-06 01:11:00 +00:00
|
|
|
import { tracked } from '@glimmer/tracking';
|
2020-09-11 06:29:07 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
import { reduceToLargestUnit } from 'nomad-ui/helpers/format-bytes';
|
|
|
|
|
2020-10-15 17:40:32 +00:00
|
|
|
const sumAggregator = (sum, value) => sum + (value || 0);
|
|
|
|
|
2020-09-11 06:29:07 +00:00
|
|
|
@classic
|
|
|
|
export default class TopologyControllers extends Controller {
|
2020-11-05 03:22:59 +00:00
|
|
|
@service userSettings;
|
|
|
|
|
|
|
|
@alias('userSettings.showTopoVizPollingNotice') showPollingNotice;
|
|
|
|
|
2021-01-06 01:11:00 +00:00
|
|
|
@tracked filteredNodes = null;
|
|
|
|
|
2020-10-10 22:37:18 +00:00
|
|
|
@computed('model.nodes.@each.datacenter')
|
2020-09-11 06:29:07 +00:00
|
|
|
get datacenters() {
|
|
|
|
return Array.from(new Set(this.model.nodes.mapBy('datacenter'))).compact();
|
2020-10-10 22:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('model.allocations.@each.isScheduled')
|
|
|
|
get scheduledAllocations() {
|
|
|
|
return this.model.allocations.filterBy('isScheduled');
|
2020-09-11 06:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('model.nodes.@each.resources')
|
|
|
|
get totalMemory() {
|
2020-10-15 17:40:32 +00:00
|
|
|
const mibs = this.model.nodes.mapBy('resources.memory').reduce(sumAggregator, 0);
|
2020-09-11 06:29:07 +00:00
|
|
|
return mibs * 1024 * 1024;
|
|
|
|
}
|
|
|
|
|
|
|
|
@computed('model.nodes.@each.resources')
|
|
|
|
get totalCPU() {
|
|
|
|
return this.model.nodes.mapBy('resources.cpu').reduce((sum, cpu) => sum + (cpu || 0), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@computed('totalMemory')
|
|
|
|
get totalMemoryFormatted() {
|
|
|
|
return reduceToLargestUnit(this.totalMemory)[0].toFixed(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
@computed('totalCPU')
|
|
|
|
get totalMemoryUnits() {
|
|
|
|
return reduceToLargestUnit(this.totalMemory)[1];
|
|
|
|
}
|
|
|
|
|
2020-10-13 14:53:05 +00:00
|
|
|
@computed('model.allocations.@each.allocatedResources')
|
2020-09-11 06:29:07 +00:00
|
|
|
get totalReservedMemory() {
|
2020-10-15 17:40:32 +00:00
|
|
|
const mibs = this.model.allocations.mapBy('allocatedResources.memory').reduce(sumAggregator, 0);
|
2020-09-11 06:29:07 +00:00
|
|
|
return mibs * 1024 * 1024;
|
|
|
|
}
|
|
|
|
|
2020-10-13 14:53:05 +00:00
|
|
|
@computed('model.allocations.@each.allocatedResources')
|
2020-09-11 06:29:07 +00:00
|
|
|
get totalReservedCPU() {
|
2020-10-15 17:40:32 +00:00
|
|
|
return this.model.allocations.mapBy('allocatedResources.cpu').reduce(sumAggregator, 0);
|
2020-09-11 06:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('totalMemory', 'totalReservedMemory')
|
|
|
|
get reservedMemoryPercent() {
|
2020-09-11 19:15:41 +00:00
|
|
|
if (!this.totalReservedMemory || !this.totalMemory) return 0;
|
2020-09-11 06:29:07 +00:00
|
|
|
return this.totalReservedMemory / this.totalMemory;
|
|
|
|
}
|
|
|
|
|
|
|
|
@computed('totalCPU', 'totalReservedCPU')
|
|
|
|
get reservedCPUPercent() {
|
2020-09-11 19:15:41 +00:00
|
|
|
if (!this.totalReservedCPU || !this.totalCPU) return 0;
|
2020-09-11 06:29:07 +00:00
|
|
|
return this.totalReservedCPU / this.totalCPU;
|
|
|
|
}
|
2020-09-11 06:59:58 +00:00
|
|
|
|
|
|
|
@computed('activeAllocation', 'model.allocations.@each.{taskGroupName,job}')
|
|
|
|
get siblingAllocations() {
|
|
|
|
if (!this.activeAllocation) return [];
|
|
|
|
const taskGroup = this.activeAllocation.taskGroupName;
|
|
|
|
const jobId = this.activeAllocation.belongsTo('job').id();
|
|
|
|
|
|
|
|
return this.model.allocations.filter(allocation => {
|
|
|
|
return allocation.taskGroupName === taskGroup && allocation.belongsTo('job').id() === jobId;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-29 23:46:56 +00:00
|
|
|
@computed('activeNode')
|
|
|
|
get nodeUtilization() {
|
|
|
|
const node = this.activeNode;
|
|
|
|
const [formattedMemory, memoryUnits] = reduceToLargestUnit(node.memory * 1024 * 1024);
|
2020-10-15 17:40:32 +00:00
|
|
|
const totalReservedMemory = node.allocations.mapBy('memory').reduce(sumAggregator, 0);
|
|
|
|
const totalReservedCPU = node.allocations.mapBy('cpu').reduce(sumAggregator, 0);
|
2020-09-29 23:46:56 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
totalMemoryFormatted: formattedMemory.toFixed(2),
|
|
|
|
totalMemoryUnits: memoryUnits,
|
|
|
|
|
|
|
|
totalMemory: node.memory * 1024 * 1024,
|
|
|
|
totalReservedMemory: totalReservedMemory * 1024 * 1024,
|
|
|
|
reservedMemoryPercent: totalReservedMemory / node.memory,
|
|
|
|
|
|
|
|
totalCPU: node.cpu,
|
|
|
|
totalReservedCPU,
|
|
|
|
reservedCPUPercent: totalReservedCPU / node.cpu,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-09-11 06:59:58 +00:00
|
|
|
@computed('siblingAllocations.@each.node')
|
|
|
|
get uniqueActiveAllocationNodes() {
|
|
|
|
return this.siblingAllocations.mapBy('node').uniq();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
2020-10-13 14:53:05 +00:00
|
|
|
async setAllocation(allocation) {
|
2020-09-11 06:59:58 +00:00
|
|
|
if (allocation) {
|
2020-10-13 14:53:05 +00:00
|
|
|
await allocation.reload();
|
|
|
|
await allocation.job.reload();
|
2020-09-11 06:59:58 +00:00
|
|
|
}
|
2020-10-13 14:53:05 +00:00
|
|
|
this.set('activeAllocation', allocation);
|
2020-09-11 06:59:58 +00:00
|
|
|
}
|
2020-09-29 23:46:56 +00:00
|
|
|
|
|
|
|
@action
|
|
|
|
setNode(node) {
|
|
|
|
this.set('activeNode', node);
|
|
|
|
}
|
2021-01-06 01:11:00 +00:00
|
|
|
|
|
|
|
@action
|
|
|
|
handleTopoVizDataError(errors) {
|
|
|
|
const filteredNodesError = errors.findBy('type', 'filtered-nodes');
|
|
|
|
if (filteredNodesError) {
|
|
|
|
this.filteredNodes = filteredNodesError.context;
|
|
|
|
}
|
|
|
|
}
|
2020-09-11 06:29:07 +00:00
|
|
|
}
|