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

73 lines
2.2 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';
2021-12-28 16:08:12 +00:00
import {
watchRecord,
2022-01-20 15:39:02 +00:00
watchRelationship,
2021-12-28 16:08:12 +00:00
} from 'nomad-ui/utils/properties/watch';
import WithWatchers from 'nomad-ui/mixins/with-watchers';
import notifyError from 'nomad-ui/utils/notify-error';
2017-09-19 14:47:10 +00:00
export default class TaskGroupRoute extends Route.extend(WithWatchers) {
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) {
2021-12-28 16:08:12 +00:00
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)
2021-12-28 16:08:12 +00:00
return all([
job.hasMany('allocations').reload(),
2022-01-20 15:39:02 +00:00
job.get('scaleState'),
2021-12-28 16:08:12 +00:00
]).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.get('summary')),
scale: this.watchScale.perform(job.get('scaleState')),
2019-03-26 07:46:44 +00:00
allocations: this.watchAllocations.perform(job),
2021-12-28 16:08:12 +00:00
latestDeployment:
job.get('supportsDeployments') &&
2022-01-20 15:39:02 +00:00
this.watchLatestDeployment.perform(job),
});
}
}
@watchRecord('job') watchJob;
@watchRecord('job-summary') watchSummary;
@watchRecord('job-scale') watchScale;
@watchRelationship('allocations') watchAllocations;
@watchRelationship('latestDeployment') watchLatestDeployment;
2021-12-28 16:08:12 +00:00
@collect(
'watchJob',
'watchSummary',
'watchScale',
'watchAllocations',
'watchLatestDeployment'
)
watchers;
}