github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/app/serializers/allocation.js (about) 1 import { inject as service } from '@ember/service'; 2 import { get } from '@ember/object'; 3 import ApplicationSerializer from './application'; 4 5 const taskGroupFromJob = (job, taskGroupName) => { 6 const taskGroups = job && job.TaskGroups; 7 const taskGroup = taskGroups && taskGroups.find(group => group.Name === taskGroupName); 8 return taskGroup ? taskGroup : null; 9 }; 10 11 export default ApplicationSerializer.extend({ 12 system: service(), 13 14 attrs: { 15 taskGroupName: 'TaskGroup', 16 states: 'TaskStates', 17 }, 18 19 normalize(typeHash, hash) { 20 // Transform the map-based TaskStates object into an array-based 21 // TaskState fragment list 22 const states = hash.TaskStates || {}; 23 hash.TaskStates = Object.keys(states).map(key => { 24 const state = states[key] || {}; 25 const summary = { Name: key }; 26 Object.keys(state).forEach(stateKey => (summary[stateKey] = state[stateKey])); 27 summary.Resources = hash.TaskResources && hash.TaskResources[key]; 28 return summary; 29 }); 30 31 hash.JobVersion = hash.JobVersion != null ? hash.JobVersion : get(hash, 'Job.Version'); 32 33 hash.PlainJobId = hash.JobID; 34 hash.Namespace = 35 hash.Namespace || 36 get(hash, 'Job.Namespace') || 37 this.get('system.activeNamespace.id') || 38 'default'; 39 hash.JobID = JSON.stringify([hash.JobID, hash.Namespace]); 40 41 hash.ModifyTimeNanos = hash.ModifyTime % 1000000; 42 hash.ModifyTime = Math.floor(hash.ModifyTime / 1000000); 43 44 hash.CreateTimeNanos = hash.CreateTime % 1000000; 45 hash.CreateTime = Math.floor(hash.CreateTime / 1000000); 46 47 hash.RescheduleEvents = (hash.RescheduleTracker || {}).Events; 48 49 hash.IsMigrating = (hash.DesiredTransition || {}).Migrate; 50 51 // API returns empty strings instead of null 52 hash.PreviousAllocationID = hash.PreviousAllocation ? hash.PreviousAllocation : null; 53 hash.NextAllocationID = hash.NextAllocation ? hash.NextAllocation : null; 54 hash.FollowUpEvaluationID = hash.FollowupEvalID ? hash.FollowupEvalID : null; 55 56 hash.PreemptedAllocationIDs = hash.PreemptedAllocations || []; 57 hash.PreemptedByAllocationID = hash.PreemptedByAllocation || null; 58 hash.WasPreempted = !!hash.PreemptedByAllocationID; 59 60 // When present, the resources are nested under AllocatedResources.Shared 61 hash.AllocatedResources = hash.AllocatedResources && hash.AllocatedResources.Shared; 62 63 // The Job definition for an allocation is only included in findRecord responses. 64 hash.AllocationTaskGroup = !hash.Job ? null : taskGroupFromJob(hash.Job, hash.TaskGroup); 65 66 return this._super(typeHash, hash); 67 }, 68 });