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

erose pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new c7f65e7ebb HDDS-11740. Add debug command to show internal component 
versions (#7450)
c7f65e7ebb is described below

commit c7f65e7ebb1bb9a78752d3219eccad879872e2e0
Author: Doroszlai, Attila <[email protected]>
AuthorDate: Wed Nov 20 00:39:54 2024 +0100

    HDDS-11740. Add debug command to show internal component versions (#7450)
---
 .../main/smoketest/debug/ozone-debug-tests.robot   |  5 ++
 .../apache/hadoop/ozone/debug/VersionDebug.java    | 77 ++++++++++++++++++++++
 2 files changed, 82 insertions(+)

diff --git a/hadoop-ozone/dist/src/main/smoketest/debug/ozone-debug-tests.robot 
b/hadoop-ozone/dist/src/main/smoketest/debug/ozone-debug-tests.robot
index ca1995bf3a..4e013e2a64 100644
--- a/hadoop-ozone/dist/src/main/smoketest/debug/ozone-debug-tests.robot
+++ b/hadoop-ozone/dist/src/main/smoketest/debug/ozone-debug-tests.robot
@@ -49,3 +49,8 @@ Test ozone debug read-replicas
     FOR    ${replica}    IN RANGE    3
         Verify Healthy Replica   ${json}    ${replica}    ${md5sum}
     END
+
+
+Test ozone debug version
+    ${output} =    Execute    ozone debug version
+                   Execute    echo '${output}' | jq -r '.' # validate JSON
diff --git 
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/VersionDebug.java
 
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/VersionDebug.java
new file mode 100644
index 0000000000..b7be569adb
--- /dev/null
+++ 
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/VersionDebug.java
@@ -0,0 +1,77 @@
+/*
+ * 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
+ *
+ * http://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.hadoop.ozone.debug;
+
+import com.google.common.collect.ImmutableSortedMap;
+import org.apache.hadoop.hdds.ComponentVersion;
+import org.apache.hadoop.hdds.DatanodeVersion;
+import org.apache.hadoop.hdds.cli.SubcommandWithParent;
+import org.apache.hadoop.hdds.server.JsonUtils;
+import org.apache.hadoop.ozone.ClientVersion;
+import org.apache.hadoop.ozone.OzoneManagerVersion;
+import org.apache.hadoop.ozone.util.OzoneVersionInfo;
+import org.kohsuke.MetaInfServices;
+import picocli.CommandLine;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+/** Show internal component version information as JSON. */
[email protected](
+    name = "version",
+    description = "Show internal version of Ozone components, as defined in 
the artifacts where this command is " +
+        "executed.  It does not communicate with any Ozone services.  Run the 
same command on different nodes to " +
+        "get a cross-component view of versions.  The goal of this command is 
to help quickly get a glance of the " +
+        "latest features supported by Ozone on the current node."
+)
+@MetaInfServices(SubcommandWithParent.class)
+public class VersionDebug implements Callable<Void>, SubcommandWithParent {
+
+  @Override
+  public Class<?> getParentType() {
+    return OzoneDebug.class;
+  }
+
+  @Override
+  public Void call() throws IOException {
+    
System.out.println(JsonUtils.toJsonStringWithDefaultPrettyPrinter(ImmutableSortedMap.of(
+        "ozone", ImmutableSortedMap.of(
+            "revision", OzoneVersionInfo.OZONE_VERSION_INFO.getRevision(),
+            "url", OzoneVersionInfo.OZONE_VERSION_INFO.getUrl(),
+            "version", OzoneVersionInfo.OZONE_VERSION_INFO.getVersion()
+        ),
+        "components", ImmutableSortedMap.of(
+            "client", asMap(ClientVersion.CURRENT),
+            "datanode", asMap(DatanodeVersion.CURRENT),
+            "om", asMap(OzoneManagerVersion.CURRENT)
+        )
+    )));
+    return null;
+  }
+
+  private static <T extends Enum<T> & ComponentVersion> Map<String, Object> 
asMap(T version) {
+    return ImmutableSortedMap.of(
+        "componentVersion", ImmutableSortedMap.of(
+            "name", version.name(),
+            "protoValue", version.toProtoValue()
+        )
+    );
+  }
+
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to