ui: Send kind query to the service-topology endpoint (#8909)
This commit is contained in:
parent
ef2b6f848e
commit
aa4618312b
|
@ -1,12 +1,12 @@
|
||||||
import Adapter from './application';
|
import Adapter from './application';
|
||||||
// TODO: Update to use this.formatDatacenter()
|
// TODO: Update to use this.formatDatacenter()
|
||||||
export default Adapter.extend({
|
export default Adapter.extend({
|
||||||
requestForQueryRecord: function(request, { dc, ns, index, id, uri }) {
|
requestForQueryRecord: function(request, { dc, ns, index, id, uri, kind }) {
|
||||||
if (typeof id === 'undefined') {
|
if (typeof id === 'undefined') {
|
||||||
throw new Error('You must specify an id');
|
throw new Error('You must specify an id');
|
||||||
}
|
}
|
||||||
return request`
|
return request`
|
||||||
GET /v1/internal/ui/service-topology/${id}?${{ dc }}
|
GET /v1/internal/ui/service-topology/${id}?${{ dc, kind }}
|
||||||
X-Request-ID: ${uri}
|
X-Request-ID: ${uri}
|
||||||
|
|
||||||
${{
|
${{
|
||||||
|
|
|
@ -39,6 +39,10 @@ export default Route.extend({
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(model => {
|
.then(model => {
|
||||||
|
let kind = get(model, 'items.firstObject.Service.Kind');
|
||||||
|
if (typeof kind === 'undefined') {
|
||||||
|
kind = '';
|
||||||
|
}
|
||||||
return ['mesh-gateway', 'terminating-gateway'].includes(
|
return ['mesh-gateway', 'terminating-gateway'].includes(
|
||||||
get(model, 'items.firstObject.Service.Kind')
|
get(model, 'items.firstObject.Service.Kind')
|
||||||
)
|
)
|
||||||
|
@ -46,7 +50,7 @@ export default Route.extend({
|
||||||
: hash({
|
: hash({
|
||||||
...model,
|
...model,
|
||||||
topology: this.data.source(
|
topology: this.data.source(
|
||||||
uri => uri`/${nspace}/${dc}/topology/for-service/${params.name}`
|
uri => uri`/${nspace}/${dc}/topology/${params.name}/${kind}`
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -105,14 +105,6 @@ export default Service.extend({
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'topology':
|
|
||||||
[method, slug] = rest;
|
|
||||||
switch (method) {
|
|
||||||
case 'for-service':
|
|
||||||
find = configuration => repo.findBySlug(slug, dc, nspace, configuration);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'sessions':
|
case 'sessions':
|
||||||
[method, ...slug] = rest;
|
[method, ...slug] = rest;
|
||||||
switch (method) {
|
switch (method) {
|
||||||
|
@ -138,6 +130,10 @@ export default Service.extend({
|
||||||
find = configuration =>
|
find = configuration =>
|
||||||
repo.findInstanceBySlug(rest[0], rest[1], rest[2], dc, nspace, configuration);
|
repo.findInstanceBySlug(rest[0], rest[1], rest[2], dc, nspace, configuration);
|
||||||
break;
|
break;
|
||||||
|
case 'topology':
|
||||||
|
// id, service kind
|
||||||
|
find = configuration => repo.findBySlug(rest[0], rest[1], dc, nspace, configuration);
|
||||||
|
break;
|
||||||
case 'policy':
|
case 'policy':
|
||||||
case 'kv':
|
case 'kv':
|
||||||
case 'intention':
|
case 'intention':
|
||||||
|
|
|
@ -10,12 +10,22 @@ export default RepositoryService.extend({
|
||||||
getModelName: function() {
|
getModelName: function() {
|
||||||
return modelName;
|
return modelName;
|
||||||
},
|
},
|
||||||
findBySlug: function(slug, dc, nspace, configuration = {}) {
|
findBySlug: function(slug, kind, dc, nspace, configuration = {}) {
|
||||||
const datacenter = this.dcs.peekOne(dc);
|
const datacenter = this.dcs.peekOne(dc);
|
||||||
if (datacenter !== null && !get(datacenter, 'MeshEnabled')) {
|
if (datacenter !== null && !get(datacenter, 'MeshEnabled')) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
return this._super(...arguments).catch(e => {
|
const query = {
|
||||||
|
dc: dc,
|
||||||
|
ns: nspace,
|
||||||
|
id: slug,
|
||||||
|
kind: kind,
|
||||||
|
};
|
||||||
|
if (typeof configuration.cursor !== 'undefined') {
|
||||||
|
query.index = configuration.cursor;
|
||||||
|
query.uri = configuration.uri;
|
||||||
|
}
|
||||||
|
return this.store.queryRecord(this.getModelName(), query).catch(e => {
|
||||||
const code = get(e, 'errors.firstObject.status');
|
const code = get(e, 'errors.firstObject.status');
|
||||||
const body = get(e, 'errors.firstObject.detail').trim();
|
const body = get(e, 'errors.firstObject.detail').trim();
|
||||||
switch (code) {
|
switch (code) {
|
||||||
|
|
|
@ -7,13 +7,15 @@ module('Integration | Adapter | topology', function(hooks) {
|
||||||
setupTest(hooks);
|
setupTest(hooks);
|
||||||
const dc = 'dc-1';
|
const dc = 'dc-1';
|
||||||
const id = 'slug';
|
const id = 'slug';
|
||||||
|
const kind = '';
|
||||||
test('requestForQueryRecord returns the correct url/method', function(assert) {
|
test('requestForQueryRecord returns the correct url/method', function(assert) {
|
||||||
const adapter = this.owner.lookup('adapter:topology');
|
const adapter = this.owner.lookup('adapter:topology');
|
||||||
const client = this.owner.lookup('service:client/http');
|
const client = this.owner.lookup('service:client/http');
|
||||||
const expected = `GET /v1/internal/ui/service-topology/${id}?dc=${dc}`;
|
const expected = `GET /v1/internal/ui/service-topology/${id}?dc=${dc}&kind=${kind}`;
|
||||||
const actual = adapter.requestForQueryRecord(client.requestParams.bind(client), {
|
const actual = adapter.requestForQueryRecord(client.requestParams.bind(client), {
|
||||||
dc: dc,
|
dc: dc,
|
||||||
id: id,
|
id: id,
|
||||||
|
kind: kind,
|
||||||
});
|
});
|
||||||
assert.equal(`${actual.method} ${actual.url}`, expected);
|
assert.equal(`${actual.method} ${actual.url}`, expected);
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,18 +7,19 @@ moduleFor('service:repository/topology', 'Integration | Repository | topology',
|
||||||
});
|
});
|
||||||
const dc = 'dc-1';
|
const dc = 'dc-1';
|
||||||
const id = 'slug';
|
const id = 'slug';
|
||||||
|
const kind = '';
|
||||||
test('findBySlug returns the correct data for item endpoint', function(assert) {
|
test('findBySlug returns the correct data for item endpoint', function(assert) {
|
||||||
return repo(
|
return repo(
|
||||||
'Service',
|
'Service',
|
||||||
'findBySlug',
|
'findBySlug',
|
||||||
this.subject(),
|
this.subject(),
|
||||||
function retrieveStub(stub) {
|
function retrieveStub(stub) {
|
||||||
return stub(`/v1/internal/ui/service-topology/${id}?dc=${dc}`, {
|
return stub(`/v1/internal/ui/service-topology/${id}?dc=${dc}&${kind}`, {
|
||||||
CONSUL_DISCOVERY_CHAIN_COUNT: 1,
|
CONSUL_DISCOVERY_CHAIN_COUNT: 1,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function performTest(service) {
|
function performTest(service) {
|
||||||
return service.findBySlug(id, dc);
|
return service.findBySlug(id, kind, dc);
|
||||||
},
|
},
|
||||||
function performAssertion(actual, expected) {
|
function performAssertion(actual, expected) {
|
||||||
const result = expected(function(payload) {
|
const result = expected(function(payload) {
|
||||||
|
|
Loading…
Reference in New Issue