Skip to content

Commit

Permalink
HIVE-2139. Enable HiveServer to accept -hiveconf option (Patrick Hunt…
Browse files Browse the repository at this point in the history
… via cws)

git-svn-id: https://svn.apache.org/repos/asf/hive/trunk@1149311 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
cwsteinbach committed Jul 21, 2011
1 parent 111df79 commit 51c1a12
Show file tree
Hide file tree
Showing 14 changed files with 516 additions and 64 deletions.
6 changes: 3 additions & 3 deletions bin/ext/hiveserver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ hiveserver() {
JAR=${HIVE_LIB}/hive-service-*.jar

# hadoop 20 or newer - skip the aux_jars option and hiveconf
exec $HADOOP jar $JAR $CLASS $HIVE_PORT "$@"

exec $HADOOP jar $JAR $CLASS "$@"
}

hiveserver_help() {
echo "usage HIVE_PORT=xxxx ./hive --service hiveserver"
echo " HIVE_PORT : Specify the server port"
hiveserver -h
}

6 changes: 3 additions & 3 deletions bin/ext/metastore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ metastore() {
JAR=${HIVE_LIB}/hive-service-*.jar

# hadoop 20 or newer - skip the aux_jars option and hiveconf
exec $HADOOP jar $JAR $CLASS $METASTORE_PORT "$@"

exec $HADOOP jar $JAR $CLASS "$@"
}

metastore_help() {
echo "usage METASTORE_PORT=xxxx ./hive --service metastore"
echo " METASTORE_PORT : Specify the metastore server port"
metastore -h
}

24 changes: 20 additions & 4 deletions cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@
import java.util.Set;

