http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-queryserver/src/it/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/phoenix-queryserver/src/it/resources/log4j.properties b/phoenix-queryserver/src/it/resources/log4j.properties new file mode 100644 index 0000000..6b1ce50 --- /dev/null +++ b/phoenix-queryserver/src/it/resources/log4j.properties @@ -0,0 +1,63 @@ +# 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. + +# Define some default values that can be overridden by system properties +hbase.root.logger=DEBUG,console +hbase.log.dir=. +hbase.log.file=hbase.log + +# Define the root logger to the system property "hbase.root.logger". +log4j.rootLogger=${hbase.root.logger} + +# Logging Threshold +log4j.threshhold=ALL + +# +# Daily Rolling File Appender +# +log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender +log4j.appender.DRFA.File=${hbase.log.dir}/${hbase.log.file} + +# Rollver at midnight +log4j.appender.DRFA.DatePattern=.yyyy-MM-dd + +# 30-day backup +#log4j.appender.DRFA.MaxBackupIndex=30 +log4j.appender.DRFA.layout=org.apache.log4j.PatternLayout + +# Pattern format: Date LogLevel LoggerName LogMessage +#log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %p %c: %m%n + +# Debugging Pattern format +log4j.appender.DRFA.layout.ConversionPattern=%d %-5p [%t] %C{2}(%L): %m%n + + +# +# console +# Add "console" to rootlogger above if you want to use this +# +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.target=System.err +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d %-5p [%t] %C{2}(%L): %m%n + +# Custom Logging levels + +#log4j.logger.org.apache.hadoop.fs.FSNamesystem=DEBUG + +log4j.logger.org.apache.hadoop=WARN +log4j.logger.org.apache.zookeeper=ERROR +log4j.logger.org.apache.hadoop.hbase=DEBUG
http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/Main.java ---------------------------------------------------------------------- diff --git a/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/Main.java b/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/Main.java new file mode 100644 index 0000000..106d422 --- /dev/null +++ b/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/Main.java @@ -0,0 +1,236 @@ +/* + * 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.phoenix.queryserver.server; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.calcite.avatica.Meta; +import org.apache.calcite.avatica.remote.Driver; +import org.apache.calcite.avatica.remote.LocalService; +import org.apache.calcite.avatica.remote.Service; +import org.apache.calcite.avatica.server.HandlerFactory; +import org.apache.calcite.avatica.server.HttpServer; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.conf.Configured; +import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.util.Strings; +import org.apache.hadoop.net.DNS; +import org.apache.hadoop.security.SecurityUtil; +import org.apache.hadoop.util.Tool; +import org.apache.hadoop.util.ToolRunner; +import org.apache.phoenix.query.QueryServices; +import org.apache.phoenix.query.QueryServicesOptions; +import org.eclipse.jetty.server.Handler; + +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** + * A query server for Phoenix over Calcite's Avatica. + */ +public final class Main extends Configured implements Tool, Runnable { + + protected static final Log LOG = LogFactory.getLog(Main.class); + + private final String[] argv; + private final CountDownLatch runningLatch = new CountDownLatch(1); + private HttpServer server = null; + private int retCode = 0; + private Throwable t = null; + + /** + * Log information about the currently running JVM. + */ + public static void logJVMInfo() { + // Print out vm stats before starting up. + RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); + if (runtime != null) { + LOG.info("vmName=" + runtime.getVmName() + ", vmVendor=" + + runtime.getVmVendor() + ", vmVersion=" + runtime.getVmVersion()); + LOG.info("vmInputArguments=" + runtime.getInputArguments()); + } + } + + /** + * Logs information about the currently running JVM process including + * the environment variables. Logging of env vars can be disabled by + * setting {@code "phoenix.envvars.logging.disabled"} to {@code "true"}. + * <p>If enabled, you can also exclude environment variables containing + * certain substrings by setting {@code "phoenix.envvars.logging.skipwords"} + * to comma separated list of such substrings. + */ + public static void logProcessInfo(Configuration conf) { + // log environment variables unless asked not to + if (conf == null || !conf.getBoolean(QueryServices.QUERY_SERVER_ENV_LOGGING_ATTRIB, false)) { + Set<String> skipWords = new HashSet<String>(QueryServicesOptions.DEFAULT_QUERY_SERVER_SKIP_WORDS); + if (conf != null) { + String[] confSkipWords = conf.getStrings(QueryServices.QUERY_SERVER_ENV_LOGGING_SKIPWORDS_ATTRIB); + if (confSkipWords != null) { + skipWords.addAll(Arrays.asList(confSkipWords)); + } + } + + nextEnv: + for (Map.Entry<String, String> entry : System.getenv().entrySet()) { + String key = entry.getKey().toLowerCase(); + String value = entry.getValue().toLowerCase(); + // exclude variables which may contain skip words + for(String skipWord : skipWords) { + if (key.contains(skipWord) || value.contains(skipWord)) + continue nextEnv; + } + LOG.info("env:"+entry); + } + } + // and JVM info + logJVMInfo(); + } + + /** Constructor for use from {@link org.apache.hadoop.util.ToolRunner}. */ + public Main() { + this(null, null); + } + + /** Constructor for use as {@link java.lang.Runnable}. */ + public Main(String[] argv, Configuration conf) { + this.argv = argv; + setConf(conf); + } + + /** + * @return the port number this instance is bound to, or {@code -1} if the server is not running. + */ + @VisibleForTesting + public int getPort() { + if (server == null) return -1; + return server.getPort(); + } + + /** + * @return the return code from running as a {@link Tool}. + */ + @VisibleForTesting + public int getRetCode() { + return retCode; + } + + /** + * @return the throwable from an unsuccessful run, or null otherwise. + */ + @VisibleForTesting + public Throwable getThrowable() { + return t; + } + + /** Calling thread waits until the server is running. */ + public void awaitRunning() throws InterruptedException { + runningLatch.await(); + } + + /** Calling thread waits until the server is running. */ + public void awaitRunning(long timeout, TimeUnit unit) throws InterruptedException { + runningLatch.await(timeout, unit); + } + + @Override + public int run(String[] args) throws Exception { + logProcessInfo(getConf()); + try { + // handle secure cluster credentials + if ("kerberos".equalsIgnoreCase(getConf().get(QueryServices.QUERY_SERVER_HBASE_SECURITY_CONF_ATTRIB))) { + String hostname = Strings.domainNamePointerToHostName(DNS.getDefaultHost( + getConf().get(QueryServices.QUERY_SERVER_DNS_INTERFACE_ATTRIB, "default"), + getConf().get(QueryServices.QUERY_SERVER_DNS_NAMESERVER_ATTRIB, "default"))); + if (LOG.isDebugEnabled()) { + LOG.debug("Login to " + hostname + " using " + getConf().get(QueryServices.QUERY_SERVER_KEYTAB_FILENAME_ATTRIB) + + " and principal " + getConf().get(QueryServices.QUERY_SERVER_KERBEROS_PRINCIPAL_ATTRIB) + "."); + } + SecurityUtil.login(getConf(), QueryServices.QUERY_SERVER_KEYTAB_FILENAME_ATTRIB, + QueryServices.QUERY_SERVER_KERBEROS_PRINCIPAL_ATTRIB, hostname); + LOG.info("Login successful."); + } + Class<? extends PhoenixMetaFactory> factoryClass = getConf().getClass( + QueryServices.QUERY_SERVER_META_FACTORY_ATTRIB, PhoenixMetaFactoryImpl.class, PhoenixMetaFactory.class); + int port = getConf().getInt(QueryServices.QUERY_SERVER_HTTP_PORT_ATTRIB, + QueryServicesOptions.DEFAULT_QUERY_SERVER_HTTP_PORT); + LOG.debug("Listening on port " + port); + PhoenixMetaFactory factory = + factoryClass.getDeclaredConstructor(Configuration.class).newInstance(getConf()); + Meta meta = factory.create(Arrays.asList(args)); + final HandlerFactory handlerFactory = new HandlerFactory(); + Service service = new LocalService(meta); + server = new HttpServer(port, getHandler(getConf(), service, handlerFactory)); + server.start(); + runningLatch.countDown(); + server.join(); + return 0; + } catch (Throwable t) { + LOG.fatal("Unrecoverable service error. Shutting down.", t); + this.t = t; + return -1; + } + } + + /** + * Instantiates the Handler for use by the Avatica (Jetty) server. + * + * @param conf The configuration + * @param service The Avatica Service implementation + * @param handlerFactory Factory used for creating a Handler + * @return The Handler to use based on the configuration. + */ + Handler getHandler(Configuration conf, Service service, HandlerFactory handlerFactory) { + String serializationName = conf.get(QueryServices.QUERY_SERVER_SERIALIZATION_ATTRIB, + QueryServicesOptions.DEFAULT_QUERY_SERVER_SERIALIZATION); + + Driver.Serialization serialization; + // Otherwise, use what was provided in the configuration + try { + serialization = Driver.Serialization.valueOf(serializationName); + } catch (Exception e) { + LOG.error("Unknown message serialization type for " + serializationName); + throw e; + } + + Handler handler = handlerFactory.getHandler(service, serialization); + + LOG.info("Instantiated " + handler.getClass() + " for QueryServer"); + + return handler; + } + + @Override public void run() { + try { + retCode = run(argv); + } catch (Exception e) { + // already logged + } + } + + public static void main(String[] argv) throws Exception { + int ret = ToolRunner.run(HBaseConfiguration.create(), new Main(), argv); + System.exit(ret); + } +} http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/PhoenixMetaFactory.java ---------------------------------------------------------------------- diff --git a/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/PhoenixMetaFactory.java b/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/PhoenixMetaFactory.java new file mode 100644 index 0000000..02344a3 --- /dev/null +++ b/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/PhoenixMetaFactory.java @@ -0,0 +1,28 @@ +/* + * 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.phoenix.queryserver.server; + +import org.apache.calcite.avatica.Meta; +import org.apache.hadoop.conf.Configurable; + +/** + * A @{link Meta.Factory} that can also respect Hadoop + * {@link org.apache.hadoop.conf.Configuration} objects. + */ +public interface PhoenixMetaFactory extends Meta.Factory, Configurable { +} http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/PhoenixMetaFactoryImpl.java ---------------------------------------------------------------------- diff --git a/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/PhoenixMetaFactoryImpl.java b/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/PhoenixMetaFactoryImpl.java new file mode 100644 index 0000000..c74d2c9 --- /dev/null +++ b/phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/PhoenixMetaFactoryImpl.java @@ -0,0 +1,76 @@ +/* + * 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.phoenix.queryserver.server; + +import com.google.common.base.Preconditions; +import org.apache.calcite.avatica.Meta; +import org.apache.calcite.avatica.jdbc.JdbcMeta; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.conf.Configured; +import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HConstants; +import org.apache.phoenix.jdbc.PhoenixConnection; +import org.apache.phoenix.mapreduce.util.PhoenixConfigurationUtil; +import org.apache.phoenix.util.QueryUtil; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +/** + * Bridge between Phoenix and Avatica. + */ +public class PhoenixMetaFactoryImpl extends Configured implements PhoenixMetaFactory { + + // invoked via reflection + public PhoenixMetaFactoryImpl() { + super(HBaseConfiguration.create()); + } + + // invoked via reflection + public PhoenixMetaFactoryImpl(Configuration conf) { + super(conf); + } + + @Override + public Meta create(List<String> args) { + Configuration conf = Preconditions.checkNotNull(getConf(), "Configuration must not be null."); + Properties info = new Properties(); + info.putAll(conf.getValByRegex("avatica.*")); + try { + final String url; + if (args.size() == 0) { + url = QueryUtil.getConnectionUrl(info, conf); + } else if (args.size() == 1) { + url = args.get(0); + } else { + throw new RuntimeException( + "0 or 1 argument expected. Received " + Arrays.toString(args.toArray())); + } + // TODO: what about -D configs passed in from cli? How do they get pushed down? + return new JdbcMeta(url, info); + } catch (SQLException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + } +} http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-queryserver/src/test/java/org/apache/phoenix/DriverCohabitationTest.java ---------------------------------------------------------------------- diff --git a/phoenix-queryserver/src/test/java/org/apache/phoenix/DriverCohabitationTest.java b/phoenix-queryserver/src/test/java/org/apache/phoenix/DriverCohabitationTest.java new file mode 100644 index 0000000..1df6d2c --- /dev/null +++ b/phoenix-queryserver/src/test/java/org/apache/phoenix/DriverCohabitationTest.java @@ -0,0 +1,65 @@ +/* + * 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.phoenix; + +import org.apache.phoenix.queryserver.client.ThinClientUtil; +import org.apache.phoenix.util.QueryUtil; +import org.junit.Test; + +import java.sql.Driver; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Collections; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +/** + * Ensure the "thick" Phoenix driver and it's "thin" counterpart can coexist on + * the same classpath. + */ +public class DriverCohabitationTest { + + @Test + public void testDriverCohabitation() throws SQLException { + Driver thickDriver = null; + Driver thinDriver = null; + + for (Driver d : Collections.list(DriverManager.getDrivers())) { + if (d instanceof org.apache.phoenix.jdbc.PhoenixDriver) { + thickDriver = d; + } else if (d instanceof org.apache.phoenix.queryserver.client.Driver) { + thinDriver = d; + } + } + assertNotNull("Thick driver not registered with DriverManager.", thickDriver); + assertNotNull("Thin driver not registered with DriverManager.", thinDriver); + + final String thickUrl = QueryUtil.getUrl("localhost"); + final String thinUrl = ThinClientUtil.getConnectionUrl("localhost", 1234); + assertTrue("Thick driver should accept connections like " + thickUrl, + thickDriver.acceptsURL(thickUrl)); + assertFalse("Thick driver should reject connections like " + thinUrl, + thickDriver.acceptsURL(thinUrl)); + assertTrue("Thin driver should accept connections like " + thinUrl, + thinDriver.acceptsURL(thinUrl)); + assertFalse("Thin driver should reject connections like " + thickUrl, + thinDriver.acceptsURL(thickUrl)); + } +} http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-server-client/pom.xml ---------------------------------------------------------------------- diff --git a/phoenix-server-client/pom.xml b/phoenix-server-client/pom.xml deleted file mode 100644 index 1270c46..0000000 --- a/phoenix-server-client/pom.xml +++ /dev/null @@ -1,66 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.phoenix</groupId> - <artifactId>phoenix</artifactId> - <version>4.8.0-HBase-1.1-SNAPSHOT</version> - </parent> - <artifactId>phoenix-server-client</artifactId> - <name>Phoenix Query Server Client</name> - <description>A thin JDBC client for interacting with the query server</description> - - <licenses> - <license> - <name>The Apache Software License, Version 2.0</name> - <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> - <distribution>repo</distribution> - <comments /> - </license> - </licenses> - - <organization> - <name>Apache Software Foundation</name> - <url>http://www.apache.org</url> - </organization> - - <properties> - <top.dir>${project.basedir}/..</top.dir> - </properties> - - <build> - <plugins> - <plugin> - <artifactId>maven-assembly-plugin</artifactId> - <executions> - <execution> - <id>thin-client</id> - <phase>package</phase> - <goals> - <goal>single</goal> - </goals> - <configuration> - <attach>false</attach> - <finalName>phoenix-${project.version}</finalName> - <descriptors> - <descriptor>src/build/thin-client.xml</descriptor> - </descriptors> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - - <dependencies> - <dependency> - <groupId>org.apache.calcite.avatica</groupId> - <artifactId>avatica</artifactId> - </dependency> - <dependency> - <!-- a dependency for the thin-client uberjar --> - <groupId>sqlline</groupId> - <artifactId>sqlline</artifactId> - </dependency> - </dependencies> -</project> http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-server-client/src/build/thin-client.xml ---------------------------------------------------------------------- diff --git a/phoenix-server-client/src/build/thin-client.xml b/phoenix-server-client/src/build/thin-client.xml deleted file mode 100644 index 0e7ca52..0000000 --- a/phoenix-server-client/src/build/thin-client.xml +++ /dev/null @@ -1,49 +0,0 @@ -<?xml version='1.0'?> -<!-- - - 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. - ---> - -<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> - - <id>thin-client</id> - <!-- All the dependencies (unpacked) necessary to run phoenix from a single, stand-alone jar --> - <formats> - <format>jar</format> - </formats> - <includeBaseDirectory>false</includeBaseDirectory> - <dependencySets> - <dependencySet> - <outputDirectory>/</outputDirectory> - <useProjectArtifact>true</useProjectArtifact> - <unpack>true</unpack> - <scope>runtime</scope> - </dependencySet> - </dependencySets> - <files> - <file> - <!-- Specify this file directly to make sure we don't get the file - with the same path/name from Avatica. --> - <source>src/main/resources/META-INF/services/java.sql.Driver</source> - <outputDirectory>/META-INF/services/</outputDirectory> - </file> - </files> -</assembly> http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-server-client/src/main/java/org/apache/phoenix/queryserver/client/Driver.java ---------------------------------------------------------------------- diff --git a/phoenix-server-client/src/main/java/org/apache/phoenix/queryserver/client/Driver.java b/phoenix-server-client/src/main/java/org/apache/phoenix/queryserver/client/Driver.java deleted file mode 100644 index 5c8f119..0000000 --- a/phoenix-server-client/src/main/java/org/apache/phoenix/queryserver/client/Driver.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.phoenix.queryserver.client; - -import org.apache.calcite.avatica.DriverVersion; - -public class Driver extends org.apache.calcite.avatica.remote.Driver { - - public static final String CONNECT_STRING_PREFIX = "jdbc:phoenix:thin:"; - - static { - new Driver().register(); - } - - public Driver() { - super(); - } - - @Override - protected DriverVersion createDriverVersion() { - return DriverVersion.load( - Driver.class, - "org-apache-phoenix-remote-jdbc.properties", - "Phoenix Remote JDBC Driver", - "unknown version", - "Apache Phoenix", - "unknown version"); - } - - @Override - protected String getConnectStringPrefix() { - return CONNECT_STRING_PREFIX; - } -} http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-server-client/src/main/java/org/apache/phoenix/queryserver/client/ThinClientUtil.java ---------------------------------------------------------------------- diff --git a/phoenix-server-client/src/main/java/org/apache/phoenix/queryserver/client/ThinClientUtil.java b/phoenix-server-client/src/main/java/org/apache/phoenix/queryserver/client/ThinClientUtil.java deleted file mode 100644 index af56c33..0000000 --- a/phoenix-server-client/src/main/java/org/apache/phoenix/queryserver/client/ThinClientUtil.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.phoenix.queryserver.client; - -/** - * Utilities for thin clients. - */ -public final class ThinClientUtil { - // The default serialization is also defined in QueryServicesOptions. phoenix-server-client - // currently doesn't depend on phoenix-core so we have to deal with the duplication. - private static final String DEFAULT_SERIALIZATION = "PROTOBUF"; - - private ThinClientUtil() {} - - public static String getConnectionUrl(String hostname, int port) { - return getConnectionUrl("http", hostname, port); - } - - public static String getConnectionUrl(String protocol, String hostname, int port) { - return getConnectionUrl(protocol, hostname, port, DEFAULT_SERIALIZATION); - } - - public static String getConnectionUrl(String protocol, String hostname, int port, String serialization) { - String urlFmt = Driver.CONNECT_STRING_PREFIX + "url=%s://%s:%s;serialization=%s"; - return String.format(urlFmt, protocol, hostname, port, serialization); - } -} http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-server-client/src/main/resources/META-INF/services/java.sql.Driver ---------------------------------------------------------------------- diff --git a/phoenix-server-client/src/main/resources/META-INF/services/java.sql.Driver b/phoenix-server-client/src/main/resources/META-INF/services/java.sql.Driver deleted file mode 100644 index f94d657..0000000 --- a/phoenix-server-client/src/main/resources/META-INF/services/java.sql.Driver +++ /dev/null @@ -1 +0,0 @@ -org.apache.phoenix.queryserver.client.Driver http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-server-client/src/main/resources/version/org-apache-phoenix-remote-jdbc.properties ---------------------------------------------------------------------- diff --git a/phoenix-server-client/src/main/resources/version/org-apache-phoenix-remote-jdbc.properties b/phoenix-server-client/src/main/resources/version/org-apache-phoenix-remote-jdbc.properties deleted file mode 100644 index 7e8eb7e..0000000 --- a/phoenix-server-client/src/main/resources/version/org-apache-phoenix-remote-jdbc.properties +++ /dev/null @@ -1,25 +0,0 @@ -# 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. -# -driver.name=Apache Phoenix Remote JDBC Driver -driver.version=${pom.version} -product.name=Apache Phoenix -product.version=${pom.version} -jdbc.compliant=true -driver.version.major=${version.major} -driver.version.minor=${version.minor} -database.version.major=${version.major} -database.version.minor=${version.minor} -build.timestamp=${build.timestamp} http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-server/pom.xml ---------------------------------------------------------------------- diff --git a/phoenix-server/pom.xml b/phoenix-server/pom.xml index b1dcad5..692b8db 100644 --- a/phoenix-server/pom.xml +++ b/phoenix-server/pom.xml @@ -1,4 +1,27 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +<?xml version='1.0'?> +<!-- + + 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. + +--> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -7,52 +30,118 @@ <version>4.8.0-HBase-1.1-SNAPSHOT</version> </parent> <artifactId>phoenix-server</artifactId> - <name>Phoenix Query Server</name> - <description>A query server for exposing Phoenix to thin clients</description> - - <licenses> - <license> - <name>The Apache Software License, Version 2.0</name> - <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> - <distribution>repo</distribution> - <comments /> - </license> - </licenses> - - <organization> - <name>Apache Software Foundation</name> - <url>http://www.apache.org</url> - </organization> - + <name>Phoenix Server</name> + <description>Phoenix Server</description> + <packaging>jar</packaging> <properties> + <!-- Don't make a test-jar --> + <maven.test.skip>true</maven.test.skip> + <!-- Don't make a source-jar --> + <source.skip>true</source.skip> + <license.bundles.dependencies>true</license.bundles.dependencies> <top.dir>${project.basedir}/..</top.dir> </properties> <build> <plugins> <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-site-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <plugin> + <!--Make it so assembly:single does nothing in here--> + <artifactId>maven-assembly-plugin</artifactId> + <configuration> + <skipAssembly>true</skipAssembly> + </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-failsafe-plugin</artifactId> + <artifactId>maven-jar-plugin</artifactId> + <executions> + <execution> + <id>default-jar</id> + <phase>none</phase> + </execution> + </executions> </plugin> <plugin> - <artifactId>maven-assembly-plugin</artifactId> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-install-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>install-file</goal> + </goals> + <id>default-install</id> + <configuration> + <skip>true</skip> + </configuration> + <phase>install</phase> + </execution> + </executions> + <configuration> + <file>${basedir}/target/phoenix-${project.version}-server.jar</file> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> <executions> <execution> - <id>runnable</id> <phase>package</phase> <goals> - <goal>single</goal> + <goal>shade</goal> </goals> <configuration> - <attach>false</attach> - <finalName>${project.artifactId}-${project.version}</finalName> - <descriptors> - <descriptor>src/build/query-server-runnable.xml</descriptor> - </descriptors> + <finalName>phoenix-${project.version}-server</finalName> + <shadedArtifactAttached>false</shadedArtifactAttached> + <promoteTransitiveDependencies>true</promoteTransitiveDependencies> + <shadeTestJar>false</shadeTestJar> + <transformers> + <!--<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer">--> + <!--</transformer>--> + <transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer"> + <resources> + <resource>LICENSE.txt</resource> + <resource>ASL2.0</resource> + </resources> + </transformer> + <transformer + implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer"> + <addHeader>false</addHeader> + </transformer> + <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> + <transformer + implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer"> + <resource>LICENSE.txt</resource> + <file>${project.basedir}/../LICENSE.txt</file> + </transformer> + </transformers> + <artifactSet> + <includes> + <include>org.apache.phoenix:phoenix-core</include> + <include>org.iq80.snappy:snappy</include> + <include>org.antlr:antlr*</include> + <include>org.apache.tephra:tephra*</include> + <include>com.google.code.gson:gson</include> + <include>org.jruby.joni:joni</include> + <include>org.jruby.jcodings:jcodings</include> + <include>joda-time:joda-time</include> + <include>org.apache.twill:twill*</include> + <include>com.google.inject.extensions:guice-assistedinject</include> + <include>it.unimi.dsi:fastutil</include> + <include>io.dropwizard.metrics:metrics-core</include> + <include>org.apache.thrift:libthrift</include> + </includes> + <excludes> + <exclude>org.apache.phoenix:phoenix-server</exclude> + </excludes> + </artifactSet> </configuration> </execution> </executions> @@ -61,45 +150,10 @@ </build> <dependencies> - <dependency> - <groupId>org.apache.phoenix</groupId> - <artifactId>phoenix-server-client</artifactId> - </dependency> - <dependency> - <groupId>org.apache.calcite.avatica</groupId> - <artifactId>avatica</artifactId> - <version>${avatica.version}</version> - </dependency> - <dependency> - <groupId>org.apache.calcite.avatica</groupId> - <artifactId>avatica-server</artifactId> - <version>${avatica.version}</version> - </dependency> - <dependency> - <groupId>org.apache.phoenix</groupId> - <artifactId>phoenix-core</artifactId> - </dependency> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </dependency> - <!-- for tests --> + <!-- Depend on all other internal projects --> <dependency> <groupId>org.apache.phoenix</groupId> <artifactId>phoenix-core</artifactId> - <classifier>tests</classifier> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.hbase</groupId> - <artifactId>hbase-it</artifactId> - <type>test-jar</type> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.hadoop</groupId> - <artifactId>hadoop-minicluster</artifactId> - <scope>test</scope> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-server/src/build/query-server-runnable.xml ---------------------------------------------------------------------- diff --git a/phoenix-server/src/build/query-server-runnable.xml b/phoenix-server/src/build/query-server-runnable.xml deleted file mode 100644 index db22142..0000000 --- a/phoenix-server/src/build/query-server-runnable.xml +++ /dev/null @@ -1,52 +0,0 @@ -<?xml version='1.0'?> -<!-- - - 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. - ---> - -<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> - <id>runnable</id> - <formats> - <format>jar</format> - </formats> - <includeBaseDirectory>false</includeBaseDirectory> - <containerDescriptorHandlers> - <containerDescriptorHandler> - <!-- - aggregate SPI's so that things like HDFS FileSystem works in uberjar - http://docs.oracle.com/javase/tutorial/sound/SPI-intro.html - --> - <handlerName>metaInf-services</handlerName> - </containerDescriptorHandler> - </containerDescriptorHandlers> - <dependencySets> - <dependencySet> - <unpack>true</unpack> - <scope>runtime</scope> - <outputDirectory>/</outputDirectory> - <includes> - <include>org.apache.phoenix:phoenix-server</include> - <include>org.apache.phoenix:phoenix-server-client</include> - <include>org.apache.calcite.avatica:*</include> - </includes> - </dependencySet> - </dependencySets> -</assembly> http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-server/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java ---------------------------------------------------------------------- diff --git a/phoenix-server/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java b/phoenix-server/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java deleted file mode 100644 index ba49bab..0000000 --- a/phoenix-server/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * 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.phoenix.end2end; - -import static java.lang.String.format; -import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_CAT; -import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_CATALOG; -import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM; -import static org.apache.phoenix.query.QueryConstants.SYSTEM_SCHEMA_NAME; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.Statement; -import java.util.Properties; -import java.util.concurrent.TimeUnit; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.conf.Configuration; -import org.apache.phoenix.query.QueryServices; -import org.apache.phoenix.queryserver.client.ThinClientUtil; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * Smoke test for query server. - */ -public class QueryServerBasicsIT extends BaseHBaseManagedTimeIT { - - private static final Log LOG = LogFactory.getLog(QueryServerBasicsIT.class); - - private static QueryServerThread AVATICA_SERVER; - private static Configuration CONF; - private static String CONN_STRING; - - @BeforeClass - public static void beforeClass() throws Exception { - CONF = getTestClusterConfig(); - CONF.setInt(QueryServices.QUERY_SERVER_HTTP_PORT_ATTRIB, 0); - String url = getUrl(); - AVATICA_SERVER = new QueryServerThread(new String[] { url }, CONF, - QueryServerBasicsIT.class.getName()); - AVATICA_SERVER.start(); - AVATICA_SERVER.getMain().awaitRunning(); - final int port = AVATICA_SERVER.getMain().getPort(); - LOG.info("Avatica server started on port " + port); - CONN_STRING = ThinClientUtil.getConnectionUrl("localhost", port); - LOG.info("JDBC connection string is " + CONN_STRING); - } - - @AfterClass - public static void afterClass() throws Exception { - if (AVATICA_SERVER != null) { - AVATICA_SERVER.join(TimeUnit.MINUTES.toMillis(1)); - Throwable t = AVATICA_SERVER.getMain().getThrowable(); - if (t != null) { - fail("query server threw. " + t.getMessage()); - } - assertEquals("query server didn't exit cleanly", 0, AVATICA_SERVER.getMain().getRetCode()); - } - } - - @Test - public void testCatalogs() throws Exception { - try (final Connection connection = DriverManager.getConnection(CONN_STRING)) { - assertThat(connection.isClosed(), is(false)); - try (final ResultSet resultSet = connection.getMetaData().getCatalogs()) { - final ResultSetMetaData metaData = resultSet.getMetaData(); - assertFalse("unexpected populated resultSet", resultSet.next()); - assertEquals(1, metaData.getColumnCount()); - assertEquals(TABLE_CAT, metaData.getColumnName(1)); - } - } - } - - @Test - public void testSchemas() throws Exception { - Properties props=new Properties(); - props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(true)); - try (final Connection connection = DriverManager.getConnection(CONN_STRING, props)) { - connection.createStatement().executeUpdate("CREATE SCHEMA IF NOT EXISTS " + SYSTEM_SCHEMA_NAME); - assertThat(connection.isClosed(), is(false)); - try (final ResultSet resultSet = connection.getMetaData().getSchemas()) { - final ResultSetMetaData metaData = resultSet.getMetaData(); - assertTrue("unexpected empty resultset", resultSet.next()); - assertEquals(2, metaData.getColumnCount()); - assertEquals(TABLE_SCHEM, metaData.getColumnName(1)); - assertEquals(TABLE_CATALOG, metaData.getColumnName(2)); - boolean containsSystem = false; - do { - if (resultSet.getString(1).equalsIgnoreCase(SYSTEM_SCHEMA_NAME)) containsSystem = true; - } while (resultSet.next()); - assertTrue(format("should contain at least %s schema.", SYSTEM_SCHEMA_NAME), containsSystem); - } - } - } - - @Test - public void smokeTest() throws Exception { - final String tableName = getClass().getSimpleName().toUpperCase() + System.currentTimeMillis(); - try (final Connection connection = DriverManager.getConnection(CONN_STRING)) { - assertThat(connection.isClosed(), is(false)); - connection.setAutoCommit(true); - try (final Statement stmt = connection.createStatement()) { - assertFalse(stmt.execute("DROP TABLE IF EXISTS " + tableName)); - assertFalse(stmt.execute("CREATE TABLE " + tableName + "(" - + "id INTEGER NOT NULL, " - + "pk varchar(3) NOT NULL " - + "CONSTRAINT PK_CONSTRAINT PRIMARY KEY (id, pk))")); - assertEquals(0, stmt.getUpdateCount()); - assertEquals(1, stmt.executeUpdate("UPSERT INTO " + tableName + " VALUES(1, 'foo')")); - assertEquals(1, stmt.executeUpdate("UPSERT INTO " + tableName + " VALUES(2, 'bar')")); - assertTrue(stmt.execute("SELECT * FROM " + tableName)); - try (final ResultSet resultSet = stmt.getResultSet()) { - assertTrue(resultSet.next()); - assertEquals(1, resultSet.getInt(1)); - assertEquals("foo", resultSet.getString(2)); - assertTrue(resultSet.next()); - assertEquals(2, resultSet.getInt(1)); - assertEquals("bar", resultSet.getString(2)); - } - } - final String sql = "SELECT * FROM " + tableName + " WHERE id = ?"; - try (final PreparedStatement stmt = connection.prepareStatement(sql)) { - stmt.setInt(1, 1); - try (ResultSet resultSet = stmt.executeQuery()) { - assertTrue(resultSet.next()); - assertEquals(1, resultSet.getInt(1)); - assertEquals("foo", resultSet.getString(2)); - } - stmt.clearParameters(); - stmt.setInt(1, 5); - try (final ResultSet resultSet = stmt.executeQuery()) { - assertFalse(resultSet.next()); - } - } - } - } -} http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-server/src/it/java/org/apache/phoenix/end2end/QueryServerThread.java ---------------------------------------------------------------------- diff --git a/phoenix-server/src/it/java/org/apache/phoenix/end2end/QueryServerThread.java b/phoenix-server/src/it/java/org/apache/phoenix/end2end/QueryServerThread.java deleted file mode 100644 index ef94bf7..0000000 --- a/phoenix-server/src/it/java/org/apache/phoenix/end2end/QueryServerThread.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.phoenix.end2end; - -import org.apache.hadoop.conf.Configuration; -import org.apache.phoenix.queryserver.server.Main; - -/** Wraps up the query server for tests. */ -public class QueryServerThread extends Thread { - - private final Main main; - - public QueryServerThread(String[] argv, Configuration conf) { - this(argv, conf, null); - } - - public QueryServerThread(String[] argv, Configuration conf, String name) { - this(new Main(argv, conf), name); - } - - private QueryServerThread(Main m, String name) { - super(m, "query server" + (name == null ? "" : (" - " + name))); - this.main = m; - setDaemon(true); - } - - public Main getMain() { - return main; - } -} http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-server/src/it/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/phoenix-server/src/it/resources/log4j.properties b/phoenix-server/src/it/resources/log4j.properties deleted file mode 100644 index 6b1ce50..0000000 --- a/phoenix-server/src/it/resources/log4j.properties +++ /dev/null @@ -1,63 +0,0 @@ -# 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. - -# Define some default values that can be overridden by system properties -hbase.root.logger=DEBUG,console -hbase.log.dir=. -hbase.log.file=hbase.log - -# Define the root logger to the system property "hbase.root.logger". -log4j.rootLogger=${hbase.root.logger} - -# Logging Threshold -log4j.threshhold=ALL - -# -# Daily Rolling File Appender -# -log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender -log4j.appender.DRFA.File=${hbase.log.dir}/${hbase.log.file} - -# Rollver at midnight -log4j.appender.DRFA.DatePattern=.yyyy-MM-dd - -# 30-day backup -#log4j.appender.DRFA.MaxBackupIndex=30 -log4j.appender.DRFA.layout=org.apache.log4j.PatternLayout - -# Pattern format: Date LogLevel LoggerName LogMessage -#log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %p %c: %m%n - -# Debugging Pattern format -log4j.appender.DRFA.layout.ConversionPattern=%d %-5p [%t] %C{2}(%L): %m%n - - -# -# console -# Add "console" to rootlogger above if you want to use this -# -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.target=System.err -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d %-5p [%t] %C{2}(%L): %m%n - -# Custom Logging levels - -#log4j.logger.org.apache.hadoop.fs.FSNamesystem=DEBUG - -log4j.logger.org.apache.hadoop=WARN -log4j.logger.org.apache.zookeeper=ERROR -log4j.logger.org.apache.hadoop.hbase=DEBUG http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-server/src/main/java/org/apache/phoenix/queryserver/server/Main.java ---------------------------------------------------------------------- diff --git a/phoenix-server/src/main/java/org/apache/phoenix/queryserver/server/Main.java b/phoenix-server/src/main/java/org/apache/phoenix/queryserver/server/Main.java deleted file mode 100644 index 106d422..0000000 --- a/phoenix-server/src/main/java/org/apache/phoenix/queryserver/server/Main.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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.phoenix.queryserver.server; - -import com.google.common.annotations.VisibleForTesting; -import org.apache.calcite.avatica.Meta; -import org.apache.calcite.avatica.remote.Driver; -import org.apache.calcite.avatica.remote.LocalService; -import org.apache.calcite.avatica.remote.Service; -import org.apache.calcite.avatica.server.HandlerFactory; -import org.apache.calcite.avatica.server.HttpServer; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.conf.Configured; -import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.hbase.util.Strings; -import org.apache.hadoop.net.DNS; -import org.apache.hadoop.security.SecurityUtil; -import org.apache.hadoop.util.Tool; -import org.apache.hadoop.util.ToolRunner; -import org.apache.phoenix.query.QueryServices; -import org.apache.phoenix.query.QueryServicesOptions; -import org.eclipse.jetty.server.Handler; - -import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -/** - * A query server for Phoenix over Calcite's Avatica. - */ -public final class Main extends Configured implements Tool, Runnable { - - protected static final Log LOG = LogFactory.getLog(Main.class); - - private final String[] argv; - private final CountDownLatch runningLatch = new CountDownLatch(1); - private HttpServer server = null; - private int retCode = 0; - private Throwable t = null; - - /** - * Log information about the currently running JVM. - */ - public static void logJVMInfo() { - // Print out vm stats before starting up. - RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); - if (runtime != null) { - LOG.info("vmName=" + runtime.getVmName() + ", vmVendor=" + - runtime.getVmVendor() + ", vmVersion=" + runtime.getVmVersion()); - LOG.info("vmInputArguments=" + runtime.getInputArguments()); - } - } - - /** - * Logs information about the currently running JVM process including - * the environment variables. Logging of env vars can be disabled by - * setting {@code "phoenix.envvars.logging.disabled"} to {@code "true"}. - * <p>If enabled, you can also exclude environment variables containing - * certain substrings by setting {@code "phoenix.envvars.logging.skipwords"} - * to comma separated list of such substrings. - */ - public static void logProcessInfo(Configuration conf) { - // log environment variables unless asked not to - if (conf == null || !conf.getBoolean(QueryServices.QUERY_SERVER_ENV_LOGGING_ATTRIB, false)) { - Set<String> skipWords = new HashSet<String>(QueryServicesOptions.DEFAULT_QUERY_SERVER_SKIP_WORDS); - if (conf != null) { - String[] confSkipWords = conf.getStrings(QueryServices.QUERY_SERVER_ENV_LOGGING_SKIPWORDS_ATTRIB); - if (confSkipWords != null) { - skipWords.addAll(Arrays.asList(confSkipWords)); - } - } - - nextEnv: - for (Map.Entry<String, String> entry : System.getenv().entrySet()) { - String key = entry.getKey().toLowerCase(); - String value = entry.getValue().toLowerCase(); - // exclude variables which may contain skip words - for(String skipWord : skipWords) { - if (key.contains(skipWord) || value.contains(skipWord)) - continue nextEnv; - } - LOG.info("env:"+entry); - } - } - // and JVM info - logJVMInfo(); - } - - /** Constructor for use from {@link org.apache.hadoop.util.ToolRunner}. */ - public Main() { - this(null, null); - } - - /** Constructor for use as {@link java.lang.Runnable}. */ - public Main(String[] argv, Configuration conf) { - this.argv = argv; - setConf(conf); - } - - /** - * @return the port number this instance is bound to, or {@code -1} if the server is not running. - */ - @VisibleForTesting - public int getPort() { - if (server == null) return -1; - return server.getPort(); - } - - /** - * @return the return code from running as a {@link Tool}. - */ - @VisibleForTesting - public int getRetCode() { - return retCode; - } - - /** - * @return the throwable from an unsuccessful run, or null otherwise. - */ - @VisibleForTesting - public Throwable getThrowable() { - return t; - } - - /** Calling thread waits until the server is running. */ - public void awaitRunning() throws InterruptedException { - runningLatch.await(); - } - - /** Calling thread waits until the server is running. */ - public void awaitRunning(long timeout, TimeUnit unit) throws InterruptedException { - runningLatch.await(timeout, unit); - } - - @Override - public int run(String[] args) throws Exception { - logProcessInfo(getConf()); - try { - // handle secure cluster credentials - if ("kerberos".equalsIgnoreCase(getConf().get(QueryServices.QUERY_SERVER_HBASE_SECURITY_CONF_ATTRIB))) { - String hostname = Strings.domainNamePointerToHostName(DNS.getDefaultHost( - getConf().get(QueryServices.QUERY_SERVER_DNS_INTERFACE_ATTRIB, "default"), - getConf().get(QueryServices.QUERY_SERVER_DNS_NAMESERVER_ATTRIB, "default"))); - if (LOG.isDebugEnabled()) { - LOG.debug("Login to " + hostname + " using " + getConf().get(QueryServices.QUERY_SERVER_KEYTAB_FILENAME_ATTRIB) - + " and principal " + getConf().get(QueryServices.QUERY_SERVER_KERBEROS_PRINCIPAL_ATTRIB) + "."); - } - SecurityUtil.login(getConf(), QueryServices.QUERY_SERVER_KEYTAB_FILENAME_ATTRIB, - QueryServices.QUERY_SERVER_KERBEROS_PRINCIPAL_ATTRIB, hostname); - LOG.info("Login successful."); - } - Class<? extends PhoenixMetaFactory> factoryClass = getConf().getClass( - QueryServices.QUERY_SERVER_META_FACTORY_ATTRIB, PhoenixMetaFactoryImpl.class, PhoenixMetaFactory.class); - int port = getConf().getInt(QueryServices.QUERY_SERVER_HTTP_PORT_ATTRIB, - QueryServicesOptions.DEFAULT_QUERY_SERVER_HTTP_PORT); - LOG.debug("Listening on port " + port); - PhoenixMetaFactory factory = - factoryClass.getDeclaredConstructor(Configuration.class).newInstance(getConf()); - Meta meta = factory.create(Arrays.asList(args)); - final HandlerFactory handlerFactory = new HandlerFactory(); - Service service = new LocalService(meta); - server = new HttpServer(port, getHandler(getConf(), service, handlerFactory)); - server.start(); - runningLatch.countDown(); - server.join(); - return 0; - } catch (Throwable t) { - LOG.fatal("Unrecoverable service error. Shutting down.", t); - this.t = t; - return -1; - } - } - - /** - * Instantiates the Handler for use by the Avatica (Jetty) server. - * - * @param conf The configuration - * @param service The Avatica Service implementation - * @param handlerFactory Factory used for creating a Handler - * @return The Handler to use based on the configuration. - */ - Handler getHandler(Configuration conf, Service service, HandlerFactory handlerFactory) { - String serializationName = conf.get(QueryServices.QUERY_SERVER_SERIALIZATION_ATTRIB, - QueryServicesOptions.DEFAULT_QUERY_SERVER_SERIALIZATION); - - Driver.Serialization serialization; - // Otherwise, use what was provided in the configuration - try { - serialization = Driver.Serialization.valueOf(serializationName); - } catch (Exception e) { - LOG.error("Unknown message serialization type for " + serializationName); - throw e; - } - - Handler handler = handlerFactory.getHandler(service, serialization); - - LOG.info("Instantiated " + handler.getClass() + " for QueryServer"); - - return handler; - } - - @Override public void run() { - try { - retCode = run(argv); - } catch (Exception e) { - // already logged - } - } - - public static void main(String[] argv) throws Exception { - int ret = ToolRunner.run(HBaseConfiguration.create(), new Main(), argv); - System.exit(ret); - } -} http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-server/src/main/java/org/apache/phoenix/queryserver/server/PhoenixMetaFactory.java ---------------------------------------------------------------------- diff --git a/phoenix-server/src/main/java/org/apache/phoenix/queryserver/server/PhoenixMetaFactory.java b/phoenix-server/src/main/java/org/apache/phoenix/queryserver/server/PhoenixMetaFactory.java deleted file mode 100644 index 02344a3..0000000 --- a/phoenix-server/src/main/java/org/apache/phoenix/queryserver/server/PhoenixMetaFactory.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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.phoenix.queryserver.server; - -import org.apache.calcite.avatica.Meta; -import org.apache.hadoop.conf.Configurable; - -/** - * A @{link Meta.Factory} that can also respect Hadoop - * {@link org.apache.hadoop.conf.Configuration} objects. - */ -public interface PhoenixMetaFactory extends Meta.Factory, Configurable { -} http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-server/src/main/java/org/apache/phoenix/queryserver/server/PhoenixMetaFactoryImpl.java ---------------------------------------------------------------------- diff --git a/phoenix-server/src/main/java/org/apache/phoenix/queryserver/server/PhoenixMetaFactoryImpl.java b/phoenix-server/src/main/java/org/apache/phoenix/queryserver/server/PhoenixMetaFactoryImpl.java deleted file mode 100644 index c74d2c9..0000000 --- a/phoenix-server/src/main/java/org/apache/phoenix/queryserver/server/PhoenixMetaFactoryImpl.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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.phoenix.queryserver.server; - -import com.google.common.base.Preconditions; -import org.apache.calcite.avatica.Meta; -import org.apache.calcite.avatica.jdbc.JdbcMeta; -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.conf.Configured; -import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.hbase.HConstants; -import org.apache.phoenix.jdbc.PhoenixConnection; -import org.apache.phoenix.mapreduce.util.PhoenixConfigurationUtil; -import org.apache.phoenix.util.QueryUtil; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -/** - * Bridge between Phoenix and Avatica. - */ -public class PhoenixMetaFactoryImpl extends Configured implements PhoenixMetaFactory { - - // invoked via reflection - public PhoenixMetaFactoryImpl() { - super(HBaseConfiguration.create()); - } - - // invoked via reflection - public PhoenixMetaFactoryImpl(Configuration conf) { - super(conf); - } - - @Override - public Meta create(List<String> args) { - Configuration conf = Preconditions.checkNotNull(getConf(), "Configuration must not be null."); - Properties info = new Properties(); - info.putAll(conf.getValByRegex("avatica.*")); - try { - final String url; - if (args.size() == 0) { - url = QueryUtil.getConnectionUrl(info, conf); - } else if (args.size() == 1) { - url = args.get(0); - } else { - throw new RuntimeException( - "0 or 1 argument expected. Received " + Arrays.toString(args.toArray())); - } - // TODO: what about -D configs passed in from cli? How do they get pushed down? - return new JdbcMeta(url, info); - } catch (SQLException | ClassNotFoundException e) { - throw new RuntimeException(e); - } - } -} http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/phoenix-server/src/test/java/org/apache/phoenix/DriverCohabitationTest.java ---------------------------------------------------------------------- diff --git a/phoenix-server/src/test/java/org/apache/phoenix/DriverCohabitationTest.java b/phoenix-server/src/test/java/org/apache/phoenix/DriverCohabitationTest.java deleted file mode 100644 index 1df6d2c..0000000 --- a/phoenix-server/src/test/java/org/apache/phoenix/DriverCohabitationTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.phoenix; - -import org.apache.phoenix.queryserver.client.ThinClientUtil; -import org.apache.phoenix.util.QueryUtil; -import org.junit.Test; - -import java.sql.Driver; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.Collections; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/** - * Ensure the "thick" Phoenix driver and it's "thin" counterpart can coexist on - * the same classpath. - */ -public class DriverCohabitationTest { - - @Test - public void testDriverCohabitation() throws SQLException { - Driver thickDriver = null; - Driver thinDriver = null; - - for (Driver d : Collections.list(DriverManager.getDrivers())) { - if (d instanceof org.apache.phoenix.jdbc.PhoenixDriver) { - thickDriver = d; - } else if (d instanceof org.apache.phoenix.queryserver.client.Driver) { - thinDriver = d; - } - } - assertNotNull("Thick driver not registered with DriverManager.", thickDriver); - assertNotNull("Thin driver not registered with DriverManager.", thinDriver); - - final String thickUrl = QueryUtil.getUrl("localhost"); - final String thinUrl = ThinClientUtil.getConnectionUrl("localhost", 1234); - assertTrue("Thick driver should accept connections like " + thickUrl, - thickDriver.acceptsURL(thickUrl)); - assertFalse("Thick driver should reject connections like " + thinUrl, - thickDriver.acceptsURL(thinUrl)); - assertTrue("Thin driver should accept connections like " + thinUrl, - thinDriver.acceptsURL(thinUrl)); - assertFalse("Thin driver should reject connections like " + thickUrl, - thinDriver.acceptsURL(thickUrl)); - } -} http://git-wip-us.apache.org/repos/asf/phoenix/blob/3f7e1c46/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 0af7f93..c43c498 100644 --- a/pom.xml +++ b/pom.xml @@ -26,11 +26,13 @@ <module>phoenix-core</module> <module>phoenix-flume</module> <module>phoenix-pig</module> - <module>phoenix-server-client</module> - <module>phoenix-server</module> + <module>phoenix-queryserver-client</module> + <module>phoenix-queryserver</module> <module>phoenix-pherf</module> <module>phoenix-spark</module> <module>phoenix-hive</module> + <module>phoenix-client</module> + <module>phoenix-server</module> <module>phoenix-assembly</module> <module>phoenix-tracing-webapp</module> </modules> @@ -163,6 +165,11 @@ </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-install-plugin</artifactId> + <version>2.5.2</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <version>${maven-eclipse-plugin.version}</version> </plugin> @@ -340,6 +347,11 @@ </execution> </executions> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>2.4.3</version> + </plugin> </plugins> </pluginManagement> @@ -478,12 +490,12 @@ </dependency> <dependency> <groupId>org.apache.phoenix</groupId> - <artifactId>phoenix-server</artifactId> + <artifactId>phoenix-queryserver</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>org.apache.phoenix</groupId> - <artifactId>phoenix-server-client</artifactId> + <artifactId>phoenix-queryserver-client</artifactId> <version>${project.version}</version> </dependency>