diff --git a/hadoop-hdds/docs/content/feature/ErasureCoding.md b/hadoop-hdds/docs/content/feature/ErasureCoding.md index c174da2bc64..9e60c3a923a 100644 --- a/hadoop-hdds/docs/content/feature/ErasureCoding.md +++ b/hadoop-hdds/docs/content/feature/ErasureCoding.md @@ -246,7 +246,7 @@ The default value of java.library.path depends on the OS and Java version. For e You can check if ISA-L is accessible to Ozone by running the following command: ```shell -ozone checknative +ozone debug checknative ``` diff --git a/hadoop-ozone/dist/src/shell/ozone/ozone b/hadoop-ozone/dist/src/shell/ozone/ozone index 08bbf1acfe6..40485a95235 100755 --- a/hadoop-ozone/dist/src/shell/ozone/ozone +++ b/hadoop-ozone/dist/src/shell/ozone/ozone @@ -59,7 +59,6 @@ function ozone_usage ozone_add_subcommand "admin" client "Ozone admin tool" ozone_add_subcommand "debug" client "Ozone debug tool" ozone_add_subcommand "repair" client "Ozone repair tool" - ozone_add_subcommand "checknative" client "checks if native libraries are loaded" ozone_add_subcommand "ratis" client "Ozone ratis tool" ozone_generate_usage "${OZONE_SHELL_EXECNAME}" false @@ -224,10 +223,6 @@ function ozonecmd_case OZONE_DEBUG_OPTS="${OZONE_DEBUG_OPTS} ${RATIS_OPTS} ${OZONE_MODULE_ACCESS_ARGS}" OZONE_RUN_ARTIFACT_NAME="ozone-tools" ;; - checknative) - OZONE_CLASSNAME=org.apache.hadoop.ozone.shell.checknative.CheckNative - OZONE_RUN_ARTIFACT_NAME="ozone-tools" - ;; ratis) OZONE_CLASSNAME=org.apache.hadoop.ozone.shell.OzoneRatis OZONE_RUN_ARTIFACT_NAME="ozone-tools" @@ -305,8 +300,8 @@ fi OZONE_SUBCMD=$1 -if [[ "$OZONE_SUBCMD" == "auditparser" ]]; then - echo "warning: 'ozone auditparser' is deprecated, use 'ozone debug auditparser' instead." +if [[ "$OZONE_SUBCMD" == "auditparser" ]] || [[ "$OZONE_SUBCMD" == "checknative" ]]; then + echo "warning: 'ozone $OZONE_SUBCMD' is deprecated, use 'ozone debug $OZONE_SUBCMD' instead." OZONE_SUBCMD="debug" else shift diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/checknative/CheckNative.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/CheckNative.java similarity index 87% rename from hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/checknative/CheckNative.java rename to hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/CheckNative.java index e3bdd475c99..1225122b4e4 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/checknative/CheckNative.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/CheckNative.java @@ -15,28 +15,27 @@ * limitations under the License. */ -package org.apache.hadoop.ozone.shell.checknative; +package org.apache.hadoop.ozone.debug; import static org.apache.hadoop.hdds.utils.NativeConstants.ROCKS_TOOLS_NATIVE_LIBRARY_NAME; import java.util.Collections; import java.util.concurrent.Callable; -import org.apache.hadoop.hdds.cli.GenericCli; +import org.apache.hadoop.hdds.cli.AbstractSubcommand; +import org.apache.hadoop.hdds.cli.DebugSubcommand; import org.apache.hadoop.hdds.utils.NativeLibraryLoader; import org.apache.hadoop.hdds.utils.db.managed.ManagedRocksObjectUtils; import org.apache.hadoop.io.erasurecode.ErasureCodeNative; +import org.kohsuke.MetaInfServices; import picocli.CommandLine; /** * CLI command to check if native libraries are loaded. */ -@CommandLine.Command(name = "ozone checknative", +@CommandLine.Command(name = "checknative", description = "Checks if native libraries are loaded") -public class CheckNative extends GenericCli implements Callable { - - public static void main(String[] argv) { - new CheckNative().run(argv); - } +@MetaInfServices(DebugSubcommand.class) +public class CheckNative extends AbstractSubcommand implements Callable, DebugSubcommand { @Override public Void call() throws Exception { diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/checknative/package-info.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/checknative/package-info.java deleted file mode 100644 index a4ca463b834..00000000000 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/checknative/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 for commands related to checking native libraries. - */ -package org.apache.hadoop.ozone.shell.checknative; diff --git a/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/checknative/TestCheckNative.java b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/checknative/TestCheckNative.java deleted file mode 100644 index ab066129ad5..00000000000 --- a/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/checknative/TestCheckNative.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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.checknative; - -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.apache.hadoop.hdds.utils.NativeConstants.ROCKS_TOOLS_NATIVE_LIBRARY_NAME; -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.io.UnsupportedEncodingException; -import org.apache.hadoop.ozone.shell.checknative.CheckNative; -import org.apache.ozone.test.tag.Native; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -/** - * Tests for {@link CheckNative}. - */ -public class TestCheckNative { - - private static PrintStream psBackup; - private static ByteArrayOutputStream outputStream; - - private static final String DEFAULT_ENCODING = UTF_8.name(); - - @BeforeAll - public static void init() throws UnsupportedEncodingException { - psBackup = System.out; - outputStream = new ByteArrayOutputStream(); - PrintStream psOut = new PrintStream(outputStream, false, DEFAULT_ENCODING); - System.setOut(psOut); - } - - @Test - public void testCheckNativeNotLoaded() throws UnsupportedEncodingException { - outputStream.reset(); - new CheckNative() - .run(new String[] {}); - // trims multiple spaces - String stdOut = outputStream.toString(DEFAULT_ENCODING) - .replaceAll(" +", " "); - assertThat(stdOut).contains("Native library checking:"); - assertThat(stdOut).contains("hadoop: false"); - assertThat(stdOut).contains("ISA-L: false"); - assertThat(stdOut).contains("rocks-tools: false"); - } - - @Native(ROCKS_TOOLS_NATIVE_LIBRARY_NAME) - @Test - public void testCheckNativeRocksToolsLoaded() throws UnsupportedEncodingException { - outputStream.reset(); - new CheckNative() - .run(new String[] {}); - // trims multiple spaces - String stdOut = outputStream.toString(DEFAULT_ENCODING) - .replaceAll(" +", " "); - assertThat(stdOut).contains("Native library checking:"); - assertThat(stdOut).contains("hadoop: false"); - assertThat(stdOut).contains("ISA-L: false"); - assertThat(stdOut).contains("rocks-tools: true"); - } - - @AfterEach - public void setUp() { - outputStream.reset(); - } - - @AfterAll - public static void tearDown() { - System.setOut(psBackup); - } -} diff --git a/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/debug/TestCheckNative.java b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/debug/TestCheckNative.java new file mode 100644 index 00000000000..eb6009a686b --- /dev/null +++ b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/debug/TestCheckNative.java @@ -0,0 +1,74 @@ +/* + * 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 static org.apache.hadoop.hdds.utils.NativeConstants.ROCKS_TOOLS_NATIVE_LIBRARY_NAME; +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.hadoop.hdds.utils.IOUtils; +import org.apache.ozone.test.GenericTestUtils; +import org.apache.ozone.test.tag.Native; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * Tests for {@link CheckNative}. + */ +class TestCheckNative { + + private GenericTestUtils.PrintStreamCapturer out; + + @BeforeEach + void init() { + out = GenericTestUtils.captureOut(); + } + + @Test + void testCheckNativeNotLoaded() { + executeCheckNative(); + assertOutput(false); + } + + @Native(ROCKS_TOOLS_NATIVE_LIBRARY_NAME) + @Test + void testCheckNativeRocksToolsLoaded() { + executeCheckNative(); + assertOutput(true); + } + + private void assertOutput(boolean expectedRocksNative) { + // trims multiple spaces + String stdOut = out.get() + .replaceAll(" +", " "); + assertThat(stdOut) + .contains("Native library checking:") + .contains("hadoop: false") + .contains("ISA-L: false") + .contains("rocks-tools: " + expectedRocksNative); + } + + @AfterEach + void setUp() { + IOUtils.closeQuietly(out); + } + + private static void executeCheckNative() { + new OzoneDebug().getCmd().execute("checknative"); + } +}