diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/conf/OzoneManagersCommandHandler.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/conf/OzoneManagersCommandHandler.java index 763fecfd63ce..763055ecdc6b 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/conf/OzoneManagersCommandHandler.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/conf/OzoneManagersCommandHandler.java @@ -28,6 +28,7 @@ * Handler for ozone getconf ozonemanagers. */ @Command(name = "ozonemanagers", + aliases = {"-ozonemanagers"}, description = "gets list of ozone storage container " + "manager nodes in the cluster", mixinStandardHelpOptions = true, diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/conf/PrintConfKeyCommandHandler.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/conf/PrintConfKeyCommandHandler.java index fe70ee401aba..d5106e643528 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/conf/PrintConfKeyCommandHandler.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/conf/PrintConfKeyCommandHandler.java @@ -26,6 +26,7 @@ * Handler for ozone getconf confKey [key]. */ @Command(name = "confKey", + aliases = {"-confKey"}, description = "gets a specific key from the configuration", mixinStandardHelpOptions = true, versionProvider = HddsVersionProvider.class) @@ -42,8 +43,9 @@ public Void call() throws Exception { String value = tool.getConf().getTrimmed(confKey); if (value != null) { tool.printOut(value); + } else { + tool.printError("Configuration " + confKey + " is missing."); } - tool.printError("Configuration " + confKey + " is missing."); return null; } } diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/conf/StorageContainerManagersCommandHandler.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/conf/StorageContainerManagersCommandHandler.java index bded94f5fb2a..8d0094945042 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/conf/StorageContainerManagersCommandHandler.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/conf/StorageContainerManagersCommandHandler.java @@ -29,6 +29,7 @@ * Handler for ozone getconf storagecontainermanagers. */ @Command(name = "storagecontainermanagers", + aliases = {"-storagecontainermanagers"}, description = "gets list of ozone storage container " + "manager nodes in the cluster", mixinStandardHelpOptions = true, diff --git a/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/conf/TestGetConfOptions.java b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/conf/TestGetConfOptions.java new file mode 100644 index 000000000000..c3e79fd15a99 --- /dev/null +++ b/hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/conf/TestGetConfOptions.java @@ -0,0 +1,90 @@ +/** + * 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.conf; + +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.scm.ScmConfigKeys; +import org.apache.hadoop.ozone.om.OMConfigKeys; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +/** + * Tests the ozone getconf command. + */ +public class TestGetConfOptions { + private static OzoneConfiguration conf; + private static ByteArrayOutputStream bout; + private static PrintStream psBackup; + + @BeforeClass + public static void init() { + conf = new OzoneConfiguration(); + conf.set(OMConfigKeys.OZONE_OM_NODE_ID_KEY, "1"); + conf.set(OMConfigKeys.OZONE_OM_SERVICE_IDS_KEY, "service1"); + conf.set(ScmConfigKeys.OZONE_SCM_NAMES, "localhost"); + psBackup = System.out; + bout = new ByteArrayOutputStream(); + PrintStream psOut = new PrintStream(bout); + System.setOut(psOut); + } + + @After + public void setUp(){ + bout.reset(); + } + + @AfterClass + public static void tearDown(){ + System.setOut(psBackup); + } + + @Test + public void testGetConfWithTheOptionConfKey() { + new OzoneGetConf(conf) + .run(new String[] {"-confKey", ScmConfigKeys.OZONE_SCM_NAMES}); + Assert.assertEquals("localhost\n", bout.toString()); + bout.reset(); + new OzoneGetConf(conf) + .run(new String[] {"confKey", OMConfigKeys.OZONE_OM_NODE_ID_KEY}); + Assert.assertEquals("1\n", bout.toString()); + } + + @Test + public void testGetConfWithTheOptionStorageContainerManagers() { + new OzoneGetConf(conf).run(new String[] {"-storagecontainermanagers"}); + Assert.assertEquals("localhost\n", bout.toString()); + bout.reset(); + new OzoneGetConf(conf).run(new String[] {"storagecontainermanagers"}); + Assert.assertEquals("localhost\n", bout.toString()); + } + + @Test + public void testGetConfWithTheOptionOzoneManagers() { + new OzoneGetConf(conf).run(new String[] {"-ozonemanagers"}); + Assert.assertEquals("{service1=[]}\n", bout.toString()); + bout.reset(); + new OzoneGetConf(conf).run(new String[] {"ozonemanagers"}); + Assert.assertEquals("{service1=[]}\n", bout.toString()); + } +}