import jline.ArgumentCompletor;
import jline.ArgumentCompletor.AbstractArgumentDelimiter;
import jline.ArgumentCompletor.ArgumentDelimiter;
import jline.Completor;
import jline.ConsoleReader;
import jline.History;
import jline.SimpleCompletor;
import jline.ArgumentCompletor.AbstractArgumentDelimiter;
import jline.ArgumentCompletor.ArgumentDelimiter;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hive.common.HiveInterruptUtils;
import org.apache.hadoop.hive.common.LogUtils;
import org.apache.hadoop.hive.common.LogUtils.LogInitializationException;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
import org.apache.hadoop.hive.metastore.api.Schema;
Expand Down Expand Up @@ -512,7 +514,14 @@ public static void main(String[] args) throws Exception {

// NOTE: It is critical to do this here so that log4j is reinitialized
// before any of the other core hive classes are loaded
SessionState.initHiveLog4j();
boolean logInitFailed = false;
String logInitDetailMessage;
try {
logInitDetailMessage = LogUtils.initHiveLog4j();
} catch (LogInitializationException e) {
logInitFailed = true;
logInitDetailMessage = e.getMessage();
}

CliSessionState ss = new CliSessionState(new HiveConf(SessionState.class));
ss.in = System.in;
Expand All @@ -526,7 +535,14 @@ public static void main(String[] args) throws Exception {
if (!oproc.process_stage2(ss)) {
System.exit(2);
}
ss.printInitInfo();

if (!ss.getIsSilent()) {
if (logInitFailed) {
System.err.println(logInitDetailMessage);
} else {
SessionState.getConsole().printInfo(logInitDetailMessage);
}
}

// set all properties specified via command line
HiveConf conf = ss.getConf();
Expand Down
18 changes: 17 additions & 1 deletion common/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,25 @@ to call at top-level: ant deploy-contrib compile-core-test
<property name="src.dir" location="${basedir}/src/java"/>
<import file="../build-common.xml"/>

<target name="compile" depends="init, setup, ivy-retrieve">
<echo message="Compiling: ${ant.project.name}"/>
<javac
encoding="${build.encoding}"
srcdir="${src.dir}"
includes="**/*.java"
destdir="${build.classes}"
debug="${javac.debug}"
deprecation="${javac.deprecation}">
<compilerarg line="${javac.args} ${javac.args.warnings}" />
<classpath refid="classpath"/>
</javac>
<copy todir="${build.classes}" failonerror="false">
<fileset dir="${src.dir}/conf"/>
</copy>
</target>

<target name="test">
<echo message="Nothing to do!"/>
</target>


</project>
2 changes: 2 additions & 0 deletions common/ivy.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
Expand Down Expand Up @@ -26,5 +27,6 @@
<dependency org="hadoop" name="core" rev="${hadoop.version.ant-internal}">
<artifact name="hadoop" type="source" ext="tar.gz"/>
</dependency>
<dependency org="commons-cli" name="commons-cli" rev="${commons-cli.version}"/>
</dependencies>
</ivy-module>
59 changes: 59 additions & 0 deletions common/src/java/org/apache/hadoop/hive/common/LogUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* 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.hive.common;

import java.net.URL;

import org.apache.log4j.LogManager;
import org.apache.log4j.PropertyConfigurator;

/**
* Utilities common to logging operations.
*/
public class LogUtils {

public static final String HIVE_L4J = "hive-log4j.properties";
public static final String HIVE_EXEC_L4J = "hive-exec-log4j.properties";

@SuppressWarnings("serial")
public static class LogInitializationException extends Exception {
public LogInitializationException(String msg) {
super(msg);
}
}

/**
* Initialize log4j based on hive-log4j.properties.
*
* @return an message suitable for display to the user
* @throws LogInitializationException if log4j fails to initialize correctly
*/
public static String initHiveLog4j() throws LogInitializationException {
// allow hive log4j to override any normal initialized one
URL hive_l4j = LogUtils.class.getClassLoader().getResource(HIVE_L4J);
if (hive_l4j != null) {
LogManager.resetConfiguration();
PropertyConfigurator.configure(hive_l4j);
return "Logging initialized using configuration in " + hive_l4j;
} else {
throw new LogInitializationException("Unable to initialize logging using "
+ LogUtils.HIVE_L4J + ", not found on CLASSPATH!");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* 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.hive.common.cli;

import java.util.Properties;

import org.apache.commons.cli.CommandLine;
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;

/**
* Reusable code for Hive Cli's.
* <p>
* Basic usage is: create an instance (usually a subclass if you want to
* all your own options or processing instructions), parse, and then use
* the resulting information.
* <p>
* See {@link HiveServer} or {@link HiveMetaStore} for examples of use.
*
*/
public class CommonCliOptions {
/**
* Options for parsing the command line.
*/
protected final Options OPTIONS = new Options();

protected CommandLine commandLine;

/**
* The name of this cli.
*/
protected final String cliname;

private boolean verbose = false;

/**
* Create an instance with common options (help, verbose, etc...).
*
* @param includeHiveConf include "hiveconf" as an option if true
*/
@SuppressWarnings("static-access")
public CommonCliOptions(String cliname, boolean includeHiveconf) {
this.cliname = cliname;

// [-v|--verbose]
OPTIONS.addOption(new Option("v", "verbose", false, "Verbose mode"));

// [-h|--help]
OPTIONS.addOption(new Option("h", "help", false, "Print help information"));

if (includeHiveconf) {
OPTIONS.addOption(OptionBuilder
.withValueSeparator()
.hasArgs(2)
.withArgName("property=value")
.withLongOpt("hiveconf")
.withDescription("Use value for given property")
.create());
}
}

/**
* Add the hiveconf properties to the Java system properties, override
* anything therein.
*
* @return a copy of the properties specified in hiveconf
*/
public Properties addHiveconfToSystemProperties() {
Properties confProps = commandLine.getOptionProperties("hiveconf");
for (String propKey : confProps.stringPropertyNames()) {
if (verbose) {
System.err.println(
"hiveconf: " + propKey + "=" + confProps.getProperty(propKey));
}
System.setProperty(propKey, confProps.getProperty(propKey));
}
return confProps;
}

/**
* Print usage information for the CLI.
*/
public void printUsage() {
new HelpFormatter().printHelp(cliname, OPTIONS);
}

/**
* Parse the arguments.
* @param args
*/
public void parse(String[] args) {
try {
commandLine = new GnuParser().parse(OPTIONS, args);

if (commandLine.hasOption('h')) {
printUsage();
System.exit(1);
}
if (commandLine.hasOption('v')) {
verbose = true;
}
} catch (ParseException e) {
System.err.println(e.getMessage());
printUsage();
System.exit(1);
}

}

/**
* Should the client be verbose.
*/
public boolean isVerbose() {
return verbose;
}

}
8 changes: 7 additions & 1 deletion hwi/src/java/org/apache/hadoop/hive/hwi/HWISessionItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.cli.CliSessionState;
import org.apache.hadoop.hive.cli.OptionsProcessor;
import org.apache.hadoop.hive.common.LogUtils;
import org.apache.hadoop.hive.common.LogUtils.LogInitializationException;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.CommandNeedRetryException;
import org.apache.hadoop.hive.ql.Driver;
Expand Down Expand Up @@ -140,7 +142,11 @@ private void itemInit() {
}
}

SessionState.initHiveLog4j();
try {
LogUtils.initHiveLog4j();
} catch (LogInitializationException e) {
l4j.warn(e);
}
conf = new HiveConf(SessionState.class);
ss = new CliSessionState(conf);
SessionState.start(ss);
Expand Down
1 change: 1 addition & 0 deletions metastore/ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<dependency org="hadoop" name="core" rev="${hadoop.version.ant-internal}">
<artifact name="hadoop" type="source" ext="tar.gz"/>
</dependency>
<dependency org="commons-cli" name="commons-cli" rev="${commons-cli.version}"/>
<dependency org="commons-dbcp" name="commons-dbcp" rev="${commons-dbcp.version}">
<exclude module="commons-pool" />
<exclude org="org.apache.geronimo.specs" module="geronimo-jta_1.1_spec"/>
Expand Down
Loading

0 comments on commit 51c1a12

Please sign in to comment.