2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2022-10-19 19:00:35 +00:00
|
|
|
/* eslint-disable ember/no-incorrect-calls-with-inline-anonymous-functions */
|
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';
|
2021-03-30 05:21:00 +00:00
|
|
|
import { reduceBytes, reduceHertz } from 'nomad-ui/utils/units';
|
2022-10-19 19:00:35 +00:00
|
|
|
import {
|
|
|
|
serialize,
|
|
|
|
deserializedQueryParam as selection,
|
|
|
|
} from 'nomad-ui/utils/qp-serialize';
|
|
|
|
import { scheduleOnce } from '@ember/runloop';
|
|
|
|
import intersection from 'lodash.intersection';
|
|
|
|
import Searchable from 'nomad-ui/mixins/searchable';
|
2020-09-11 06:29:07 +00:00
|
|
|
|
2020-10-15 17:40:32 +00:00
|
|
|
const sumAggregator = (sum, value) => sum + (value || 0);
|
2021-03-30 05:21:00 +00:00
|
|
|
const formatter = new Intl.NumberFormat(window.navigator.locale || 'en', {
|
|
|
|
maximumFractionDigits: 2,
|
|
|
|
});
|
2020-10-15 17:40:32 +00:00
|
|
|
|
2020-09-11 06:29:07 +00:00
|
|
|
@classic
|
2022-10-19 19:00:35 +00:00
|
|
|
export default class TopologyControllers extends Controller.extend(Searchable) {
|
2020-11-05 03:22:59 +00:00
|
|
|
@service userSettings;
|
|
|
|
|
2022-10-19 19:00:35 +00:00
|
|
|
queryParams = [
|
|
|
|
{
|
|
|
|
searchTerm: 'search',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qpState: 'status',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qpVersion: 'version',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qpClass: 'class',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qpDatacenter: 'dc',
|
|
|
|
},
|
2023-06-22 17:11:44 +00:00
|
|
|
{
|
|
|
|
qpNodePool: 'nodePool',
|
|
|
|
},
|
2022-10-19 19:00:35 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
@tracked searchTerm = '';
|
|
|
|
qpState = '';
|
|
|
|
qpVersion = '';
|
|
|
|
qpClass = '';
|
|
|
|
qpDatacenter = '';
|
2023-06-22 17:11:44 +00:00
|
|
|
qpNodePool = '';
|
2022-10-19 19:00:35 +00:00
|
|
|
|
|
|
|
setFacetQueryParam(queryParam, selection) {
|
|
|
|
this.set(queryParam, serialize(selection));
|
|
|
|
}
|
|
|
|
|
|
|
|
@selection('qpState') selectionState;
|
|
|
|
@selection('qpClass') selectionClass;
|
|
|
|
@selection('qpDatacenter') selectionDatacenter;
|
2023-06-22 17:11:44 +00:00
|
|
|
@selection('qpNodePool') selectionNodePool;
|
2022-10-19 19:00:35 +00:00
|
|
|
@selection('qpVersion') selectionVersion;
|
|
|
|
|
|
|
|
@computed
|
|
|
|
get optionsState() {
|
|
|
|
return [
|
|
|
|
{ key: 'initializing', label: 'Initializing' },
|
|
|
|
{ key: 'ready', label: 'Ready' },
|
|
|
|
{ key: 'down', label: 'Down' },
|
|
|
|
{ key: 'ineligible', label: 'Ineligible' },
|
|
|
|
{ key: 'draining', label: 'Draining' },
|
|
|
|
{ key: 'disconnected', label: 'Disconnected' },
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
@computed('model.nodes', 'nodes.[]', 'selectionClass')
|
|
|
|
get optionsClass() {
|
|
|
|
const classes = Array.from(new Set(this.model.nodes.mapBy('nodeClass')))
|
|
|
|
.compact()
|
|
|
|
.without('');
|
|
|
|
|
|
|
|
// Remove any invalid node classes from the query param/selection
|
|
|
|
scheduleOnce('actions', () => {
|
|
|
|
// eslint-disable-next-line ember/no-side-effects
|
|
|
|
this.set(
|
|
|
|
'qpClass',
|
|
|
|
serialize(intersection(classes, this.selectionClass))
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
return classes.sort().map((dc) => ({ key: dc, label: dc }));
|
|
|
|
}
|
|
|
|
|
|
|
|
@computed('model.nodes', 'nodes.[]', 'selectionDatacenter')
|
|
|
|
get optionsDatacenter() {
|
|
|
|
const datacenters = Array.from(
|
|
|
|
new Set(this.model.nodes.mapBy('datacenter'))
|
|
|
|
).compact();
|
|
|
|
|
|
|
|
// Remove any invalid datacenters from the query param/selection
|
|
|
|
scheduleOnce('actions', () => {
|
|
|
|
// eslint-disable-next-line ember/no-side-effects
|
|
|
|
this.set(
|
|
|
|
'qpDatacenter',
|
|
|
|
serialize(intersection(datacenters, this.selectionDatacenter))
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
return datacenters.sort().map((dc) => ({ key: dc, label: dc }));
|
|
|
|
}
|
|
|
|
|
2023-06-22 17:11:44 +00:00
|
|
|
@computed('model.nodePools.[]', 'selectionNodePool')
|
|
|
|
get optionsNodePool() {
|
|
|
|
const availableNodePools = this.model.nodePools;
|
|
|
|
|
|
|
|
scheduleOnce('actions', () => {
|
|
|
|
// eslint-disable-next-line ember/no-side-effects
|
|
|
|
this.set(
|
|
|
|
'qpNodePool',
|
|
|
|
serialize(
|
|
|
|
intersection(
|
|
|
|
availableNodePools.map(({ name }) => name),
|
|
|
|
this.selectionNodePool
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
return availableNodePools.sort().map((nodePool) => ({
|
|
|
|
key: nodePool.name,
|
|
|
|
label: nodePool.name,
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2022-10-19 19:00:35 +00:00
|
|
|
@computed('model.nodes', 'nodes.[]', 'selectionVersion')
|
|
|
|
get optionsVersion() {
|
|
|
|
const versions = Array.from(
|
|
|
|
new Set(this.model.nodes.mapBy('version'))
|
|
|
|
).compact();
|
|
|
|
|
|
|
|
// Remove any invalid versions from the query param/selection
|
|
|
|
scheduleOnce('actions', () => {
|
|
|
|
// eslint-disable-next-line ember/no-side-effects
|
|
|
|
this.set(
|
|
|
|
'qpVersion',
|
|
|
|
serialize(intersection(versions, this.selectionVersion))
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
return versions.sort().map((v) => ({ key: v, label: v }));
|
|
|
|
}
|
|
|
|
|
2020-11-05 03:22:59 +00:00
|
|
|
@alias('userSettings.showTopoVizPollingNotice') showPollingNotice;
|
|
|
|
|
2022-10-19 19:00:35 +00:00
|
|
|
@tracked pre09Nodes = null;
|
|
|
|
|
|
|
|
get filteredNodes() {
|
|
|
|
const { nodes } = this.model;
|
|
|
|
return nodes.filter((node) => {
|
|
|
|
const {
|
|
|
|
searchTerm,
|
|
|
|
selectionState,
|
|
|
|
selectionVersion,
|
|
|
|
selectionDatacenter,
|
|
|
|
selectionClass,
|
2023-06-22 17:11:44 +00:00
|
|
|
selectionNodePool,
|
2022-10-19 19:00:35 +00:00
|
|
|
} = this;
|
2023-07-19 20:38:55 +00:00
|
|
|
const matchState =
|
|
|
|
selectionState.includes(node.status) ||
|
|
|
|
(selectionState.includes('ineligible') && !node.isEligible) ||
|
|
|
|
(selectionState.includes('draining') && node.isDraining);
|
|
|
|
|
2022-10-19 19:00:35 +00:00
|
|
|
return (
|
2023-07-19 20:38:55 +00:00
|
|
|
(selectionState.length ? matchState : true) &&
|
2022-10-19 19:00:35 +00:00
|
|
|
(selectionVersion.length
|
|
|
|
? selectionVersion.includes(node.version)
|
|
|
|
: true) &&
|
|
|
|
(selectionDatacenter.length
|
|
|
|
? selectionDatacenter.includes(node.datacenter)
|
|
|
|
: true) &&
|
|
|
|
(selectionClass.length
|
|
|
|
? selectionClass.includes(node.nodeClass)
|
|
|
|
: true) &&
|
2023-06-22 17:11:44 +00:00
|
|
|
(selectionNodePool.length
|
|
|
|
? selectionNodePool.includes(node.nodePool)
|
|
|
|
: true) &&
|
2022-10-19 19:00:35 +00:00
|
|
|
(node.name.includes(searchTerm) ||
|
|
|
|
node.datacenter.includes(searchTerm) ||
|
|
|
|
node.nodeClass.includes(searchTerm))
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2021-01-06 01:11:00 +00:00
|
|
|
|
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() {
|
2021-12-28 16:08:12 +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() {
|
2021-12-28 16:08:12 +00:00
|
|
|
return this.model.nodes
|
|
|
|
.mapBy('resources.cpu')
|
|
|
|
.reduce((sum, cpu) => sum + (cpu || 0), 0);
|
2020-09-11 06:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('totalMemory')
|
|
|
|
get totalMemoryFormatted() {
|
2021-03-30 05:21:00 +00:00
|
|
|
return formatter.format(reduceBytes(this.totalMemory)[0]);
|
2020-09-11 06:29:07 +00:00
|
|
|
}
|
|
|
|
|
2021-02-17 21:01:44 +00:00
|
|
|
@computed('totalMemory')
|
2020-09-11 06:29:07 +00:00
|
|
|
get totalMemoryUnits() {
|
2021-03-26 04:55:55 +00:00
|
|
|
return reduceBytes(this.totalMemory)[1];
|
2020-09-11 06:29:07 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 05:21:00 +00:00
|
|
|
@computed('totalCPU')
|
|
|
|
get totalCPUFormatted() {
|
|
|
|
return formatter.format(reduceHertz(this.totalCPU, null, 'MHz')[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
@computed('totalCPU')
|
|
|
|
get totalCPUUnits() {
|
|
|
|
return reduceHertz(this.totalCPU, null, 'MHz')[1];
|
|
|
|
}
|
|
|
|
|
2021-01-26 03:01:11 +00:00
|
|
|
@computed('scheduledAllocations.@each.allocatedResources')
|
2020-09-11 06:29:07 +00:00
|
|
|
get totalReservedMemory() {
|
2021-01-26 03:01:11 +00:00
|
|
|
const mibs = this.scheduledAllocations
|
|
|
|
.mapBy('allocatedResources.memory')
|
|
|
|
.reduce(sumAggregator, 0);
|
2020-09-11 06:29:07 +00:00
|
|
|
return mibs * 1024 * 1024;
|
|
|
|
}
|
|
|
|
|
2021-01-26 03:01:11 +00:00
|
|
|
@computed('scheduledAllocations.@each.allocatedResources')
|
2020-09-11 06:29:07 +00:00
|
|
|
get totalReservedCPU() {
|
2021-12-28 16:08:12 +00:00
|
|
|
return this.scheduledAllocations
|
|
|
|
.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
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
@computed(
|
|
|
|
'activeAllocation.taskGroupName',
|
|
|
|
'scheduledAllocations.@each.{job,taskGroupName}'
|
|
|
|
)
|
2020-09-11 06:59:58 +00:00
|
|
|
get siblingAllocations() {
|
|
|
|
if (!this.activeAllocation) return [];
|
|
|
|
const taskGroup = this.activeAllocation.taskGroupName;
|
|
|
|
const jobId = this.activeAllocation.belongsTo('job').id();
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
return this.scheduledAllocations.filter((allocation) => {
|
2021-12-28 16:08:12 +00:00
|
|
|
return (
|
|
|
|
allocation.taskGroupName === taskGroup &&
|
|
|
|
allocation.belongsTo('job').id() === jobId
|
|
|
|
);
|
2020-09-11 06:59:58 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-29 23:46:56 +00:00
|
|
|
@computed('activeNode')
|
|
|
|
get nodeUtilization() {
|
|
|
|
const node = this.activeNode;
|
2021-12-28 16:08:12 +00:00
|
|
|
const [formattedMemory, memoryUnits] = reduceBytes(
|
|
|
|
node.memory * 1024 * 1024
|
|
|
|
);
|
|
|
|
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() {
|
2021-01-26 03:01:11 +00:00
|
|
|
return this.siblingAllocations.mapBy('node.id').uniq();
|
2020-09-11 06:59:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@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) {
|
2022-10-19 19:00:35 +00:00
|
|
|
const pre09NodesError = errors.findBy('type', 'filtered-nodes');
|
|
|
|
if (pre09NodesError) {
|
|
|
|
this.pre09Nodes = pre09NodesError.context;
|
2021-01-06 01:11:00 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-11 06:29:07 +00:00
|
|
|
}
|