github.com/manicqin/nomad@v0.9.5/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 export default ApplicationSerializer.extend({ 6 system: service(), 7 8 attrs: { 9 taskGroupName: 'TaskGroup', 10 states: 'TaskStates', 11 }, 12 13 normalize(typeHash, hash) { 14 // Transform the map-based TaskStates object into an array-based 15 // TaskState fragment list 16 const states = hash.TaskStates || {}; 17 hash.TaskStates = Object.keys(states).map(key => { 18 const state = states[key] || {}; 19 const summary = { Name: key }; 20 Object.keys(state).forEach(stateKey => (summary[stateKey] = state[stateKey])); 21 summary.Resources = hash.TaskResources && hash.TaskResources[key]; 22 return summary; 23 }); 24 25 hash.JobVersion = hash.JobVersion != null ? hash.JobVersion : get(hash, 'Job.Version'); 26 27 hash.PlainJobId = hash.JobID; 28 hash.Namespace = 29 hash.Namespace || 30 get(hash, 'Job.Namespace') || 31 this.get('system.activeNamespace.id') || 32 'default'; 33 hash.JobID = JSON.stringify([hash.JobID, hash.Namespace]); 34 35 hash.ModifyTimeNanos = hash.ModifyTime % 1000000; 36 hash.ModifyTime = Math.floor(hash.ModifyTime / 1000000); 37 38 hash.CreateTimeNanos = hash.CreateTime % 1000000; 39 hash.CreateTime = Math.floor(hash.CreateTime / 1000000); 40 41 hash.RescheduleEvents = (hash.RescheduleTracker || {}).Events; 42 43 // API returns empty strings instead of null 44 hash.PreviousAllocationID = hash.PreviousAllocation ? hash.PreviousAllocation : null; 45 hash.NextAllocationID = hash.NextAllocation ? hash.NextAllocation : null; 46 hash.FollowUpEvaluationID = hash.FollowupEvalID ? hash.FollowupEvalID : null; 47 48 hash.PreemptedAllocationIDs = hash.PreemptedAllocations || []; 49 hash.PreemptedByAllocationID = hash.PreemptedByAllocation || null; 50 hash.WasPreempted = !!hash.PreemptedByAllocationID; 51 52 // When present, the resources are nested under AllocatedResources.Shared 53 hash.AllocatedResources = hash.AllocatedResources && hash.AllocatedResources.Shared; 54 55 return this._super(typeHash, hash); 56 }, 57 });