github.com/emate/nomad@v0.8.2-wo-binpacking/ui/app/models/allocation.js (about)

     1  import { inject as service } from '@ember/service';
     2  import { computed } from '@ember/object';
     3  import Model from 'ember-data/model';
     4  import attr from 'ember-data/attr';
     5  import { belongsTo } from 'ember-data/relationships';
     6  import { fragment, fragmentArray } from 'ember-data-model-fragments/attributes';
     7  import shortUUIDProperty from '../utils/properties/short-uuid';
     8  import AllocationStats from '../utils/classes/allocation-stats';
     9  
    10  const STATUS_ORDER = {
    11    pending: 1,
    12    running: 2,
    13    complete: 3,
    14    failed: 4,
    15    lost: 5,
    16  };
    17  
    18  export default Model.extend({
    19    token: service(),
    20  
    21    shortId: shortUUIDProperty('id'),
    22    job: belongsTo('job'),
    23    node: belongsTo('node'),
    24    name: attr('string'),
    25    taskGroupName: attr('string'),
    26    resources: fragment('resources'),
    27    modifyIndex: attr('number'),
    28    modifyTime: attr('date'),
    29    jobVersion: attr('number'),
    30  
    31    // TEMPORARY: https://github.com/emberjs/data/issues/5209
    32    originalJobId: attr('string'),
    33  
    34    clientStatus: attr('string'),
    35    desiredStatus: attr('string'),
    36    statusIndex: computed('clientStatus', function() {
    37      return STATUS_ORDER[this.get('clientStatus')] || 100;
    38    }),
    39  
    40    statusClass: computed('clientStatus', function() {
    41      const classMap = {
    42        pending: 'is-pending',
    43        running: 'is-primary',
    44        complete: 'is-complete',
    45        failed: 'is-error',
    46        lost: 'is-light',
    47      };
    48  
    49      return classMap[this.get('clientStatus')] || 'is-dark';
    50    }),
    51  
    52    taskGroup: computed('taskGroupName', 'job.taskGroups.[]', function() {
    53      const taskGroups = this.get('job.taskGroups');
    54      return taskGroups && taskGroups.findBy('name', this.get('taskGroupName'));
    55    }),
    56  
    57    fetchStats() {
    58      return this.get('token')
    59        .authorizedRequest(`/v1/client/allocation/${this.get('id')}/stats`)
    60        .then(res => res.json())
    61        .then(json => {
    62          return new AllocationStats({
    63            stats: json,
    64            allocation: this,
    65          });
    66        });
    67    },
    68  
    69    states: fragmentArray('task-state'),
    70  });