This is an automated email from the ASF dual-hosted git repository. ddanielr pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/accumulo.git
commit a54414f867b8b4dbeb4d677443ca3d72f1e2f9d9 Merge: 37c95acaad 53925f577e Author: Daniel Roberts ddanielr <[email protected]> AuthorDate: Thu Aug 7 17:54:42 2025 +0000 Merge branch '2.1' .../org/apache/accumulo/server/util/Admin.java | 3 +- .../accumulo/server/util/ServiceStatusCmd.java | 26 +++++++----- .../util/serviceStatus/ServiceStatusReport.java | 34 ++++++++-------- .../server/util/serviceStatus/StatusSummary.java | 45 ++++++++------------- .../accumulo/server/util/ServiceStatusCmdTest.java | 10 ++--- .../serviceStatus/ServiceStatusReportTest.java | 47 ++++++++++++++++------ 6 files changed, 92 insertions(+), 73 deletions(-) diff --cc server/base/src/main/java/org/apache/accumulo/server/util/ServiceStatusCmd.java index 6700d0d6c9,1f5e9fb856..ee1bc90e1d --- a/server/base/src/main/java/org/apache/accumulo/server/util/ServiceStatusCmd.java +++ b/server/base/src/main/java/org/apache/accumulo/server/util/ServiceStatusCmd.java @@@ -20,6 -20,8 +20,7 @@@ package org.apache.accumulo.server.util import static java.nio.charset.StandardCharsets.UTF_8; -import java.util.Collection; + import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.TreeMap; @@@ -43,9 -44,9 +44,6 @@@ import com.google.common.annotations.Vi public class ServiceStatusCmd { -- // used when grouping by resource group when there is no group. -- public static final String NO_GROUP_TAG = "NO_GROUP"; -- private static final Logger LOG = LoggerFactory.getLogger(ServiceStatusCmd.class); public ServiceStatusCmd() {} @@@ -101,39 -105,70 +99,43 @@@ } /** - * The tserver paths in ZooKeeper are: {@code /accumulo/[IID]/tservers/[host:port]/zlock#[NUM]} - * with the lock data providing TSERV_CLIENT=host:port. + * The tserver paths in ZooKeeper are: + * {@code /accumulo/[IID]/tservers/[resourceGroup]/[host:port]/zlock#[NUM]} with the lock data + * providing TSERV_CLIENT=host:port. */ @VisibleForTesting - StatusSummary getTServerStatus(final ZooReader zooReader, String zRootPath) { - String lockPath = zRootPath + Constants.ZTSERVERS; - return getServerHostStatus(zooReader, lockPath, ServiceStatusReport.ReportKey.T_SERVER); + StatusSummary getTServerStatus(ServerContext context) { + final AtomicInteger errors = new AtomicInteger(0); + final Map<String,Set<String>> hostsByGroups = new TreeMap<>(); ++ final Map<String,Integer> resourceGroups = new HashMap<>(); + final Set<ServiceLockPath> compactors = + context.getServerPaths().getTabletServer(rg -> true, AddressSelector.all(), true); + compactors.forEach( + c -> hostsByGroups.computeIfAbsent(c.getResourceGroup().canonical(), (k) -> new TreeSet<>()) + .add(c.getServer())); - return new StatusSummary(ServiceStatusReport.ReportKey.T_SERVER, hostsByGroups.keySet(), - hostsByGroups, errors.get()); ++ hostsByGroups.forEach((group, hosts) -> resourceGroups.put(group, hosts.size())); ++ return new StatusSummary(ServiceStatusReport.ReportKey.T_SERVER, resourceGroups, hostsByGroups, ++ errors.get()); } /** - * The sserver paths in ZooKeeper are: {@code /accumulo/[IID]/sservers/[host:port]/zlock#[NUM]} - * with the lock data providing [UUID],[GROUP] + * The sserver paths in ZooKeeper are: + * {@code /accumulo/[IID]/sservers/[resourceGroup]/[host:port]/zlock#[NUM]} with the lock data + * providing [UUID],[GROUP] */ @VisibleForTesting - StatusSummary getScanServerStatus(final ZooReader zooReader, String zRootPath) { - String lockPath = zRootPath + Constants.ZSSERVERS; - return getServerHostStatus(zooReader, lockPath, ServiceStatusReport.ReportKey.S_SERVER); - } - - /** - * handles paths for tservers and servers with the lock stored beneath the host: port like: - * {@code /accumulo/IID/[tservers | sservers]/HOST:PORT/[LOCK]} - */ - private StatusSummary getServerHostStatus(final ZooReader zooReader, String basePath, - ServiceStatusReport.ReportKey displayNames) { - AtomicInteger errorSum = new AtomicInteger(0); - - Map<String,Set<String>> hostsByGroups = new TreeMap<>(); - - var nodeNames = readNodeNames(zooReader, basePath); - - nodeNames.getHosts().forEach(host -> { - var lock = readNodeNames(zooReader, basePath + "/" + host); - lock.getHosts().forEach(l -> { - var nodeData = readNodeData(zooReader, basePath + "/" + host + "/" + l); - int err = nodeData.getErrorCount(); - if (err > 0) { - errorSum.addAndGet(nodeData.getErrorCount()); - } else { - // process resource groups - String[] tokens = nodeData.getHosts().split(","); - if (tokens.length == 2) { - String groupName = tokens[1]; - hostsByGroups.computeIfAbsent(groupName, s -> new TreeSet<>()).add(host); - } else { - hostsByGroups.computeIfAbsent(NO_GROUP_TAG, s -> new TreeSet<>()).add(host); - } - } - - }); - errorSum.addAndGet(lock.getFirst()); - }); - - AtomicInteger hostTotal = new AtomicInteger(); - Map<String,Integer> groupSummary = new HashMap<>(); - hostsByGroups.forEach((group, host) -> { - hostTotal.set(hostTotal.get() + host.size()); - if (!group.equals(NO_GROUP_TAG)) { - groupSummary.put(group, host.size()); - } - }); - - return new StatusSummary(displayNames, groupSummary, hostsByGroups, hostTotal.get(), - errorSum.get()); + StatusSummary getScanServerStatus(ServerContext context) { + final AtomicInteger errors = new AtomicInteger(0); + final Map<String,Set<String>> hostsByGroups = new TreeMap<>(); ++ final Map<String,Integer> resourceGroups = new HashMap<>(); + final Set<ServiceLockPath> scanServers = + context.getServerPaths().getScanServer(rg -> true, AddressSelector.all(), true); + scanServers.forEach( + c -> hostsByGroups.computeIfAbsent(c.getResourceGroup().canonical(), (k) -> new TreeSet<>()) + .add(c.getServer())); - return new StatusSummary(ServiceStatusReport.ReportKey.S_SERVER, hostsByGroups.keySet(), - hostsByGroups, errors.get()); ++ hostsByGroups.forEach((group, hosts) -> resourceGroups.put(group, hosts.size())); ++ return new StatusSummary(ServiceStatusReport.ReportKey.S_SERVER, resourceGroups, hostsByGroups, ++ errors.get()); } /** @@@ -148,20 -217,13 +150,22 @@@ /** * The compactor paths in ZooKeeper are: - * {@code /accumulo/[IID]/compactors/[QUEUE_NAME]/host:port/zlock#[NUM]} with the host:port pulled - * from the path + * {@code /accumulo/[IID]/compactors/[resourceGroup]/host:port/zlock#[NUM]} with the host:port + * pulled from the path */ @VisibleForTesting - StatusSummary getCompactorStatus(final ZooReader zooReader, String zRootPath) { - String lockPath = zRootPath + Constants.ZCOMPACTORS; - return getCompactorHosts(zooReader, lockPath); + StatusSummary getCompactorStatus(ServerContext context) { + final AtomicInteger errors = new AtomicInteger(0); + final Map<String,Set<String>> hostsByGroups = new TreeMap<>(); ++ final Map<String,Integer> resourceGroups = new HashMap<>(); + final Set<ServiceLockPath> compactors = + context.getServerPaths().getCompactor(rg -> true, AddressSelector.all(), true); + compactors.forEach( + c -> hostsByGroups.computeIfAbsent(c.getResourceGroup().canonical(), (k) -> new TreeSet<>()) + .add(c.getServer())); - return new StatusSummary(ServiceStatusReport.ReportKey.COMPACTOR, hostsByGroups.keySet(), - hostsByGroups, errors.get()); ++ hostsByGroups.forEach((group, hosts) -> resourceGroups.put(group, hosts.size())); ++ return new StatusSummary(ServiceStatusReport.ReportKey.COMPACTOR, resourceGroups, hostsByGroups, ++ errors.get()); } /** @@@ -171,18 -233,64 +175,20 @@@ * @return service status */ private StatusSummary getStatusSummary(ServiceStatusReport.ReportKey displayNames, - ZooReader zooReader, String lockPath) { - var result = readAllNodesData(zooReader, lockPath); + ServerContext context, String lockPath) { + var result = readAllNodesData(context.getZooSession().asReader(), lockPath); Map<String,Set<String>> byGroup = new TreeMap<>(); - byGroup.put(NO_GROUP_TAG, result.getHosts()); - return new StatusSummary(displayNames, Map.of(), byGroup, result.getHosts().size(), - result.getErrorCount()); - } - - /** - * Pull host:port from path {@code /accumulo/IID/compactors/[QUEUE][host:port]} - */ - private StatusSummary getCompactorHosts(final ZooReader zooReader, final String zRootPath) { - final AtomicInteger errors = new AtomicInteger(0); - - Map<String,Set<String>> hostsByGroups = new TreeMap<>(); - - // get group names - Result<Set<String>> queueNodes = readNodeNames(zooReader, zRootPath); - errors.addAndGet(queueNodes.getErrorCount()); - Set<String> queues = new TreeSet<>(queueNodes.getHosts()); - - queues.forEach(group -> { - var hostNames = readNodeNames(zooReader, zRootPath + "/" + group); - errors.addAndGet(hostNames.getErrorCount()); - Collection<String> hosts = hostNames.getHosts(); - hosts.forEach(host -> { - hostsByGroups.computeIfAbsent(group, set -> new TreeSet<>()).add(host); ++ final Map<String,Integer> resourceGroups = new HashMap<>(); + result.getData().forEach(data -> { + ServiceLockData.ServiceDescriptors sld = ServiceLockData.parseServiceDescriptors(data); + var services = sld.getServices(); + services.forEach(sd -> { + byGroup.computeIfAbsent(sd.getGroup().canonical(), set -> new TreeSet<>()) + .add(sd.getAddress()); }); }); - return new StatusSummary(displayNames, byGroup.keySet(), byGroup, result.getErrorCount()); - Map<String,Integer> groupSummary = new HashMap<>(); - hostsByGroups.forEach((group, hosts) -> groupSummary.put(group, hosts.size())); - - return new StatusSummary(ServiceStatusReport.ReportKey.COMPACTOR, groupSummary, hostsByGroups, - groupSummary.values().stream().reduce(Integer::sum).orElse(0), errors.get()); - } - - /** - * Read the node names from ZooKeeper. Exceptions are counted but ignored. - * - * @return Result with error count, Set of the node names. - */ - @VisibleForTesting - Result<Set<String>> readNodeNames(final ZooReader zooReader, final String path) { - Set<String> nodeNames = new TreeSet<>(); - final AtomicInteger errorCount = new AtomicInteger(0); - try { - var children = zooReader.getChildren(path); - if (children != null) { - nodeNames.addAll(children); - } - } catch (KeeperException | InterruptedException ex) { - if (Thread.currentThread().isInterrupted()) { - Thread.currentThread().interrupt(); - throw new IllegalStateException(ex); - } - errorCount.incrementAndGet(); - } - return new Result<>(errorCount.get(), nodeNames); ++ byGroup.forEach((group, hosts) -> resourceGroups.put(group, hosts.size())); ++ return new StatusSummary(displayNames, resourceGroups, byGroup, result.getErrorCount()); } /** diff --cc server/base/src/main/java/org/apache/accumulo/server/util/serviceStatus/ServiceStatusReport.java index 7efc6d5a37,c51d02dc99..22b1f58c9e --- a/server/base/src/main/java/org/apache/accumulo/server/util/serviceStatus/ServiceStatusReport.java +++ b/server/base/src/main/java/org/apache/accumulo/server/util/serviceStatus/ServiceStatusReport.java @@@ -54,16 -50,6 +54,16 @@@ public class ServiceStatusReport private final boolean showHosts; private final Map<ReportKey,StatusSummary> summaries; + // Gson requires a default constructor when JDK Unsafe usage is disabled + @SuppressWarnings("unused") + private ServiceStatusReport() { + reportTime = ""; + zkReadErrors = 0; + showHosts = false; - summaries = Map.of(); ++ summaries = Map.<ReportKey,StatusSummary>of(); + + } + public ServiceStatusReport(final Map<ReportKey,StatusSummary> summaries, final boolean showHosts) { reportTime = rptTimeFmt.format(ZonedDateTime.now(ZoneId.of("UTC"))); @@@ -167,26 -145,22 +170,25 @@@ fmtCounts(sb, summary); - // skip host info if NOT showing hosts - if (!showHosts) { - return; - // add summary info only when not displaying the hosts - if (!summary.getResourceGroups().isEmpty() && !showHosts) { - sb.append(I2).append("resource groups:\n"); - summary.getResourceGroups().forEach( - (group, size) -> sb.append(I4).append(group).append(": ").append(size).append("\n")); -- } -- - if (summary.getServiceCount() > 0 && showHosts) { - var groups = summary.getServiceByGroups(); - sb.append(I2).append("hosts (by group):\n"); - groups.forEach((g, h) -> { - sb.append(I4).append(g).append(" (").append(h.size()).append(")").append(":\n"); - h.forEach(n -> { - sb.append(I6).append(n).append("\n"); + if (!summary.getResourceGroups().isEmpty()) { + - sb.append(I2).append("resource groups:\n"); - summary.getResourceGroups().forEach(g -> sb.append(I4).append(g).append("\n")); ++ // add summary info only when not displaying the hosts ++ if (!summary.getResourceGroups().isEmpty() && !showHosts) { ++ sb.append(I2).append("resource groups:\n"); ++ summary.getResourceGroups().forEach( ++ (group, size) -> sb.append(I4).append(group).append(": ").append(size).append("\n")); ++ } + - if (summary.getServiceCount() > 0) { - sb.append(I2).append("hosts (by group):\n"); ++ if (summary.getServiceCount() > 0 && showHosts) { + var groups = summary.getServiceByGroups(); ++ sb.append(I2).append("hosts (by group):\n"); + groups.forEach((g, h) -> { + sb.append(I4).append(g).append(" (").append(h.size()).append(")").append(":\n"); + h.forEach(n -> { + sb.append(I6).append(n).append("\n"); + }); }); - }); + } } } diff --cc server/base/src/main/java/org/apache/accumulo/server/util/serviceStatus/StatusSummary.java index 3ef8c07992,67a668d37e..fb9e4bb3c8 --- a/server/base/src/main/java/org/apache/accumulo/server/util/serviceStatus/StatusSummary.java +++ b/server/base/src/main/java/org/apache/accumulo/server/util/serviceStatus/StatusSummary.java @@@ -25,19 -24,15 +24,25 @@@ import java.util.Set public class StatusSummary { - private ServiceStatusReport.ReportKey serviceType; - private Set<String> resourceGroups; - private Map<String,Set<String>> serviceByGroups; - private int serviceCount; - private int errorCount; + private final ServiceStatusReport.ReportKey serviceType; + private final Map<String,Integer> resourceGroups; + private final Map<String,Set<String>> serviceByGroups; + private final int serviceCount; + private final int errorCount; + // Default constructor required for Gson + @SuppressWarnings("unused") - private StatusSummary() {} ++ private StatusSummary() { ++ serviceType = null; ++ resourceGroups = Map.of(); ++ serviceByGroups = Map.of(); ++ serviceCount = 0; ++ errorCount = 0; ++ } + - public StatusSummary(ServiceStatusReport.ReportKey serviceType, final Set<String> resourceGroups, - final Map<String,Set<String>> serviceByGroups, final int errorCount) { + public StatusSummary(ServiceStatusReport.ReportKey serviceType, + final Map<String,Integer> resourceGroups, final Map<String,Set<String>> serviceByGroups, - final int serviceCount, final int errorCount) { ++ final int errorCount) { this.serviceType = serviceType; this.resourceGroups = resourceGroups; this.serviceByGroups = serviceByGroups; @@@ -71,23 -65,7 +76,7 @@@ } public StatusSummary withoutHosts() { - Map<String,Set<String>> tmpHosts = new TreeMap<>(); - - for (Map.Entry<String,Set<String>> entry : this.serviceByGroups.entrySet()) { - - String group = entry.getKey(); - int size = entry.getValue().size(); - ; - - Set<String> hosts = new HashSet<>(); - for (int i = 0; i < size; i++) { - hosts.add(""); - } - - tmpHosts.put(group, hosts); - } - - return new StatusSummary(this.serviceType, this.resourceGroups, tmpHosts, this.errorCount); - return new StatusSummary(serviceType, resourceGroups, Map.of(), serviceCount, errorCount); ++ return new StatusSummary(serviceType, resourceGroups, Map.of(), errorCount); } @Override diff --cc server/base/src/test/java/org/apache/accumulo/server/util/ServiceStatusCmdTest.java index c25b4a91d6,7d3efe68b7..70c738ff7a --- a/server/base/src/test/java/org/apache/accumulo/server/util/ServiceStatusCmdTest.java +++ b/server/base/src/test/java/org/apache/accumulo/server/util/ServiceStatusCmdTest.java @@@ -110,12 -106,12 +110,12 @@@ public class ServiceStatusCmdTest assertEquals(3, status.getServiceCount()); // expect sorted by name - Set<String> hosts = new TreeSet<>(List.of(host1, host2, host3)); Map<String,Set<String>> hostByGroup = new TreeMap<>(); - hostByGroup.put(NO_GROUP_TAG, hosts); + hostByGroup.put("default", new TreeSet<>(List.of("localhost:9991", "localhost:9992"))); + hostByGroup.put("manager1", new TreeSet<>(List.of("hostA:9999"))); - StatusSummary expected = - new StatusSummary(ServiceStatusReport.ReportKey.MANAGER, Map.of(), hostByGroup, 3, 0); + StatusSummary expected = new StatusSummary(ServiceStatusReport.ReportKey.MANAGER, - new TreeSet<>(List.of("default", "manager1")), hostByGroup, 0); ++ Map.of("default", 2, "manager1", 1), hostByGroup, 0); assertEquals(expected.hashCode(), status.hashCode()); assertEquals(expected.getDisplayName(), status.getDisplayName()); @@@ -154,10 -147,10 +154,10 @@@ // expect sorted by name Map<String,Set<String>> hostByGroup = new TreeMap<>(); - hostByGroup.put(NO_GROUP_TAG, new TreeSet<>(List.of(host1, host2))); + hostByGroup.put("default", new TreeSet<>(List.of("hostA", "hostB"))); - StatusSummary expected = - new StatusSummary(ServiceStatusReport.ReportKey.MONITOR, Map.of(), hostByGroup, 2, 0); + StatusSummary expected = new StatusSummary(ServiceStatusReport.ReportKey.MONITOR, - new TreeSet<>(List.of("default")), hostByGroup, 0); ++ Map.of("default", 2), hostByGroup, 0); assertEquals(expected.hashCode(), status.hashCode()); assertEquals(expected.getDisplayName(), status.getDisplayName()); @@@ -250,13 -196,10 +250,13 @@@ // expect sorted by name Map<String,Set<String>> hostByGroup = new TreeMap<>(); - hostByGroup.put(NO_GROUP_TAG, new TreeSet<>(List.of(host1, host2, host3))); + hostByGroup.put("default", new TreeSet<>(List.of(host1, host2, host3))); + + StatusSummary expected = new StatusSummary(ServiceStatusReport.ReportKey.T_SERVER, - Set.of("default"), hostByGroup, 0); ++ Map.of("default", 3), hostByGroup, 0); - StatusSummary expected = - new StatusSummary(ServiceStatusReport.ReportKey.T_SERVER, Map.of(), hostByGroup, 3, 0); + LOG.info("read: {}", status); + LOG.info("need: {}", expected); assertEquals(expected.hashCode(), status.hashCode()); assertEquals(expected.getDisplayName(), status.getDisplayName()); @@@ -341,10 -255,10 +341,10 @@@ Map<String,Set<String>> hostByGroup = new TreeMap<>(); hostByGroup.put("default", new TreeSet<>(List.of("host2:9090", "host4:9091"))); - hostByGroup.put("rg1", new TreeSet<>(List.of("host1:8080", "host3:9091"))); + hostByGroup.put("sg1", new TreeSet<>(List.of("host1:8080", "host3:9091"))); StatusSummary expected = new StatusSummary(ServiceStatusReport.ReportKey.S_SERVER, - Set.of("default", "sg1"), hostByGroup, 0); - Map.of("default", 2, "rg1", 2), hostByGroup, 4, 0); ++ Map.of("default", 2, "sg1", 2), hostByGroup, 0); assertEquals(expected, status); @@@ -434,17 -348,15 +434,17 @@@ replay(zooReader); ServiceStatusCmd cmd = new ServiceStatusCmd(); - StatusSummary status = cmd.getGcStatus(zooReader, zRoot); + StatusSummary status = cmd.getGcStatus(context); LOG.info("gc server counts: {}", status); - assertEquals(0, status.getResourceGroups().size()); + assertEquals(2, status.getResourceGroups().size()); assertEquals(2, status.getServiceCount()); assertEquals(0, status.getErrorCount()); - assertEquals(1, status.getServiceByGroups().size()); - assertEquals(2, status.getServiceByGroups().get(NO_GROUP_TAG).size()); - assertEquals(new TreeSet<>(List.of(host1, host2)), - status.getServiceByGroups().get(NO_GROUP_TAG)); + assertEquals(2, status.getServiceByGroups().size()); + assertEquals(1, status.getServiceByGroups().get("default").size()); + assertEquals(1, status.getServiceByGroups().get("gc1").size()); - assertEquals(new TreeSet<>(List.of("default", "gc1")), status.getResourceGroups()); ++ assertEquals(Map.of("default", 1, "gc1", 1), status.getResourceGroups()); + assertEquals(new TreeSet<>(List.of(host1)), status.getServiceByGroups().get("gc1")); + assertEquals(new TreeSet<>(List.of(host2)), status.getServiceByGroups().get("default")); } /** diff --cc server/base/src/test/java/org/apache/accumulo/server/util/serviceStatus/ServiceStatusReportTest.java index be0555c04f,101d173e47..f10a10cf03 --- a/server/base/src/test/java/org/apache/accumulo/server/util/serviceStatus/ServiceStatusReportTest.java +++ b/server/base/src/test/java/org/apache/accumulo/server/util/serviceStatus/ServiceStatusReportTest.java @@@ -18,7 -18,8 +18,7 @@@ */ package org.apache.accumulo.server.util.serviceStatus; --import static org.apache.accumulo.server.util.ServiceStatusCmd.NO_GROUP_TAG; + import static org.apache.accumulo.server.util.serviceStatus.ServiceStatusReport.ReportKey.COMPACTOR; import static org.apache.accumulo.server.util.serviceStatus.ServiceStatusReport.ReportKey.MANAGER; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@@ -73,8 -74,8 +73,9 @@@ public class ServiceStatusReportTest final Map<ServiceStatusReport.ReportKey,StatusSummary> services = new TreeMap<>(); Map<String,Set<String>> managerByGroup = new TreeMap<>(); -- managerByGroup.put(NO_GROUP_TAG, new TreeSet<>(List.of("hostZ:8080", "hostA:9090"))); - StatusSummary managerSummary = new StatusSummary(MANAGER, Set.of(), managerByGroup, 1); - StatusSummary managerSummary = new StatusSummary(MANAGER, Map.of(), managerByGroup, 2, 1); ++ managerByGroup.put("default", new TreeSet<>(List.of("hostZ:8080", "hostA:9090"))); ++ StatusSummary managerSummary = ++ new StatusSummary(MANAGER, Map.of("default", 2), managerByGroup, 1); services.put(MANAGER, managerSummary); ServiceStatusReport report = new ServiceStatusReport(services, false); var encoded = report.toJson(); @@@ -85,7 -86,28 +86,28 @@@ assertEquals(1, report.getSummaries().size()); var byGroup = report.getSummaries().get(MANAGER).getServiceByGroups(); -- assertEquals(new TreeSet<>(List.of("hostZ:8080", "hostA:9090")), byGroup.get(NO_GROUP_TAG)); ++ assertEquals(new TreeSet<>(List.of("hostZ:8080", "hostA:9090")), byGroup.get("default")); + } + + @Test + public void jsonCompactorsTest() { + final Map<ServiceStatusReport.ReportKey,StatusSummary> services = new TreeMap<>(); + Map<String,Set<String>> compactorsByGroup = new TreeMap<>(); + compactorsByGroup.put("TEST", new TreeSet<>(List.of("hostZ:8080", "hostA:9090"))); + StatusSummary compactorSummary = - new StatusSummary(COMPACTOR, Map.of("TEST", 2), compactorsByGroup, 2, 1); ++ new StatusSummary(COMPACTOR, Map.of("TEST", 2), compactorsByGroup, 1); + services.put(COMPACTOR, compactorSummary); + ServiceStatusReport report = new ServiceStatusReport(services, false); + var encoded = report.toJson(); + + ServiceStatusReport decoded = ServiceStatusReport.fromJson(encoded); + assertNotNull(decoded.getReportTime()); + assertEquals(1, decoded.getTotalZkReadErrors()); + assertEquals(1, report.getSummaries().size()); + assertEquals(1, decoded.getSummaries().values().size()); + + var byGroup = report.getSummaries().get(COMPACTOR).getServiceByGroups(); + assertEquals(new TreeSet<>(List.of("hostZ:8080", "hostA:9090")), byGroup.get("TEST")); } /** @@@ -103,29 -125,29 +125,30 @@@ final Map<ServiceStatusReport.ReportKey,StatusSummary> services = new TreeMap<>(); Map<String,Set<String>> managerByGroup = new TreeMap<>(); - managerByGroup.put(NO_GROUP_TAG, new TreeSet<>(List.of("host1:8080", "host2:9090"))); - StatusSummary managerSummary = new StatusSummary(MANAGER, Map.of(), managerByGroup, 2, 1); + managerByGroup.put("default", new TreeSet<>(List.of("host1:8080", "host2:9090"))); - StatusSummary managerSummary = new StatusSummary(MANAGER, Set.of("default"), managerByGroup, 1); ++ StatusSummary managerSummary = ++ new StatusSummary(MANAGER, Map.of("default", 2), managerByGroup, 1); services.put(MANAGER, managerSummary); Map<String,Set<String>> monitorByGroup = new TreeMap<>(); - monitorByGroup.put(NO_GROUP_TAG, new TreeSet<>(List.of("host1:8080", "host2:9090"))); - StatusSummary monitorSummary = - new StatusSummary(ServiceStatusReport.ReportKey.MONITOR, Map.of(), monitorByGroup, 2, 0); + monitorByGroup.put("default", new TreeSet<>(List.of("host1:8080", "host2:9090"))); + StatusSummary monitorSummary = new StatusSummary(ServiceStatusReport.ReportKey.MONITOR, - Set.of("default"), monitorByGroup, 0); ++ Map.of("default", 2), monitorByGroup, 0); services.put(ServiceStatusReport.ReportKey.MONITOR, monitorSummary); Map<String,Set<String>> gcByGroup = new TreeMap<>(); - gcByGroup.put(NO_GROUP_TAG, new TreeSet<>(List.of("host1:8080", "host2:9090"))); + gcByGroup.put("default", new TreeSet<>(List.of("host1:8080", "host2:9090"))); StatusSummary gcSummary = - new StatusSummary(ServiceStatusReport.ReportKey.GC, Set.of("default"), gcByGroup, 0); - new StatusSummary(ServiceStatusReport.ReportKey.GC, Map.of(), gcByGroup, 2, 0); ++ new StatusSummary(ServiceStatusReport.ReportKey.GC, Map.of("default", 2), gcByGroup, 0); services.put(ServiceStatusReport.ReportKey.GC, gcSummary); Map<String,Set<String>> tserverByGroup = new TreeMap<>(); - tserverByGroup.put(NO_GROUP_TAG, + tserverByGroup.put("default", new TreeSet<>(List.of("host2:9090", "host4:9091", "host1:8080", "host3:9091"))); - StatusSummary tserverSummary = - new StatusSummary(ServiceStatusReport.ReportKey.T_SERVER, Map.of(), tserverByGroup, 4, 1); + StatusSummary tserverSummary = new StatusSummary(ServiceStatusReport.ReportKey.T_SERVER, - Set.of("default"), tserverByGroup, 1); ++ Map.of("default", 4), tserverByGroup, 1); services.put(ServiceStatusReport.ReportKey.T_SERVER, tserverSummary); Map<String,Set<String>> sserverByGroup = new TreeMap<>(); @@@ -134,15 -156,21 +157,15 @@@ sserverByGroup.put("rg2", new TreeSet<>(List.of("host4:9091"))); StatusSummary scanServerSummary = new StatusSummary(ServiceStatusReport.ReportKey.S_SERVER, - new TreeSet<>(List.of("default", "rg1", "rg2")), sserverByGroup, 2); - Map.of("default", 1, "rg1", 2, "rg2", 1), sserverByGroup, 4, 2); ++ Map.of("default", 1, "rg1", 2, "rg2", 1), sserverByGroup, 2); services.put(ServiceStatusReport.ReportKey.S_SERVER, scanServerSummary); - Map<String,Set<String>> coordinatorByGroup = new TreeMap<>(); - coordinatorByGroup.put(NO_GROUP_TAG, new TreeSet<>(List.of("host4:9090", "host2:9091"))); - StatusSummary coordinatorSummary = new StatusSummary(ServiceStatusReport.ReportKey.COORDINATOR, - Map.of(), coordinatorByGroup, 2, 0); - services.put(ServiceStatusReport.ReportKey.COORDINATOR, coordinatorSummary); - Map<String,Set<String>> compactorByGroup = new TreeMap<>(); compactorByGroup.put("q2", new TreeSet<>(List.of("host5:8080", "host2:9090", "host4:9091"))); compactorByGroup.put("q1", new TreeSet<>(List.of("host3:8080", "host1:9091"))); StatusSummary compactorSummary = new StatusSummary(ServiceStatusReport.ReportKey.COMPACTOR, - new TreeSet<>(List.of("q2", "q1")), compactorByGroup, 0); - Map.of("q2", 3, "q1", 2), compactorByGroup, 5, 0); ++ Map.of("q2", 3, "q1", 2), compactorByGroup, 0); services.put(ServiceStatusReport.ReportKey.COMPACTOR, compactorSummary); return services;
