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 ca1995bf3a1..4e013e2a64b 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 00000000000..b7be569adbf --- /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. */ +@CommandLine.Command( + 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, 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 & ComponentVersion> Map asMap(T version) { + return ImmutableSortedMap.of( + "componentVersion", ImmutableSortedMap.of( + "name", version.name(), + "protoValue", version.toProtoValue() + ) + ); + } + +}