2020-08-26 14:24:30 +00:00
|
|
|
import RepositoryService from 'consul-ui/services/repository';
|
2020-12-07 09:14:30 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2020-12-14 15:28:35 +00:00
|
|
|
import { set } from '@ember/object';
|
2020-12-07 09:14:30 +00:00
|
|
|
|
2020-08-26 14:24:30 +00:00
|
|
|
const modelName = 'service-instance';
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class ServiceInstanceService extends RepositoryService {
|
2020-12-07 09:14:30 +00:00
|
|
|
@service('repository/proxy') proxyRepo;
|
2020-11-09 09:25:35 +00:00
|
|
|
getModelName() {
|
2020-08-26 14:24:30 +00:00
|
|
|
return modelName;
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 09:14:30 +00:00
|
|
|
async findByService(slug, dc, nspace, configuration = {}) {
|
2020-08-26 14:24:30 +00:00
|
|
|
const query = {
|
|
|
|
dc: dc,
|
2020-10-07 14:08:13 +00:00
|
|
|
ns: nspace,
|
2020-08-26 14:24:30 +00:00
|
|
|
id: slug,
|
|
|
|
};
|
|
|
|
if (typeof configuration.cursor !== 'undefined') {
|
|
|
|
query.index = configuration.cursor;
|
|
|
|
query.uri = configuration.uri;
|
|
|
|
}
|
|
|
|
return this.store.query(this.getModelName(), query);
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 09:14:30 +00:00
|
|
|
async findBySlug(serviceId, node, service, dc, nspace, configuration = {}) {
|
2020-08-26 14:24:30 +00:00
|
|
|
const query = {
|
|
|
|
dc: dc,
|
|
|
|
ns: nspace,
|
|
|
|
serviceId: serviceId,
|
|
|
|
node: node,
|
|
|
|
id: service,
|
|
|
|
};
|
|
|
|
if (typeof configuration.cursor !== 'undefined') {
|
|
|
|
query.index = configuration.cursor;
|
|
|
|
query.uri = configuration.uri;
|
|
|
|
}
|
|
|
|
return this.store.queryRecord(this.getModelName(), query);
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
2020-12-07 09:14:30 +00:00
|
|
|
|
|
|
|
async findProxyBySlug(serviceId, node, service, dc, nspace, configuration = {}) {
|
|
|
|
const instance = await this.findBySlug(...arguments);
|
|
|
|
let proxy = this.store.peekRecord('proxy', instance.uid);
|
|
|
|
// if(typeof proxy === 'undefined') {
|
|
|
|
// await proxyRepo.create({})
|
|
|
|
// }
|
|
|
|
|
|
|
|
// Copy over all the things to the ProxyServiceInstance
|
|
|
|
['Service', 'Node'].forEach(prop => {
|
|
|
|
set(proxy, prop, instance[prop]);
|
|
|
|
});
|
|
|
|
['Checks'].forEach(prop => {
|
|
|
|
instance[prop].forEach(item => {
|
|
|
|
if (typeof item !== 'undefined') {
|
|
|
|
proxy[prop].addFragment(item.copy());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// delete the ServiceInstance record as we now have a ProxyServiceInstance
|
|
|
|
instance.unloadRecord();
|
|
|
|
return proxy;
|
|
|
|
}
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|