This is an automated email from the ASF dual-hosted git repository. edcoleman pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push: new 814ac68a67 Admin service status server lock changes (#4605) 814ac68a67 is described below commit 814ac68a6732601b7bbcbe61f6785741deee7ca5 Author: EdColeman <d...@etcoleman.com> AuthorDate: Tue May 28 09:42:29 2024 -0400 Admin service status server lock changes (#4605) * update admin serviceStatus to read host info from ServiceLockData --- .../accumulo/server/util/ServiceStatusCmd.java | 63 +++--- .../util/serviceStatus/ServiceStatusReport.java | 29 ++- .../accumulo/server/util/ServiceStatusCmdTest.java | 214 +++++++++++++++------ .../serviceStatus/ServiceStatusReportTest.java | 22 +-- 4 files changed, 226 insertions(+), 102 deletions(-) diff --git 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 index 3f5dbafaf5..b042fcf838 100644 --- 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 @@ -19,6 +19,9 @@ package org.apache.accumulo.server.util; import static java.nio.charset.StandardCharsets.UTF_8; +import static org.apache.accumulo.core.lock.ServiceLockData.ThriftService.TABLET_SCAN; +import static org.apache.accumulo.core.lock.ServiceLockData.ThriftService.TSERV; +import static org.apache.accumulo.core.util.LazySingletons.GSON; import java.util.Collection; import java.util.Map; @@ -29,6 +32,7 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.fate.zookeeper.ZooReader; +import org.apache.accumulo.core.lock.ServiceLockData; import org.apache.accumulo.core.util.Pair; import org.apache.accumulo.server.ServerContext; import org.apache.accumulo.server.util.serviceStatus.ServiceStatusReport; @@ -85,7 +89,7 @@ public class ServiceStatusCmd { /** * The manager paths in ZooKeeper are: {@code /accumulo/[IID]/managers/lock/zlock#[NUM]} with the - * lock data providing host:port. + * lock data providing a service descriptor with host and port. */ @VisibleForTesting StatusSummary getManagerStatus(final ZooReader zooReader, String zRootPath) { @@ -95,7 +99,7 @@ public class ServiceStatusCmd { /** * The monitor paths in ZooKeeper are: {@code /accumulo/[IID]/monitor/lock/zlock#[NUM]} with the - * lock data providing host:port. + * lock data providing a service descriptor with host and port. */ @VisibleForTesting StatusSummary getMonitorStatus(final ZooReader zooReader, String zRootPath) { @@ -110,7 +114,7 @@ public class ServiceStatusCmd { @VisibleForTesting StatusSummary getTServerStatus(final ZooReader zooReader, String zRootPath) { String lockPath = zRootPath + Constants.ZTSERVERS; - return getServerHostStatus(zooReader, lockPath, ServiceStatusReport.ReportKey.T_SERVER); + return getServerHostStatus(zooReader, lockPath, ServiceStatusReport.ReportKey.T_SERVER, TSERV); } /** @@ -120,7 +124,8 @@ public class ServiceStatusCmd { @VisibleForTesting StatusSummary getScanServerStatus(final ZooReader zooReader, String zRootPath) { String lockPath = zRootPath + Constants.ZSSERVERS; - return getServerHostStatus(zooReader, lockPath, ServiceStatusReport.ReportKey.S_SERVER); + return getServerHostStatus(zooReader, lockPath, ServiceStatusReport.ReportKey.S_SERVER, + TABLET_SCAN); } /** @@ -128,7 +133,7 @@ public class ServiceStatusCmd { * {@code /accumulo/IID/[tservers | sservers]/HOST:PORT/[LOCK]} */ private StatusSummary getServerHostStatus(final ZooReader zooReader, String basePath, - ServiceStatusReport.ReportKey displayNames) { + ServiceStatusReport.ReportKey displayNames, ServiceLockData.ThriftService serviceType) { AtomicInteger errorSum = new AtomicInteger(0); // Set<String> hostNames = new TreeSet<>(); @@ -137,25 +142,26 @@ public class ServiceStatusCmd { var nodeNames = readNodeNames(zooReader, basePath); - nodeNames.getHosts().forEach(host -> { + nodeNames.getData().forEach(host -> { var lock = readNodeNames(zooReader, basePath + "/" + host); - lock.getHosts().forEach(l -> { + lock.getData().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]; - groupNames.add(groupName); - hostsByGroups.computeIfAbsent(groupName, s -> new TreeSet<>()).add(host); - } else { - hostsByGroups.computeIfAbsent(NO_GROUP_TAG, s -> new TreeSet<>()).add(host); - } - } + ServiceLockData.ServiceDescriptors sld = + GSON.get().fromJson(nodeData.getData(), ServiceLockData.ServiceDescriptors.class); + + sld.getServices().forEach(sd -> { + if (serviceType == sd.getService()) { + groupNames.add(sd.getGroup()); + hostsByGroups.computeIfAbsent(sd.getGroup(), set -> new TreeSet<>()) + .add(sd.getAddress()); + } + }); + } }); errorSum.addAndGet(lock.getFirst()); }); @@ -203,8 +209,15 @@ public class ServiceStatusCmd { ZooReader zooReader, String lockPath) { var result = readAllNodesData(zooReader, lockPath); Map<String,Set<String>> byGroup = new TreeMap<>(); - byGroup.put(NO_GROUP_TAG, result.getHosts()); - return new StatusSummary(displayNames, Set.of(), byGroup, result.getErrorCount()); + result.getData().forEach(data -> { + ServiceLockData.ServiceDescriptors sld = + GSON.get().fromJson(data, ServiceLockData.ServiceDescriptors.class); + var services = sld.getServices(); + services.forEach(sd -> { + byGroup.computeIfAbsent(sd.getGroup(), set -> new TreeSet<>()).add(sd.getAddress()); + }); + }); + return new StatusSummary(displayNames, byGroup.keySet(), byGroup, result.getErrorCount()); } /** @@ -218,12 +231,12 @@ public class ServiceStatusCmd { // get group names Result<Integer,Set<String>> queueNodes = readNodeNames(zooReader, zRootPath); errors.addAndGet(queueNodes.getErrorCount()); - Set<String> queues = new TreeSet<>(queueNodes.getHosts()); + Set<String> queues = new TreeSet<>(queueNodes.getData()); queues.forEach(group -> { var hostNames = readNodeNames(zooReader, zRootPath + "/" + group); errors.addAndGet(hostNames.getErrorCount()); - Collection<String> hosts = hostNames.getHosts(); + Collection<String> hosts = hostNames.getData(); hosts.forEach(host -> { hostsByGroups.computeIfAbsent(group, set -> new TreeSet<>()).add(host); }); @@ -286,7 +299,7 @@ public class ServiceStatusCmd { */ @VisibleForTesting Result<Integer,Set<String>> readAllNodesData(final ZooReader zooReader, final String path) { - Set<String> hosts = new TreeSet<>(); + Set<String> data = new TreeSet<>(); final AtomicInteger errorCount = new AtomicInteger(0); try { var locks = zooReader.getChildren(path); @@ -296,7 +309,7 @@ public class ServiceStatusCmd { if (err > 0) { errorCount.addAndGet(nodeData.getErrorCount()); } else { - hosts.add(nodeData.getHosts()); + data.add(nodeData.getData()); } }); } catch (KeeperException | InterruptedException ex) { @@ -307,7 +320,7 @@ public class ServiceStatusCmd { LOG.info("Could not read node names from ZooKeeper for path {}", path, ex); errorCount.incrementAndGet(); } - return new Result<>(errorCount.get(), hosts); + return new Result<>(errorCount.get(), data); } @Parameters(commandDescription = "show service status") @@ -335,7 +348,7 @@ public class ServiceStatusCmd { return getFirst(); } - public B getHosts() { + public B getData() { return getSecond(); } } diff --git 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 index 0951831028..b715534d9d 100644 --- 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 @@ -18,10 +18,13 @@ */ package org.apache.accumulo.server.util.serviceStatus; +import static org.apache.accumulo.core.lock.ServiceLockData.ServiceDescriptor.DEFAULT_GROUP_NAME; + import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.Map; +import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -83,12 +86,12 @@ public class ServiceStatusReport { .reduce(Integer::sum).orElse(0); sb.append("ZooKeeper read errors: ").append(zkErrors).append("\n"); - fmtServiceStatus(sb, ReportKey.MANAGER, summaries.get(ReportKey.MANAGER), noHosts); - fmtServiceStatus(sb, ReportKey.MONITOR, summaries.get(ReportKey.MONITOR), noHosts); - fmtServiceStatus(sb, ReportKey.GC, summaries.get(ReportKey.GC), noHosts); - fmtServiceStatus(sb, ReportKey.T_SERVER, summaries.get(ReportKey.T_SERVER), noHosts); + fmtResourceGroups(sb, ReportKey.MANAGER, summaries.get(ReportKey.MANAGER), noHosts); + fmtResourceGroups(sb, ReportKey.MONITOR, summaries.get(ReportKey.MONITOR), noHosts); + fmtResourceGroups(sb, ReportKey.GC, summaries.get(ReportKey.GC), noHosts); + fmtResourceGroups(sb, ReportKey.T_SERVER, summaries.get(ReportKey.T_SERVER), noHosts); fmtResourceGroups(sb, ReportKey.S_SERVER, summaries.get(ReportKey.S_SERVER), noHosts); - fmtServiceStatus(sb, ReportKey.COORDINATOR, summaries.get(ReportKey.COORDINATOR), noHosts); + fmtResourceGroups(sb, ReportKey.COORDINATOR, summaries.get(ReportKey.COORDINATOR), noHosts); fmtResourceGroups(sb, ReportKey.COMPACTOR, summaries.get(ReportKey.COMPACTOR), noHosts); sb.append("\n"); @@ -96,6 +99,12 @@ public class ServiceStatusReport { return sb.toString(); } + /** + * This method can be used instead of + * {@link #fmtResourceGroups(StringBuilder, ReportKey, StatusSummary, boolean)} if there are + * services that do not make sense to group by a resource group. With the data in ServiceLock, all + * services has at least the default group. + */ private void fmtServiceStatus(final StringBuilder sb, final ReportKey displayNames, final StatusSummary summary, boolean noHosts) { if (summary == null) { @@ -109,9 +118,10 @@ public class ServiceStatusReport { if (noHosts) { return; } + sb.append(I2).append("resource group: (default)").append("\n"); if (summary.getServiceCount() > 0) { var hosts = summary.getServiceByGroups(); - hosts.values().forEach(s -> s.forEach(h -> sb.append(I2).append(h).append("\n"))); + hosts.values().forEach(s -> s.forEach(h -> sb.append(I4).append(h).append("\n"))); } } @@ -130,6 +140,12 @@ public class ServiceStatusReport { sb.append(reportKey).append(": unavailable").append("\n"); return; } + // only default group is present, omit grouping from report + if (!summary.getResourceGroups().isEmpty() + && summary.getResourceGroups().equals(Set.of(DEFAULT_GROUP_NAME))) { + fmtServiceStatus(sb, reportKey, summary, noHosts); + return; + } fmtCounts(sb, summary); @@ -139,6 +155,7 @@ public class ServiceStatusReport { } if (!summary.getResourceGroups().isEmpty()) { + sb.append(I2).append("resource groups:\n"); summary.getResourceGroups().forEach(g -> sb.append(I4).append(g).append("\n")); diff --git 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 index f4af749798..2a8be3a157 100644 --- 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 @@ -20,7 +20,6 @@ package org.apache.accumulo.server.util; import static java.nio.charset.StandardCharsets.UTF_8; import static org.apache.accumulo.core.Constants.ZGC_LOCK; -import static org.apache.accumulo.server.util.ServiceStatusCmd.NO_GROUP_TAG; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.eq; import static org.easymock.EasyMock.expect; @@ -83,18 +82,21 @@ public class ServiceStatusCmdTest { String lock2Name = "zlock#" + UUID.randomUUID() + "#0000000002"; String lock3Name = "zlock#" + UUID.randomUUID() + "#0000000003"; - String host1 = "hostA:8080"; - String host2 = "hostB:9090"; - String host3 = "host1:9091"; + String lock1data = + "{\"descriptors\":[{\"uuid\":\"6effb690-c29c-4e0b-92ff-f6b308385a42\",\"service\":\"MANAGER\",\"address\":\"localhost:9991\",\"group\":\"default\"}]}"; + String lock2Data = + "{\"descriptors\":[{\"uuid\":\"6effb690-c29c-4e0b-92ff-f6b308385a42\",\"service\":\"MANAGER\",\"address\":\"localhost:9992\",\"group\":\"default\"}]}"; + String lock3Data = + "{\"descriptors\":[{\"uuid\":\"6effb690-c29c-4e0b-92ff-f6b308385a42\",\"service\":\"MANAGER\",\"address\":\"hostA:9999\",\"group\":\"manager1\"}]}"; String lockPath = zRoot + Constants.ZMANAGER_LOCK; expect(zooReader.getChildren(eq(lockPath))).andReturn(List.of(lock1Name, lock2Name, lock3Name)) .anyTimes(); - expect(zooReader.getData(eq(lockPath + "/" + lock1Name))).andReturn(host1.getBytes(UTF_8)) + expect(zooReader.getData(eq(lockPath + "/" + lock1Name))).andReturn(lock1data.getBytes(UTF_8)) .anyTimes(); - expect(zooReader.getData(eq(lockPath + "/" + lock2Name))).andReturn(host2.getBytes(UTF_8)) + expect(zooReader.getData(eq(lockPath + "/" + lock2Name))).andReturn(lock2Data.getBytes(UTF_8)) .anyTimes(); - expect(zooReader.getData(eq(lockPath + "/" + lock3Name))).andReturn(host3.getBytes(UTF_8)) + expect(zooReader.getData(eq(lockPath + "/" + lock3Name))).andReturn(lock3Data.getBytes(UTF_8)) .anyTimes(); replay(zooReader); @@ -106,12 +108,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, Set.of(), hostByGroup, 0); + StatusSummary expected = new StatusSummary(ServiceStatusReport.ReportKey.MANAGER, + new TreeSet<>(List.of("default", "manager1")), hostByGroup, 0); assertEquals(expected.hashCode(), status.hashCode()); assertEquals(expected.getDisplayName(), status.getDisplayName()); @@ -127,8 +129,10 @@ public class ServiceStatusCmdTest { String lock1Name = "zlock#" + UUID.randomUUID() + "#0000000001"; String lock2Name = "zlock#" + UUID.randomUUID() + "#0000000002"; - String host1 = "hostA:8080"; - String host2 = "host1:9091"; + String host1 = + "{\"descriptors\":[{\"uuid\":\"87465459-9c8f-4f95-b4c6-ef3029030d05\",\"service\":\"NONE\",\"address\":\"hostA\",\"group\":\"default\"}]}"; + String host2 = + "{\"descriptors\":[{\"uuid\":\"87465459-9c8f-4f95-b4c6-ef3029030d05\",\"service\":\"NONE\",\"address\":\"hostB\",\"group\":\"default\"}]}"; String lockPath = zRoot + Constants.ZMONITOR_LOCK; expect(zooReader.getChildren(eq(lockPath))).andReturn(List.of(lock1Name, lock2Name)).anyTimes(); @@ -147,10 +151,10 @@ public class ServiceStatusCmdTest { // 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, Set.of(), hostByGroup, 0); + StatusSummary expected = new StatusSummary(ServiceStatusReport.ReportKey.MONITOR, + new TreeSet<>(List.of("default")), hostByGroup, 0); assertEquals(expected.hashCode(), status.hashCode()); assertEquals(expected.getDisplayName(), status.getDisplayName()); @@ -167,24 +171,58 @@ public class ServiceStatusCmdTest { String lock2Name = "zlock#" + UUID.randomUUID() + "#0000000002"; String lock3Name = "zlock#" + UUID.randomUUID() + "#0000000003"; - String host1 = "hostA:8080"; - String host2 = "hostB:9090"; - String host3 = "host1:9091"; + String host1 = "localhost:9997"; + String host2 = "localhost:10000"; + String host3 = "hostZ:9999"; + + String lockData1 = + "{\"descriptors\":[{\"uuid\":\"e0a717f2-43a1-466c-aa91-8b33e20e17e5\",\"service\":\"TABLET_SCAN\",\"address\":\"" + + host1 + + "\",\"group\":\"default\"},{\"uuid\":\"e0a717f2-43a1-466c-aa91-8b33e20e17e5\",\"service\":\"CLIENT\",\"address\":\"" + + host1 + + "\",\"group\":\"default\"},{\"uuid\":\"e0a717f2-43a1-466c-aa91-8b33e20e17e5\",\"service\":\"TABLET_INGEST\",\"address\":\"" + + host1 + + "\",\"group\":\"default\"},{\"uuid\":\"e0a717f2-43a1-466c-aa91-8b33e20e17e5\",\"service\":\"TABLET_MANAGEMENT\",\"address\":\"" + + host1 + + "\",\"group\":\"default\"},{\"uuid\":\"e0a717f2-43a1-466c-aa91-8b33e20e17e5\",\"service\":\"TSERV\",\"address\":\"" + + host1 + "\",\"group\":\"default\"}]}\n"; + String lockData2 = + "{\"descriptors\":[{\"uuid\":\"d0e29f70-1eb5-4dc5-9ad6-2466ab56ea32\",\"service\":\"TABLET_SCAN\",\"address\":\"" + + host2 + + "\",\"group\":\"default\"},{\"uuid\":\"d0e29f70-1eb5-4dc5-9ad6-2466ab56ea32\",\"service\":\"TABLET_MANAGEMENT\",\"address\":\"" + + host2 + + "\",\"group\":\"default\"},{\"uuid\":\"d0e29f70-1eb5-4dc5-9ad6-2466ab56ea32\",\"service\":\"CLIENT\",\"address\":\"" + + host2 + + "\",\"group\":\"default\"},{\"uuid\":\"d0e29f70-1eb5-4dc5-9ad6-2466ab56ea32\",\"service\":\"TSERV\",\"address\":\"" + + host2 + + "\",\"group\":\"default\"},{\"uuid\":\"d0e29f70-1eb5-4dc5-9ad6-2466ab56ea32\",\"service\":\"TABLET_INGEST\",\"address\":\"" + + host2 + "\",\"group\":\"default\"}]}"; + String lockData3 = + "{\"descriptors\":[{\"uuid\":\"d0e29f70-1eb5-4dc5-9ad6-2466ab56ea32\",\"service\":\"TABLET_SCAN\",\"address\":\"" + + host3 + + "\",\"group\":\"default\"},{\"uuid\":\"d0e29f70-1eb5-4dc5-9ad6-2466ab56ea32\",\"service\":\"TABLET_MANAGEMENT\",\"address\":\"" + + host3 + + "\",\"group\":\"default\"},{\"uuid\":\"d0e29f70-1eb5-4dc5-9ad6-2466ab56ea32\",\"service\":\"CLIENT\",\"address\":\"" + + host3 + + "\",\"group\":\"default\"},{\"uuid\":\"d0e29f70-1eb5-4dc5-9ad6-2466ab56ea32\",\"service\":\"TSERV\",\"address\":\"" + + host3 + + "\",\"group\":\"default\"},{\"uuid\":\"d0e29f70-1eb5-4dc5-9ad6-2466ab56ea32\",\"service\":\"TABLET_INGEST\",\"address\":\"" + + host3 + "\",\"group\":\"default\"}]}"; String basePath = zRoot + Constants.ZTSERVERS; expect(zooReader.getChildren(eq(basePath))).andReturn(List.of(host1, host2, host3)).anyTimes(); expect(zooReader.getChildren(eq(basePath + "/" + host1))).andReturn(List.of(lock1Name)).once(); expect(zooReader.getData(eq(basePath + "/" + host1 + "/" + lock1Name))) - .andReturn(("TSERV_CLIENT=" + host1).getBytes(UTF_8)).anyTimes(); + .andReturn(lockData1.getBytes(UTF_8)).anyTimes(); expect(zooReader.getChildren(eq(basePath + "/" + host2))).andReturn(List.of(lock2Name)).once(); expect(zooReader.getData(eq(basePath + "/" + host2 + "/" + lock2Name))) - .andReturn(("TSERV_CLIENT=" + host2).getBytes(UTF_8)).anyTimes(); + .andReturn(lockData2.getBytes(UTF_8)).anyTimes(); expect(zooReader.getChildren(eq(basePath + "/" + host3))).andReturn(List.of(lock3Name)).once(); expect(zooReader.getData(eq(basePath + "/" + host3 + "/" + lock3Name))) - .andReturn(("TSERV_CLIENT=" + host3).getBytes(UTF_8)).anyTimes(); + .andReturn(lockData3.getBytes(UTF_8)).anyTimes(); replay(zooReader); @@ -196,10 +234,13 @@ public class ServiceStatusCmdTest { // 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(), hostByGroup, 0); + StatusSummary expected = new StatusSummary(ServiceStatusReport.ReportKey.T_SERVER, + Set.of("default"), hostByGroup, 0); + + LOG.info("read: {}", status); + LOG.info("need: {}", expected); assertEquals(expected.hashCode(), status.hashCode()); assertEquals(expected.getDisplayName(), status.getDisplayName()); @@ -220,32 +261,51 @@ public class ServiceStatusCmdTest { String lock3Name = "zlock#" + uuid3 + "#0000000033"; String lock4Name = "zlock#" + uuid3 + "#0000000044"; - // UUID uuidLock = UUID.randomUUID(); - String host1 = "host1:8080"; String host2 = "host2:9090"; String host3 = "host3:9091"; String host4 = "host4:9091"; + String lockData1 = + "{\"descriptors\":[{\"uuid\":\"f408fed7-ce93-40d2-8e60-63e8a3daf416\",\"service\":\"TABLET_SCAN\",\"address\":\"" + + host1 + + "\",\"group\":\"sg1\"},{\"uuid\":\"f408fed7-ce93-40d2-8e60-63e8a3daf416\",\"service\":\"CLIENT\",\"address\":\"" + + host1 + "\",\"group\":\"sg1\"}]}"; + String lockData2 = + "{\"descriptors\":[{\"uuid\":\"f408fed7-ce93-40d2-8e60-63e8a3daf416\",\"service\":\"TABLET_SCAN\",\"address\":\"" + + host2 + + "\",\"group\":\"default\"},{\"uuid\":\"f408fed7-ce93-40d2-8e60-63e8a3daf416\",\"service\":\"CLIENT\",\"address\":\"" + + host2 + "\",\"group\":\"default\"}]}"; + String lockData3 = + "{\"descriptors\":[{\"uuid\":\"f408fed7-ce93-40d2-8e60-63e8a3daf416\",\"service\":\"TABLET_SCAN\",\"address\":\"" + + host3 + + "\",\"group\":\"sg1\"},{\"uuid\":\"f408fed7-ce93-40d2-8e60-63e8a3daf416\",\"service\":\"CLIENT\",\"address\":\"" + + host3 + "\",\"group\":\"sg1\"}]}"; + String lockData4 = + "{\"descriptors\":[{\"uuid\":\"f408fed7-ce93-40d2-8e60-63e8a3daf416\",\"service\":\"TABLET_SCAN\",\"address\":\"" + + host4 + + "\",\"group\":\"default\"},{\"uuid\":\"f408fed7-ce93-40d2-8e60-63e8a3daf416\",\"service\":\"CLIENT\",\"address\":\"" + + host4 + "\",\"group\":\"default\"}]}"; + String lockPath = zRoot + Constants.ZSSERVERS; expect(zooReader.getChildren(eq(lockPath))).andReturn(List.of(host1, host2, host3, host4)) .anyTimes(); expect(zooReader.getChildren(eq(lockPath + "/" + host1))).andReturn(List.of(lock1Name)).once(); expect(zooReader.getData(eq(lockPath + "/" + host1 + "/" + lock1Name))) - .andReturn((UUID.randomUUID() + ",rg1").getBytes(UTF_8)).once(); + .andReturn(lockData1.getBytes(UTF_8)).once(); expect(zooReader.getChildren(eq(lockPath + "/" + host2))).andReturn(List.of(lock2Name)).once(); expect(zooReader.getData(eq(lockPath + "/" + host2 + "/" + lock2Name))) - .andReturn((UUID.randomUUID() + ",default").getBytes(UTF_8)).once(); + .andReturn(lockData2.getBytes(UTF_8)).once(); expect(zooReader.getChildren(eq(lockPath + "/" + host3))).andReturn(List.of(lock3Name)).once(); expect(zooReader.getData(eq(lockPath + "/" + host3 + "/" + lock3Name))) - .andReturn((UUID.randomUUID() + ",rg1").getBytes(UTF_8)).once(); + .andReturn(lockData3.getBytes(UTF_8)).once(); expect(zooReader.getChildren(eq(lockPath + "/" + host4))).andReturn(List.of(lock4Name)).once(); expect(zooReader.getData(eq(lockPath + "/" + host4 + "/" + lock4Name))) - .andReturn((UUID.randomUUID() + ",default").getBytes(UTF_8)).once(); + .andReturn(lockData4.getBytes(UTF_8)).once(); replay(zooReader); @@ -255,10 +315,10 @@ public class ServiceStatusCmdTest { 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", "rg1"), hostByGroup, 0); + Set.of("default", "sg1"), hostByGroup, 0); assertEquals(expected, status); @@ -274,14 +334,24 @@ public class ServiceStatusCmdTest { String host2 = "hostB:9090"; String host3 = "host1:9091"; + String lockData1 = + "{\"descriptors\":[{\"uuid\":\"1d55f7a5-090d-48fc-a3ea-f1a66e984a21\",\"service\":\"COORDINATOR\",\"address\":\"" + + host1 + "\",\"group\":\"default\"}]}\n"; + String lockData2 = + "{\"descriptors\":[{\"uuid\":\"1d55f7a5-090d-48fc-a3ea-f1a66e984a21\",\"service\":\"COORDINATOR\",\"address\":\"" + + host2 + "\",\"group\":\"coord1\"}]}\n"; + String lockData3 = + "{\"descriptors\":[{\"uuid\":\"1d55f7a5-090d-48fc-a3ea-f1a66e984a21\",\"service\":\"COORDINATOR\",\"address\":\"" + + host3 + "\",\"group\":\"coord2\"}]}\n"; + String lockPath = zRoot + Constants.ZCOORDINATOR_LOCK; expect(zooReader.getChildren(eq(lockPath))).andReturn(List.of(lock1Name, lock2Name, lock3Name)) .anyTimes(); - expect(zooReader.getData(eq(lockPath + "/" + lock1Name))).andReturn(host1.getBytes(UTF_8)) + expect(zooReader.getData(eq(lockPath + "/" + lock1Name))).andReturn(lockData1.getBytes(UTF_8)) .anyTimes(); - expect(zooReader.getData(eq(lockPath + "/" + lock2Name))).andReturn(host2.getBytes(UTF_8)) + expect(zooReader.getData(eq(lockPath + "/" + lock2Name))).andReturn(lockData2.getBytes(UTF_8)) .anyTimes(); - expect(zooReader.getData(eq(lockPath + "/" + lock3Name))).andReturn(host3.getBytes(UTF_8)) + expect(zooReader.getData(eq(lockPath + "/" + lock3Name))).andReturn(lockData3.getBytes(UTF_8)) .anyTimes(); replay(zooReader); @@ -293,12 +363,13 @@ 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(host1))); + hostByGroup.put("coord1", new TreeSet<>(List.of(host2))); + hostByGroup.put("coord2", new TreeSet<>(List.of(host3))); - StatusSummary expected = - new StatusSummary(ServiceStatusReport.ReportKey.COORDINATOR, Set.of(), hostByGroup, 0); + StatusSummary expected = new StatusSummary(ServiceStatusReport.ReportKey.COORDINATOR, + new TreeSet<>(List.of("coord1", "default", "coord2")), hostByGroup, 0); assertEquals(expected.hashCode(), status.hashCode()); assertEquals(expected.getDisplayName(), status.getDisplayName()); @@ -339,24 +410,33 @@ public class ServiceStatusCmdTest { String host1 = "host1:8080"; String host2 = "host2:9090"; + String lockData1 = + "{\"descriptors\":[{\"uuid\":\"5c901352-b027-4f78-8ee1-05ae163fbb0e\",\"service\":\"GC\",\"address\":\"" + + host2 + "\",\"group\":\"default\"}]}"; + String lockData2 = + "{\"descriptors\":[{\"uuid\":\"5c901352-b027-4f78-8ee1-05ae163fbb0e\",\"service\":\"GC\",\"address\":\"" + + host1 + "\",\"group\":\"gc1\"}]}"; + expect(zooReader.getChildren(eq(lockPath))).andReturn(List.of(lock1Name, lock2Name)).once(); - expect(zooReader.getData(eq(lockPath + "/" + lock1Name))) - .andReturn(("GC_CLIENT=" + host1).getBytes(UTF_8)).once(); - expect(zooReader.getData(eq(lockPath + "/" + lock2Name))) - .andReturn(("GC_CLIENT=" + host2).getBytes(UTF_8)).once(); + expect(zooReader.getData(eq(lockPath + "/" + lock1Name))).andReturn(lockData1.getBytes(UTF_8)) + .once(); + expect(zooReader.getData(eq(lockPath + "/" + lock2Name))).andReturn(lockData2.getBytes(UTF_8)) + .once(); replay(zooReader); ServiceStatusCmd cmd = new ServiceStatusCmd(); StatusSummary status = cmd.getGcStatus(zooReader, zRoot); 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(new TreeSet<>(List.of(host1)), status.getServiceByGroups().get("gc1")); + assertEquals(new TreeSet<>(List.of(host2)), status.getServiceByGroups().get("default")); } /** @@ -366,33 +446,47 @@ public class ServiceStatusCmdTest { @Test void zkNodeDeletedTest() throws Exception { String lock1Name = "zlock#" + UUID.randomUUID() + "#0000000001"; - String lock2Name = "zlock#" + UUID.randomUUID() + "#0000000022"; - String lock3Name = "zlock#" + UUID.randomUUID() + "#0000000099"; - String host2 = "hostZ:8080"; - String host3 = "hostA:8080"; + String lock2Name = "zlock#" + UUID.randomUUID() + "#0000000002"; + String lock3Name = "zlock#" + UUID.randomUUID() + "#0000000003"; + + String host2 = "localhost:9992"; + String host3 = "hostA:9999"; + + String lock1data = + "{\"descriptors\":[{\"uuid\":\"6effb690-c29c-4e0b-92ff-f6b308385a42\",\"service\":\"MANAGER\",\"address\":\"localhost:9991\",\"group\":\"default\"}]}"; + String lock2Data = + "{\"descriptors\":[{\"uuid\":\"6effb690-c29c-4e0b-92ff-f6b308385a42\",\"service\":\"MANAGER\",\"address\":\"" + + host2 + "\",\"group\":\"default\"}]}"; + String lock3Data = + "{\"descriptors\":[{\"uuid\":\"6effb690-c29c-4e0b-92ff-f6b308385a42\",\"service\":\"MANAGER\",\"address\":\"" + + host3 + "\",\"group\":\"manager1\"}]}"; String lockPath = zRoot + Constants.ZMANAGER_LOCK; expect(zooReader.getChildren(eq(lockPath))).andReturn(List.of(lock1Name, lock2Name, lock3Name)) .anyTimes(); + // expect(zooReader.getData(eq(lockPath + "/" + lock1Name))) + // .andThrow(new KeeperException.NoNodeException("no node forced exception")).once(); expect(zooReader.getData(eq(lockPath + "/" + lock1Name))) - .andThrow(new KeeperException.NoNodeException("no node forced exception")).anyTimes(); - expect(zooReader.getData(eq(lockPath + "/" + lock2Name))).andReturn(host2.getBytes(UTF_8)) + .andThrow(new KeeperException.NoNodeException("no node forced exception")).once(); + expect(zooReader.getData(eq(lockPath + "/" + lock2Name))).andReturn(lock2Data.getBytes(UTF_8)) .anyTimes(); - expect(zooReader.getData(eq(lockPath + "/" + lock3Name))).andReturn(host3.getBytes(UTF_8)) + expect(zooReader.getData(eq(lockPath + "/" + lock3Name))).andReturn(lock3Data.getBytes(UTF_8)) .anyTimes(); + replay(zooReader); ServiceStatusCmd cmd = new ServiceStatusCmd(); StatusSummary status = cmd.getManagerStatus(zooReader, zRoot); LOG.info("manager status data: {}", status); - assertEquals(1, status.getServiceByGroups().size()); - assertEquals(2, status.getServiceByGroups().get(NO_GROUP_TAG).size()); + assertEquals(2, status.getServiceByGroups().size()); + assertEquals(1, status.getServiceByGroups().get("default").size()); + assertEquals(1, status.getServiceByGroups().get("manager1").size()); assertEquals(1, status.getErrorCount()); // host 1 missing - no node exception - Set<String> sortedHosts = new TreeSet<>(List.of(host3, host2)); - assertEquals(sortedHosts, status.getServiceByGroups().get(NO_GROUP_TAG)); + assertEquals(new TreeSet<>(List.of(host2)), status.getServiceByGroups().get("default")); + assertEquals(new TreeSet<>(List.of(host3)), status.getServiceByGroups().get("manager1")); } @Test diff --git 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 index b90e2c8378..84b99a12d4 100644 --- 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 @@ -103,29 +103,29 @@ 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("host1:8080", "host2:9090"))); - StatusSummary managerSummary = new StatusSummary(MANAGER, Set.of(), managerByGroup, 1); + managerByGroup.put("default", new TreeSet<>(List.of("host1:8080", "host2:9090"))); + StatusSummary managerSummary = new StatusSummary(MANAGER, Set.of("default"), 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, Set.of(), monitorByGroup, 0); + monitorByGroup.put("default", new TreeSet<>(List.of("host1:8080", "host2:9090"))); + StatusSummary monitorSummary = new StatusSummary(ServiceStatusReport.ReportKey.MONITOR, + Set.of("default"), 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(), gcByGroup, 0); + new StatusSummary(ServiceStatusReport.ReportKey.GC, Set.of("default"), 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, Set.of(), tserverByGroup, 1); + StatusSummary tserverSummary = new StatusSummary(ServiceStatusReport.ReportKey.T_SERVER, + Set.of("default"), tserverByGroup, 1); services.put(ServiceStatusReport.ReportKey.T_SERVER, tserverSummary); Map<String,Set<String>> sserverByGroup = new TreeMap<>(); @@ -138,7 +138,7 @@ public class ServiceStatusReportTest { 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"))); + coordinatorByGroup.put("default", new TreeSet<>(List.of("host4:9090", "host2:9091"))); StatusSummary coordinatorSummary = new StatusSummary(ServiceStatusReport.ReportKey.COORDINATOR, Set.of(), coordinatorByGroup, 0); services.put(ServiceStatusReport.ReportKey.COORDINATOR, coordinatorSummary);