2021-11-20 20:07:27 +00:00
|
|
|
/* eslint-disable ember/no-incorrect-calls-with-inline-anonymous-functions */
|
2020-03-31 04:29:30 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2020-06-10 13:49:16 +00:00
|
|
|
import { alias, readOnly } from '@ember/object/computed';
|
2018-06-27 20:39:57 +00:00
|
|
|
import Controller from '@ember/controller';
|
2020-07-28 06:18:10 +00:00
|
|
|
import { action, computed, get } from '@ember/object';
|
2021-11-20 20:07:27 +00:00
|
|
|
import { scheduleOnce } from '@ember/runloop';
|
|
|
|
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';
|
2017-10-23 23:59:30 +00:00
|
|
|
import WithNamespaceResetting from 'nomad-ui/mixins/with-namespace-resetting';
|
2021-12-28 16:08:12 +00:00
|
|
|
import {
|
|
|
|
serialize,
|
|
|
|
deserializedQueryParam as selection,
|
|
|
|
} from 'nomad-ui/utils/qp-serialize';
|
2020-06-10 13:49:16 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@classic
|
|
|
|
export default class TaskGroupController extends Controller.extend(
|
2021-12-28 14:45:20 +00:00
|
|
|
Sortable,
|
|
|
|
Searchable,
|
|
|
|
WithNamespaceResetting
|
|
|
|
) {
|
2020-06-10 13:49:16 +00:00
|
|
|
@service userSettings;
|
2020-06-29 22:53:52 +00:00
|
|
|
@service can;
|
2020-03-31 04:29:30 +00:00
|
|
|
|
2020-06-11 13:38:33 +00:00
|
|
|
queryParams = [
|
|
|
|
{
|
|
|
|
currentPage: 'page',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
searchTerm: 'search',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sortProperty: 'sort',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sortDescending: 'desc',
|
|
|
|
},
|
2021-11-20 20:07:27 +00:00
|
|
|
{
|
|
|
|
qpStatus: 'status',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qpClient: 'client',
|
|
|
|
},
|
2020-06-11 13:38:33 +00:00
|
|
|
];
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
currentPage = 1;
|
|
|
|
@readOnly('userSettings.pageSize') pageSize;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2021-11-20 20:07:27 +00:00
|
|
|
qpStatus = '';
|
|
|
|
qpClient = '';
|
2020-06-10 13:49:16 +00:00
|
|
|
sortProperty = 'modifyIndex';
|
|
|
|
sortDescending = true;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed
|
|
|
|
get searchProps() {
|
2020-06-09 21:03:28 +00:00
|
|
|
return ['shortId', 'name'];
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2021-12-17 23:45:31 +00:00
|
|
|
@computed('model.allocations.[]')
|
2020-06-10 13:49:16 +00:00
|
|
|
get allocations() {
|
2021-12-17 23:45:31 +00:00
|
|
|
return this.get('model.allocations') || [];
|
|
|
|
}
|
2021-11-20 20:07:27 +00:00
|
|
|
|
2021-12-17 23:45:31 +00:00
|
|
|
@computed('allocations.[]', 'selectionStatus', 'selectionClient')
|
|
|
|
get filteredAllocations() {
|
|
|
|
const { selectionStatus, selectionClient } = this;
|
2021-11-20 20:07:27 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
return this.allocations.filter((alloc) => {
|
2021-12-28 16:08:12 +00:00
|
|
|
if (
|
|
|
|
selectionStatus.length &&
|
|
|
|
!selectionStatus.includes(alloc.clientStatus)
|
|
|
|
) {
|
2021-11-20 20:07:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-12-28 16:08:12 +00:00
|
|
|
if (
|
|
|
|
selectionClient.length &&
|
|
|
|
!selectionClient.includes(alloc.get('node.shortId'))
|
|
|
|
) {
|
2021-11-20 20:07:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
|
2021-12-17 23:45:31 +00:00
|
|
|
@alias('filteredAllocations') listToSort;
|
2020-06-10 13:49:16 +00:00
|
|
|
@alias('listSorted') listToSearch;
|
|
|
|
@alias('listSearched') sortedAllocations;
|
|
|
|
|
2021-11-20 20:07:27 +00:00
|
|
|
@selection('qpStatus') selectionStatus;
|
|
|
|
@selection('qpClient') selectionClient;
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
@computed('model.scaleState.events.@each.time', function () {
|
2020-07-28 06:18:10 +00:00
|
|
|
const events = get(this, 'model.scaleState.events');
|
|
|
|
if (events) {
|
|
|
|
return events.sortBy('time').reverse();
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
})
|
|
|
|
sortedScaleEvents;
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
@computed('sortedScaleEvents.@each.hasCount', function () {
|
2020-08-05 05:54:26 +00:00
|
|
|
const countEventsCount = this.sortedScaleEvents.filterBy('hasCount').length;
|
2021-12-28 16:08:12 +00:00
|
|
|
return (
|
|
|
|
countEventsCount > 1 &&
|
|
|
|
countEventsCount >= this.sortedScaleEvents.length / 2
|
|
|
|
);
|
2020-08-05 05:54:26 +00:00
|
|
|
})
|
|
|
|
shouldShowScaleEventTimeline;
|
|
|
|
|
2021-07-14 20:27:24 +00:00
|
|
|
@computed('model.job.{namespace,runningDeployment}')
|
2020-06-29 22:53:52 +00:00
|
|
|
get tooltipText() {
|
2021-12-28 16:08:12 +00:00
|
|
|
if (
|
|
|
|
this.can.cannot('scale job', null, {
|
|
|
|
namespace: this.model.job.namespace.get('name'),
|
|
|
|
})
|
|
|
|
)
|
2021-07-14 20:27:24 +00:00
|
|
|
return "You aren't allowed to scale task groups";
|
2021-12-28 16:08:12 +00:00
|
|
|
if (this.model.job.runningDeployment)
|
|
|
|
return 'You cannot scale task groups during a deployment';
|
2020-06-29 22:53:52 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@action
|
|
|
|
gotoAllocation(allocation) {
|
|
|
|
this.transitionToRoute('allocations.allocation', allocation);
|
|
|
|
}
|
2020-06-19 05:50:47 +00:00
|
|
|
|
|
|
|
@action
|
|
|
|
scaleTaskGroup(count) {
|
|
|
|
return this.model.scale(count);
|
|
|
|
}
|
2021-11-20 20:07:27 +00:00
|
|
|
|
|
|
|
get optionsAllocationStatus() {
|
|
|
|
return [
|
2021-12-17 23:45:31 +00:00
|
|
|
{ key: 'pending', label: 'Pending' },
|
2021-11-20 20:07:27 +00:00
|
|
|
{ key: 'running', label: 'Running' },
|
|
|
|
{ key: 'complete', label: 'Complete' },
|
|
|
|
{ key: 'failed', label: 'Failed' },
|
|
|
|
{ key: 'lost', label: 'Lost' },
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
@computed('model.allocations.[]', 'selectionClient')
|
|
|
|
get optionsClients() {
|
2021-12-28 16:08:12 +00:00
|
|
|
const clients = Array.from(
|
|
|
|
new Set(this.model.allocations.mapBy('node.shortId'))
|
|
|
|
).compact();
|
2021-11-20 20:07:27 +00:00
|
|
|
|
|
|
|
// Update query param when the list of clients changes.
|
|
|
|
scheduleOnce('actions', () => {
|
|
|
|
// eslint-disable-next-line ember/no-side-effects
|
2021-12-28 16:08:12 +00:00
|
|
|
this.set(
|
|
|
|
'qpClient',
|
|
|
|
serialize(intersection(clients, this.selectionClient))
|
|
|
|
);
|
2021-11-20 20:07:27 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
return clients.sort().map((dc) => ({ key: dc, label: dc }));
|
2021-11-20 20:07:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setFacetQueryParam(queryParam, selection) {
|
|
|
|
this.set(queryParam, serialize(selection));
|
|
|
|
}
|
2021-12-17 16:29:36 +00:00
|
|
|
|
|
|
|
get taskGroup() {
|
|
|
|
return this.model;
|
|
|
|
}
|
|
|
|
|
|
|
|
get breadcrumb() {
|
|
|
|
const { job, name } = this.taskGroup;
|
|
|
|
return {
|
|
|
|
title: 'Task Group',
|
|
|
|
label: name,
|
2022-02-17 13:38:27 +00:00
|
|
|
args: ['jobs.job.task-group', job, name],
|
2021-12-17 16:29:36 +00:00
|
|
|
};
|
2021-11-30 20:10:01 +00:00
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|