github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/app/models/node.js (about)

     1  import { computed } from '@ember/object';
     2  import { equal } from '@ember/object/computed';
     3  import Model from '@ember-data/model';
     4  import { attr } from '@ember-data/model';
     5  import { hasMany } from '@ember-data/model';
     6  import { fragment, fragmentArray } from 'ember-data-model-fragments/attributes';
     7  import RSVP from 'rsvp';
     8  import shortUUIDProperty from '../utils/properties/short-uuid';
     9  import ipParts from '../utils/ip-parts';
    10  import classic from 'ember-classic-decorator';
    11  
    12  @classic
    13  export default class Node extends Model {
    14    // Available from list response
    15    @attr('string') name;
    16    @attr('string') datacenter;
    17    @attr('string') nodeClass;
    18    @attr('boolean') isDraining;
    19    @attr('string') schedulingEligibility;
    20    @attr('string') status;
    21    @attr('string') statusDescription;
    22    @shortUUIDProperty('id') shortId;
    23    @attr('number') modifyIndex;
    24  
    25    // Available from single response
    26    @attr('string') httpAddr;
    27    @attr('boolean') tlsEnabled;
    28    @fragment('node-attributes') attributes;
    29    @fragment('node-attributes') meta;
    30    @fragment('resources') resources;
    31    @fragment('resources') reserved;
    32    @fragment('drain-strategy') drainStrategy;
    33  
    34    @equal('schedulingEligibility', 'eligible') isEligible;
    35  
    36    @computed('httpAddr')
    37    get address() {
    38      return ipParts(this.httpAddr).address;
    39    }
    40  
    41    @computed('httpAddr')
    42    get port() {
    43      return ipParts(this.httpAddr).port;
    44    }
    45  
    46    @computed('httpAddr')
    47    get isPartial() {
    48      return this.httpAddr == null;
    49    }
    50  
    51    @hasMany('allocations', { inverse: 'node' }) allocations;
    52  
    53    @computed('allocations.@each.clientStatus')
    54    get completeAllocations() {
    55      return this.allocations.filterBy('clientStatus', 'complete');
    56    }
    57  
    58    @computed('allocations.@each.isRunning')
    59    get runningAllocations() {
    60      return this.allocations.filterBy('isRunning');
    61    }
    62  
    63    @computed('allocations.@each.{isMigrating,isRunning}')
    64    get migratingAllocations() {
    65      return this.allocations.filter(alloc => alloc.isRunning && alloc.isMigrating);
    66    }
    67  
    68    @computed('allocations.@each.{isMigrating,isRunning,modifyTime}')
    69    get lastMigrateTime() {
    70      const allocation = this.allocations
    71        .filterBy('isRunning', false)
    72        .filterBy('isMigrating')
    73        .sortBy('modifyTime')
    74        .reverse()[0];
    75      if (allocation) {
    76        return allocation.modifyTime;
    77      }
    78  
    79      return undefined;
    80    }
    81  
    82    @fragmentArray('node-driver') drivers;
    83    @fragmentArray('node-event') events;
    84    @fragmentArray('host-volume') hostVolumes;
    85  
    86    @computed('drivers.@each.detected')
    87    get detectedDrivers() {
    88      return this.drivers.filterBy('detected');
    89    }
    90  
    91    @computed('detectedDrivers.@each.healthy')
    92    get unhealthyDrivers() {
    93      return this.detectedDrivers.filterBy('healthy', false);
    94    }
    95  
    96    @computed('unhealthyDrivers.@each.name')
    97    get unhealthyDriverNames() {
    98      return this.unhealthyDrivers.mapBy('name');
    99    }
   100  
   101    // A status attribute that includes states not included in node status.
   102    // Useful for coloring and sorting nodes
   103    @computed('isDraining', 'isEligible', 'status')
   104    get compositeStatus() {
   105      if (this.status === 'down') {
   106        return 'down';
   107      } else if (this.isDraining) {
   108        return 'draining';
   109      } else if (!this.isEligible) {
   110        return 'ineligible';
   111      } else {
   112        return this.status;
   113      }
   114    }
   115  
   116    @computed('isDraining', 'isEligible', 'status')
   117    get compositeStatusIcon() {
   118      if (this.isDraining || !this.isEligible) {
   119        return 'alert-circle-fill';
   120      } else if (this.status === 'down') {
   121        return 'cancel-circle-fill';
   122      } else if (this.status === 'initializing') {
   123        return 'node-init-circle-fill';
   124      }
   125      return 'check-circle-fill';
   126    }
   127  
   128    setEligible() {
   129      if (this.isEligible) return RSVP.resolve();
   130      // Optimistically update schedulingEligibility for immediate feedback
   131      this.set('schedulingEligibility', 'eligible');
   132      return this.store.adapterFor('node').setEligible(this);
   133    }
   134  
   135    setIneligible() {
   136      if (!this.isEligible) return RSVP.resolve();
   137      // Optimistically update schedulingEligibility for immediate feedback
   138      this.set('schedulingEligibility', 'ineligible');
   139      return this.store.adapterFor('node').setIneligible(this);
   140    }
   141  
   142    drain(drainSpec) {
   143      return this.store.adapterFor('node').drain(this, drainSpec);
   144    }
   145  
   146    forceDrain(drainSpec) {
   147      return this.store.adapterFor('node').forceDrain(this, drainSpec);
   148    }
   149  
   150    cancelDrain() {
   151      return this.store.adapterFor('node').cancelDrain(this);
   152    }
   153  }