From 454424145a1c9396fe0aba52a58a9900f5ae3330 Mon Sep 17 00:00:00 2001 From: Michael Klein Date: Tue, 11 Oct 2022 14:36:21 +0200 Subject: [PATCH] Update peer repo with latest API changes --- ui/packages/consul-ui/app/models/peer.js | 14 ++++++++-- .../consul-ui/app/services/repository/peer.js | 28 ++++++++++++------- ui/packages/consul-ui/mock-api/v1/peerings | 9 ++++-- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/ui/packages/consul-ui/app/models/peer.js b/ui/packages/consul-ui/app/models/peer.js index 934c1bd462..c0e7cba28d 100644 --- a/ui/packages/consul-ui/app/models/peer.js +++ b/ui/packages/consul-ui/app/models/peer.js @@ -16,7 +16,17 @@ export default class Peer extends Model { @attr('string') Name; @attr('string') State; @attr('string') ID; - @attr('number') ImportedServiceCount; - @attr('number') ExportedServiceCount; + @attr() ImportedServices; + @attr() ExportedServices; + @attr('date') LastHeartbeat; + @attr('date') LastReceive; + @attr('date') LastSend; @attr() PeerServerAddresses; + + get ImportedServiceCount() { + return this.ImportedServices.length; + } + get ExportedServiceCount() { + return this.ExportedServices.length; + } } diff --git a/ui/packages/consul-ui/app/services/repository/peer.js b/ui/packages/consul-ui/app/services/repository/peer.js index 961fcd79bb..77cf9f17db 100644 --- a/ui/packages/consul-ui/app/services/repository/peer.js +++ b/ui/packages/consul-ui/app/services/repository/peer.js @@ -1,6 +1,22 @@ import RepositoryService from 'consul-ui/services/repository'; import dataSource from 'consul-ui/decorators/data-source'; +function normalizePeerPayload(peerPayload, dc, partition) { + const { + StreamStatus: { LastHeartbeat, LastReceive, LastSend, ImportedServices, ExportedServices }, + } = peerPayload; + + return { + ...peerPayload, + LastHeartbeat, + LastReceive, + LastSend, + ImportedServices, + ExportedServices, + Datacenter: dc, + Partition: partition, + }; +} export default class PeerService extends RepositoryService { getModelName() { return 'peer'; @@ -39,11 +55,7 @@ export default class PeerService extends RepositoryService { }, body: body.map((item) => { return cache( - { - ...item, - Datacenter: dc, - Partition: partition, - }, + normalizePeerPayload(item), (uri) => uri`peer:///${partition}/${ns}/${dc}/peer/${item.Name}` ); }), @@ -80,11 +92,7 @@ export default class PeerService extends RepositoryService { uri: uri, }, body: cache( - { - ...body, - Datacenter: dc, - Partition: partition, - }, + normalizePeerPayload(body), (uri) => uri`peer:///${partition}/${ns}/${dc}/peer/${body.Name}` ), }; diff --git a/ui/packages/consul-ui/mock-api/v1/peerings b/ui/packages/consul-ui/mock-api/v1/peerings index a579a06ddd..f240e49d21 100644 --- a/ui/packages/consul-ui/mock-api/v1/peerings +++ b/ui/packages/consul-ui/mock-api/v1/peerings @@ -18,8 +18,13 @@ 'TERMINATED', 'UNDEFINED' ])}", - "ImportedServiceCount": ${fake.random.number({min: 0, max: 4000})}, - "ExportedServiceCount": ${fake.random.number({min: 0, max: 4000})}, + "StreamStatus": { + "LastHeartbeat": "${fake.date.past(10).toISOString()}", + "LastReceive": "${fake.date.past(10).toISOString()}", + "LastSend": "${fake.date.past(10).toISOString()}", + "ExportedServices": ["${`export-service-${i}`}"], + "ImportedServices": ["${`import-service-${i}`}"] + }, "PeerID": "${id}", "PeerServerName": "${fake.internet.domainName()}", "PeerServerAddresses": [