2017-09-19 14:47:10 +00:00
|
|
|
import Ember from 'ember';
|
|
|
|
import PromiseObject from '../utils/classes/promise-object';
|
|
|
|
import { namespace } from '../adapters/application';
|
|
|
|
|
2017-10-07 00:14:08 +00:00
|
|
|
const { Service, computed, inject } = Ember;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
export default Service.extend({
|
2017-10-07 00:14:08 +00:00
|
|
|
token: inject.service(),
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
leader: computed(function() {
|
2017-10-07 00:14:08 +00:00
|
|
|
const token = this.get('token');
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
return PromiseObject.create({
|
2017-10-07 00:14:08 +00:00
|
|
|
promise: token
|
|
|
|
.authorizedRequest(`/${namespace}/status/leader`)
|
2017-09-19 14:47:10 +00:00
|
|
|
.then(res => res.json())
|
|
|
|
.then(rpcAddr => ({ rpcAddr }))
|
|
|
|
.then(leader => {
|
|
|
|
// Dirty self so leader can be used as a dependent key
|
|
|
|
this.notifyPropertyChange('leader.rpcAddr');
|
|
|
|
return leader;
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
});
|