github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/models/service.js (about)

     1  // @ts-check
     2  import { attr, belongsTo } from '@ember-data/model';
     3  import Model from '@ember-data/model';
     4  import { alias } from '@ember/object/computed';
     5  
     6  export default class Service extends Model {
     7    @belongsTo('allocation') allocation;
     8    @belongsTo('job') job;
     9    @belongsTo('node') node;
    10  
    11    @attr('string') address;
    12    @attr('number') createIndex;
    13    @attr('string') datacenter;
    14    @attr('number') modifyIndex;
    15    @attr('string') namespace;
    16    @attr('number') port;
    17    @attr('string') serviceName;
    18    @attr() tags;
    19    @attr() canary_tags;
    20  
    21    @alias('serviceName') name;
    22  
    23    // Services can exist at either Group or Task level.
    24    // While our endpoints to get them do not explicitly tell us this,
    25    // we can infer it from the service's ID:
    26    get derivedLevel() {
    27      const idWithoutServiceName = this.id.replace(this.serviceName, '');
    28      if (idWithoutServiceName.includes('group-')) {
    29        return 'group';
    30      } else {
    31        return 'task';
    32      }
    33    }
    34  }