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..455b178 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,7 @@ public String toString() { ConfVars.REPLDIR, ConfVars.THRIFT_URIS, ConfVars.SERVER_PORT, + ConfVars.SERVER_PORT_HTTP, ConfVars.THRIFT_BIND_HOST, ConfVars.THRIFT_ZOOKEEPER_CLIENT_PORT, ConfVars.THRIFT_ZOOKEEPER_NAMESPACE, @@ -843,6 +844,8 @@ 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_PORT_HTTP("metastore.thrift.http.port", "hive.metastore.http.port", 9084, + "Hive metastore http listener port"), 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/HiveMetaStoreServerHttp.java standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreServerHttp.java new file mode 100644 index 0000000..444dc14 --- /dev/null +++ standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreServerHttp.java @@ -0,0 +1,104 @@ +/* * 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.HiveMetaStore; +import org.apache.hadoop.hive.metastore.IHMSHandler; +import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler; +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.TJSONProtocol.Factory; +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 class HiveMetaStoreServerHttp { + private static final Logger LOG = LoggerFactory.getLogger(HiveMetaStoreServerHttp.class); + + public static void main(String[] args) throws Exception { + Configuration configuration = getConf(); + int port = MetastoreConf.getIntVar(configuration, ConfVars.SERVER_PORT_HTTP); + + Server server = new Server(port); + + LOG.info("Preparing thrift servlet"); + + ThriftHiveMetastore.Iface handler = getHandler(configuration); + TProcessor processor = new ThriftHiveMetastore.Processor<>(handler); + TProtocolFactory protocol = getProtocol(); + TServlet thriftHttpServlet = new TServlet(processor, protocol); + + LOG.info("Preparing servlet context"); + final ServletContextHandler context = new ServletContextHandler(); + context.setContextPath("/"); + context.addServlet(new ServletHolder(thriftHttpServlet), "/api/hms"); + + LOG.info("Registering handler"); + server.setHandler(context); + + 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 static Factory getProtocol() { + LOG.debug("Creating protocol object"); + return new TJSONProtocol.Factory(); + } + + private static ThriftHiveMetastore.Iface getHandler(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; + } + + private static Configuration getConf() { + LOG.debug("Reading config file"); + Configuration conf = MetastoreConf.newMetastoreConf(); + + LOG.info("Config file read successfuly" + conf); + return conf; + } +}