diff --git bin/ext/metastorehttp.sh bin/ext/metastorehttp.sh new file mode 100644 index 0000000..478278f --- /dev/null +++ bin/ext/metastorehttp.sh @@ -0,0 +1,41 @@ +# 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. + +THISSERVICE=metastorehttp +export SERVICE_LIST="${SERVICE_LIST}${THISSERVICE} " + +metastorehttp() { + echo "$(timestamp): Starting Hive Metastore Server on HTTP" + CLASS=org.apache.hadoop.hive.metastore.HiveMetaStoreHttpServer + if $cygwin; then + HIVE_LIB=`cygpath -w "$HIVE_LIB"` + fi + JAR=${HIVE_LIB}/hive-metastore-*.jar + + # hadoop 20 or newer - skip the aux_jars option and hiveconf + + export HADOOP_CLIENT_OPTS=" -Dproc_metastore $HADOOP_CLIENT_OPTS " + export HADOOP_OPTS="$HIVE_METASTORE_HADOOP_OPTS $HADOOP_OPTS" + exec $HADOOP jar $JAR $CLASS "$@" +} + +metastorehttp_help() { + metastorehttp -h +} + +timestamp() +{ + date +"%Y-%m-%d %T" +} diff --git bin/hive bin/hive index ef9ef95..18797b5 100755 --- bin/hive +++ bin/hive @@ -90,7 +90,7 @@ if [[ "$SERVICE" == "cli" && "$USE_BEELINE_FOR_HIVE_CLI" == "true" ]] ; then SERVICE="beeline" fi -if [[ "$SERVICE" =~ ^(help|version|orcfiledump|rcfilecat|schemaTool|cleardanglingscratchdir|metastore|beeline|llapstatus|llap)$ ]] ; then +if [[ "$SERVICE" =~ ^(help|version|orcfiledump|rcfilecat|schemaTool|cleardanglingscratchdir|metastore|metastorehttp|beeline|llapstatus|llap)$ ]] ; then SKIP_HBASECP=true fi diff --git standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java index c918e2b..5cdb456 100644 --- standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java +++ standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java @@ -148,6 +148,8 @@ public String toString() { ConfVars.REPLDIR, ConfVars.THRIFT_URIS, ConfVars.SERVER_PORT, + ConfVars.SERVER_HTTP_PORT, + ConfVars.SERVER_HTTP_CONTEXT_PATH, ConfVars.THRIFT_BIND_HOST, ConfVars.THRIFT_ZOOKEEPER_CLIENT_PORT, ConfVars.THRIFT_ZOOKEEPER_NAMESPACE, @@ -843,6 +845,10 @@ public static ConfVars getMetaConf(String name) { "Minimum number of worker threads in the Thrift server's pool."), SERVER_PORT("metastore.thrift.port", "hive.metastore.port", 9083, "Hive metastore listener port"), + SERVER_HTTP_PORT("metastore.thrift.http.port", "hive.metastore.http.port", 9084, + "Hive metastore http listener port"), + SERVER_HTTP_CONTEXT_PATH("metastore.thrift.http.contextpath", "hive.metastore.http.contextpath", "/api/hms", + "Context path of servlet that handles HTTP Thrift requests"), SSL_KEYSTORE_PASSWORD("metastore.keystore.password", "hive.metastore.keystore.password", "", "Metastore SSL certificate keystore password."), SSL_KEYSTORE_PATH("metastore.keystore.path", "hive.metastore.keystore.path", "", diff --git standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreHttpServer.java standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreHttpServer.java new file mode 100644 index 0000000..69fac81 --- /dev/null +++ standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreHttpServer.java @@ -0,0 +1,96 @@ +/* + * 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.metastore; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.metastore.conf.MetastoreConf; +import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars; +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore; +import org.slf4j.LoggerFactory; +import org.apache.thrift.TProcessor; +import org.apache.thrift.protocol.TJSONProtocol; +import org.apache.thrift.protocol.TProtocolFactory; +import org.apache.thrift.server.TServlet; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.slf4j.Logger; + +/** + * Hive metastore hosted on Jetty Server. + */ +public final class HiveMetaStoreHttpServer { + private static final Logger LOG = LoggerFactory.getLogger(HiveMetaStoreHttpServer.class); + private Server server; + + public static void main(String[] args) throws Exception { + HiveMetaStoreHttpServer httpServer = new HiveMetaStoreHttpServer(); + Configuration configuration = MetastoreConf.newMetastoreConf(); + httpServer.init(configuration); + httpServer.start(); + } + + public void init(Configuration configuration) throws MetaException{ + LOG.info("Preparing thrift servlet"); + ThriftHiveMetastore.Iface handler = this.createRequestHandler(configuration); + TProcessor processor = new ThriftHiveMetastore.Processor<>(handler); + TProtocolFactory protocol = new TJSONProtocol.Factory(); + TServlet thriftHttpServlet = new TServlet(processor, protocol); + + LOG.info("Preparing servlet context"); + String contextPath = MetastoreConf.getVar(configuration, ConfVars.SERVER_HTTP_CONTEXT_PATH); + final ServletContextHandler context = new ServletContextHandler(); + context.addServlet(new ServletHolder(thriftHttpServlet), contextPath); + + int port = MetastoreConf.getIntVar(configuration, ConfVars.SERVER_HTTP_PORT); + + this.server = new Server(port); + + LOG.info("Registering handler"); + this.server.setHandler(context); + } + + public void start() throws Exception { + LOG.info("Starting server"); + server.start(); + + LOG.info("Server Started"); + try { + server.join(); + } catch (InterruptedException ex) { + LOG.error("Server interrupted " + ex); + } finally { + LOG.info("Starting shutting down"); + } + } + + private ThriftHiveMetastore.Iface createRequestHandler(Configuration conf) throws MetaException { + LOG.debug("Preparing Thrift Handler"); + + LOG.debug("Creating base handler"); + IHMSHandler baseHandler = new HiveMetaStore.HMSHandler("new db based metaserver", conf, false); + + LOG.debug("Creating retrying handler"); + IHMSHandler handler = RetryingHMSHandler.getProxy(conf, baseHandler, false); + + LOG.debug("Handler created successfully"); + return handler; + } +}