2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2020-06-09 21:03:28 +00:00
|
|
|
/* eslint-disable ember/no-observers */
|
2021-11-20 17:18:02 +00:00
|
|
|
/* eslint-disable ember/no-incorrect-calls-with-inline-anonymous-functions */
|
2017-12-15 21:39:18 +00:00
|
|
|
import { alias } from '@ember/object/computed';
|
|
|
|
import Controller from '@ember/controller';
|
2020-06-11 21:23:00 +00:00
|
|
|
import { action, computed } from '@ember/object';
|
|
|
|
import { observes } from '@ember-decorators/object';
|
2021-11-20 17:18:02 +00:00
|
|
|
import { scheduleOnce } from '@ember/runloop';
|
2019-11-02 07:55:01 +00:00
|
|
|
import { task } from 'ember-concurrency';
|
2021-11-20 17:18:02 +00:00
|
|
|
import intersection from 'lodash.intersection';
|
2017-09-19 14:47:10 +00:00
|
|
|
import Sortable from 'nomad-ui/mixins/sortable';
|
|
|
|
import Searchable from 'nomad-ui/mixins/searchable';
|
2019-11-02 07:55:01 +00:00
|
|
|
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
|
2021-12-28 16:08:12 +00:00
|
|
|
import {
|
|
|
|
serialize,
|
|
|
|
deserializedQueryParam as selection,
|
|
|
|
} from 'nomad-ui/utils/qp-serialize';
|
2020-06-11 21:23:00 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2022-09-16 19:58:22 +00:00
|
|
|
import localStorageProperty from 'nomad-ui/utils/properties/local-storage';
|
2023-02-07 22:42:25 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { tracked } from '@glimmer/tracking';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@classic
|
2021-12-28 16:08:12 +00:00
|
|
|
export default class ClientController extends Controller.extend(
|
|
|
|
Sortable,
|
|
|
|
Searchable
|
|
|
|
) {
|
2023-03-02 18:52:16 +00:00
|
|
|
@service notifications;
|
2023-02-07 22:42:25 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
queryParams = [
|
|
|
|
{
|
|
|
|
currentPage: 'page',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
searchTerm: 'search',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sortProperty: 'sort',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sortDescending: 'desc',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
onlyPreemptions: 'preemptions',
|
|
|
|
},
|
2021-11-20 16:22:48 +00:00
|
|
|
{
|
2021-12-17 21:55:40 +00:00
|
|
|
qpNamespace: 'namespace',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qpJob: 'job',
|
2021-11-20 16:22:48 +00:00
|
|
|
},
|
2021-11-20 17:18:02 +00:00
|
|
|
{
|
2021-12-17 21:55:40 +00:00
|
|
|
qpStatus: 'status',
|
2021-11-20 17:18:02 +00:00
|
|
|
},
|
2022-09-22 14:58:52 +00:00
|
|
|
'activeTask',
|
2020-06-11 21:23:00 +00:00
|
|
|
];
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-11-15 04:23:47 +00:00
|
|
|
// Set in the route
|
2020-06-11 21:23:00 +00:00
|
|
|
flagAsDraining = false;
|
2019-11-15 04:23:47 +00:00
|
|
|
|
2021-12-17 21:55:40 +00:00
|
|
|
qpNamespace = '';
|
|
|
|
qpJob = '';
|
2021-11-20 16:22:48 +00:00
|
|
|
qpStatus = '';
|
2020-06-11 21:23:00 +00:00
|
|
|
currentPage = 1;
|
|
|
|
pageSize = 8;
|
2022-09-22 14:58:52 +00:00
|
|
|
activeTask = null;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
sortProperty = 'modifyIndex';
|
|
|
|
sortDescending = true;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2022-09-16 19:58:22 +00:00
|
|
|
@localStorageProperty('nomadShowSubTasks', false) showSubTasks;
|
|
|
|
|
|
|
|
@action
|
|
|
|
toggleShowSubTasks(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.set('showSubTasks', !this.get('showSubTasks'));
|
|
|
|
}
|
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@computed()
|
|
|
|
get searchProps() {
|
2020-06-09 21:03:28 +00:00
|
|
|
return ['shortId', 'name'];
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
onlyPreemptions = false;
|
2019-04-17 18:19:54 +00:00
|
|
|
|
2021-12-17 22:38:04 +00:00
|
|
|
@computed('model.allocations.[]', 'preemptions.[]', 'onlyPreemptions')
|
2020-06-11 21:23:00 +00:00
|
|
|
get visibleAllocations() {
|
2021-12-17 22:38:04 +00:00
|
|
|
return this.onlyPreemptions ? this.preemptions : this.model.allocations;
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
@computed(
|
|
|
|
'visibleAllocations.[]',
|
|
|
|
'selectionNamespace',
|
|
|
|
'selectionJob',
|
|
|
|
'selectionStatus'
|
|
|
|
)
|
2021-12-17 22:38:04 +00:00
|
|
|
get filteredAllocations() {
|
2021-12-17 21:55:40 +00:00
|
|
|
const { selectionNamespace, selectionJob, selectionStatus } = this;
|
2021-11-20 16:22:48 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
return this.visibleAllocations.filter((alloc) => {
|
2021-12-28 16:08:12 +00:00
|
|
|
if (
|
|
|
|
selectionNamespace.length &&
|
|
|
|
!selectionNamespace.includes(alloc.get('namespace'))
|
|
|
|
) {
|
2021-12-17 21:55:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-12-28 16:08:12 +00:00
|
|
|
if (
|
|
|
|
selectionJob.length &&
|
|
|
|
!selectionJob.includes(alloc.get('plainJobId'))
|
|
|
|
) {
|
2021-11-20 16:22:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-12-28 16:08:12 +00:00
|
|
|
if (
|
|
|
|
selectionStatus.length &&
|
|
|
|
!selectionStatus.includes(alloc.clientStatus)
|
|
|
|
) {
|
2021-11-20 17:18:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-11-20 16:22:48 +00:00
|
|
|
return true;
|
|
|
|
});
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2019-04-17 18:19:54 +00:00
|
|
|
|
2021-12-17 22:38:04 +00:00
|
|
|
@alias('filteredAllocations') listToSort;
|
2020-06-11 21:23:00 +00:00
|
|
|
@alias('listSorted') listToSearch;
|
|
|
|
@alias('listSearched') sortedAllocations;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2021-12-17 21:55:40 +00:00
|
|
|
@selection('qpNamespace') selectionNamespace;
|
|
|
|
@selection('qpJob') selectionJob;
|
2021-11-20 16:22:48 +00:00
|
|
|
@selection('qpStatus') selectionStatus;
|
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
eligibilityError = null;
|
|
|
|
stopDrainError = null;
|
|
|
|
drainError = null;
|
|
|
|
showDrainNotification = false;
|
|
|
|
showDrainUpdateNotification = false;
|
|
|
|
showDrainStoppedNotification = false;
|
2019-11-02 07:55:01 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@computed('model.allocations.@each.wasPreempted')
|
|
|
|
get preemptions() {
|
2019-04-17 18:19:54 +00:00
|
|
|
return this.model.allocations.filterBy('wasPreempted');
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2019-04-17 18:19:54 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@computed('model.events.@each.time')
|
|
|
|
get sortedEvents() {
|
2021-12-28 14:45:20 +00:00
|
|
|
return this.get('model.events').sortBy('time').reverse();
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2018-05-08 18:23:42 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@computed('model.drivers.@each.name')
|
|
|
|
get sortedDrivers() {
|
2018-05-09 01:09:20 +00:00
|
|
|
return this.get('model.drivers').sortBy('name');
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2018-05-09 01:09:20 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@computed('model.hostVolumes.@each.name')
|
|
|
|
get sortedHostVolumes() {
|
2020-02-11 03:12:12 +00:00
|
|
|
return this.model.hostVolumes.sortBy('name');
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2020-02-11 03:12:12 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
@(task(function* (value) {
|
2019-11-02 07:55:01 +00:00
|
|
|
try {
|
|
|
|
yield value ? this.model.setEligible() : this.model.setIneligible();
|
|
|
|
} catch (err) {
|
|
|
|
const error = messageFromAdapterError(err) || 'Could not set eligibility';
|
|
|
|
this.set('eligibilityError', error);
|
|
|
|
}
|
2020-06-11 21:23:00 +00:00
|
|
|
}).drop())
|
|
|
|
setEligibility;
|
2019-11-02 07:55:01 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
@(task(function* () {
|
2019-11-19 06:36:07 +00:00
|
|
|
try {
|
|
|
|
this.set('flagAsDraining', false);
|
|
|
|
yield this.model.cancelDrain();
|
|
|
|
this.set('showDrainStoppedNotification', true);
|
|
|
|
} catch (err) {
|
|
|
|
this.set('flagAsDraining', true);
|
|
|
|
const error = messageFromAdapterError(err) || 'Could not stop drain';
|
|
|
|
this.set('stopDrainError', error);
|
|
|
|
}
|
2020-06-11 21:23:00 +00:00
|
|
|
}).drop())
|
|
|
|
stopDrain;
|
2019-11-19 06:36:07 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
@(task(function* () {
|
2019-11-19 08:12:34 +00:00
|
|
|
try {
|
|
|
|
yield this.model.forceDrain({
|
|
|
|
IgnoreSystemJobs: this.model.drainStrategy.ignoreSystemJobs,
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
const error = messageFromAdapterError(err) || 'Could not force drain';
|
|
|
|
this.set('drainError', error);
|
|
|
|
}
|
2020-06-11 21:23:00 +00:00
|
|
|
}).drop())
|
|
|
|
forceDrain;
|
2019-11-19 08:12:34 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@observes('model.isDraining')
|
|
|
|
triggerDrainNotification() {
|
2019-11-15 04:23:47 +00:00
|
|
|
if (!this.model.isDraining && this.flagAsDraining) {
|
|
|
|
this.set('showDrainNotification', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.set('flagAsDraining', this.model.isDraining);
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
gotoAllocation(allocation) {
|
|
|
|
this.transitionToRoute('allocations.allocation', allocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
setPreemptionFilter(value) {
|
|
|
|
this.set('onlyPreemptions', value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
drainNotify(isUpdating) {
|
|
|
|
this.set('showDrainUpdateNotification', isUpdating);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
2020-06-12 13:22:46 +00:00
|
|
|
setDrainError(err) {
|
2020-06-11 21:23:00 +00:00
|
|
|
const error = messageFromAdapterError(err) || 'Could not run drain';
|
|
|
|
this.set('drainError', error);
|
|
|
|
}
|
2021-11-20 16:22:48 +00:00
|
|
|
|
|
|
|
get optionsAllocationStatus() {
|
|
|
|
return [
|
2021-12-17 21:55:40 +00:00
|
|
|
{ key: 'pending', label: 'Pending' },
|
2021-11-20 16:22:48 +00:00
|
|
|
{ key: 'running', label: 'Running' },
|
|
|
|
{ key: 'complete', label: 'Complete' },
|
|
|
|
{ key: 'failed', label: 'Failed' },
|
|
|
|
{ key: 'lost', label: 'Lost' },
|
2022-04-22 15:25:02 +00:00
|
|
|
{ key: 'unknown', label: 'Unknown' },
|
2021-11-20 16:22:48 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-12-17 21:55:40 +00:00
|
|
|
@computed('model.allocations.[]', 'selectionJob', 'selectionNamespace')
|
|
|
|
get optionsJob() {
|
|
|
|
// Only show options for jobs in the selected namespaces, if any.
|
|
|
|
const ns = this.selectionNamespace;
|
|
|
|
const jobs = Array.from(
|
|
|
|
new Set(
|
|
|
|
this.model.allocations
|
2021-12-28 14:45:20 +00:00
|
|
|
.filter((a) => ns.length === 0 || ns.includes(a.namespace))
|
2021-12-17 21:55:40 +00:00
|
|
|
.mapBy('plainJobId')
|
|
|
|
)
|
|
|
|
).compact();
|
|
|
|
|
|
|
|
// Update query param when the list of jobs changes.
|
|
|
|
scheduleOnce('actions', () => {
|
|
|
|
// eslint-disable-next-line ember/no-side-effects
|
|
|
|
this.set('qpJob', serialize(intersection(jobs, this.selectionJob)));
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
return jobs.sort().map((job) => ({ key: job, label: job }));
|
2021-12-17 21:55:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('model.allocations.[]', 'selectionNamespace')
|
|
|
|
get optionsNamespace() {
|
2021-12-28 16:08:12 +00:00
|
|
|
const ns = Array.from(
|
|
|
|
new Set(this.model.allocations.mapBy('namespace'))
|
|
|
|
).compact();
|
2021-11-20 17:18:02 +00:00
|
|
|
|
2021-12-17 21:55:40 +00:00
|
|
|
// Update query param when the list of namespaces changes.
|
2021-11-20 17:18:02 +00:00
|
|
|
scheduleOnce('actions', () => {
|
|
|
|
// eslint-disable-next-line ember/no-side-effects
|
2021-12-28 16:08:12 +00:00
|
|
|
this.set(
|
|
|
|
'qpNamespace',
|
|
|
|
serialize(intersection(ns, this.selectionNamespace))
|
|
|
|
);
|
2021-11-20 17:18:02 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
return ns.sort().map((n) => ({ key: n, label: n }));
|
2021-11-20 17:18:02 +00:00
|
|
|
}
|
|
|
|
|
2021-11-20 16:22:48 +00:00
|
|
|
setFacetQueryParam(queryParam, selection) {
|
|
|
|
this.set(queryParam, serialize(selection));
|
|
|
|
}
|
2022-09-22 14:58:52 +00:00
|
|
|
|
|
|
|
@action
|
|
|
|
setActiveTaskQueryParam(task) {
|
|
|
|
if (task) {
|
|
|
|
this.set('activeTask', `${task.allocation.id}-${task.name}`);
|
|
|
|
} else {
|
|
|
|
this.set('activeTask', null);
|
|
|
|
}
|
|
|
|
}
|
2023-02-07 22:42:25 +00:00
|
|
|
|
|
|
|
// #region metadata
|
|
|
|
|
|
|
|
@tracked editingMetadata = false;
|
|
|
|
|
|
|
|
get hasMeta() {
|
|
|
|
return (
|
|
|
|
this.model.meta?.structured && Object.keys(this.model.meta?.structured)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@tracked newMetaData = {
|
|
|
|
key: '',
|
|
|
|
value: '',
|
|
|
|
};
|
|
|
|
|
|
|
|
@action resetNewMetaData() {
|
|
|
|
this.newMetaData = {
|
|
|
|
key: '',
|
|
|
|
value: '',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@action validateMetadata(event) {
|
|
|
|
if (event.key === 'Escape') {
|
|
|
|
this.resetNewMetaData();
|
|
|
|
this.editingMetadata = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@action async addDynamicMetaData({ key, value }, e) {
|
|
|
|
try {
|
|
|
|
e.preventDefault();
|
|
|
|
await this.model.addMeta({ [key]: value });
|
|
|
|
|
2023-03-02 18:52:16 +00:00
|
|
|
this.notifications.add({
|
2023-02-07 22:42:25 +00:00
|
|
|
title: 'Metadata added',
|
|
|
|
message: `${key} successfully saved`,
|
2023-03-02 18:52:16 +00:00
|
|
|
color: 'success',
|
2023-02-07 22:42:25 +00:00
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
const error =
|
|
|
|
messageFromAdapterError(err) || 'Could not save new dynamic metadata';
|
2023-03-02 18:52:16 +00:00
|
|
|
this.notifications.add({
|
2023-02-07 22:42:25 +00:00
|
|
|
title: `Error saving Metadata`,
|
|
|
|
message: error,
|
2023-03-02 18:52:16 +00:00
|
|
|
color: 'critical',
|
2023-02-07 22:42:25 +00:00
|
|
|
sticky: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// #endregion metadata
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|