github.com/manicqin/nomad@v0.9.5/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/attr'; 5 import { hasMany } from 'ember-data/relationships'; 6 import { fragment, fragmentArray } from 'ember-data-model-fragments/attributes'; 7 import shortUUIDProperty from '../utils/properties/short-uuid'; 8 import ipParts from '../utils/ip-parts'; 9 10 export default Model.extend({ 11 // Available from list response 12 name: attr('string'), 13 datacenter: attr('string'), 14 nodeClass: attr('string'), 15 isDraining: attr('boolean'), 16 schedulingEligibility: attr('string'), 17 status: attr('string'), 18 statusDescription: attr('string'), 19 shortId: shortUUIDProperty('id'), 20 modifyIndex: attr('number'), 21 22 // Available from single response 23 httpAddr: attr('string'), 24 tlsEnabled: attr('boolean'), 25 attributes: fragment('node-attributes'), 26 meta: fragment('node-attributes'), 27 resources: fragment('resources'), 28 reserved: fragment('resources'), 29 drainStrategy: fragment('drain-strategy'), 30 31 isEligible: equal('schedulingEligibility', 'eligible'), 32 33 address: computed('httpAddr', function() { 34 return ipParts(this.httpAddr).address; 35 }), 36 37 port: computed('httpAddr', function() { 38 return ipParts(this.httpAddr).port; 39 }), 40 41 isPartial: computed('httpAddr', function() { 42 return this.httpAddr == null; 43 }), 44 45 allocations: hasMany('allocations', { inverse: 'node' }), 46 47 drivers: fragmentArray('node-driver'), 48 events: fragmentArray('node-event'), 49 50 detectedDrivers: computed('drivers.@each.detected', function() { 51 return this.drivers.filterBy('detected'); 52 }), 53 54 unhealthyDrivers: computed('detectedDrivers.@each.healthy', function() { 55 return this.detectedDrivers.filterBy('healthy', false); 56 }), 57 58 unhealthyDriverNames: computed('unhealthyDrivers.@each.name', function() { 59 return this.unhealthyDrivers.mapBy('name'); 60 }), 61 62 // A status attribute that includes states not included in node status. 63 // Useful for coloring and sorting nodes 64 compositeStatus: computed('isDraining', 'isEligible', 'status', function() { 65 if (this.isDraining) { 66 return 'draining'; 67 } else if (!this.isEligible) { 68 return 'ineligible'; 69 } else { 70 return this.status; 71 } 72 }), 73 });