mirror of
https://github.com/status-im/consul.git
synced 2025-01-22 11:40:06 +00:00
a9fe39e035
> In the future, this should all be moved to each individual repository now, which will mean we can finally get rid of this service. This PR moves reconciliation to 'each individual repository'. I stopped short of getting rid of the service, but its so small now we pretty much don't need it. I'd rather wait until I look at the equivalent DataSink service and see if we can get rid of both equivalent services together (this also currently dependant on work soon to be merged) Reconciliation of models (basically doing the extra work to clean up the ember-data store and bring our frontend 'truth' into line with the actual backend truth) when blocking/long-polling on different views/filters of data is slightly more complicated due to figuring out what should be cleaned up and what should be left in the store. This is especially apparent for KVs. I built in a such a way to hopefully make sure it will all make sense for the future. I also checked that this all worked nicely with all our models, even KV which has never supported blocking queries. I left all that work in so that if we want to enable blocking queries/live updates for KV it now just involves deleting a couple of lines of code. There is a tonne of old stuff that we can clean up here now (our 'fake headers' that we pass around) and I've added that to my list of thing for a 'Big Cleanup PR' that will remove lots of code that we no longer require.
75 lines
2.5 KiB
JavaScript
75 lines
2.5 KiB
JavaScript
import RepositoryService from 'consul-ui/services/repository';
|
|
import { inject as service } from '@ember/service';
|
|
import { set } from '@ember/object';
|
|
import { ACCESS_READ } from 'consul-ui/abilities/base';
|
|
import dataSource from 'consul-ui/decorators/data-source';
|
|
|
|
const modelName = 'service-instance';
|
|
export default class ServiceInstanceService extends RepositoryService {
|
|
@service('repository/proxy') proxyRepo;
|
|
getModelName() {
|
|
return modelName;
|
|
}
|
|
|
|
shouldReconcile(item, params) {
|
|
return super.shouldReconcile(...arguments) && item.Service.Service === params.id;
|
|
}
|
|
|
|
@dataSource('/:partition/:ns/:dc/service-instances/for-service/:id')
|
|
async findByService(params, configuration = {}) {
|
|
if (typeof configuration.cursor !== 'undefined') {
|
|
params.index = configuration.cursor;
|
|
params.uri = configuration.uri;
|
|
}
|
|
const instances = await this.authorizeBySlug(
|
|
async () => this.query(params),
|
|
ACCESS_READ,
|
|
params
|
|
);
|
|
return instances;
|
|
}
|
|
|
|
@dataSource('/:partition/:ns/:dc/service-instance/:serviceId/:node/:id')
|
|
async findBySlug(params, configuration = {}) {
|
|
if (typeof configuration.cursor !== 'undefined') {
|
|
params.index = configuration.cursor;
|
|
params.uri = configuration.uri;
|
|
}
|
|
return this.authorizeBySlug(
|
|
async () => this.store.queryRecord(this.getModelName(), params),
|
|
ACCESS_READ,
|
|
params
|
|
);
|
|
}
|
|
|
|
@dataSource('/:partition/:ns/:dc/proxy-service-instance/:serviceId/:node/:id')
|
|
async findProxyBySlug(params, configuration = {}) {
|
|
const instance = await this.findBySlug(...arguments);
|
|
let proxy = this.store.peekRecord('proxy', instance.uid);
|
|
// Currently, we call the proxy endpoint before this endpoint
|
|
// therefore proxy is never undefined. If we ever call this endpoint
|
|
// first we'll need to do something like the following
|
|
// if(typeof proxy === 'undefined') {
|
|
// await proxyRepo.create({})
|
|
// }
|
|
|
|
// Copy over all the things to the ProxyServiceInstance
|
|
['Service', 'Node', 'meta'].forEach(prop => {
|
|
set(proxy, prop, instance[prop]);
|
|
});
|
|
['Checks'].forEach(prop => {
|
|
// completely wipe out any previous values so we don't accumulate things
|
|
// eternally
|
|
proxy.set(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;
|
|
}
|
|
}
|