2018-04-03 14:16:57 +00:00
|
|
|
import Ember from 'ember';
|
|
|
|
import { task } from 'ember-concurrency';
|
|
|
|
|
|
|
|
const { Service, inject, computed } = Ember;
|
|
|
|
|
|
|
|
const hasFeature = featureKey => {
|
|
|
|
return computed('features', 'features.[]', function() {
|
|
|
|
const features = this.get('features');
|
|
|
|
if (!features) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return features.includes(featureKey);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
export default Service.extend({
|
|
|
|
_features: null,
|
|
|
|
features: computed.readOnly('_features'),
|
|
|
|
version: null,
|
|
|
|
store: inject.service(),
|
|
|
|
|
|
|
|
hasPerfReplication: hasFeature('Performance Replication'),
|
|
|
|
|
|
|
|
hasDRReplication: hasFeature('DR Replication'),
|
|
|
|
|
2018-04-05 21:08:18 +00:00
|
|
|
hasSentinel: hasFeature('Sentinel'),
|
2018-08-16 17:48:24 +00:00
|
|
|
hasNamespaces: hasFeature('Namespaces'),
|
2018-04-05 21:08:18 +00:00
|
|
|
|
2018-05-10 21:44:17 +00:00
|
|
|
isEnterprise: computed.match('version', /\+.+$/),
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
|
|
isOSS: computed.not('isEnterprise'),
|
|
|
|
|
|
|
|
setVersion(resp) {
|
|
|
|
this.set('version', resp.version);
|
|
|
|
},
|
|
|
|
|
|
|
|
setFeatures(resp) {
|
|
|
|
if (!resp.features) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.set('_features', resp.features);
|
|
|
|
},
|
|
|
|
|
|
|
|
getVersion: task(function*() {
|
|
|
|
if (this.get('version')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let response = yield this.get('store').adapterFor('cluster').health();
|
|
|
|
this.setVersion(response);
|
|
|
|
return;
|
|
|
|
}),
|
|
|
|
|
|
|
|
getFeatures: task(function*() {
|
|
|
|
if (this.get('features.length') || this.get('isOSS')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
let response = yield this.get('store').adapterFor('cluster').features();
|
|
|
|
this.setFeatures(response);
|
|
|
|
return;
|
|
|
|
} catch (err) {
|
2018-05-31 21:22:49 +00:00
|
|
|
// if we fail here, we're likely in DR Secondary mode and don't need to worry about it
|
2018-04-03 14:16:57 +00:00
|
|
|
}
|
|
|
|
}).keepLatest(),
|
|
|
|
|
|
|
|
fetchVersion: function() {
|
|
|
|
return this.get('getVersion').perform();
|
|
|
|
},
|
|
|
|
fetchFeatures: function() {
|
|
|
|
return this.get('getFeatures').perform();
|
|
|
|
},
|
|
|
|
});
|