open-nomad/ui/app/routes/jobs/job/task-group.js

75 lines
2.5 KiB
JavaScript
Raw Normal View History

import Route from '@ember/routing/route';
import { collect } from '@ember/object/computed';
import EmberError from '@ember/error';
import { resolve, all } from 'rsvp';
import { watchRecord, watchRelationship } from 'nomad-ui/utils/properties/watch';
import WithWatchers from 'nomad-ui/mixins/with-watchers';
import { qpBuilder } from 'nomad-ui/utils/classes/query-params';
import notifyError from 'nomad-ui/utils/notify-error';
2017-09-19 14:47:10 +00:00
export default class TaskGroupRoute extends Route.extend(WithWatchers) {
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'),
model.get('name'),
qpBuilder({ jobNamespace: model.get('job.namespace.name') || 'default' }),
],
},
];
}
2017-09-19 14:47:10 +00:00
model({ name }) {
const job = this.modelFor('jobs.job');
// If there is no job, then there is no task group.
// Let the job route handle the 404.
if (!job) return;
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.
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)
return all([job.hasMany('allocations').reload(), job.get('scaleState')]).then(
() => taskGroup
);
})
.catch(notifyError(this));
}
startWatchers(controller, model) {
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),
scale: this.watchScale.perform(job),
2019-03-26 07:46:44 +00:00
allocations: this.watchAllocations.perform(job),
latestDeployment: job.get('supportsDeployments') && this.watchLatestDeployment.perform(job),
});
}
}
@watchRecord('job') watchJob;
@watchRelationship('job-summary') watchSummary;
@watchRelationship('job-scale') watchScale;
@watchRelationship('allocations') watchAllocations;
@watchRelationship('latestDeployment') watchLatestDeployment;
@collect('watchJob', 'watchSummary', 'watchScale', 'watchAllocations', 'watchLatestDeployment')
watchers;
}