dlmarion commented on code in PR #6419:
URL: https://github.com/apache/accumulo/pull/6419#discussion_r3451993821


##########
core/src/main/java/org/apache/accumulo/core/cli/CommandOutputEnvelope.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.core.cli;
+
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+
+import com.google.gson.Gson;
+
+/**
+ * A stable, versioned outer wrapper for all admin command JSON output.
+ *
+ * <p>
+ * Every command that supports --json output wraps its command-specific data 
in this envelope. This
+ * provides a consistent structure that scripts can rely on regardless of 
which command produced the
+ * output:
+ *
+ * <pre>
+ * {
+ *   "command": "accumulo admin fate --summary",
+ *   "version": "1",
+ *   "reportTime": "2026-06-04T12:00:00Z",
+ *   "status": "OK",
+ *   "message": null,
+ *   "data": { ...command-specific payload... }

Review Comment:
   I wonder if the command output should be it's own top level element instead. 
For example,
   
   ```
   {
     "status": {
       "command": "accumulo admin fate --summary",
       "version": "1",
       "reportTime": "2026-06-04T12:00:00Z",
       "status": "OK",
       "message": ""
     },
     "output": {
     }
   }
   ```



##########
core/src/main/java/org/apache/accumulo/core/cli/CommandOutputEnvelope.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.core.cli;
+
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+
+import com.google.gson.Gson;
+
+/**
+ * A stable, versioned outer wrapper for all admin command JSON output.
+ *
+ * <p>
+ * Every command that supports --json output wraps its command-specific data 
in this envelope. This
+ * provides a consistent structure that scripts can rely on regardless of 
which command produced the
+ * output:
+ *
+ * <pre>
+ * {
+ *   "command": "accumulo admin fate --summary",
+ *   "version": "1",
+ *   "reportTime": "2026-06-04T12:00:00Z",
+ *   "status": "OK",
+ *   "message": null,
+ *   "data": { ...command-specific payload... }
+ * }
+ * </pre>
+ *
+ * <p>
+ * The {@link version} field is a stability contract. When a breaking change 
is made to the envelope
+ * structure, the version will be incremented. Scripts should check this field 
and handle the
+ * version they were written against.
+ *
+ */
+public class CommandOutputEnvelope {
+
+  /**
+   * Current envelop schema version. Increment this if a breaking structural 
change is made to the
+   * envelope fields (not to the {@link data} field, data changes command 
specific).
+   */
+  public static final String VERSION = "1.0";
+  private static final DateTimeFormatter ISO_FMT =
+      DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
+  private static final Gson PRETTY_GSON =
+      new Gson().newBuilder().setPrettyPrinting().disableJdkUnsafe().create();
+
+  private String command;
+  private String version;
+  private String reportTime;
+  private String status;
+  private String message;
+  private Object data;
+
+  @SuppressWarnings("unused")
+  private CommandOutputEnvelope() {}
+
+  private CommandOutputEnvelope(String command, String status, String message, 
Object data) {
+    this.command = command;
+    this.version = VERSION;
+    this.reportTime = ISO_FMT.format(ZonedDateTime.now(ZoneOffset.UTC));
+    this.status = status;
+    this.message = message;

Review Comment:
   Might be able to combine these two fields into one. For success the value 
could be `OK`. For a failure the value could be `ERROR: <message>`



##########
core/src/main/java/org/apache/accumulo/core/cli/CommandOutputEnvelope.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.accumulo.core.cli;
+
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+
+import com.google.gson.Gson;
+
+/**
+ * A stable, versioned outer wrapper for all admin command JSON output.
+ *
+ * <p>
+ * Every command that supports --json output wraps its command-specific data 
in this envelope. This
+ * provides a consistent structure that scripts can rely on regardless of 
which command produced the
+ * output:
+ *
+ * <pre>
+ * {
+ *   "command": "accumulo admin fate --summary",
+ *   "version": "1",
+ *   "reportTime": "2026-06-04T12:00:00Z",
+ *   "status": "OK",
+ *   "message": null,
+ *   "data": { ...command-specific payload... }
+ * }
+ * </pre>
+ *
+ * <p>
+ * The {@link version} field is a stability contract. When a breaking change 
is made to the envelope
+ * structure, the version will be incremented. Scripts should check this field 
and handle the
+ * version they were written against.
+ *
+ */
+public class CommandOutputEnvelope {
+
+  /**
+   * Current envelop schema version. Increment this if a breaking structural 
change is made to the
+   * envelope fields (not to the {@link data} field, data changes command 
specific).
+   */
+  public static final String VERSION = "1.0";
+  private static final DateTimeFormatter ISO_FMT =
+      DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");

Review Comment:
   I wonder if it would be more user friendly to use the hosts timezone. 



##########
server/base/src/main/java/org/apache/accumulo/server/util/adminCommand/ServiceStatus.java:
##########
@@ -106,17 +103,15 @@ public void execute(JCommander cl, ServiceStatusCmdOpts 
options) throws Exceptio
     ServiceStatusReport report = new ServiceStatusReport(services, 
options.showHosts);
 
     if (options.json) {
-      System.out.println(report.toJson());
+      System.out.println(report.toEnvelopedJson("accumulo admin 
service-status"));

Review Comment:
   It might make sense to add a method to ServerKeywordExecutable that returns 
the invoked command. This would make this more flexible if the command group or 
command name changes in the future.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to