open-nomad/ui/app/serializers/job-summary.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

import { get } from '@ember/object';
import ApplicationSerializer from './application';
export default class JobSummary extends ApplicationSerializer {
normalize(modelClass, hash) {
hash.PlainJobId = hash.JobID;
hash.ID = JSON.stringify([hash.JobID, hash.Namespace || 'default']);
hash.JobID = hash.ID;
// Transform the map-based Summary object into an array-based
// TaskGroupSummary fragment list
const fullSummary = hash.Summary || {};
hash.TaskGroupSummaries = Object.keys(fullSummary)
.sort()
2021-12-28 14:45:20 +00:00
.map((key) => {
const allocStats = fullSummary[key] || {};
const summary = { Name: key };
Object.keys(allocStats).forEach(
2021-12-28 14:45:20 +00:00
(allocKey) => (summary[`${allocKey}Allocs`] = allocStats[allocKey])
);
return summary;
});
// Lift the children stats out of the Children object
const childrenStats = get(hash, 'Children');
if (childrenStats) {
Object.keys(childrenStats).forEach(
2021-12-28 16:08:12 +00:00
(childrenKey) =>
(hash[`${childrenKey}Children`] = childrenStats[childrenKey])
);
}
return super.normalize(modelClass, hash);
}
}