This is an automated email from the ASF dual-hosted git repository.

dlmarion 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 20da5e1e43 Fixes serviceStatus json output (#6094)
20da5e1e43 is described below

commit 20da5e1e43422ebfa582ecba2d97a84cca10d0cd
Author: Dave Marion <[email protected]>
AuthorDate: Thu Jan 29 15:34:12 2026 -0500

    Fixes serviceStatus json output (#6094)
    
    This change removes the StatusSummary.serviceType
    field from the json serialization. The serviceType
    field is redundant in the json output as the same
    information is used as the key in a map that contains
    the StatusSummary object.
    
    This change also removes the StatusSummary.serviceByGroups
    field from the json serialization using a custom
    ExclusionStrategy.
    
    Closes #6088
    
    
    ---------
    
    Co-authored-by: Keith Turner <[email protected]>
---
 .../util/serviceStatus/ServiceStatusReport.java    | 43 ++++++++++++++++++----
 .../server/util/serviceStatus/StatusSummary.java   |  7 +---
 2 files changed, 38 insertions(+), 12 deletions(-)

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 7b6279404c..0c628cd604 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
@@ -21,24 +21,55 @@ package org.apache.accumulo.server.util.serviceStatus;
 import static org.apache.accumulo.core.Constants.DEFAULT_RESOURCE_GROUP_NAME;
 import static org.apache.accumulo.core.util.LazySingletons.GSON;
 
+import java.lang.reflect.Field;
 import java.time.ZoneId;
 import java.time.ZonedDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.Map;
 import java.util.Set;
-import java.util.TreeMap;
-import java.util.stream.Collectors;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.gson.ExclusionStrategy;
+import com.google.gson.FieldAttributes;
 import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
 
 /**
  * Wrapper for JSON formatted report.
  */
 public class ServiceStatusReport {
 
+  private static class HostExclusionStrategy implements ExclusionStrategy {
+
+    private final static String field = "serviceByGroups";
+    private final Field fieldToIgnore;
+
+    public HostExclusionStrategy() {
+      try {
+        fieldToIgnore = StatusSummary.class.getDeclaredField(field);
+      } catch (NoSuchFieldException e) {
+        throw new IllegalStateException(e);
+      }
+    }
+
+    @Override
+    public boolean shouldSkipField(FieldAttributes f) {
+      if (f.getDeclaringClass().equals(StatusSummary.class)
+          && f.getName().equals(fieldToIgnore.getName())) {
+        return true;
+      }
+      return false;
+    }
+
+    @Override
+    public boolean shouldSkipClass(Class<?> clazz) {
+      return false;
+    }
+
+  }
+
   private static final Logger LOG = 
LoggerFactory.getLogger(ServiceStatusReport.class);
 
   private static final Gson gson = GSON.get();
@@ -89,11 +120,9 @@ public class ServiceStatusReport {
     if (showHosts) {
       return gson.toJson(this, ServiceStatusReport.class);
     } else {
-      Map<ReportKey,StatusSummary> noHostSummaries =
-          
summaries.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
-              e -> e.getValue().withoutHosts(), (a, b) -> b, TreeMap::new));
-      ServiceStatusReport noHostReport = new 
ServiceStatusReport(noHostSummaries, false);
-      return gson.toJson(noHostReport, ServiceStatusReport.class);
+      return new GsonBuilder().disableJdkUnsafe()
+          .setExclusionStrategies(new HostExclusionStrategy()).create()
+          .toJson(this, ServiceStatusReport.class);
     }
   }
 
diff --git 
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
index f27268a963..25ecfee025 100644
--- 
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
@@ -24,7 +24,8 @@ import java.util.Set;
 
 public class StatusSummary {
 
-  private final ServiceStatusReport.ReportKey serviceType;
+  // marked transient to exclude from json serialization
+  private final transient ServiceStatusReport.ReportKey serviceType;
   private final Map<String,Integer> resourceGroups;
   private final Map<String,Set<String>> serviceByGroups;
   private final int serviceCount;
@@ -75,10 +76,6 @@ public class StatusSummary {
     return errorCount;
   }
 
-  public StatusSummary withoutHosts() {
-    return new StatusSummary(serviceType, resourceGroups, Map.of(), 
errorCount);
-  }
-
   @Override
   public boolean equals(Object o) {
     if (this == o) {

Reply via email to