add online status to node details

This commit is contained in:
Carsten Otto
2021-11-19 20:46:58 +01:00
parent 9e0f4e58aa
commit e6b2e74891
16 changed files with 138 additions and 50 deletions

View File

@@ -2,6 +2,7 @@ package de.cotto.lndmanagej.controller;
import com.codahale.metrics.MetricRegistry;
import de.cotto.lndmanagej.metrics.Metrics;
import de.cotto.lndmanagej.model.Node;
import de.cotto.lndmanagej.model.Pubkey;
import de.cotto.lndmanagej.service.NodeService;
import org.springframework.web.bind.annotation.GetMapping;
@@ -29,6 +30,7 @@ public class NodeController {
@GetMapping("/details")
public NodeDetailsDto getDetails(@PathVariable Pubkey pubkey) {
metrics.mark(MetricRegistry.name(getClass(), "getDetails"));
return new NodeDetailsDto(pubkey, getAlias(pubkey));
Node node = nodeService.getNode(pubkey);
return new NodeDetailsDto(pubkey, node.alias(), node.online());
}
}

View File

@@ -6,6 +6,7 @@ import de.cotto.lndmanagej.model.Pubkey;
public record NodeDetailsDto(
@JsonSerialize(using = ToStringSerializer.class) Pubkey pubkey,
String alias
String alias,
boolean online
) {
}

View File

@@ -3,6 +3,7 @@ package de.cotto.lndmanagej.service;
import com.google.common.cache.LoadingCache;
import de.cotto.lndmanagej.caching.CacheBuilder;
import de.cotto.lndmanagej.grpc.GrpcNodeInfo;
import de.cotto.lndmanagej.model.Node;
import de.cotto.lndmanagej.model.Pubkey;
import org.springframework.stereotype.Component;
@@ -25,8 +26,12 @@ public class NodeService {
return aliasCache.getUnchecked(pubkey);
}
public Node getNode(Pubkey pubkey) {
return grpcNodeInfo.getNode(pubkey);
}
private String getAliasWithoutCache(Pubkey pubkey) {
return grpcNodeInfo.getNode(pubkey).alias();
return getNode(pubkey).alias();
}
}