2019-02-21 13:10:53 +00:00
|
|
|
import RepositoryService from 'consul-ui/services/repository';
|
|
|
|
import { PRIMARY_KEY } from 'consul-ui/models/proxy';
|
2019-03-22 17:24:40 +00:00
|
|
|
import { get, set } from '@ember/object';
|
2021-02-23 08:56:42 +00:00
|
|
|
import dataSource from 'consul-ui/decorators/data-source';
|
|
|
|
|
2019-02-21 13:10:53 +00:00
|
|
|
const modelName = 'proxy';
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class ProxyService extends RepositoryService {
|
|
|
|
getModelName() {
|
2019-02-21 13:10:53 +00:00
|
|
|
return modelName;
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getPrimaryKey() {
|
2019-02-21 13:10:53 +00:00
|
|
|
return PRIMARY_KEY;
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 08:56:42 +00:00
|
|
|
@dataSource('/:ns/:dc/proxies/for-service/:id')
|
|
|
|
findAllBySlug(params, configuration = {}) {
|
2019-02-21 13:10:53 +00:00
|
|
|
if (typeof configuration.cursor !== 'undefined') {
|
2021-02-23 08:56:42 +00:00
|
|
|
params.index = configuration.cursor;
|
|
|
|
params.uri = configuration.uri;
|
2019-02-21 13:10:53 +00:00
|
|
|
}
|
2021-02-23 08:56:42 +00:00
|
|
|
return this.store.query(this.getModelName(), params).then(items => {
|
2020-08-26 14:24:30 +00:00
|
|
|
items.forEach(item => {
|
|
|
|
// swap out the id for the services id
|
|
|
|
// so we can then assign the proxy to it if it exists
|
|
|
|
const id = JSON.parse(item.uid);
|
|
|
|
id.pop();
|
|
|
|
id.push(item.ServiceProxy.DestinationServiceID);
|
|
|
|
const service = this.store.peekRecord('service-instance', JSON.stringify(id));
|
|
|
|
if (service) {
|
|
|
|
set(service, 'ProxyInstance', item);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return items;
|
|
|
|
});
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 08:56:42 +00:00
|
|
|
@dataSource('/:ns/:dc/proxy-instance/:serviceId/:node/:id')
|
2021-04-15 18:18:07 +00:00
|
|
|
findInstanceBySlug(params, configuration) {
|
2021-02-23 08:56:42 +00:00
|
|
|
return this.findAllBySlug(params, configuration).then(function(items) {
|
2019-03-22 17:24:40 +00:00
|
|
|
let res = {};
|
2019-02-21 13:10:53 +00:00
|
|
|
if (get(items, 'length') > 0) {
|
2021-01-29 15:51:23 +00:00
|
|
|
let instance = items
|
2021-02-23 08:56:42 +00:00
|
|
|
.filterBy('ServiceProxy.DestinationServiceID', params.serviceId)
|
|
|
|
.findBy('NodeName', params.node);
|
2019-03-07 10:51:39 +00:00
|
|
|
if (instance) {
|
2019-03-22 17:24:40 +00:00
|
|
|
res = instance;
|
|
|
|
} else {
|
2021-02-23 08:56:42 +00:00
|
|
|
instance = items.findBy('ServiceProxy.DestinationServiceName', params.id);
|
2019-03-22 17:24:40 +00:00
|
|
|
if (instance) {
|
|
|
|
res = instance;
|
|
|
|
}
|
2019-02-21 13:10:53 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-22 17:24:40 +00:00
|
|
|
set(res, 'meta', get(items, 'meta'));
|
|
|
|
return res;
|
2019-02-21 13:10:53 +00:00
|
|
|
});
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|