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