open-nomad/ui/app/serializers/deployment.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.4 KiB
JavaScript
Raw Normal View History

import { get } from '@ember/object';
import { assign } from '@ember/polyfills';
2017-09-19 14:47:10 +00:00
import ApplicationSerializer from './application';
import classic from 'ember-classic-decorator';
2017-09-19 14:47:10 +00:00
@classic
export default class DeploymentSerializer extends ApplicationSerializer {
attrs = {
2017-09-19 14:47:10 +00:00
versionNumber: 'JobVersion',
};
2017-09-19 14:47:10 +00:00
mapToArray = [{ beforeName: 'TaskGroups', afterName: 'TaskGroupSummaries' }];
2017-09-19 14:47:10 +00:00
normalize(typeHash, hash) {
if (hash) {
hash.PlainJobId = hash.JobID;
2021-12-28 16:08:12 +00:00
hash.Namespace =
hash.Namespace || get(hash, 'Job.Namespace') || 'default';
// Ember Data doesn't support multiple inverses. This means that since jobs have
// two relationships to a deployment (hasMany deployments, and belongsTo latestDeployment),
// the deployment must in turn have two relationships to the job, despite it being the
// same job.
2021-12-28 16:08:12 +00:00
hash.JobID = hash.JobForLatestID = JSON.stringify([
hash.JobID,
hash.Namespace,
]);
}
return super.normalize(typeHash, hash);
}
2017-09-19 14:47:10 +00:00
extractRelationships(modelClass, hash) {
2021-12-28 16:08:12 +00:00
const namespace = this.store
.adapterFor(modelClass.modelName)
.get('namespace');
2017-09-19 14:47:10 +00:00
const id = this.extractId(modelClass, hash);
return assign(
{
allocations: {
links: {
related: `/${namespace}/deployment/allocations/${id}`,
},
},
},
super.extractRelationships(modelClass, hash)
2017-09-19 14:47:10 +00:00
);
}
}