2017-12-15 21:39:18 +00:00
|
|
|
import { computed } from '@ember/object';
|
2018-05-29 17:05:16 +00:00
|
|
|
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';
|
2018-05-08 16:39:27 +00:00
|
|
|
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'),
|
2019-02-12 04:01:14 +00:00
|
|
|
nodeClass: attr('string'),
|
2017-09-19 14:47:10 +00:00
|
|
|
isDraining: attr('boolean'),
|
2018-05-29 17:05:16 +00:00
|
|
|
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'),
|
2018-02-07 02:52:16 +00:00
|
|
|
meta: fragment('node-attributes'),
|
2017-09-19 14:47:10 +00:00
|
|
|
resources: fragment('resources'),
|
|
|
|
reserved: fragment('resources'),
|
2018-05-30 08:04:51 +00:00
|
|
|
drainStrategy: fragment('drain-strategy'),
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-05-29 17:05:16 +00:00
|
|
|
isEligible: equal('schedulingEligibility', 'eligible'),
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
address: computed('httpAddr', function() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return ipParts(this.httpAddr).address;
|
2017-09-19 14:47:10 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
port: computed('httpAddr', function() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return ipParts(this.httpAddr).port;
|
2017-09-19 14:47:10 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
isPartial: computed('httpAddr', function() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return this.httpAddr == null;
|
2017-09-19 14:47:10 +00:00
|
|
|
}),
|
|
|
|
|
2018-04-25 22:50:15 +00:00
|
|
|
allocations: hasMany('allocations', { inverse: 'node' }),
|
2018-05-08 16:39:27 +00:00
|
|
|
|
|
|
|
drivers: fragmentArray('node-driver'),
|
|
|
|
events: fragmentArray('node-event'),
|
2018-05-08 18:22:36 +00:00
|
|
|
|
|
|
|
detectedDrivers: computed('drivers.@each.detected', function() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return this.drivers.filterBy('detected');
|
2018-05-08 18:22:36 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
unhealthyDrivers: computed('detectedDrivers.@each.healthy', function() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return this.detectedDrivers.filterBy('healthy', false);
|
2018-05-08 18:22:36 +00:00
|
|
|
}),
|
2018-05-10 00:04:45 +00:00
|
|
|
|
|
|
|
unhealthyDriverNames: computed('unhealthyDrivers.@each.name', function() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return this.unhealthyDrivers.mapBy('name');
|
2018-05-10 00:04:45 +00:00
|
|
|
}),
|
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() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return this.isEligible ? this.status : 'ineligible';
|
2018-05-29 17:27:24 +00:00
|
|
|
}),
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|