2020-11-09 17:29:12 +00:00
|
|
|
import Model, { attr, belongsTo } from '@ember-data/model';
|
2020-09-01 18:13:11 +00:00
|
|
|
import { computed } from '@ember/object';
|
|
|
|
import { or, filter, alias } from '@ember/object/computed';
|
2020-08-26 14:24:30 +00:00
|
|
|
|
|
|
|
export const PRIMARY_KEY = 'uid';
|
|
|
|
export const SLUG_KEY = 'Node.Node,Service.ID';
|
|
|
|
|
2020-11-09 17:29:12 +00:00
|
|
|
export default class ServiceInstance extends Model {
|
|
|
|
@attr('string') uid;
|
|
|
|
|
|
|
|
@attr('string') Datacenter;
|
2020-08-26 14:24:30 +00:00
|
|
|
// ProxyInstance is the ember-data model relationship
|
2020-11-09 17:29:12 +00:00
|
|
|
@belongsTo('Proxy') ProxyInstance;
|
2020-08-26 14:24:30 +00:00
|
|
|
// Proxy is the actual JSON api response
|
2020-11-09 17:29:12 +00:00
|
|
|
@attr() Proxy;
|
|
|
|
@attr() Node;
|
|
|
|
@attr() Service;
|
|
|
|
@attr() Checks;
|
|
|
|
@attr('number') SyncTime;
|
|
|
|
@attr() meta;
|
|
|
|
|
|
|
|
@or('Service.ID', 'Service.Service') Name;
|
2020-12-01 15:45:09 +00:00
|
|
|
@or('Service.Address', 'Node.Service') Address;
|
|
|
|
|
2020-11-09 17:29:12 +00:00
|
|
|
@alias('Service.Tags') Tags;
|
|
|
|
@alias('Service.Meta') Meta;
|
|
|
|
@alias('Service.Namespace') Namespace;
|
|
|
|
@filter('Checks.[]', (item, i, arr) => item.ServiceID !== '') ServiceChecks;
|
|
|
|
@filter('Checks.[]', (item, i, arr) => item.ServiceID === '') NodeChecks;
|
|
|
|
|
|
|
|
@computed('Service.Meta')
|
|
|
|
get ExternalSources() {
|
2020-09-01 18:13:11 +00:00
|
|
|
const sources = Object.entries(this.Service.Meta || {})
|
|
|
|
.filter(([key, value]) => key === 'external-source')
|
|
|
|
.map(([key, value]) => {
|
|
|
|
return value;
|
|
|
|
});
|
|
|
|
return [...new Set(sources)];
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('ChecksPassing', 'ChecksWarning', 'ChecksCritical')
|
|
|
|
get Status() {
|
2020-09-01 18:13:11 +00:00
|
|
|
switch (true) {
|
|
|
|
case this.ChecksCritical.length !== 0:
|
|
|
|
return 'critical';
|
|
|
|
case this.ChecksWarning.length !== 0:
|
|
|
|
return 'warning';
|
|
|
|
case this.ChecksPassing.length !== 0:
|
|
|
|
return 'passing';
|
|
|
|
default:
|
|
|
|
return 'empty';
|
|
|
|
}
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('Checks.[]')
|
|
|
|
get ChecksPassing() {
|
2020-09-01 18:13:11 +00:00
|
|
|
return this.Checks.filter(item => item.Status === 'passing');
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('Checks.[]')
|
|
|
|
get ChecksWarning() {
|
2020-09-01 18:13:11 +00:00
|
|
|
return this.Checks.filter(item => item.Status === 'warning');
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('Checks.[]')
|
|
|
|
get ChecksCritical() {
|
2020-09-01 18:13:11 +00:00
|
|
|
return this.Checks.filter(item => item.Status === 'critical');
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('Checks.[]', 'ChecksPassing')
|
|
|
|
get PercentageChecksPassing() {
|
2020-09-01 18:13:11 +00:00
|
|
|
return (this.ChecksPassing.length / this.Checks.length) * 100;
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('Checks.[]', 'ChecksWarning')
|
|
|
|
get PercentageChecksWarning() {
|
2020-09-01 18:13:11 +00:00
|
|
|
return (this.ChecksWarning.length / this.Checks.length) * 100;
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('Checks.[]', 'ChecksCritical')
|
|
|
|
get PercentageChecksCritical() {
|
2020-09-01 18:13:11 +00:00
|
|
|
return (this.ChecksCritical.length / this.Checks.length) * 100;
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
}
|