2022-04-05 18:34:37 +00:00
|
|
|
import { getOwner } from '@ember/application';
|
2021-12-20 20:11:01 +00:00
|
|
|
import Controller from '@ember/controller';
|
|
|
|
import { action } from '@ember/object';
|
|
|
|
import { tracked } from '@glimmer/tracking';
|
2022-04-05 18:34:37 +00:00
|
|
|
import { schedule } from '@ember/runloop';
|
2021-12-23 16:54:47 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2022-04-05 18:34:37 +00:00
|
|
|
import { useMachine } from 'ember-statecharts';
|
|
|
|
import { use } from 'ember-usable';
|
|
|
|
import evaluationsMachine from '../../machines/evaluations';
|
2021-12-20 20:11:01 +00:00
|
|
|
|
2022-04-05 19:30:36 +00:00
|
|
|
const ALL_NAMESPACE_WILDCARD = '*';
|
|
|
|
|
2021-12-20 20:11:01 +00:00
|
|
|
export default class EvaluationsController extends Controller {
|
2022-04-05 18:34:37 +00:00
|
|
|
@service store;
|
2021-12-23 16:54:47 +00:00
|
|
|
@service userSettings;
|
|
|
|
|
2022-04-05 18:34:37 +00:00
|
|
|
// We use statecharts here to manage complex user flows for the sidebar logic
|
|
|
|
@use
|
|
|
|
statechart = useMachine(evaluationsMachine).withConfig({
|
|
|
|
services: {
|
|
|
|
loadEvaluation: this.loadEvaluation,
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
updateEvaluationQueryParameter: this.updateEvaluationQueryParameter,
|
|
|
|
removeCurrentEvaluationQueryParameter:
|
|
|
|
this.removeCurrentEvaluationQueryParameter,
|
|
|
|
},
|
|
|
|
guards: {
|
|
|
|
sidebarIsOpen: this._sidebarIsOpen,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-04-05 19:30:36 +00:00
|
|
|
queryParams = [
|
|
|
|
'nextToken',
|
|
|
|
'currentEval',
|
|
|
|
'pageSize',
|
|
|
|
'status',
|
2022-07-11 20:42:17 +00:00
|
|
|
{ qpNamespace: 'namespace' },
|
2022-04-05 19:30:36 +00:00
|
|
|
'type',
|
|
|
|
'searchTerm',
|
|
|
|
];
|
2022-04-05 18:34:37 +00:00
|
|
|
@tracked currentEval = null;
|
|
|
|
|
|
|
|
@action
|
|
|
|
_sidebarIsOpen() {
|
|
|
|
return !!this.currentEval;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
async loadEvaluation(context, { evaluation }) {
|
|
|
|
let evaluationId;
|
|
|
|
if (evaluation?.id) {
|
|
|
|
evaluationId = evaluation.id;
|
|
|
|
} else {
|
|
|
|
evaluationId = this.currentEval;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.store.findRecord('evaluation', evaluationId, {
|
|
|
|
reload: true,
|
|
|
|
adapterOptions: { related: true },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
async handleEvaluationClick(evaluation, e) {
|
|
|
|
if (
|
|
|
|
e instanceof MouseEvent ||
|
2022-08-17 16:59:33 +00:00
|
|
|
(e instanceof KeyboardEvent &&
|
|
|
|
(e.code === 'Enter' || e.code === 'Space')) ||
|
|
|
|
!e
|
2022-04-05 18:34:37 +00:00
|
|
|
) {
|
|
|
|
this.statechart.send('LOAD_EVALUATION', { evaluation });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
notifyEvalChange([evaluation]) {
|
|
|
|
schedule('actions', this, () => {
|
|
|
|
this.statechart.send('CHANGE_EVAL', { evaluation });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
updateEvaluationQueryParameter(context, { evaluation }) {
|
|
|
|
this.currentEval = evaluation.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
removeCurrentEvaluationQueryParameter() {
|
|
|
|
this.currentEval = null;
|
|
|
|
}
|
2021-12-21 18:31:28 +00:00
|
|
|
|
|
|
|
get shouldDisableNext() {
|
|
|
|
return !this.model.meta?.nextToken;
|
|
|
|
}
|
|
|
|
|
|
|
|
get shouldDisablePrev() {
|
|
|
|
return !this.previousTokens.length;
|
|
|
|
}
|
2021-12-20 20:11:01 +00:00
|
|
|
|
2021-12-23 16:54:47 +00:00
|
|
|
get optionsEvaluationsStatus() {
|
|
|
|
return [
|
|
|
|
{ key: null, label: 'All' },
|
|
|
|
{ key: 'blocked', label: 'Blocked' },
|
|
|
|
{ key: 'pending', label: 'Pending' },
|
|
|
|
{ key: 'complete', label: 'Complete' },
|
|
|
|
{ key: 'failed', label: 'Failed' },
|
|
|
|
{ key: 'canceled', label: 'Canceled' },
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-04-05 19:30:36 +00:00
|
|
|
get optionsTriggeredBy() {
|
|
|
|
return [
|
|
|
|
{ key: null, label: 'All' },
|
|
|
|
{ key: 'job-register', label: 'Job Register' },
|
|
|
|
{ key: 'job-deregister', label: 'Job Deregister' },
|
|
|
|
{ key: 'periodic-job', label: 'Periodic Job' },
|
|
|
|
{ key: 'node-drain', label: 'Node Drain' },
|
|
|
|
{ key: 'node-update', label: 'Node Update' },
|
|
|
|
{ key: 'alloc-stop', label: 'Allocation Stop' },
|
|
|
|
{ key: 'scheduled', label: 'Scheduled' },
|
|
|
|
{ key: 'rolling-update', label: 'Rolling Update' },
|
|
|
|
{ key: 'deployment-watcher', label: 'Deployment Watcher' },
|
|
|
|
{ key: 'failed-follow-up', label: 'Failed Follow Up' },
|
2022-04-22 19:40:13 +00:00
|
|
|
{ key: 'max-disconnect-timeout', label: 'Max Disconnect Timeout' },
|
2022-04-05 19:30:36 +00:00
|
|
|
{ key: 'max-plan-attempts', label: 'Max Plan Attempts' },
|
|
|
|
{ key: 'alloc-failure', label: 'Allocation Failure' },
|
|
|
|
{ key: 'queued-allocs', label: 'Queued Allocations' },
|
|
|
|
{ key: 'preemption', label: 'Preemption' },
|
|
|
|
{ key: 'job-scaling', label: 'Job Scalling' },
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
get optionsNamespaces() {
|
|
|
|
const namespaces = this.store.peekAll('namespace').map((namespace) => ({
|
|
|
|
key: namespace.name,
|
|
|
|
label: namespace.name,
|
|
|
|
}));
|
|
|
|
|
|
|
|
// Create default namespace selection
|
|
|
|
namespaces.unshift({
|
|
|
|
key: ALL_NAMESPACE_WILDCARD,
|
|
|
|
label: 'All (*)',
|
|
|
|
});
|
|
|
|
|
|
|
|
return namespaces;
|
|
|
|
}
|
|
|
|
|
|
|
|
get optionsType() {
|
|
|
|
return [
|
|
|
|
{ key: null, label: 'All' },
|
|
|
|
{ key: 'client', label: 'Client' },
|
|
|
|
{ key: 'no client', label: 'No Client' },
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-04-22 19:40:13 +00:00
|
|
|
filters = ['status', 'qpNamespace', 'type', 'triggeredBy', 'searchTerm'];
|
|
|
|
|
|
|
|
get hasFiltersApplied() {
|
|
|
|
return this.filters.reduce((result, filter) => {
|
|
|
|
// By default we always set qpNamespace to the '*' wildcard
|
|
|
|
// We need to ensure that if namespace is the only filter, that we send the correct error message to the user
|
|
|
|
if (this[filter] && filter !== 'qpNamespace') {
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
get currentFilters() {
|
|
|
|
const result = [];
|
|
|
|
for (const filter of this.filters) {
|
|
|
|
const isNamespaceWildcard =
|
|
|
|
filter === 'qpNamespace' && this[filter] === '*';
|
|
|
|
if (this[filter] && !isNamespaceWildcard) {
|
|
|
|
result.push({ [filter]: this[filter] });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
get noMatchText() {
|
|
|
|
let text = '';
|
|
|
|
const cleanNames = {
|
|
|
|
status: 'Status',
|
|
|
|
qpNamespace: 'Namespace',
|
|
|
|
type: 'Type',
|
|
|
|
triggeredBy: 'Triggered By',
|
|
|
|
searchTerm: 'Search Term',
|
|
|
|
};
|
|
|
|
if (this.hasFiltersApplied) {
|
|
|
|
for (let i = 0; i < this.currentFilters.length; i++) {
|
|
|
|
const filter = this.currentFilters[i];
|
|
|
|
const [name] = Object.keys(filter);
|
|
|
|
const filterName = cleanNames[name];
|
|
|
|
const filterValue = filter[name];
|
|
|
|
if (this.currentFilters.length === 1)
|
|
|
|
return `${filterName}: ${filterValue}.`;
|
|
|
|
if (i !== 0 && i !== this.currentFilters.length - 1)
|
|
|
|
text = text.concat(`, ${filterName}: ${filterValue}`);
|
|
|
|
if (i === 0) text = text.concat(`${filterName}: ${filterValue}`);
|
|
|
|
if (i === this.currentFilters.length - 1) {
|
|
|
|
return text.concat(`, ${filterName}: ${filterValue}.`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2021-12-23 16:54:47 +00:00
|
|
|
@tracked pageSize = this.userSettings.pageSize;
|
2021-12-21 18:31:28 +00:00
|
|
|
@tracked nextToken = null;
|
|
|
|
@tracked previousTokens = [];
|
2021-12-23 16:54:47 +00:00
|
|
|
@tracked status = null;
|
2022-04-05 19:30:36 +00:00
|
|
|
@tracked triggeredBy = null;
|
|
|
|
@tracked qpNamespace = ALL_NAMESPACE_WILDCARD;
|
|
|
|
@tracked type = null;
|
|
|
|
@tracked searchTerm = null;
|
2021-12-20 20:11:01 +00:00
|
|
|
|
|
|
|
@action
|
|
|
|
onChange(newPageSize) {
|
|
|
|
this.pageSize = newPageSize;
|
|
|
|
}
|
2021-12-21 18:31:28 +00:00
|
|
|
|
|
|
|
@action
|
|
|
|
onNext(nextToken) {
|
|
|
|
this.previousTokens = [...this.previousTokens, this.nextToken];
|
|
|
|
this.nextToken = nextToken;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
2021-12-23 16:54:47 +00:00
|
|
|
onPrev() {
|
|
|
|
const lastToken = this.previousTokens.pop();
|
2021-12-21 18:31:28 +00:00
|
|
|
this.previousTokens = [...this.previousTokens];
|
|
|
|
this.nextToken = lastToken;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
refresh() {
|
2022-04-05 18:34:37 +00:00
|
|
|
const isDefaultParams = this.nextToken === null && this.status === null;
|
|
|
|
if (isDefaultParams) {
|
|
|
|
getOwner(this).lookup('route:evaluations.index').refresh();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-23 16:54:47 +00:00
|
|
|
this._resetTokens();
|
|
|
|
this.status = null;
|
|
|
|
this.pageSize = this.userSettings.pageSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
2022-04-05 19:30:36 +00:00
|
|
|
setQueryParam(qp, selection) {
|
2021-12-23 16:54:47 +00:00
|
|
|
this._resetTokens();
|
2022-04-05 19:30:36 +00:00
|
|
|
this[qp] = selection;
|
2021-12-23 16:54:47 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 19:30:36 +00:00
|
|
|
@action
|
|
|
|
toggle() {
|
|
|
|
this._resetTokens();
|
|
|
|
this.shouldOnlyDisplayClientEvals = !this.shouldOnlyDisplayClientEvals;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
2021-12-23 16:54:47 +00:00
|
|
|
_resetTokens() {
|
2021-12-21 18:31:28 +00:00
|
|
|
this.nextToken = null;
|
|
|
|
this.previousTokens = [];
|
|
|
|
}
|
2021-12-20 20:11:01 +00:00
|
|
|
}
|