2018-09-25 16:28:26 +00:00
|
|
|
import { readOnly, match, not } from '@ember/object/computed';
|
|
|
|
import Service, { inject as service } from '@ember/service';
|
|
|
|
import { computed } from '@ember/object';
|
2018-04-03 14:16:57 +00:00
|
|
|
import { task } from 'ember-concurrency';
|
|
|
|
|
2018-08-28 05:03:55 +00:00
|
|
|
const hasFeatureMethod = (context, featureKey) => {
|
|
|
|
const features = context.get('features');
|
|
|
|
if (!features) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return features.includes(featureKey);
|
|
|
|
};
|
2018-04-03 14:16:57 +00:00
|
|
|
const hasFeature = featureKey => {
|
|
|
|
return computed('features', 'features.[]', function() {
|
2018-08-28 05:03:55 +00:00
|
|
|
return hasFeatureMethod(this, featureKey);
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
export default Service.extend({
|
|
|
|
_features: null,
|
2018-09-25 16:28:26 +00:00
|
|
|
features: readOnly('_features'),
|
2018-04-03 14:16:57 +00:00
|
|
|
version: null,
|
2018-09-25 16:28:26 +00:00
|
|
|
store: service(),
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
|
|
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-09-25 16:28:26 +00:00
|
|
|
isEnterprise: match('version', /\+.+$/),
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
isOSS: not('isEnterprise'),
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
|
|
setVersion(resp) {
|
|
|
|
this.set('version', resp.version);
|
|
|
|
},
|
|
|
|
|
2018-08-28 05:03:55 +00:00
|
|
|
hasFeature(feature) {
|
|
|
|
return hasFeatureMethod(this, feature);
|
|
|
|
},
|
|
|
|
|
2018-04-03 14:16:57 +00:00
|
|
|
setFeatures(resp) {
|
|
|
|
if (!resp.features) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.set('_features', resp.features);
|
|
|
|
},
|
|
|
|
|
|
|
|
getVersion: task(function*() {
|
|
|
|
if (this.get('version')) {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-12 19:03:01 +00:00
|
|
|
let response = yield this.get('store')
|
|
|
|
.adapterFor('cluster')
|
|
|
|
.health();
|
2018-04-03 14:16:57 +00:00
|
|
|
this.setVersion(response);
|
|
|
|
return;
|
|
|
|
}),
|
|
|
|
|
|
|
|
getFeatures: task(function*() {
|
|
|
|
if (this.get('features.length') || this.get('isOSS')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
2018-10-12 19:03:01 +00:00
|
|
|
let response = yield this.get('store')
|
|
|
|
.adapterFor('cluster')
|
|
|
|
.features();
|
2018-04-03 14:16:57 +00:00
|
|
|
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();
|
|
|
|
},
|
|
|
|
});
|