open-nomad/ui/app/models/node.js

67 lines
2.1 KiB
JavaScript
Raw Normal View History

import { computed } from '@ember/object';
import { equal } from '@ember/object/computed';
2017-09-19 14:47:10 +00:00
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { hasMany } from 'ember-data/relationships';
import { fragment, fragmentArray } from 'ember-data-model-fragments/attributes';
2017-09-19 14:47:10 +00:00
import shortUUIDProperty from '../utils/properties/short-uuid';
import ipParts from '../utils/ip-parts';
export default Model.extend({
// Available from list response
name: attr('string'),
datacenter: attr('string'),
isDraining: attr('boolean'),
schedulingEligibility: attr('string'),
2017-09-19 14:47:10 +00:00
status: attr('string'),
statusDescription: attr('string'),
shortId: shortUUIDProperty('id'),
modifyIndex: attr('number'),
// Available from single response
httpAddr: attr('string'),
tlsEnabled: attr('boolean'),
attributes: fragment('node-attributes'),
meta: fragment('node-attributes'),
2017-09-19 14:47:10 +00:00
resources: fragment('resources'),
reserved: fragment('resources'),
drainStrategy: fragment('drain-strategy'),
2017-09-19 14:47:10 +00:00
isEligible: equal('schedulingEligibility', 'eligible'),
2017-09-19 14:47:10 +00:00
address: computed('httpAddr', function() {
return ipParts(this.get('httpAddr')).address;
}),
port: computed('httpAddr', function() {
return ipParts(this.get('httpAddr')).port;
}),
isPartial: computed('httpAddr', function() {
return this.get('httpAddr') == null;
}),
2018-04-25 22:50:15 +00:00
allocations: hasMany('allocations', { inverse: 'node' }),
drivers: fragmentArray('node-driver'),
events: fragmentArray('node-event'),
detectedDrivers: computed('drivers.@each.detected', function() {
return this.get('drivers').filterBy('detected');
}),
unhealthyDrivers: computed('detectedDrivers.@each.healthy', function() {
return this.get('detectedDrivers').filterBy('healthy', false);
}),
unhealthyDriverNames: computed('unhealthyDrivers.@each.name', function() {
return this.get('unhealthyDrivers').mapBy('name');
}),
2018-05-29 17:27:24 +00:00
// A status attribute that includes states not included in node status.
// Useful for coloring and sorting nodes
compositeStatus: computed('status', 'isEligible', function() {
return this.get('isEligible') ? this.get('status') : 'ineligible';
}),
2017-09-19 14:47:10 +00:00
});