2019-03-22 17:24:40 +00:00
|
|
|
import { get } from '@ember/object';
|
2018-10-26 16:36:15 +00:00
|
|
|
import RepositoryService from 'consul-ui/services/repository';
|
|
|
|
|
2019-03-22 17:24:40 +00:00
|
|
|
import tomographyFactory from 'consul-ui/utils/tomography';
|
|
|
|
import distance from 'consul-ui/utils/distance';
|
|
|
|
const tomography = tomographyFactory(distance);
|
|
|
|
|
2018-10-26 16:36:15 +00:00
|
|
|
const modelName = 'coordinate';
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class CoordinateService extends RepositoryService {
|
|
|
|
getModelName() {
|
2018-10-26 16:36:15 +00:00
|
|
|
return modelName;
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 18:12:47 +00:00
|
|
|
// Coordinates don't need nspaces so we have a custom method here
|
|
|
|
// that doesn't accept nspaces
|
2020-11-09 09:25:35 +00:00
|
|
|
findAllByDatacenter(dc, configuration = {}) {
|
2020-03-04 18:12:47 +00:00
|
|
|
const query = {
|
|
|
|
dc: dc,
|
|
|
|
};
|
|
|
|
if (typeof configuration.cursor !== 'undefined') {
|
|
|
|
query.index = configuration.cursor;
|
2020-07-17 13:42:45 +00:00
|
|
|
query.uri = configuration.uri;
|
2020-03-04 18:12:47 +00:00
|
|
|
}
|
|
|
|
return this.store.query(this.getModelName(), query);
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
findAllByNode(node, dc, configuration) {
|
2020-03-04 18:12:47 +00:00
|
|
|
return this.findAllByDatacenter(dc, configuration).then(function(coordinates) {
|
2019-03-22 17:24:40 +00:00
|
|
|
let results = {};
|
|
|
|
if (get(coordinates, 'length') > 1) {
|
2020-07-17 13:42:45 +00:00
|
|
|
results = tomography(
|
|
|
|
node,
|
2020-11-18 18:55:59 +00:00
|
|
|
coordinates
|
2020-07-17 13:42:45 +00:00
|
|
|
);
|
2019-03-22 17:24:40 +00:00
|
|
|
}
|
|
|
|
results.meta = get(coordinates, 'meta');
|
|
|
|
return results;
|
|
|
|
});
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|