2017-12-15 21:39:18 +00:00
|
|
|
import Route from '@ember/routing/route';
|
2021-12-13 15:29:25 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2018-03-01 00:27:15 +00:00
|
|
|
import { collect } from '@ember/object/computed';
|
2022-08-26 22:02:12 +00:00
|
|
|
import {
|
|
|
|
watchRecord,
|
|
|
|
watchNonStoreRecords,
|
|
|
|
} from 'nomad-ui/utils/properties/watch';
|
2018-03-01 00:27:15 +00:00
|
|
|
import WithWatchers from 'nomad-ui/mixins/with-watchers';
|
2018-03-13 21:58:22 +00:00
|
|
|
import notifyError from 'nomad-ui/utils/notify-error';
|
2020-06-10 13:49:16 +00:00
|
|
|
export default class AllocationRoute extends Route.extend(WithWatchers) {
|
2023-03-02 18:52:16 +00:00
|
|
|
@service notifications;
|
2023-01-31 19:59:05 +00:00
|
|
|
@service router;
|
2021-12-13 15:29:25 +00:00
|
|
|
@service store;
|
|
|
|
|
2018-03-06 22:27:01 +00:00
|
|
|
startWatchers(controller, model) {
|
2018-11-06 00:33:33 +00:00
|
|
|
if (model) {
|
2019-03-26 07:46:44 +00:00
|
|
|
controller.set('watcher', this.watch.perform(model));
|
2022-08-29 18:04:55 +00:00
|
|
|
|
2022-09-29 14:39:42 +00:00
|
|
|
const anyGroupServicesAreNomad = !!model.taskGroup?.services?.filterBy(
|
|
|
|
'provider',
|
|
|
|
'nomad'
|
|
|
|
).length;
|
|
|
|
|
|
|
|
const anyTaskServicesAreNomad = model.states
|
|
|
|
.mapBy('task.services')
|
|
|
|
.compact()
|
|
|
|
.map((fragmentClass) => fragmentClass.mapBy('provider'))
|
|
|
|
.flat()
|
|
|
|
.any((provider) => provider === 'nomad');
|
2022-08-29 18:04:55 +00:00
|
|
|
|
2022-09-29 14:39:42 +00:00
|
|
|
// Conditionally Long Poll /checks endpoint if alloc has nomad services
|
|
|
|
if (anyGroupServicesAreNomad || anyTaskServicesAreNomad) {
|
2022-08-29 18:04:55 +00:00
|
|
|
controller.set(
|
|
|
|
'watchHealthChecks',
|
2022-09-13 02:10:43 +00:00
|
|
|
this.watchHealthChecks.perform(model, 'getServiceHealth', 2000)
|
2022-08-29 18:04:55 +00:00
|
|
|
);
|
|
|
|
}
|
2018-11-06 00:33:33 +00:00
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-02-28 19:48:06 +00:00
|
|
|
|
2023-01-31 19:59:05 +00:00
|
|
|
async model() {
|
2022-10-24 13:04:39 +00:00
|
|
|
// Preload the job for the allocation since it's required for the breadcrumb trail
|
2023-01-31 19:59:05 +00:00
|
|
|
try {
|
|
|
|
const [allocation] = await Promise.all([
|
|
|
|
super.model(...arguments),
|
|
|
|
this.store.findAll('namespace'),
|
|
|
|
]);
|
|
|
|
const jobId = allocation.belongsTo('job').id();
|
|
|
|
await this.store.findRecord('job', jobId);
|
|
|
|
return allocation;
|
|
|
|
} catch (e) {
|
|
|
|
const [allocId, transition] = arguments;
|
|
|
|
if (e?.errors[0]?.detail === 'alloc not found' && !!transition.from) {
|
2023-03-02 18:52:16 +00:00
|
|
|
this.notifications.add({
|
2023-01-31 19:59:05 +00:00
|
|
|
title: `Error: Not Found`,
|
|
|
|
message: `Allocation of id: ${allocId} was not found.`,
|
2023-03-02 18:52:16 +00:00
|
|
|
color: 'critical',
|
2023-01-31 19:59:05 +00:00
|
|
|
sticky: true,
|
|
|
|
});
|
|
|
|
this.goBackToReferrer(transition.from.name);
|
|
|
|
} else {
|
|
|
|
notifyError(this)(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
goBackToReferrer(referringRoute) {
|
|
|
|
this.router.transitionTo(referringRoute);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-03-13 21:58:22 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@watchRecord('allocation') watch;
|
2022-08-26 22:02:12 +00:00
|
|
|
@watchNonStoreRecords('allocation') watchHealthChecks;
|
2018-03-01 00:27:15 +00:00
|
|
|
|
2022-09-06 15:46:11 +00:00
|
|
|
@collect('watch', 'watchHealthChecks') watchers;
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|