open-nomad/ui/mirage/serializers/allocation.js

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

32 lines
893 B
JavaScript
Raw Normal View History

2017-09-19 14:47:10 +00:00
import ApplicationSerializer from './application';
import { arrToObj } from '../utils';
export default ApplicationSerializer.extend({
embed: true,
include: ['taskStates', 'taskResources'],
2017-09-19 14:47:10 +00:00
serialize() {
var json = ApplicationSerializer.prototype.serialize.apply(this, arguments);
if (json instanceof Array) {
json.forEach(serializeAllocation);
} else {
serializeAllocation(json);
}
return json;
},
});
function serializeAllocation(allocation) {
allocation.TaskStates = allocation.TaskStates.reduce(arrToObj('Name'), {});
const { Ports, Networks } = allocation.TaskResources[0]
? allocation.TaskResources[0].Resources
: {};
allocation.AllocatedResources = {
Shared: { Ports, Networks },
Tasks: allocation.TaskResources.map(({ Name, Resources }) => ({ Name, ...Resources })).reduce(
arrToObj('Name'),
{}
),
};
2017-09-19 14:47:10 +00:00
}