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 { hash } from 'rsvp';
|
|
|
|
import { get } from '@ember/object';
|
|
|
|
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class InstanceRoute extends Route {
|
|
|
|
@service('data-source/service')
|
|
|
|
data;
|
|
|
|
|
|
|
|
model(params) {
|
2019-02-21 13:10:53 +00:00
|
|
|
const dc = this.modelFor('dc').dc.Name;
|
2020-07-17 13:42:45 +00:00
|
|
|
const nspace = this.modelFor('nspace').nspace.substr(1) || 'default';
|
2019-02-21 13:10:53 +00:00
|
|
|
return hash({
|
2020-06-17 09:25:54 +00:00
|
|
|
dc: dc,
|
2020-07-17 13:42:45 +00:00
|
|
|
nspace: nspace,
|
|
|
|
item: this.data.source(
|
|
|
|
uri => uri`/${nspace}/${dc}/service-instance/${params.id}/${params.node}/${params.name}`
|
|
|
|
),
|
2019-12-17 18:47:37 +00:00
|
|
|
}).then(model => {
|
2019-03-22 17:24:40 +00:00
|
|
|
// this will not be run in a blocking loop, but this is ok as
|
|
|
|
// its highly unlikely that a service will suddenly change to being a
|
|
|
|
// connect-proxy or vice versa so leave as is for now
|
2019-02-21 13:10:53 +00:00
|
|
|
return hash({
|
2020-07-17 13:42:45 +00:00
|
|
|
...model,
|
2020-05-07 13:57:15 +00:00
|
|
|
proxyMeta:
|
2019-07-05 08:07:25 +00:00
|
|
|
// proxies and mesh-gateways can't have proxies themselves so don't even look
|
|
|
|
['connect-proxy', 'mesh-gateway'].includes(get(model.item, 'Kind'))
|
2019-03-07 10:51:39 +00:00
|
|
|
? null
|
2020-07-17 13:42:45 +00:00
|
|
|
: this.data.source(
|
|
|
|
uri =>
|
|
|
|
uri`/${nspace}/${dc}/proxy-instance/${params.id}/${params.node}/${params.name}`
|
|
|
|
),
|
2020-05-07 13:57:15 +00:00
|
|
|
}).then(model => {
|
|
|
|
if (typeof get(model, 'proxyMeta.ServiceID') === 'undefined') {
|
|
|
|
return model;
|
|
|
|
}
|
2020-07-17 13:42:45 +00:00
|
|
|
const proxy = {
|
|
|
|
id: get(model, 'proxyMeta.ServiceID'),
|
|
|
|
node: get(model, 'proxyMeta.Node'),
|
|
|
|
name: get(model, 'proxyMeta.ServiceName'),
|
|
|
|
};
|
2020-05-07 13:57:15 +00:00
|
|
|
return hash({
|
2020-07-17 13:42:45 +00:00
|
|
|
...model,
|
2020-05-07 13:57:15 +00:00
|
|
|
// Proxies have identical dc/nspace as their parent instance
|
|
|
|
// No need to use Proxy's dc/nspace response
|
2020-07-17 13:42:45 +00:00
|
|
|
proxy: this.data.source(
|
|
|
|
uri => uri`/${nspace}/${dc}/service-instance/${proxy.id}/${proxy.node}/${proxy.name}`
|
|
|
|
),
|
2020-05-07 13:57:15 +00:00
|
|
|
});
|
2019-02-21 13:10:53 +00:00
|
|
|
});
|
|
|
|
});
|
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
|
|
|
}
|
|
|
|
}
|