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';
|
2019-10-25 00:52:34 +00:00
|
|
|
import RSVP from 'rsvp';
|
2017-09-19 14:47:10 +00:00
|
|
|
import shortUUIDProperty from '../utils/properties/short-uuid';
|
|
|
|
import ipParts from '../utils/ip-parts';
|
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
export default class Node extends Model {
|
2017-09-19 14:47:10 +00:00
|
|
|
// Available from list response
|
2020-06-10 13:49:16 +00:00
|
|
|
@attr('string') name;
|
|
|
|
@attr('string') datacenter;
|
|
|
|
@attr('string') nodeClass;
|
|
|
|
@attr('boolean') isDraining;
|
|
|
|
@attr('string') schedulingEligibility;
|
|
|
|
@attr('string') status;
|
|
|
|
@attr('string') statusDescription;
|
|
|
|
@shortUUIDProperty('id') shortId;
|
|
|
|
@attr('number') modifyIndex;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
// Available from single response
|
2020-06-10 13:49:16 +00:00
|
|
|
@attr('string') httpAddr;
|
|
|
|
@attr('boolean') tlsEnabled;
|
|
|
|
@fragment('node-attributes') attributes;
|
|
|
|
@fragment('node-attributes') meta;
|
|
|
|
@fragment('resources') resources;
|
|
|
|
@fragment('resources') reserved;
|
|
|
|
@fragment('drain-strategy') drainStrategy;
|
|
|
|
|
|
|
|
@equal('schedulingEligibility', 'eligible') isEligible;
|
|
|
|
|
|
|
|
@computed('httpAddr')
|
|
|
|
get address() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return ipParts(this.httpAddr).address;
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('httpAddr')
|
|
|
|
get port() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return ipParts(this.httpAddr).port;
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('httpAddr')
|
|
|
|
get isPartial() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return this.httpAddr == null;
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@hasMany('allocations', { inverse: 'node' }) allocations;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('allocations.@each.clientStatus')
|
|
|
|
get completeAllocations() {
|
2019-11-15 01:26:20 +00:00
|
|
|
return this.allocations.filterBy('clientStatus', 'complete');
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('allocations.@each.isRunning')
|
|
|
|
get runningAllocations() {
|
2019-11-15 01:26:20 +00:00
|
|
|
return this.allocations.filterBy('isRunning');
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('allocations.@each.{isMigrating,isRunning}')
|
|
|
|
get migratingAllocations() {
|
2019-11-15 01:26:20 +00:00
|
|
|
return this.allocations.filter(alloc => alloc.isRunning && alloc.isMigrating);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('allocations.@each.{isMigrating,isRunning,modifyTime}')
|
|
|
|
get lastMigrateTime() {
|
2019-11-15 01:26:20 +00:00
|
|
|
const allocation = this.allocations
|
|
|
|
.filterBy('isRunning', false)
|
|
|
|
.filterBy('isMigrating')
|
|
|
|
.sortBy('modifyTime')
|
|
|
|
.reverse()[0];
|
|
|
|
if (allocation) {
|
|
|
|
return allocation.modifyTime;
|
|
|
|
}
|
2020-06-09 21:03:28 +00:00
|
|
|
|
2020-06-10 14:07:16 +00:00
|
|
|
return undefined;
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-05-08 16:39:27 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@fragmentArray('node-driver') drivers;
|
|
|
|
@fragmentArray('node-event') events;
|
|
|
|
@fragmentArray('host-volume') hostVolumes;
|
2018-05-08 18:22:36 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('drivers.@each.detected')
|
|
|
|
get detectedDrivers() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return this.drivers.filterBy('detected');
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-05-08 18:22:36 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('detectedDrivers.@each.healthy')
|
|
|
|
get unhealthyDrivers() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return this.detectedDrivers.filterBy('healthy', false);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-05-10 00:04:45 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('unhealthyDrivers.@each.name')
|
|
|
|
get unhealthyDriverNames() {
|
2019-03-26 07:46:44 +00:00
|
|
|
return this.unhealthyDrivers.mapBy('name');
|
2020-06-10 13:49:16 +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
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('isDraining', 'isEligible', 'status')
|
|
|
|
get compositeStatus() {
|
UI: Fix client sorting (#6817)
There are two changes here, and some caveats/commentary:
1. The “State“ table column was actually sorting only by status. The state was not an actual property, just something calculated in each client row, as a product of status, isEligible, and isDraining. This PR adds isDraining as a component of compositeState so it can be used for sorting.
2. The Sortable mixin declares dependent keys that cause the sort to be live-updating, but only if the members of the array change, such as if a new client is added, but not if any of the sortable properties change. This PR adds a SortableFactory function that generates a mixin whose listSorted computed property includes dependent keys for the sortable properties, so the table will live-update if any of the sortable properties change, not just the array members. There’s a warning if you use SortableFactory without dependent keys and via the original Sortable interface, so we can eventually migrate away from it.
2019-12-12 19:06:54 +00:00
|
|
|
if (this.isDraining) {
|
|
|
|
return 'draining';
|
|
|
|
} else if (!this.isEligible) {
|
|
|
|
return 'ineligible';
|
|
|
|
} else {
|
|
|
|
return this.status;
|
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2019-10-25 00:52:34 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('isDraining', 'isEligible', 'status')
|
|
|
|
get compositeStatusIcon() {
|
2020-01-24 01:59:21 +00:00
|
|
|
if (this.isDraining || !this.isEligible) {
|
|
|
|
return 'alert-circle-fill';
|
|
|
|
} else if (this.status === 'down') {
|
2020-01-31 20:51:22 +00:00
|
|
|
return 'cancel-circle-fill';
|
2020-01-24 01:59:21 +00:00
|
|
|
} else if (this.status === 'initializing') {
|
2020-01-31 20:51:22 +00:00
|
|
|
return 'node-init-circle-fill';
|
2020-01-24 01:59:21 +00:00
|
|
|
}
|
2020-01-31 20:51:22 +00:00
|
|
|
return 'check-circle-fill';
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2020-01-24 01:59:21 +00:00
|
|
|
|
2019-10-25 00:52:34 +00:00
|
|
|
setEligible() {
|
|
|
|
if (this.isEligible) return RSVP.resolve();
|
2019-11-02 07:55:01 +00:00
|
|
|
// Optimistically update schedulingEligibility for immediate feedback
|
|
|
|
this.set('schedulingEligibility', 'eligible');
|
2019-10-25 00:52:34 +00:00
|
|
|
return this.store.adapterFor('node').setEligible(this);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2019-10-25 00:52:34 +00:00
|
|
|
|
|
|
|
setIneligible() {
|
|
|
|
if (!this.isEligible) return RSVP.resolve();
|
2019-11-02 07:55:01 +00:00
|
|
|
// Optimistically update schedulingEligibility for immediate feedback
|
|
|
|
this.set('schedulingEligibility', 'ineligible');
|
2019-10-25 00:52:34 +00:00
|
|
|
return this.store.adapterFor('node').setIneligible(this);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2019-10-25 02:58:18 +00:00
|
|
|
|
|
|
|
drain(drainSpec) {
|
|
|
|
return this.store.adapterFor('node').drain(this, drainSpec);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2019-10-25 02:58:18 +00:00
|
|
|
|
|
|
|
forceDrain(drainSpec) {
|
|
|
|
return this.store.adapterFor('node').forceDrain(this, drainSpec);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2019-11-19 06:36:07 +00:00
|
|
|
|
|
|
|
cancelDrain() {
|
|
|
|
return this.store.adapterFor('node').cancelDrain(this);
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
}
|