diff --git common/src/java/org/apache/hadoop/hive/conf/HiveConf.java common/src/java/org/apache/hadoop/hive/conf/HiveConf.java index b0cb98b..667a38d 100644 --- common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -1489,6 +1489,10 @@ "get old behavior, if desired. See, test-case in patch for HIVE-6689."), // HiveServer2 specific configs + HIVE_SERVER2_SERVICE_CLASSES("hive.server2.service.classes", "", + "Comma separated class names implementing org.apache.hive.service.Service. " + + "Managed in HiveServer2 with same lifecycle."), + HIVE_SERVER2_MAX_START_ATTEMPTS("hive.server2.max.start.attempts", 30L, new RangeValidator(0L, null), "Number of times HiveServer2 will attempt to start before exiting, sleeping 60 seconds " + "between retries. \n The default of 30 will keep trying for 30 minutes."), diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java index 155002a..7020781 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java @@ -30,6 +30,7 @@ import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.conf.Configurable; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.filecache.DistributedCache; import org.apache.hadoop.fs.ContentSummary; @@ -2035,6 +2036,43 @@ public static String getResourceFiles(Configuration conf, SessionState.ResourceT } /** + * Returns the instances specified in a configuration variable as a list + * in the order they were specified in the configuration variable. + * + * @param conf Configuration object + * @param confVar The configuration variable specifying a comma separated list + * of the class names + * @param clazz The super type of the instances + * @return A list of the instances cast as the type specified in clazz, + * in the order they are listed in the value of hookConfVar + * @throws ClassNotFoundException + * @throws IllegalAccessException + * @throws InstantiationException + */ + public static List getInstances(HiveConf conf, ConfVars confVar, Class clazz) + throws InstantiationException, IllegalAccessException, ClassNotFoundException { + String var = conf.getVar(confVar); + if (var == null) { + return Collections.emptyList(); + } + var = var.trim(); + if (var.isEmpty()) { + return Collections.emptyList(); + } + ClassLoader loader = getSessionSpecifiedClassLoader(); + List instances = new ArrayList(); + for (String className : var.split(",")) { + T instance = Class.forName(className.trim(), true, loader).asSubclass(clazz).newInstance(); + if (instance instanceof Configurable) { + ((Configurable) instance).setConf(conf); + } + instances.add(instance); + } + + return instances; + } + + /** * get session specified class loader and get current class loader if fall * * @return diff --git ql/src/java/org/apache/hadoop/hive/ql/hooks/HookUtils.java ql/src/java/org/apache/hadoop/hive/ql/hooks/HookUtils.java index 390ffd9..2a77ba9 100644 --- ql/src/java/org/apache/hadoop/hive/ql/hooks/HookUtils.java +++ ql/src/java/org/apache/hadoop/hive/ql/hooks/HookUtils.java @@ -18,15 +18,14 @@ package org.apache.hadoop.hive.ql.hooks; -import java.util.ArrayList; import java.util.List; -import org.apache.hadoop.hive.common.JavaUtils; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.conf.HiveConf.ConfVars; import org.apache.hadoop.hive.ql.exec.Utilities; public class HookUtils { + /** * Returns the hooks specified in a configuration variable. The hooks are returned * in a list in the order they were specified in the configuration variable. @@ -44,25 +43,7 @@ public static List getHooks(HiveConf conf, ConfVars hookConfVar, Class clazz) throws InstantiationException, IllegalAccessException, ClassNotFoundException { - String csHooks = conf.getVar(hookConfVar); - List hooks = new ArrayList(); - if (csHooks == null) { - return hooks; - } - - csHooks = csHooks.trim(); - if (csHooks.equals("")) { - return hooks; - } - - String[] hookClasses = csHooks.split(","); - for (String hookClass : hookClasses) { - T hook = (T) Class.forName(hookClass.trim(), true, - Utilities.getSessionSpecifiedClassLoader()).newInstance(); - hooks.add(hook); - } - - return hooks; + return Utilities.getInstances(conf, hookConfVar, clazz); } } diff --git service/src/java/org/apache/hive/service/server/HiveServer2.java service/src/java/org/apache/hive/service/server/HiveServer2.java index c667533..0781b39 100644 --- service/src/java/org/apache/hive/service/server/HiveServer2.java +++ service/src/java/org/apache/hive/service/server/HiveServer2.java @@ -19,6 +19,7 @@ package org.apache.hive.service.server; import java.nio.charset.Charset; +import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -26,12 +27,13 @@ import org.apache.hadoop.hive.common.LogUtils.LogInitializationException; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.conf.HiveConf.ConfVars; +import org.apache.hadoop.hive.ql.exec.Utilities; import org.apache.hadoop.hive.ql.exec.tez.TezSessionPoolManager; import org.apache.hadoop.hive.ql.util.ZooKeeperHiveHelper; import org.apache.hive.common.util.HiveStringUtils; import org.apache.hive.common.util.HiveVersionInfo; import org.apache.hive.service.CompositeService; -import org.apache.hive.service.ServiceException; +import org.apache.hive.service.Service; import org.apache.hive.service.cli.CLIService; import org.apache.hive.service.cli.thrift.ThriftBinaryCLIService; import org.apache.hive.service.cli.thrift.ThriftCLIService; @@ -72,6 +74,11 @@ public synchronized void init(HiveConf hiveConf) { thriftCLIService = new ThriftBinaryCLIService(cliService); } addService(thriftCLIService); + + for (Service service : getServices(hiveConf)) { + addService(service); + } + thriftCLIService.setHiveServer2(this); super.init(hiveConf); @@ -85,6 +92,14 @@ public void run() { }); } + private List getServices(HiveConf hiveConf) { + try { + return Utilities.getInstances(hiveConf, ConfVars.HIVE_SERVER2_SERVICE_CLASSES, Service.class); + } catch (Exception e) { + throw new RuntimeException("Failed to instanciate services for hiveserver2", e); + } + } + public static boolean isHTTPTransportMode(HiveConf hiveConf) { String transportMode = System.getenv("HIVE_SERVER2_TRANSPORT_MODE"); if (transportMode == null) {