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);
|
2021-02-23 08:56:42 +00:00
|
|
|
import dataSource from 'consul-ui/decorators/data-source';
|
2019-03-22 17:24:40 +00:00
|
|
|
|
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
|
2021-02-23 08:56:42 +00:00
|
|
|
@dataSource('/:ns/:dc/coordinates')
|
|
|
|
findAllByDatacenter(params, configuration = {}) {
|
2020-03-04 18:12:47 +00:00
|
|
|
if (typeof configuration.cursor !== 'undefined') {
|
2021-02-23 08:56:42 +00:00
|
|
|
params.index = configuration.cursor;
|
|
|
|
params.uri = configuration.uri;
|
2020-03-04 18:12:47 +00:00
|
|
|
}
|
2021-02-23 08:56:42 +00:00
|
|
|
return this.store.query(this.getModelName(), params);
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 08:56:42 +00:00
|
|
|
@dataSource('/:ns/:dc/coordinates/for-node/:id')
|
|
|
|
findAllByNode(params, configuration) {
|
|
|
|
return this.findAllByDatacenter(params, configuration).then(function(coordinates) {
|
2019-03-22 17:24:40 +00:00
|
|
|
let results = {};
|
|
|
|
if (get(coordinates, 'length') > 1) {
|
2021-02-23 08:56:42 +00:00
|
|
|
results = tomography(params.id, coordinates);
|
2019-03-22 17:24:40 +00:00
|
|
|
}
|
|
|
|
results.meta = get(coordinates, 'meta');
|
|
|
|
return results;
|
|
|
|
});
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|