2018-10-26 16:36:15 +00:00
|
|
|
import RepositoryService from 'consul-ui/services/repository';
|
|
|
|
|
2021-09-15 18:50:11 +00:00
|
|
|
import dataSource from 'consul-ui/decorators/data-source';
|
2019-03-22 17:24:40 +00:00
|
|
|
import tomographyFactory from 'consul-ui/utils/tomography';
|
|
|
|
import distance from 'consul-ui/utils/distance';
|
2021-09-15 18:50:11 +00:00
|
|
|
|
2019-03-22 17:24:40 +00:00
|
|
|
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
|
2021-09-15 18:50:11 +00:00
|
|
|
@dataSource('/:partition/:ns/:dc/coordinates')
|
|
|
|
async 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-09-15 18:50:11 +00:00
|
|
|
@dataSource('/:partition/:ns/:dc/coordinates/for-node/:id')
|
|
|
|
async findAllByNode(params, configuration) {
|
|
|
|
const coordinates = await this.findAllByDatacenter(params, configuration);
|
|
|
|
|
|
|
|
let results = {};
|
|
|
|
if (coordinates.length > 1) {
|
|
|
|
results = tomography(params.id, coordinates);
|
|
|
|
}
|
|
|
|
results.meta = coordinates.meta;
|
|
|
|
return results;
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|