github.com/thomasobenaus/nomad@v0.11.1/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      hash.IsMigrating = (hash.DesiredTransition || {}).Migrate;
    44  
    45      // API returns empty strings instead of null
    46      hash.PreviousAllocationID = hash.PreviousAllocation ? hash.PreviousAllocation : null;
    47      hash.NextAllocationID = hash.NextAllocation ? hash.NextAllocation : null;
    48      hash.FollowUpEvaluationID = hash.FollowupEvalID ? hash.FollowupEvalID : null;
    49  
    50      hash.PreemptedAllocationIDs = hash.PreemptedAllocations || [];
    51      hash.PreemptedByAllocationID = hash.PreemptedByAllocation || null;
    52      hash.WasPreempted = !!hash.PreemptedByAllocationID;
    53  
    54      // When present, the resources are nested under AllocatedResources.Shared
    55      hash.AllocatedResources = hash.AllocatedResources && hash.AllocatedResources.Shared;
    56  
    57      return this._super(typeHash, hash);
    58    },
    59  });