Derive allocation Resources property from TaskResources

This commit is contained in:
Michael Lange 2020-08-24 09:27:43 -07:00
parent edd904c1c4
commit 0f2fd905d8

View file

@ -18,5 +18,14 @@ export default ApplicationSerializer.extend({
function serializeAllocation(allocation) {
allocation.TaskStates = allocation.TaskStates.reduce(arrToObj('Name'), {});
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 }
);
allocation.TaskResources = allocation.TaskResources.reduce(arrToObj('Name', 'Resources'), {});
}