add node warnings functionality (at the moment: only online percentage)

This commit is contained in:
Carsten Otto
2021-12-27 20:18:05 +01:00
parent 5fa0851bd7
commit de40c32f63
21 changed files with 317 additions and 8 deletions

View File

@@ -0,0 +1,30 @@
package de.cotto.lndmanagej.controller;
import com.codahale.metrics.annotation.Timed;
import de.cotto.lndmanagej.controller.dto.NodeWarningsDto;
import de.cotto.lndmanagej.controller.dto.ObjectMapperConfiguration;
import de.cotto.lndmanagej.model.Pubkey;
import de.cotto.lndmanagej.service.NodeWarningsService;
import org.springframework.context.annotation.Import;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/")
@Import(ObjectMapperConfiguration.class)
public class WarningsController {
private final NodeWarningsService nodeWarningsService;
public WarningsController(NodeWarningsService nodeWarningsService) {
this.nodeWarningsService = nodeWarningsService;
}
@Timed
@GetMapping("/node/{pubkey}/warnings")
public NodeWarningsDto getWarningsForNode(@PathVariable Pubkey pubkey) {
return NodeWarningsDto.createFromModel(nodeWarningsService.getNodeWarnings(pubkey));
}
}

View File

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import de.cotto.lndmanagej.model.ChannelId;
import de.cotto.lndmanagej.model.NodeDetails;
import de.cotto.lndmanagej.model.NodeWarning;
import de.cotto.lndmanagej.model.Pubkey;
import java.util.List;
@@ -19,7 +20,8 @@ public record NodeDetailsDto(
BalanceInformationDto balance,
OnlineReportDto onlineReport,
FeeReportDto feeReport,
RebalanceReportDto rebalanceReport
RebalanceReportDto rebalanceReport,
List<NodeWarning> nodeWarnings
) {
public static NodeDetailsDto createFromModel(NodeDetails nodeDetails) {
return new NodeDetailsDto(
@@ -33,7 +35,8 @@ public record NodeDetailsDto(
BalanceInformationDto.createFromModel(nodeDetails.balanceInformation()),
OnlineReportDto.createFromModel(nodeDetails.onlineReport()),
FeeReportDto.createFromModel(nodeDetails.feeReport()),
RebalanceReportDto.createFromModel(nodeDetails.rebalanceReport())
RebalanceReportDto.createFromModel(nodeDetails.rebalanceReport()),
nodeDetails.nodeWarnings().warnings()
);
}
}

View File

@@ -0,0 +1,12 @@
package de.cotto.lndmanagej.controller.dto;
import de.cotto.lndmanagej.model.NodeWarning;
import de.cotto.lndmanagej.model.NodeWarnings;
import java.util.List;
public record NodeWarningsDto(List<NodeWarning> nodeWarnings) {
public static NodeWarningsDto createFromModel(NodeWarnings nodeWarnings) {
return new NodeWarningsDto(nodeWarnings.warnings());
}
}