diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/local/LocalOzoneRuntime.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/local/LocalOzoneRuntime.java new file mode 100644 index 000000000000..54a08e476ff6 --- /dev/null +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/local/LocalOzoneRuntime.java @@ -0,0 +1,39 @@ +/* + * 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.local; + +/** + * Runtime contract for local single-node Ozone commands. + */ +public interface LocalOzoneRuntime extends AutoCloseable { + + void start() throws Exception; + + String getDisplayHost(); + + int getScmPort(); + + int getOmPort(); + + int getS3gPort(); + + String getS3Endpoint(); + + @Override + void close() throws Exception; +} diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/local/OzoneLocal.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/local/OzoneLocal.java new file mode 100644 index 000000000000..bd19b9f5dbcf --- /dev/null +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/local/OzoneLocal.java @@ -0,0 +1,52 @@ +/* + * 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.local; + +import java.util.concurrent.Callable; +import org.apache.hadoop.hdds.cli.GenericCli; +import org.apache.hadoop.hdds.cli.HddsVersionProvider; +import picocli.CommandLine.Command; + +/** + * Internal CLI entry point for local single-node Ozone commands. + */ +@Command(name = "ozone local", + hidden = true, + description = "Internal commands for local single-node Ozone", + versionProvider = HddsVersionProvider.class, + mixinStandardHelpOptions = true, + subcommands = { + OzoneLocal.RunCommand.class + }) +public class OzoneLocal extends GenericCli { + + public static void main(String[] args) { + new OzoneLocal().run(args); + } + + @Command(name = "run", + hidden = true, + description = "Internal placeholder for a local Ozone runtime") + static class RunCommand implements Callable { + + @Override + public Void call() { + return null; + } + } +} diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/local/package-info.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/local/package-info.java new file mode 100644 index 000000000000..ca9e55fd6cee --- /dev/null +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/local/package-info.java @@ -0,0 +1,21 @@ +/* + * 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. + */ + +/** + * Internal local single-node Ozone runtime support. + */ +package org.apache.hadoop.ozone.local; diff --git a/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/local/TestOzoneLocal.java b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/local/TestOzoneLocal.java new file mode 100644 index 000000000000..ff44f0ee5f68 --- /dev/null +++ b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/local/TestOzoneLocal.java @@ -0,0 +1,100 @@ +/* + * 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.local; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import org.junit.jupiter.api.Test; +import picocli.CommandLine; +import picocli.CommandLine.Command; + +/** + * Tests for {@link OzoneLocal}. + */ +class TestOzoneLocal { + + @Test + void localCommandMetadataIsPresentAndHidden() { + Command command = OzoneLocal.class.getAnnotation(Command.class); + + assertNotNull(command); + assertEquals("ozone local", command.name()); + assertTrue(command.hidden()); + } + + @Test + void runCommandMetadataIsPresentAndHidden() { + Command command = OzoneLocal.RunCommand.class.getAnnotation(Command.class); + + assertNotNull(command); + assertEquals("run", command.name()); + assertTrue(command.hidden()); + } + + @Test + void genericCliRegistersRunPlaceholder() { + OzoneLocal local = new OzoneLocal(); + + assertTrue(local.getCmd().getSubcommands().containsKey("run")); + } + + @Test + void rootHelpHidesRunPlaceholder() throws Exception { + OzoneLocal local = new OzoneLocal(); + CommandLine commandLine = local.getCmd(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ByteArrayOutputStream err = new ByteArrayOutputStream(); + commandLine.setOut(new PrintWriter(new OutputStreamWriter(out, UTF_8), + true)); + commandLine.setErr(new PrintWriter(new OutputStreamWriter(err, UTF_8), + true)); + + int exitCode = local.execute(new String[] {"--help"}); + + String help = out.toString(UTF_8.name()); + assertEquals(0, exitCode); + assertTrue(help.contains("Usage: ozone local")); + assertFalse(help.contains("run")); + assertEquals("", err.toString(UTF_8.name())); + } + + @Test + void runCommandIsQuietNoOpPlaceholder() throws Exception { + OzoneLocal local = new OzoneLocal(); + CommandLine commandLine = local.getCmd(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ByteArrayOutputStream err = new ByteArrayOutputStream(); + commandLine.setOut(new PrintWriter(new OutputStreamWriter(out, UTF_8), + true)); + commandLine.setErr(new PrintWriter(new OutputStreamWriter(err, UTF_8), + true)); + + int exitCode = local.execute(new String[] {"run"}); + + assertEquals(0, exitCode); + assertEquals("", out.toString(UTF_8.name())); + assertEquals("", err.toString(UTF_8.name())); + } +}