From 766b28b8edd9bf03c54b029949164b5f3818f7f8 Mon Sep 17 00:00:00 2001 From: Kenia <19161242+kaxcode@users.noreply.github.com> Date: Fri, 9 Oct 2020 14:39:16 -0400 Subject: [PATCH] ui: Send kind query to the service-topology endpoint (#8909) --- ui-v2/app/adapters/topology.js | 4 ++-- ui-v2/app/routes/dc/services/show.js | 6 +++++- ui-v2/app/services/data-source/protocols/http.js | 12 ++++-------- ui-v2/app/services/repository/topology.js | 14 ++++++++++++-- ui-v2/tests/integration/adapters/topology-test.js | 4 +++- .../services/repository/topology-test.js | 5 +++-- 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/ui-v2/app/adapters/topology.js b/ui-v2/app/adapters/topology.js index e31e117495..f5e3d3245e 100644 --- a/ui-v2/app/adapters/topology.js +++ b/ui-v2/app/adapters/topology.js @@ -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} ${{ diff --git a/ui-v2/app/routes/dc/services/show.js b/ui-v2/app/routes/dc/services/show.js index 8265f7db3c..63e621b35f 100644 --- a/ui-v2/app/routes/dc/services/show.js +++ b/ui-v2/app/routes/dc/services/show.js @@ -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}` ), }); }); diff --git a/ui-v2/app/services/data-source/protocols/http.js b/ui-v2/app/services/data-source/protocols/http.js index 9dfe186e45..9471745db2 100644 --- a/ui-v2/app/services/data-source/protocols/http.js +++ b/ui-v2/app/services/data-source/protocols/http.js @@ -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': diff --git a/ui-v2/app/services/repository/topology.js b/ui-v2/app/services/repository/topology.js index 2532d5593a..7e9f513839 100644 --- a/ui-v2/app/services/repository/topology.js +++ b/ui-v2/app/services/repository/topology.js @@ -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) { diff --git a/ui-v2/tests/integration/adapters/topology-test.js b/ui-v2/tests/integration/adapters/topology-test.js index f53bf6561e..5cf2e361f9 100644 --- a/ui-v2/tests/integration/adapters/topology-test.js +++ b/ui-v2/tests/integration/adapters/topology-test.js @@ -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); }); diff --git a/ui-v2/tests/integration/services/repository/topology-test.js b/ui-v2/tests/integration/services/repository/topology-test.js index 78e73a51d0..45098469e0 100644 --- a/ui-v2/tests/integration/services/repository/topology-test.js +++ b/ui-v2/tests/integration/services/repository/topology-test.js @@ -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) {