-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HIVE-2139. Enable HiveServer to accept -hiveconf option (Patrick Hunt…
… via cws) git-svn-id: https://svn.apache.org/repos/asf/hive/trunk@1149311 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
1 parent
111df79
commit 51c1a12
Showing
14 changed files
with
516 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
common/src/java/org/apache/hadoop/hive/common/LogUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} | ||
} | ||
} |
136 changes: 136 additions & 0 deletions
136
common/src/java/org/apache/hadoop/hive/common/cli/CommonCliOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.