2017-12-15 21:39:18 +00:00
|
|
|
import Route from '@ember/routing/route';
|
2018-02-28 19:31:48 +00:00
|
|
|
import { collect } from '@ember/object/computed';
|
2018-11-03 01:24:33 +00:00
|
|
|
import EmberError from '@ember/error';
|
|
|
|
import { resolve } from 'rsvp';
|
2018-02-28 19:31:48 +00:00
|
|
|
import { watchRecord, watchRelationship } from 'nomad-ui/utils/properties/watch';
|
2018-03-01 00:27:15 +00:00
|
|
|
import WithWatchers from 'nomad-ui/mixins/with-watchers';
|
2018-06-27 19:17:23 +00:00
|
|
|
import { qpBuilder } from 'nomad-ui/utils/classes/query-params';
|
2018-11-03 01:24:33 +00:00
|
|
|
import notifyError from 'nomad-ui/utils/notify-error';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
export default class TaskGroupRoute extends Route.extend(WithWatchers) {
|
2018-06-27 19:17:23 +00:00
|
|
|
breadcrumbs(model) {
|
|
|
|
if (!model) return [];
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
label: model.get('name'),
|
|
|
|
args: [
|
|
|
|
'jobs.job.task-group',
|
2018-10-17 19:55:00 +00:00
|
|
|
model.get('job'),
|
2018-06-27 19:17:23 +00:00
|
|
|
model.get('name'),
|
|
|
|
qpBuilder({ jobNamespace: model.get('job.namespace.name') || 'default' }),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-06-27 19:17:23 +00:00
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
model({ name }) {
|
2018-11-03 01:24:33 +00:00
|
|
|
const job = this.modelFor('jobs.job');
|
|
|
|
|
2018-11-05 23:42:04 +00:00
|
|
|
// If there is no job, then there is no task group.
|
|
|
|
// Let the job route handle the 404.
|
|
|
|
if (!job) return;
|
2018-11-03 01:24:33 +00:00
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
// If the job is a partial (from the list request) it won't have task
|
|
|
|
// groups. Reload the job to ensure task groups are present.
|
2018-11-03 01:24:33 +00:00
|
|
|
const reload = job.get('isPartial') ? job.reload() : resolve();
|
|
|
|
return reload
|
|
|
|
.then(() => {
|
|
|
|
const taskGroup = job.get('taskGroups').findBy('name', name);
|
|
|
|
if (!taskGroup) {
|
|
|
|
const err = new EmberError(`Task group ${name} for job ${job.get('name')} not found`);
|
|
|
|
err.code = '404';
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Refresh job allocations before-hand (so page sort works on load)
|
2017-09-19 14:47:10 +00:00
|
|
|
return job
|
|
|
|
.hasMany('allocations')
|
|
|
|
.reload()
|
2018-11-03 01:24:33 +00:00
|
|
|
.then(() => taskGroup);
|
|
|
|
})
|
|
|
|
.catch(notifyError(this));
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-02-28 19:31:48 +00:00
|
|
|
|
2018-03-06 22:27:01 +00:00
|
|
|
startWatchers(controller, model) {
|
2018-11-03 01:24:33 +00:00
|
|
|
if (model) {
|
|
|
|
const job = model.get('job');
|
|
|
|
controller.set('watchers', {
|
2019-03-26 07:46:44 +00:00
|
|
|
job: this.watchJob.perform(job),
|
|
|
|
summary: this.watchSummary.perform(job.get('summary')),
|
|
|
|
allocations: this.watchAllocations.perform(job),
|
2020-06-19 05:51:05 +00:00
|
|
|
latestDeployment: job.get('supportsDeployments') && this.watchLatestDeployment.perform(job),
|
2018-11-03 01:24:33 +00:00
|
|
|
});
|
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-02-28 19:31:48 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@watchRecord('job') watchJob;
|
|
|
|
@watchRecord('job-summary') watchSummary;
|
|
|
|
@watchRelationship('allocations') watchAllocations;
|
2020-06-19 05:51:05 +00:00
|
|
|
@watchRelationship('latestDeployment') watchLatestDeployment;
|
2018-02-28 19:31:48 +00:00
|
|
|
|
2020-06-19 05:51:05 +00:00
|
|
|
@collect('watchJob', 'watchSummary', 'watchAllocations', 'watchLatestDeployment') watchers;
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|