open-nomad/ui/app/routes/jobs/job.js
Buck Doyle 8b5b2116ec
Fix job detail crash when recommendations off (#9269)
Without this, visiting any job detail page on Nomad OSS would crash with
an error like this:

Error: Ember Data Request GET
/v1/recommendations?job=ping%F0%9F%A5%B3&namespace=default returned a
404 Payload (text/xml)

The problem was twofold.

1. The recommendation ability didn’t include anything about checking
whether the feature was present. This adds a request to
/v1/operator/license on application load to determine which features are
present and store them in the system service. The ability now looks for
'Dynamic Application Sizing' in that feature list.

2. Second, I didn’t check permissions at all in the job-fetching or job
detail templates.
2020-11-06 08:21:38 -06:00

42 lines
1.2 KiB
JavaScript

import { inject as service } from '@ember/service';
import Route from '@ember/routing/route';
import RSVP from 'rsvp';
import notifyError from 'nomad-ui/utils/notify-error';
import { jobCrumbs } from 'nomad-ui/utils/breadcrumb-utils';
import classic from 'ember-classic-decorator';
@classic
export default class JobRoute extends Route {
@service can;
@service store;
@service token;
breadcrumbs = jobCrumbs;
serialize(model) {
return { job_name: model.get('plainId') };
}
model(params, transition) {
const namespace = transition.to.queryParams.namespace || this.get('system.activeNamespace.id');
const name = params.job_name;
const fullId = JSON.stringify([name, namespace || 'default']);
return this.store
.findRecord('job', fullId, { reload: true })
.then(job => {
const relatedModelsQueries = [
job.get('allocations'),
job.get('evaluations'),
];
if (this.can.can('accept recommendation')) {
relatedModelsQueries.push(job.get('recommendationSummaries'));
}
return RSVP.all(relatedModelsQueries).then(() => job);
})
.catch(notifyError(this));
}
}