Update peer repo with latest API changes

This commit is contained in:
Michael Klein 2022-10-11 14:36:21 +02:00 committed by Michael Klein
parent d17af23641
commit 454424145a
3 changed files with 37 additions and 14 deletions

View File

@ -16,7 +16,17 @@ export default class Peer extends Model {
@attr('string') Name; @attr('string') Name;
@attr('string') State; @attr('string') State;
@attr('string') ID; @attr('string') ID;
@attr('number') ImportedServiceCount; @attr() ImportedServices;
@attr('number') ExportedServiceCount; @attr() ExportedServices;
@attr('date') LastHeartbeat;
@attr('date') LastReceive;
@attr('date') LastSend;
@attr() PeerServerAddresses; @attr() PeerServerAddresses;
get ImportedServiceCount() {
return this.ImportedServices.length;
}
get ExportedServiceCount() {
return this.ExportedServices.length;
}
} }

View File

@ -1,6 +1,22 @@
import RepositoryService from 'consul-ui/services/repository'; import RepositoryService from 'consul-ui/services/repository';
import dataSource from 'consul-ui/decorators/data-source'; 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 { export default class PeerService extends RepositoryService {
getModelName() { getModelName() {
return 'peer'; return 'peer';
@ -39,11 +55,7 @@ export default class PeerService extends RepositoryService {
}, },
body: body.map((item) => { body: body.map((item) => {
return cache( return cache(
{ normalizePeerPayload(item),
...item,
Datacenter: dc,
Partition: partition,
},
(uri) => uri`peer:///${partition}/${ns}/${dc}/peer/${item.Name}` (uri) => uri`peer:///${partition}/${ns}/${dc}/peer/${item.Name}`
); );
}), }),
@ -80,11 +92,7 @@ export default class PeerService extends RepositoryService {
uri: uri, uri: uri,
}, },
body: cache( body: cache(
{ normalizePeerPayload(body),
...body,
Datacenter: dc,
Partition: partition,
},
(uri) => uri`peer:///${partition}/${ns}/${dc}/peer/${body.Name}` (uri) => uri`peer:///${partition}/${ns}/${dc}/peer/${body.Name}`
), ),
}; };

View File

@ -18,8 +18,13 @@
'TERMINATED', 'TERMINATED',
'UNDEFINED' 'UNDEFINED'
])}", ])}",
"ImportedServiceCount": ${fake.random.number({min: 0, max: 4000})}, "StreamStatus": {
"ExportedServiceCount": ${fake.random.number({min: 0, max: 4000})}, "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}", "PeerID": "${id}",
"PeerServerName": "${fake.internet.domainName()}", "PeerServerName": "${fake.internet.domainName()}",
"PeerServerAddresses": [ "PeerServerAddresses": [