Return-Path: X-Original-To: apmail-hive-commits-archive@www.apache.org Delivered-To: apmail-hive-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E7FB7FA62 for ; Sat, 6 Apr 2013 03:05:41 +0000 (UTC) Received: (qmail 94672 invoked by uid 500); 6 Apr 2013 03:05:41 -0000 Delivered-To: apmail-hive-commits-archive@hive.apache.org Received: (qmail 94621 invoked by uid 500); 6 Apr 2013 03:05:41 -0000 Mailing-List: contact commits-help@hive.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hive-dev@hive.apache.org Delivered-To: mailing list commits@hive.apache.org Received: (qmail 94601 invoked by uid 99); 6 Apr 2013 03:05:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 06 Apr 2013 03:05:40 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 06 Apr 2013 03:05:39 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id DC82D23888E7; Sat, 6 Apr 2013 03:05:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1465169 - in /hive/trunk/service/src: java/org/apache/hive/service/server/HiveServer2.java java/org/apache/hive/service/server/ServerOptionsProcessor.java test/org/apache/hive/service/server/TestServerOptionsProcessor.java Date: Sat, 06 Apr 2013 03:05:18 -0000 To: commits@hive.apache.org From: hashutosh@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130406030518.DC82D23888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: hashutosh Date: Sat Apr 6 03:05:18 2013 New Revision: 1465169 URL: http://svn.apache.org/r1465169 Log: HIVE-4292 : hiveserver2 should support -hiveconf commandline parameter (Thejas Nair via Ashutosh Chauhan) Added: hive/trunk/service/src/java/org/apache/hive/service/server/ServerOptionsProcessor.java hive/trunk/service/src/test/org/apache/hive/service/server/TestServerOptionsProcessor.java Modified: hive/trunk/service/src/java/org/apache/hive/service/server/HiveServer2.java Modified: hive/trunk/service/src/java/org/apache/hive/service/server/HiveServer2.java URL: http://svn.apache.org/viewvc/hive/trunk/service/src/java/org/apache/hive/service/server/HiveServer2.java?rev=1465169&r1=1465168&r2=1465169&view=diff ============================================================================== --- hive/trunk/service/src/java/org/apache/hive/service/server/HiveServer2.java (original) +++ hive/trunk/service/src/java/org/apache/hive/service/server/HiveServer2.java Sat Apr 6 03:05:18 2013 @@ -81,6 +81,11 @@ public class HiveServer2 extends Composi HiveStringUtils.startupShutdownMessage(HiveServer2.class, args, LOG); try { + ServerOptionsProcessor oproc = new ServerOptionsProcessor("hiveserver2"); + if (!oproc.process(args)) { + LOG.fatal("Error starting HiveServer2 with given arguments"); + System.exit(-1); + } HiveConf hiveConf = new HiveConf(); HiveServer2 server = new HiveServer2(); server.init(hiveConf); Added: hive/trunk/service/src/java/org/apache/hive/service/server/ServerOptionsProcessor.java URL: http://svn.apache.org/viewvc/hive/trunk/service/src/java/org/apache/hive/service/server/ServerOptionsProcessor.java?rev=1465169&view=auto ============================================================================== --- hive/trunk/service/src/java/org/apache/hive/service/server/ServerOptionsProcessor.java (added) +++ hive/trunk/service/src/java/org/apache/hive/service/server/ServerOptionsProcessor.java Sat Apr 6 03:05:18 2013 @@ -0,0 +1,85 @@ +/** + * 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 java.util.Properties; + +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.OptionBuilder; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * ServerOptionsProcessor. + * Process arguments given to servers (-hiveconf property=value) + * Set properties in System properties + */ +public class ServerOptionsProcessor { + protected static final Log LOG = LogFactory.getLog(ServerOptionsProcessor.class.getName()); + private final Options options = new Options(); + private org.apache.commons.cli.CommandLine commandLine; + private final String serverName; + + + @SuppressWarnings("static-access") + public ServerOptionsProcessor(String serverName) { + this.serverName = serverName; + // -hiveconf x=y + options.addOption(OptionBuilder + .withValueSeparator() + .hasArgs(2) + .withArgName("property=value") + .withLongOpt("hiveconf") + .withDescription("Use value for given property") + .create()); + + options.addOption(new Option("H", "help", false, "Print help information")); + + } + + public boolean process(String[] argv) { + try { + commandLine = new GnuParser().parse(options, argv); + if (commandLine.hasOption('H')) { + printUsage(); + return false; + } + //get hiveconf param values and set the System property values + Properties confProps = commandLine.getOptionProperties("hiveconf"); + for (String propKey : confProps.stringPropertyNames()) { + LOG.debug("Setting " + propKey + "=" + confProps.getProperty(propKey) + ";"); + System.setProperty(propKey, confProps.getProperty(propKey)); + } + } catch (ParseException e) { + System.err.println(e.getMessage()); + printUsage(); + return false; + } + return true; + } + + private void printUsage() { + new HelpFormatter().printHelp(serverName, options); + } + +} Added: hive/trunk/service/src/test/org/apache/hive/service/server/TestServerOptionsProcessor.java URL: http://svn.apache.org/viewvc/hive/trunk/service/src/test/org/apache/hive/service/server/TestServerOptionsProcessor.java?rev=1465169&view=auto ============================================================================== --- hive/trunk/service/src/test/org/apache/hive/service/server/TestServerOptionsProcessor.java (added) +++ hive/trunk/service/src/test/org/apache/hive/service/server/TestServerOptionsProcessor.java Sat Apr 6 03:05:18 2013 @@ -0,0 +1,55 @@ +/** + * 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; + +/** + * 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)); + + + boolean isSuccess = optProcessor.process(args); + Assert.assertTrue("options processor result", isSuccess); + Assert.assertEquals( + "checking system property after processing options", + value, + System.getProperty(key)); + + + + + } + +}