diff --git a/service/src/java/org/apache/hive/service/server/HiveServer2.java b/service/src/java/org/apache/hive/service/server/HiveServer2.java index 1f6a097559..9628aca7df 100644 --- a/service/src/java/org/apache/hive/service/server/HiveServer2.java +++ b/service/src/java/org/apache/hive/service/server/HiveServer2.java @@ -34,6 +34,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.GnuParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; @@ -1021,7 +1022,7 @@ public void startPrivilegeSynchonizer(HiveConf hiveConf) throws Exception { } } - private static void startHiveServer2() throws Throwable { + private static void startHiveServer2(CommandLine commandLine) throws Throwable { long attempts = 0, maxAttempts = 1; while (true) { LOG.info("Starting HiveServer2"); @@ -1039,6 +1040,25 @@ private static void startHiveServer2() throws Throwable { // avoid intial spike when using multiple HS2 scheduleClearDanglingScratchDir(hiveConf, new Random().nextInt(600)); + // Set hiveconf options + if (commandLine.hasOption("hiveconf")) { + Properties confProps = commandLine.getOptionProperties("hiveconf"); + for (String propKey : confProps.stringPropertyNames()) { + if ("hive.log.file".equals(propKey) || + "hive.log.dir".equals(propKey) || + "hive.root.logger".equals(propKey)) { + throw new IllegalArgumentException("Logs will be split in two " + + "files if the commandline argument " + propKey + " is " + + "used. To prevent this use to HADOOP_CLIENT_OPTS -D" + + propKey + "=" + confProps.getProperty(propKey) + + " or use the set the value in the configuration file" + + " (see HIVE-19886)"); + } + LOG.debug("Setting " + propKey + "=" + confProps.getProperty(propKey)); + hiveConf.set(propKey, confProps.getProperty(propKey)); + } + } + server = new HiveServer2(); server.init(hiveConf); server.start(); @@ -1210,24 +1230,6 @@ public static void main(String[] args) { ServerOptionsProcessorResponse parse(String[] argv) { try { commandLine = new GnuParser().parse(options, argv); - // Process --hiveconf - // Get hiveconf param values and set the System property values - Properties confProps = commandLine.getOptionProperties("hiveconf"); - for (String propKey : confProps.stringPropertyNames()) { - // save logging message for log4j output latter after log4j initialize properly - debugMessage.append("Setting " + propKey + "=" + confProps.getProperty(propKey) + ";\n"); - if ("hive.log.file".equals(propKey) || - "hive.log.dir".equals(propKey) || - "hive.root.logger".equals(propKey)) { - throw new IllegalArgumentException("Logs will be split in two " - + "files if the commandline argument " + propKey + " is " - + "used. To prevent this use to HADOOP_CLIENT_OPTS -D" - + propKey + "=" + confProps.getProperty(propKey) - + " or use the set the value in the configuration file" - + " (see HIVE-19886)"); - } - System.setProperty(propKey, confProps.getProperty(propKey)); - } // Process --help if (commandLine.hasOption('H')) { @@ -1258,7 +1260,7 @@ ServerOptionsProcessorResponse parse(String[] argv) { System.exit(-1); } // Default executor, when no option is specified - return new ServerOptionsProcessorResponse(new StartOptionExecutor()); + return new ServerOptionsProcessorResponse(new StartOptionExecutor(commandLine)); } StringBuilder getDebugMessage() { @@ -1312,10 +1314,16 @@ public void execute() { * This is the default executor, when no option is specified. */ static class StartOptionExecutor implements ServerOptionsExecutor { + private final CommandLine commandLine; + + StartOptionExecutor(CommandLine commandLine) { + this.commandLine = commandLine; + } + @Override public void execute() { try { - startHiveServer2(); + startHiveServer2(commandLine); } catch (Throwable t) { LOG.error("Error starting HiveServer2", t); System.exit(-1); diff --git a/service/src/test/org/apache/hive/service/server/TestServerOptionsProcessor.java b/service/src/test/org/apache/hive/service/server/TestServerOptionsProcessor.java deleted file mode 100644 index d5e4ed6e25..0000000000 --- a/service/src/test/org/apache/hive/service/server/TestServerOptionsProcessor.java +++ /dev/null @@ -1,52 +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.hive.service.server; - -import org.junit.Assert; -import org.junit.Test; - -import org.apache.hive.service.server.HiveServer2.ServerOptionsProcessor; - -/** - * Test ServerOptionsProcessor - * - */ -public class TestServerOptionsProcessor { - - @Test - public void test() { - ServerOptionsProcessor optProcessor = new ServerOptionsProcessor("HiveServer2"); - final String key = "testkey"; - final String value = "value123"; - String []args = {"-hiveconf", key + "=" + value}; - - Assert.assertEquals( - "checking system property before processing options", - null, - System.getProperty(key)); - - optProcessor.parse(args); - - Assert.assertEquals( - "checking system property after processing options", - value, - System.getProperty(key)); - } - -}