2020-06-09 21:03:28 +00:00
|
|
|
/* eslint-disable ember/no-observers */
|
2018-06-27 20:39:57 +00:00
|
|
|
import Controller from '@ember/controller';
|
2018-08-30 00:18:42 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2020-06-11 21:23:00 +00:00
|
|
|
import { action, computed } from '@ember/object';
|
|
|
|
import { observes } from '@ember-decorators/object';
|
2019-10-15 18:32:58 +00:00
|
|
|
import { computed as overridable } from 'ember-overridable-computed';
|
2019-04-17 23:17:48 +00:00
|
|
|
import { alias } from '@ember/object/computed';
|
2019-05-17 00:43:12 +00:00
|
|
|
import { task } from 'ember-concurrency';
|
2017-10-30 20:39:15 +00:00
|
|
|
import Sortable from 'nomad-ui/mixins/sortable';
|
2018-06-06 21:25:48 +00:00
|
|
|
import { lazyClick } from 'nomad-ui/helpers/lazy-click';
|
2019-05-20 22:35:21 +00:00
|
|
|
import { watchRecord } from 'nomad-ui/utils/properties/watch';
|
2021-01-28 00:40:51 +00:00
|
|
|
import messageForError from 'nomad-ui/utils/message-from-adapter-error';
|
2020-06-11 21:23:00 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2022-08-22 15:45:12 +00:00
|
|
|
import { union } from '@ember/object/computed';
|
2022-09-07 14:23:39 +00:00
|
|
|
import { tracked } from '@glimmer/tracking';
|
2017-10-30 20:39:15 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@classic
|
|
|
|
export default class IndexController extends Controller.extend(Sortable) {
|
|
|
|
@service token;
|
2022-03-08 17:28:36 +00:00
|
|
|
@service store;
|
2018-08-30 00:18:42 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
queryParams = [
|
|
|
|
{
|
|
|
|
sortProperty: 'sort',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sortDescending: 'desc',
|
|
|
|
},
|
2022-09-07 14:23:39 +00:00
|
|
|
{
|
|
|
|
activeServiceID: 'service',
|
|
|
|
},
|
2020-06-11 21:23:00 +00:00
|
|
|
];
|
2017-10-30 20:39:15 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
sortProperty = 'name';
|
|
|
|
sortDescending = false;
|
2017-10-30 20:39:15 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@alias('model.states') listToSort;
|
|
|
|
@alias('listSorted') sortedStates;
|
2018-06-06 21:25:48 +00:00
|
|
|
|
2019-04-17 23:17:48 +00:00
|
|
|
// Set in the route
|
2020-06-11 21:23:00 +00:00
|
|
|
preempter = null;
|
2019-04-17 23:17:48 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
@overridable(function () {
|
2019-05-17 00:43:12 +00:00
|
|
|
// { title, description }
|
|
|
|
return null;
|
2020-06-11 21:23:00 +00:00
|
|
|
})
|
|
|
|
error;
|
2019-05-17 00:43:12 +00:00
|
|
|
|
2020-08-20 15:07:13 +00:00
|
|
|
@computed('model.allocatedResources.ports.@each.label')
|
|
|
|
get ports() {
|
|
|
|
return (this.get('model.allocatedResources.ports') || []).sortBy('label');
|
|
|
|
}
|
2019-09-04 14:39:56 +00:00
|
|
|
|
2022-08-22 15:45:12 +00:00
|
|
|
@computed('model.states.@each.task')
|
|
|
|
get tasks() {
|
|
|
|
return this.get('model.states').mapBy('task') || [];
|
|
|
|
}
|
|
|
|
|
|
|
|
@computed('tasks.@each.services')
|
|
|
|
get taskServices() {
|
|
|
|
return this.get('tasks')
|
2022-09-07 14:23:39 +00:00
|
|
|
.map((t) => ((t && t.services) || []).toArray())
|
2022-08-22 15:45:12 +00:00
|
|
|
.flat()
|
|
|
|
.compact();
|
|
|
|
}
|
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@computed('model.taskGroup.services.@each.name')
|
2022-08-22 15:45:12 +00:00
|
|
|
get groupServices() {
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
return (this.get('model.taskGroup.services') || []).sortBy('name');
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2019-09-04 14:39:56 +00:00
|
|
|
|
2022-08-22 15:45:12 +00:00
|
|
|
@union('taskServices', 'groupServices') services;
|
|
|
|
|
2022-09-08 17:54:50 +00:00
|
|
|
@computed('model.{healthChecks,id}', 'services')
|
2022-09-07 14:23:39 +00:00
|
|
|
get servicesWithHealthChecks() {
|
|
|
|
return this.services.map((service) => {
|
|
|
|
if (this.model.healthChecks) {
|
|
|
|
const healthChecks = Object.values(this.model.healthChecks)?.filter(
|
|
|
|
(check) => {
|
|
|
|
const refPrefix =
|
|
|
|
check.Task || check.Group.split('.')[1].split('[')[0];
|
|
|
|
const currentServiceName = `${refPrefix}-${check.Service}`;
|
|
|
|
return currentServiceName === service.refID;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
healthChecks.forEach((check) => {
|
2022-09-08 15:31:38 +00:00
|
|
|
service.healthChecks.pushObject(check);
|
2022-09-07 14:23:39 +00:00
|
|
|
});
|
2022-08-29 18:04:55 +00:00
|
|
|
}
|
2022-09-08 16:03:08 +00:00
|
|
|
// Contextualize healthchecks for the allocation we're in
|
|
|
|
service.healthChecks = service.healthChecks.filterBy(
|
|
|
|
'Alloc',
|
|
|
|
this.model.id
|
|
|
|
);
|
2022-09-07 14:23:39 +00:00
|
|
|
return service;
|
2022-08-29 18:04:55 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-17 00:43:12 +00:00
|
|
|
onDismiss() {
|
|
|
|
this.set('error', null);
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2019-05-17 00:43:12 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@watchRecord('allocation') watchNext;
|
2019-05-20 22:35:21 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@observes('model.nextAllocation.clientStatus')
|
|
|
|
observeWatchNext() {
|
2019-05-20 22:35:21 +00:00
|
|
|
const nextAllocation = this.model.nextAllocation;
|
|
|
|
if (nextAllocation && nextAllocation.content) {
|
|
|
|
this.watchNext.perform(nextAllocation);
|
|
|
|
} else {
|
|
|
|
this.watchNext.cancelAll();
|
|
|
|
}
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2019-05-20 22:35:21 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
@task(function* () {
|
2019-05-17 00:43:12 +00:00
|
|
|
try {
|
|
|
|
yield this.model.stop();
|
|
|
|
// Eagerly update the allocation clientStatus to avoid flickering
|
|
|
|
this.model.set('clientStatus', 'complete');
|
|
|
|
} catch (err) {
|
|
|
|
this.set('error', {
|
|
|
|
title: 'Could Not Stop Allocation',
|
2021-01-28 00:40:51 +00:00
|
|
|
description: messageForError(err, 'manage allocation lifecycle'),
|
2019-05-17 00:43:12 +00:00
|
|
|
});
|
|
|
|
}
|
2020-06-11 21:23:00 +00:00
|
|
|
})
|
|
|
|
stopAllocation;
|
2019-05-17 00:43:12 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
@task(function* () {
|
2019-05-17 00:43:12 +00:00
|
|
|
try {
|
|
|
|
yield this.model.restart();
|
|
|
|
} catch (err) {
|
|
|
|
this.set('error', {
|
2019-05-20 22:35:21 +00:00
|
|
|
title: 'Could Not Restart Allocation',
|
2021-01-28 00:40:51 +00:00
|
|
|
description: messageForError(err, 'manage allocation lifecycle'),
|
2019-05-17 00:43:12 +00:00
|
|
|
});
|
|
|
|
}
|
2020-06-11 21:23:00 +00:00
|
|
|
})
|
|
|
|
restartAllocation;
|
2019-05-17 00:43:12 +00:00
|
|
|
|
2022-08-24 22:43:44 +00:00
|
|
|
@task(function* () {
|
|
|
|
try {
|
|
|
|
yield this.model.restartAll();
|
|
|
|
} catch (err) {
|
|
|
|
this.set('error', {
|
|
|
|
title: 'Could Not Restart All Tasks',
|
|
|
|
description: messageForError(err, 'manage allocation lifecycle'),
|
|
|
|
});
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
restartAll;
|
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@action
|
|
|
|
gotoTask(allocation, task) {
|
|
|
|
this.transitionToRoute('allocations.allocation.task', task);
|
|
|
|
}
|
2018-06-06 21:25:48 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@action
|
|
|
|
taskClick(allocation, task, event) {
|
|
|
|
lazyClick([() => this.send('gotoTask', allocation, task), event]);
|
|
|
|
}
|
2022-09-07 14:23:39 +00:00
|
|
|
|
|
|
|
//#region Services
|
|
|
|
|
|
|
|
@tracked activeServiceID = null;
|
|
|
|
|
|
|
|
@action handleServiceClick(service) {
|
|
|
|
this.set('activeServiceID', service.refID);
|
|
|
|
}
|
|
|
|
|
|
|
|
@computed('activeServiceID', 'services')
|
|
|
|
get activeService() {
|
|
|
|
return this.services.findBy('refID', this.activeServiceID);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action closeSidebar() {
|
|
|
|
this.set('activeServiceID', null);
|
|
|
|
}
|
|
|
|
|
|
|
|
keyCommands = [
|
|
|
|
{
|
|
|
|
label: 'Close Evaluations Sidebar',
|
|
|
|
pattern: ['Escape'],
|
|
|
|
action: () => this.closeSidebar(),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
//#endregion Services
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|