github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/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      hash.TaskStates = Object.keys(get(hash, 'TaskStates') || {}).map(key => {
    17        const state = get(hash, `TaskStates.${key}`);
    18        const summary = { Name: key };
    19        Object.keys(state).forEach(stateKey => (summary[stateKey] = state[stateKey]));
    20        summary.Resources = hash.TaskResources && hash.TaskResources[key];
    21        return summary;
    22      });
    23  
    24      hash.JobVersion = hash.JobVersion != null ? hash.JobVersion : get(hash, 'Job.Version');
    25  
    26      hash.PlainJobId = hash.JobID;
    27      hash.Namespace =
    28        hash.Namespace ||
    29        get(hash, 'Job.Namespace') ||
    30        this.get('system.activeNamespace.id') ||
    31        'default';
    32      hash.JobID = JSON.stringify([hash.JobID, hash.Namespace]);
    33  
    34      hash.ModifyTimeNanos = hash.ModifyTime % 1000000;
    35      hash.ModifyTime = Math.floor(hash.ModifyTime / 1000000);
    36  
    37      hash.CreateTimeNanos = hash.CreateTime % 1000000;
    38      hash.CreateTime = Math.floor(hash.CreateTime / 1000000);
    39  
    40      hash.RescheduleEvents = (hash.RescheduleTracker || {}).Events;
    41  
    42      // API returns empty strings instead of null
    43      hash.PreviousAllocationID = hash.PreviousAllocation ? hash.PreviousAllocation : null;
    44      hash.NextAllocationID = hash.NextAllocation ? hash.NextAllocation : null;
    45      hash.FollowUpEvaluationID = hash.FollowupEvalID ? hash.FollowupEvalID : null;
    46  
    47      return this._super(typeHash, hash);
    48    },
    49  });