2019-02-21 13:10:53 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2020-11-09 09:25:35 +00:00
|
|
|
import Route from 'consul-ui/routing/route';
|
2019-02-21 13:10:53 +00:00
|
|
|
import { get } from '@ember/object';
|
|
|
|
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class InstanceRoute extends Route {
|
2020-12-02 15:42:18 +00:00
|
|
|
@service('data-source/service') data;
|
2020-11-09 09:25:35 +00:00
|
|
|
|
2020-12-02 15:42:18 +00:00
|
|
|
async model(params, transition) {
|
2019-02-21 13:10:53 +00:00
|
|
|
const dc = this.modelFor('dc').dc.Name;
|
2021-05-26 16:43:46 +00:00
|
|
|
const nspace = this.optionalParams().nspace;
|
2020-12-02 15:42:18 +00:00
|
|
|
|
|
|
|
const item = await this.data.source(
|
|
|
|
uri => uri`/${nspace}/${dc}/service-instance/${params.id}/${params.node}/${params.name}`
|
|
|
|
);
|
|
|
|
|
|
|
|
let proxyMeta, proxy;
|
|
|
|
if (get(item, 'IsOrigin')) {
|
|
|
|
proxyMeta = await this.data.source(
|
|
|
|
uri => uri`/${nspace}/${dc}/proxy-instance/${params.id}/${params.node}/${params.name}`
|
|
|
|
);
|
|
|
|
if (typeof get(proxyMeta, 'ServiceID') !== 'undefined') {
|
|
|
|
const proxyParams = {
|
|
|
|
id: get(proxyMeta, 'ServiceID'),
|
2021-01-12 14:53:21 +00:00
|
|
|
node: get(proxyMeta, 'NodeName'),
|
2020-12-02 15:42:18 +00:00
|
|
|
name: get(proxyMeta, 'ServiceName'),
|
2020-07-17 13:42:45 +00:00
|
|
|
};
|
2020-12-02 15:42:18 +00:00
|
|
|
// Proxies have identical dc/nspace as their parent instance
|
|
|
|
// so no need to use Proxy's dc/nspace response
|
|
|
|
// the proxy itself is just a normal service model
|
|
|
|
proxy = await this.data.source(
|
|
|
|
uri =>
|
2020-12-07 09:14:30 +00:00
|
|
|
uri`/${nspace}/${dc}/proxy-service-instance/${proxyParams.id}/${proxyParams.node}/${proxyParams.name}`
|
2020-12-02 15:42:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
dc,
|
|
|
|
nspace,
|
|
|
|
item,
|
|
|
|
proxyMeta,
|
|
|
|
proxy,
|
|
|
|
};
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setupController(controller, model) {
|
|
|
|
super.setupController(...arguments);
|
2019-02-21 13:10:53 +00:00
|
|
|
controller.setProperties(model);
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|