diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreServerHttp.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreServerHttp.java new file mode 100644 index 0000000..555c2eb --- /dev/null +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreServerHttp.java @@ -0,0 +1,123 @@ +/* * 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.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.metastore.conf.MetastoreConf; +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.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(HiveMetaStore.class); + + public static void main(String[] args) throws Exception { + Options options = new Options(); + Option input = new Option("p", "port", true, "Server port"); + input.setRequired(true); + options.addOption(input); + + CommandLine cmd = new GnuParser().parse(options, args); + int port = Integer.parseInt(cmd.getOptionValue("port", "8080")); + + Server server = new Server(port); + + LOG.info("Preparing thrift servlet"); + + ThriftHiveMetastore.Iface handler = getHandler(); + TProcessor processor = new ThriftHiveMetastore.Processor<>(handler); + TProtocolFactory protocol = getProtocol(); + HiveMetaStoreServlet thriftHttpServlet = new HiveMetaStoreServlet(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() throws MetaException { + LOG.debug("Preparing Thrift Handler"); + + LOG.debug("Reading config file"); + Configuration conf = getConf(); + + 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; + } +} + diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreServlet.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreServlet.java new file mode 100644 index 0000000..59f512d --- /dev/null +++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreServlet.java @@ -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. + */ + +package org.apache.hadoop.hive.metastore; + +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.apache.thrift.TProcessor; +import org.apache.thrift.protocol.TProtocolFactory; +import org.apache.thrift.server.TServlet; + +/** + * Servlet for handling Hive Metastore Thrift requests. + */ +public class HiveMetaStoreServlet extends TServlet { + /** + * Initializes a new instance of HiveMetaStoreServlet class. + * @param processor Thrift Processor + * @param protocol Thrift Protocol + * @throws MetaException + */ + public HiveMetaStoreServlet(TProcessor processor, TProtocolFactory protocol) throws MetaException { + super(processor, protocol); + } + + private static final long serialVersionUID = 1L; +} +