diff --git a/hadoop-yarn-project/hadoop-yarn/bin/yarn b/hadoop-yarn-project/hadoop-yarn/bin/yarn index 6ef4e2c8e2..91dd2c3238 100755 --- a/hadoop-yarn-project/hadoop-yarn/bin/yarn +++ b/hadoop-yarn-project/hadoop-yarn/bin/yarn @@ -52,6 +52,7 @@ function hadoop_usage hadoop_add_subcommand "rmadmin" admin "admin tools" hadoop_add_subcommand "router" daemon "run the Router daemon" hadoop_add_subcommand "routeradmin" admin "router admin tools" + hadoop_add_subcommand "gpgadmin" admin "yan gpg admin tools" hadoop_add_subcommand "schedulerconf" client "Updates scheduler configuration" hadoop_add_subcommand "scmadmin" admin "SharedCacheManager admin tools" hadoop_add_subcommand "sharedcachemanager" daemon "run the SharedCacheManager daemon" @@ -193,6 +194,9 @@ ${HADOOP_COMMON_HOME}/${HADOOP_COMMON_LIB_JARS_DIR}" routeradmin) HADOOP_CLASSNAME='org.apache.hadoop.yarn.client.cli.RouterCLI' ;; + gpgadmin) + HADOOP_CLASSNAME='org.apache.hadoop.yarn.client.cli.GpgCLI' + ;; schedulerconf) HADOOP_CLASSNAME='org.apache.hadoop.yarn.client.cli.SchedConfCLI' ;; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/GpgCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/GpgCLI.java new file mode 100644 index 0000000000..e5e729cad8 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/GpgCLI.java @@ -0,0 +1,81 @@ +/** + * 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.yarn.client.cli; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.conf.Configured; +import org.apache.hadoop.util.Tool; +import org.apache.hadoop.util.ToolRunner; +import org.apache.hadoop.yarn.conf.YarnConfiguration; + +public class GpgCLI extends Configured implements Tool { + + public GpgCLI() { + super(); + } + + public GpgCLI(Configuration conf) { + super(conf); + } + + private static void printHelp() { + StringBuilder summary = new StringBuilder(); + summary.append("gpgadmin command line for YARN Federation Policy management.\n"); + StringBuilder helpBuilder = new StringBuilder(); + System.out.println(summary); + helpBuilder.append(" -help [cmd]: Displays help for the given command or all commands" + + " if none is specified."); + System.out.println(helpBuilder); + System.out.println(); + ToolRunner.printGenericCommandUsage(System.out); + } + + private static void printUsage() { + StringBuilder usageBuilder = new StringBuilder(); + buildUsageMsg(usageBuilder); + System.err.println(usageBuilder); + ToolRunner.printGenericCommandUsage(System.err); + } + + private static void buildUsageMsg(StringBuilder builder) { + builder.append("gpgadmin is only used in Yarn Federation Mode.\n"); + builder.append("Usage: gpgadmin\n"); + builder.append(" -help" + " [cmd]\n"); + } + + @Override + public int run(String[] args) throws Exception { + YarnConfiguration yarnConf = getConf() == null ? + new YarnConfiguration() : new YarnConfiguration(getConf()); + boolean isFederationEnabled = yarnConf.getBoolean(YarnConfiguration.FEDERATION_ENABLED, + YarnConfiguration.DEFAULT_FEDERATION_ENABLED); + + if (args.length < 1 || !isFederationEnabled) { + printUsage(); + return -1; + } + + String cmd = args[0]; + if ("-help".equals(cmd)) { + printHelp(); + return 0; + } + + return 0; + } +} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestGpgCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestGpgCLI.java new file mode 100644 index 0000000000..0ab981bf60 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestGpgCLI.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.yarn.client.cli; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.junit.Before; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +import static org.junit.Assert.assertEquals; + +public class TestGpgCLI { + private GpgCLI gpgCLI; + + @Before + public void setup() throws Exception { + Configuration config = new Configuration(); + config.setBoolean(YarnConfiguration.FEDERATION_ENABLED, true); + gpgCLI = new GpgCLI(config); + } + + @Test + public void testHelp() throws Exception { + PrintStream oldOutPrintStream = System.out; + PrintStream oldErrPrintStream = System.err; + ByteArrayOutputStream dataOut = new ByteArrayOutputStream(); + ByteArrayOutputStream dataErr = new ByteArrayOutputStream(); + System.setOut(new PrintStream(dataOut)); + System.setErr(new PrintStream(dataErr)); + + String[] args = {"-help"}; + assertEquals(0, gpgCLI.run(args)); + } +}