2017-09-19 14:47:10 +00:00
|
|
|
import ApplicationSerializer from './application';
|
|
|
|
import { arrToObj } from '../utils';
|
|
|
|
|
|
|
|
export default ApplicationSerializer.extend({
|
|
|
|
embed: true,
|
2020-08-28 00:58:24 +00:00
|
|
|
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'), {});
|
2020-08-24 16:27:43 +00:00
|
|
|
allocation.Resources = allocation.TaskResources.mapBy('Resources').reduce(
|
|
|
|
(hash, resources) => {
|
|
|
|
['CPU', 'DiskMB', 'IOPS', 'MemoryMB'].forEach(key => (hash[key] += resources[key]));
|
|
|
|
hash.Networks = resources.Networks;
|
|
|
|
hash.Ports = resources.Ports;
|
|
|
|
return hash;
|
|
|
|
},
|
|
|
|
{ CPU: 0, DiskMB: 0, IOPS: 0, MemoryMB: 0 }
|
|
|
|
);
|
2017-09-19 14:47:10 +00:00
|
|
|
allocation.TaskResources = allocation.TaskResources.reduce(arrToObj('Name', 'Resources'), {});
|
|
|
|
}
|