You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@livy.apache.org by va...@apache.org on 2018/11/30 23:57:38 UTC
[5/5] incubator-livy git commit: [LIVY-502] Remove dependency on
hive-exec
[LIVY-502] Remove dependency on hive-exec
## What changes were proposed in this pull request?
This PR removes the dependency on `hive-exec`. Only modules of Hive which are used after this PR are `hive-service-rpc` and `hive-service`. This drastically reduces the amount of JARs needed by the thriftserver module.
The PR takes the Hive classes which we were using and adapts them when necessary (or simpify when we don't need something) in order to work in the Livy thriftserver.
Most of the classes are just migrated replacing all occurrences of `HiveConf`, `HiveSession` and other Hive specific classes. Only one class has a quite different logic than Hive's and it is `AuthFactory`, as we are using a different UGI handling from Hive (as we are not running the TS in a standalone JVM).
The functionalities we are taking from Hive are:
- the thrift protocol endpoints (the classes in the `cli` package), ie. the classes handling lower level details about the communication with the client;
- the authentication layer (classes in the `auth` package, which are used in the ones in `cli`), despite this PR leaves LDAP and PAM as out of scope as they are not trivial to be ported and not needed for a working solution. We can add them later;
- the classes in the `operation` package which are used to answer to metadata queries by the JDBC driver.
## How was this patch tested?
existing UTs + manual tests
Author: Marco Gaido <mg...@hortonworks.com>
Closes #117 from mgaido91/LIVY-502.
Project: http://git-wip-us.apache.org/repos/asf/incubator-livy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-livy/commit/47d3ee6b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-livy/tree/47d3ee6b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-livy/diff/47d3ee6b
Branch: refs/heads/master
Commit: 47d3ee6b6555a63d0b871788a53aab022fff518a
Parents: 39fa887
Author: Marco Gaido <mg...@hortonworks.com>
Authored: Fri Nov 30 15:57:16 2018 -0800
Committer: Marcelo Vanzin <va...@cloudera.com>
Committed: Fri Nov 30 15:57:16 2018 -0800
----------------------------------------------------------------------
server/pom.xml | 4 +
.../main/scala/org/apache/livy/LivyConf.scala | 66 ++
.../org/apache/livy/server/LivyServer.scala | 9 +-
.../livy/server/ThriftServerFactory.scala | 2 +
thriftserver/server/pom.xml | 36 +-
.../hive/service/auth/HiveAuthFactory.java | 320 -------
.../apache/hive/service/cli/ColumnBasedSet.java | 205 -----
.../hive/service/cli/JobProgressUpdate.java | 55 --
.../hive/service/cli/OperationStatus.java | 75 --
.../cli/operation/GetCatalogsOperation.java | 80 --
.../cli/operation/GetTableTypesOperation.java | 101 ---
.../cli/operation/GetTypeInfoOperation.java | 147 ----
.../cli/operation/HiveTableTypeMapping.java | 61 --
.../cli/operation/MetadataOperation.java | 133 ---
.../hive/service/cli/operation/Operation.java | 290 ------
.../cli/thrift/ThriftBinaryCLIService.java | 167 ----
.../service/cli/thrift/ThriftCLIService.java | 871 -------------------
.../cli/thrift/ThriftHttpCLIService.java | 234 -----
.../service/cli/thrift/ThriftHttpServlet.java | 592 -------------
.../apache/hive/service/server/HiveServer2.java | 316 -------
.../livy/thriftserver/LivyCLIService.scala | 147 ++--
.../LivyExecuteStatementOperation.scala | 55 +-
.../thriftserver/LivyOperationManager.scala | 54 +-
.../livy/thriftserver/LivyThriftServer.scala | 60 +-
.../thriftserver/LivyThriftSessionManager.scala | 56 +-
.../thriftserver/ThriftServerFactoryImpl.scala | 5 +
.../livy/thriftserver/ThriftService.scala | 159 ++++
.../thriftserver/auth/AuthBridgeServer.scala | 299 +++++++
.../livy/thriftserver/auth/AuthFactory.scala | 196 +++++
.../auth/AuthenticationProvider.scala | 74 ++
.../auth/LivyDelegationTokenSecretManager.scala | 81 ++
.../thriftserver/auth/PlainSaslServer.scala | 184 ++++
.../cli/ThreadPoolExecutorWithOomHook.scala | 54 ++
.../cli/ThriftBinaryCLIService.scala | 176 ++++
.../thriftserver/cli/ThriftCLIService.scala | 745 ++++++++++++++++
.../thriftserver/cli/ThriftHttpCLIService.scala | 210 +++++
.../thriftserver/cli/ThriftHttpServlet.scala | 503 +++++++++++
.../operation/GetCatalogsOperation.scala | 58 ++
.../operation/GetTableTypesOperation.scala | 59 ++
.../operation/GetTypeInfoOperation.scala | 126 +++
.../operation/MetadataOperation.scala | 49 ++
.../livy/thriftserver/operation/Operation.scala | 180 ++++
.../thriftserver/serde/ThriftResultSet.scala | 124 +++
.../livy/thriftserver/types/DataTypeUtils.scala | 89 +-
.../apache/livy/thriftserver/types/Schema.scala | 111 +++
.../thriftserver/ui/ThriftJsonServlet.scala | 2 +-
.../thriftserver/ThriftServerBaseTest.scala | 11 +-
.../livy/thriftserver/ThriftServerSuites.scala | 4 +-
.../session/RegisterSessionJob.java | 2 -
.../thriftserver/session/StatementState.java | 2 -
50 files changed, 3699 insertions(+), 3940 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-livy/blob/47d3ee6b/server/pom.xml
----------------------------------------------------------------------
diff --git a/server/pom.xml b/server/pom.xml
index 0ebc329..a26b207 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -114,6 +114,10 @@
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-core</artifactId>
+ </exclusion>
</exclusions>
<scope>${hadoop.scope}</scope>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-livy/blob/47d3ee6b/server/src/main/scala/org/apache/livy/LivyConf.scala
----------------------------------------------------------------------
diff --git a/server/src/main/scala/org/apache/livy/LivyConf.scala b/server/src/main/scala/org/apache/livy/LivyConf.scala
index 63374f1..32b3522 100644
--- a/server/src/main/scala/org/apache/livy/LivyConf.scala
+++ b/server/src/main/scala/org/apache/livy/LivyConf.scala
@@ -98,9 +98,75 @@ object LivyConf {
val LAUNCH_KERBEROS_REFRESH_INTERVAL = Entry("livy.server.launch.kerberos.refresh-interval", "1h")
val KINIT_FAIL_THRESHOLD = Entry("livy.server.launch.kerberos.kinit-fail-threshold", 5)
+ // Thrift configurations
val THRIFT_SERVER_ENABLED = Entry("livy.server.thrift.enabled", false)
val THRIFT_INCR_COLLECT_ENABLED = Entry("livy.server.thrift.incrementalCollect", false)
val THRIFT_SESSION_CREATION_TIMEOUT = Entry("livy.server.thrift.session.creationTimeout", "10m")
+ // The following configs are the same present in Hive
+ val THRIFT_RESULTSET_DEFAULT_FETCH_SIZE =
+ Entry("livy.server.thrift.resultset.default.fetch.size", 1000)
+ val THRIFT_TRANSPORT_MODE = Entry("livy.server.thrift.transport.mode", "binary")
+ val THRIFT_SERVER_PORT = Entry("livy.server.thrift.port", 10090)
+ val THRIFT_LONG_POLLING_TIMEOUT = Entry("livy.server.thrift.long.polling.timeout", "5000ms")
+ val THRIFT_LIMIT_CONNECTIONS_PER_USER = Entry("livy.server.thrift.limit.connections.per.user", 0)
+ val THRIFT_LIMIT_CONNECTIONS_PER_IPADDRESS =
+ Entry("livy.server.thrift.limit.connections.per.ipaddress", 0)
+ val THRIFT_LIMIT_CONNECTIONS_PER_USER_IPADDRESS =
+ Entry("livy.server.thrift.limit.connections.per.user.ipaddress", 0)
+ val THRIFT_SESSION_CHECK_INTERVAL = Entry("livy.server.thrift.session.check.interval", "6h")
+ val THRIFT_CLOSE_SESSION_ON_DISCONNECT =
+ Entry("livy.server.thrift.close.session.on.disconnect", true)
+ val THRIFT_IDLE_SESSION_TIMEOUT = Entry("livy.server.thrift.idle.session.timeout", "7d")
+ val THRIFT_IDLE_OPERATION_TIMEOUT = Entry("livy.server.thrift.idle.operation.timeout", "5d")
+ val THRIFT_IDLE_SESSION_CHECK_OPERATION =
+ Entry("livy.server.thrift.idle.session.check.operation", true)
+ val THRIFT_LOG_OPERATION_ENABLED = Entry("livy.server.thrift.logging.operation.enabled", true)
+ val THRIFT_ASYNC_EXEC_THREADS = Entry("livy.server.thrift.async.exec.threads", 100)
+ val THRIFT_ASYNC_EXEC_SHUTDOWN_TIMEOUT =
+ Entry("livy.server.thrift.async.exec.shutdown.timeout", "10s")
+ val THRIFT_ASYNC_EXEC_WAIT_QUEUE_SIZE =
+ Entry("livy.server.thrift.async.exec.wait.queue.size", 100)
+ val THRIFT_ASYNC_EXEC_KEEPALIVE_TIME =
+ Entry("livy.server.thrift.async.exec.keepalive.time", "10s")
+ val THRIFT_BIND_HOST = Entry("livy.server.thrift.bind.host", null)
+ val THRIFT_WORKER_KEEPALIVE_TIME = Entry("livy.server.thrift.worker.keepalive.time", "60s")
+ val THRIFT_MIN_WORKER_THREADS = Entry("livy.server.thrift.min.worker.threads", 5)
+ val THRIFT_MAX_WORKER_THREADS = Entry("livy.server.thrift.max.worker.threads", 500)
+ val THRIFT_RESULTSET_MAX_FETCH_SIZE = Entry("livy.server.thrift.resultset.max.fetch.size", 10000)
+ val THRIFT_ALLOW_USER_SUBSTITUTION = Entry("livy.server.thrift.allow.user.substitution", true)
+ val THRIFT_AUTHENTICATION = Entry("livy.server.thrift.authentication", "NONE")
+ val THRIFT_ENABLE_DOAS = Entry("livy.server.thrift.enable.doAs", true)
+ val THRIFT_SSL_PROTOCOL_BLACKLIST =
+ Entry("livy.server.thrift.ssl.protocol.blacklist", "SSLv2,SSLv3")
+ val THRIFT_USE_SSL = Entry("livy.server.thrift.use.SSL", false)
+ val THRIFT_MAX_MESSAGE_SIZE = Entry("livy.server.thrift.max.message.size", 100 * 1024 * 1024)
+ val THRIFT_LOGIN_TIMEOUT = Entry("livy.server.thrift.login.timeout", "20s")
+ val THRIFT_LOGIN_BEBACKOFF_SLOT_LENGTH =
+ Entry("livy.server.thrift.exponential.backoff.slot.length", "100ms")
+ val THRIFT_HTTP_REQUEST_HEADER_SIZE =
+ Entry("livy.server.thrift.http.request.header.size", 6*1024)
+ val THRIFT_HTTP_RESPONSE_HEADER_SIZE =
+ Entry("livy.server.thrift.http.response.header.size", 6*1024)
+ val THRIFT_HTTP_MAX_IDLE_TIME = Entry("livy.server.thrift.http.max.idle.time", "1800s")
+ val THRIFT_XSRF_FILTER_ENABLED = Entry("livy.server.thrift.xsrf.filter.enabled", false)
+ val THRIFT_HTTP_PATH = Entry("livy.server.thrift.http.path", "cliservice")
+ val THRIFT_HTTP_COMPRESSION_ENABLED = Entry("livy.server.thrift.http.compression.enabled", true)
+ val THRIFT_HTTP_COOKIE_AUTH_ENABLED = Entry("livy.server.thrift.http.cookie.auth.enabled", true)
+ val THRIFT_HTTP_COOKIE_MAX_AGE = Entry("livy.server.thrift.http.cookie.max.age", "86400s")
+ val THRIFT_HTTP_COOKIE_DOMAIN = Entry("livy.server.thrift.http.cookie.domain", null)
+ val THRIFT_HTTP_COOKIE_PATH = Entry("livy.server.thrift.http.cookie.path", null)
+ val THRIFT_HTTP_COOKIE_IS_HTTPONLY = Entry("livy.server.thrift.http.cookie.is.httponly", true)
+ val THRIFT_CUSTOM_AUTHENTICATION_CLASS =
+ Entry("livy.server.thrift.custom.authentication.class", null)
+ val THRIFT_SASL_QOP = Entry("livy.server.thrift.sasl.qop", "auth")
+ val THRIFT_DELEGATION_KEY_UPDATE_INTERVAL =
+ Entry("livy.server.thrift.delegation.key.update-interval", "1d")
+ val THRIFT_DELEGATION_TOKEN_GC_INTERVAL =
+ Entry("livy.server.thrift.delegation.token.gc-interval", "1h")
+ val THRIFT_DELEGATION_TOKEN_MAX_LIFETIME =
+ Entry("livy.server.thrift.delegation.token.max-lifetime", "7d")
+ val THRIFT_DELEGATION_TOKEN_RENEW_INTERVAL =
+ Entry("livy.server.thrift.delegation.token.renew-interval", "1d")
/**
* Recovery mode of Livy. Possible values:
http://git-wip-us.apache.org/repos/asf/incubator-livy/blob/47d3ee6b/server/src/main/scala/org/apache/livy/server/LivyServer.scala
----------------------------------------------------------------------
diff --git a/server/src/main/scala/org/apache/livy/server/LivyServer.scala b/server/src/main/scala/org/apache/livy/server/LivyServer.scala
index 5f3bfd1..ed5bd81 100644
--- a/server/src/main/scala/org/apache/livy/server/LivyServer.scala
+++ b/server/src/main/scala/org/apache/livy/server/LivyServer.scala
@@ -280,17 +280,18 @@ class LivyServer extends Logging {
server.start()
+ thriftServerFactory.foreach {
+ _.start(livyConf, interactiveSessionManager, sessionStore, accessManager)
+ }
+
Runtime.getRuntime().addShutdownHook(new Thread("Livy Server Shutdown") {
override def run(): Unit = {
info("Shutting down Livy server.")
server.stop()
+ thriftServerFactory.foreach(_.stop())
}
})
- thriftServerFactory.foreach {
- _.start(livyConf, interactiveSessionManager, sessionStore, accessManager)
- }
-
_serverUrl = Some(s"${server.protocol}://${server.host}:${server.port}")
sys.props("livy.server.server-url") = _serverUrl.get
}
http://git-wip-us.apache.org/repos/asf/incubator-livy/blob/47d3ee6b/server/src/main/scala/org/apache/livy/server/ThriftServerFactory.scala
----------------------------------------------------------------------
diff --git a/server/src/main/scala/org/apache/livy/server/ThriftServerFactory.scala b/server/src/main/scala/org/apache/livy/server/ThriftServerFactory.scala
index 00c3c9f..2c47ed8 100644
--- a/server/src/main/scala/org/apache/livy/server/ThriftServerFactory.scala
+++ b/server/src/main/scala/org/apache/livy/server/ThriftServerFactory.scala
@@ -33,6 +33,8 @@ trait ThriftServerFactory {
sessionStore: SessionStore,
accessManager: AccessManager): Unit
+ def stop(): Unit
+
def getServlet(basePath: String): Servlet
def getServletMappings: Seq[String]
http://git-wip-us.apache.org/repos/asf/incubator-livy/blob/47d3ee6b/thriftserver/server/pom.xml
----------------------------------------------------------------------
diff --git a/thriftserver/server/pom.xml b/thriftserver/server/pom.xml
index e1c26db..c08c3fd 100644
--- a/thriftserver/server/pom.xml
+++ b/thriftserver/server/pom.xml
@@ -52,33 +52,6 @@
</exclusion>
</exclusions>
</dependency>
- <dependency>
- <groupId>org.apache.hive</groupId>
- <artifactId>hive-exec</artifactId>
- <version>${hive.version}</version>
- <exclusions>
- <exclusion>
- <groupId>org.apache.hive</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j-impl</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-1.2-api</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.apache.hbase</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
<dependency>
<groupId>org.apache.livy</groupId>
@@ -125,6 +98,11 @@
<artifactId>libthrift</artifactId>
<version>${libthrift.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-common</artifactId>
+ <version>2.25.1</version>
+ </dependency>
<!-- needed for compiling successfully when using JobContext -->
<dependency>
@@ -141,8 +119,8 @@
<scope>test</scope>
<exclusions>
<exclusion>
- <groupId>org.apache.hive</groupId>
- <artifactId>*</artifactId>
+ <groupId>org.apache.zookeeper</groupId>
+ <artifactId>zookeeper</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
http://git-wip-us.apache.org/repos/asf/incubator-livy/blob/47d3ee6b/thriftserver/server/src/main/java/org/apache/hive/service/auth/HiveAuthFactory.java
----------------------------------------------------------------------
diff --git a/thriftserver/server/src/main/java/org/apache/hive/service/auth/HiveAuthFactory.java b/thriftserver/server/src/main/java/org/apache/hive/service/auth/HiveAuthFactory.java
deleted file mode 100644
index f2041e3..0000000
--- a/thriftserver/server/src/main/java/org/apache/hive/service/auth/HiveAuthFactory.java
+++ /dev/null
@@ -1,320 +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.hive.service.auth;
-
-import static org.apache.hadoop.fs.CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.security.auth.login.LoginException;
-import javax.security.sasl.AuthenticationException;
-import javax.security.sasl.Sasl;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hive.conf.HiveConf;
-import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
-import org.apache.hadoop.hive.conf.HiveConfUtil;
-import org.apache.hadoop.hive.ql.metadata.Hive;
-import org.apache.hadoop.hive.shims.HadoopShims.KerberosNameShim;
-import org.apache.hadoop.hive.shims.ShimLoader;
-import org.apache.hadoop.hive.metastore.security.DBTokenStore;
-import org.apache.hadoop.hive.metastore.security.DelegationTokenStore;
-import org.apache.hadoop.hive.metastore.security.HadoopThriftAuthBridge;
-import org.apache.hadoop.hive.metastore.security.MemoryTokenStore;
-import org.apache.hadoop.hive.metastore.security.MetastoreDelegationTokenManager;
-import org.apache.hadoop.hive.metastore.security.ZooKeeperTokenStore;
-import org.apache.hadoop.hive.metastore.utils.SecurityUtils;
-import org.apache.hadoop.security.SaslRpcServer.AuthMethod;
-import org.apache.hadoop.security.SecurityUtil;
-import org.apache.hadoop.security.UserGroupInformation;
-import org.apache.hadoop.security.authorize.ProxyUsers;
-import org.apache.hive.service.cli.HiveSQLException;
-import org.apache.hive.service.cli.thrift.ThriftCLIService;
-import org.apache.thrift.TProcessorFactory;
-import org.apache.thrift.transport.TSaslServerTransport;
-import org.apache.thrift.transport.TTransportException;
-import org.apache.thrift.transport.TTransportFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class helps in some aspects of authentication. It creates the proper Thrift classes for the
- * given configuration as well as helps with authenticating requests.
- */
-public class HiveAuthFactory {
- private static final Logger LOG = LoggerFactory.getLogger(HiveAuthFactory.class);
-
- private HadoopThriftAuthBridge.Server saslServer;
- private String authTypeStr;
- private final String transportMode;
- private final HiveConf conf;
- private String hadoopAuth;
- private MetastoreDelegationTokenManager delegationTokenManager = null;
-
- public HiveAuthFactory(HiveConf conf) throws TTransportException {
- this.conf = conf;
- transportMode = conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_TRANSPORT_MODE);
- authTypeStr = conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_AUTHENTICATION);
-
- // ShimLoader.getHadoopShims().isSecurityEnabled() will only check that
- // hadoopAuth is not simple, it does not guarantee it is kerberos
- hadoopAuth = conf.get(HADOOP_SECURITY_AUTHENTICATION, "simple");
-
- // In http mode we use NOSASL as the default auth type
- if (authTypeStr == null) {
- if ("http".equalsIgnoreCase(transportMode)) {
- authTypeStr = HiveAuthConstants.AuthTypes.NOSASL.getAuthName();
- } else {
- authTypeStr = HiveAuthConstants.AuthTypes.NONE.getAuthName();
- }
- }
- if (isSASLWithKerberizedHadoop()) {
- saslServer = new HadoopThriftAuthBridge.Server();
-
- // Start delegation token manager
- delegationTokenManager = new MetastoreDelegationTokenManager();
- try {
- Object baseHandler = null;
- String tokenStoreClass = SecurityUtils.getTokenStoreClassName(conf);
-
- if (tokenStoreClass.equals(DBTokenStore.class.getName())) {
- // IMetaStoreClient is needed to access token store if DBTokenStore is to be used. It
- // will be got via Hive.get(conf).getMSC in a thread where the DelegationTokenStore
- // is called. To avoid the cyclic reference, we pass the Hive class to DBTokenStore where
- // it is used to get a threadLocal Hive object with a synchronized MetaStoreClient using
- // Java reflection.
- // Note: there will be two HS2 life-long opened MSCs, one is stored in HS2 thread local
- // Hive object, the other is in a daemon thread spawned in DelegationTokenSecretManager
- // to remove expired tokens.
- baseHandler = Hive.class;
- }
-
- delegationTokenManager.startDelegationTokenSecretManager(conf, baseHandler,
- HadoopThriftAuthBridge.Server.ServerMode.HIVESERVER2);
- saslServer.setSecretManager(delegationTokenManager.getSecretManager());
- }
- catch (IOException e) {
- throw new TTransportException("Failed to start token manager", e);
- }
- }
- }
-
- public Map<String, String> getSaslProperties() {
- Map<String, String> saslProps = new HashMap<String, String>();
- SaslQOP saslQOP = SaslQOP.fromString(conf.getVar(ConfVars.HIVE_SERVER2_THRIFT_SASL_QOP));
- saslProps.put(Sasl.QOP, saslQOP.toString());
- saslProps.put(Sasl.SERVER_AUTH, "true");
- return saslProps;
- }
-
- public TTransportFactory getAuthTransFactory() throws LoginException {
- TTransportFactory transportFactory;
- TSaslServerTransport.Factory serverTransportFactory;
-
- if (isSASLWithKerberizedHadoop()) {
- try {
- serverTransportFactory = saslServer.createSaslServerTransportFactory(
- getSaslProperties());
- } catch (TTransportException e) {
- throw new LoginException(e.getMessage());
- }
- if (authTypeStr.equalsIgnoreCase(HiveAuthConstants.AuthTypes.KERBEROS.getAuthName())) {
- // no-op
- } else if (authTypeStr.equalsIgnoreCase(HiveAuthConstants.AuthTypes.NONE.getAuthName()) ||
- authTypeStr.equalsIgnoreCase(HiveAuthConstants.AuthTypes.LDAP.getAuthName()) ||
- authTypeStr.equalsIgnoreCase(HiveAuthConstants.AuthTypes.PAM.getAuthName()) ||
- authTypeStr.equalsIgnoreCase(HiveAuthConstants.AuthTypes.CUSTOM.getAuthName())) {
- try {
- serverTransportFactory.addServerDefinition("PLAIN",
- authTypeStr, null, new HashMap<String, String>(),
- new PlainSaslHelper.PlainServerCallbackHandler(authTypeStr));
- } catch (AuthenticationException e) {
- throw new LoginException ("Error setting callback handler" + e);
- }
- } else {
- throw new LoginException("Unsupported authentication type " + authTypeStr);
- }
- transportFactory = saslServer.wrapTransportFactory(serverTransportFactory);
- } else if (authTypeStr.equalsIgnoreCase(HiveAuthConstants.AuthTypes.NONE.getAuthName()) ||
- authTypeStr.equalsIgnoreCase(HiveAuthConstants.AuthTypes.LDAP.getAuthName()) ||
- authTypeStr.equalsIgnoreCase(HiveAuthConstants.AuthTypes.PAM.getAuthName()) ||
- authTypeStr.equalsIgnoreCase(HiveAuthConstants.AuthTypes.CUSTOM.getAuthName())) {
- transportFactory = PlainSaslHelper.getPlainTransportFactory(authTypeStr);
- } else if (authTypeStr.equalsIgnoreCase(HiveAuthConstants.AuthTypes.NOSASL.getAuthName())) {
- transportFactory = new TTransportFactory();
- } else {
- throw new LoginException("Unsupported authentication type " + authTypeStr);
- }
- return transportFactory;
- }
-
- /**
- * Returns the thrift processor factory for HiveServer2 running in binary mode
- * @param service
- * @return
- * @throws LoginException
- */
- public TProcessorFactory getAuthProcFactory(ThriftCLIService service) throws LoginException {
- if (isSASLWithKerberizedHadoop()) {
- return KerberosSaslHelper.getKerberosProcessorFactory(saslServer, service);
- } else {
- return PlainSaslHelper.getPlainProcessorFactory(service);
- }
- }
-
- public String getRemoteUser() {
- return saslServer == null ? null : saslServer.getRemoteUser();
- }
-
- public String getIpAddress() {
- if (saslServer == null || saslServer.getRemoteAddress() == null) {
- return null;
- } else {
- return saslServer.getRemoteAddress().getHostAddress();
- }
- }
-
- public String getUserAuthMechanism() {
- return saslServer == null ? null : saslServer.getUserAuthMechanism();
- }
-
- public boolean isSASLWithKerberizedHadoop() {
- return "kerberos".equalsIgnoreCase(hadoopAuth)
- && !authTypeStr.equalsIgnoreCase(HiveAuthConstants.AuthTypes.NOSASL.getAuthName());
- }
-
- public boolean isSASLKerberosUser() {
- return AuthMethod.KERBEROS.getMechanismName().equals(getUserAuthMechanism())
- || AuthMethod.TOKEN.getMechanismName().equals(getUserAuthMechanism());
- }
-
- // Perform SPNEGO login using the hadoop shim API if the configuration is available
- public static UserGroupInformation loginFromSpnegoKeytabAndReturnUGI(HiveConf hiveConf)
- throws IOException {
- String principal = hiveConf.getVar(ConfVars.HIVE_SERVER2_SPNEGO_PRINCIPAL);
- String keyTabFile = hiveConf.getVar(ConfVars.HIVE_SERVER2_SPNEGO_KEYTAB);
- if (principal.isEmpty() || keyTabFile.isEmpty()) {
- throw new IOException("HiveServer2 SPNEGO principal or keytab is not correctly configured");
- } else {
- return UserGroupInformation.loginUserFromKeytabAndReturnUGI(SecurityUtil.getServerPrincipal(principal, "0.0.0.0"), keyTabFile);
- }
- }
-
- // retrieve delegation token for the given user
- public String getDelegationToken(String owner, String renewer, String remoteAddr)
- throws HiveSQLException {
- if (delegationTokenManager == null) {
- throw new HiveSQLException(
- "Delegation token only supported over kerberos authentication", "08S01");
- }
-
- try {
- String tokenStr = delegationTokenManager.getDelegationTokenWithService(owner, renewer,
- HiveAuthConstants.HS2_CLIENT_TOKEN, remoteAddr);
- if (tokenStr == null || tokenStr.isEmpty()) {
- throw new HiveSQLException(
- "Received empty retrieving delegation token for user " + owner, "08S01");
- }
- return tokenStr;
- } catch (IOException e) {
- throw new HiveSQLException(
- "Error retrieving delegation token for user " + owner, "08S01", e);
- } catch (InterruptedException e) {
- throw new HiveSQLException("delegation token retrieval interrupted", "08S01", e);
- }
- }
-
- // cancel given delegation token
- public void cancelDelegationToken(String delegationToken) throws HiveSQLException {
- if (delegationTokenManager == null) {
- throw new HiveSQLException(
- "Delegation token only supported over kerberos authentication", "08S01");
- }
- try {
- delegationTokenManager.cancelDelegationToken(delegationToken);
- } catch (IOException e) {
- throw new HiveSQLException(
- "Error canceling delegation token " + delegationToken, "08S01", e);
- }
- }
-
- public void renewDelegationToken(String delegationToken) throws HiveSQLException {
- if (delegationTokenManager == null) {
- throw new HiveSQLException(
- "Delegation token only supported over kerberos authentication", "08S01");
- }
- try {
- delegationTokenManager.renewDelegationToken(delegationToken);
- } catch (IOException e) {
- throw new HiveSQLException(
- "Error renewing delegation token " + delegationToken, "08S01", e);
- }
- }
-
- public String verifyDelegationToken(String delegationToken) throws HiveSQLException {
- if (delegationTokenManager == null) {
- throw new HiveSQLException(
- "Delegation token only supported over kerberos authentication", "08S01");
- }
- try {
- return delegationTokenManager.verifyDelegationToken(delegationToken);
- } catch (IOException e) {
- String msg = "Error verifying delegation token " + delegationToken;
- LOG.error(msg, e);
- throw new HiveSQLException(msg, "08S01", e);
- }
- }
-
- public String getUserFromToken(String delegationToken) throws HiveSQLException {
- if (delegationTokenManager == null) {
- throw new HiveSQLException(
- "Delegation token only supported over kerberos authentication", "08S01");
- }
- try {
- return delegationTokenManager.getUserFromToken(delegationToken);
- } catch (IOException e) {
- throw new HiveSQLException(
- "Error extracting user from delegation token " + delegationToken, "08S01", e);
- }
- }
-
- public static void verifyProxyAccess(String realUser, String proxyUser, String ipAddress,
- HiveConf hiveConf) throws HiveSQLException {
- try {
- UserGroupInformation sessionUgi;
- if (UserGroupInformation.isSecurityEnabled()) {
- KerberosNameShim kerbName = ShimLoader.getHadoopShims().getKerberosNameShim(realUser);
- sessionUgi = UserGroupInformation.createProxyUser(
- kerbName.getServiceName(), UserGroupInformation.getLoginUser());
- } else {
- sessionUgi = UserGroupInformation.createRemoteUser(realUser);
- }
- if (!proxyUser.equalsIgnoreCase(realUser)) {
- ProxyUsers.refreshSuperUserGroupsConfiguration(hiveConf);
- ProxyUsers.authorize(UserGroupInformation.createProxyUser(proxyUser, sessionUgi),
- ipAddress, hiveConf);
- }
- } catch (IOException e) {
- throw new HiveSQLException(
- "Failed to validate proxy privilege of " + realUser + " for " + proxyUser, "08S01", e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-livy/blob/47d3ee6b/thriftserver/server/src/main/java/org/apache/hive/service/cli/ColumnBasedSet.java
----------------------------------------------------------------------
diff --git a/thriftserver/server/src/main/java/org/apache/hive/service/cli/ColumnBasedSet.java b/thriftserver/server/src/main/java/org/apache/hive/service/cli/ColumnBasedSet.java
deleted file mode 100644
index 0dbd239..0000000
--- a/thriftserver/server/src/main/java/org/apache/hive/service/cli/ColumnBasedSet.java
+++ /dev/null
@@ -1,205 +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.hive.service.cli;
-
-import java.io.ByteArrayInputStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.hadoop.hive.common.type.HiveDecimal;
-import org.apache.hadoop.hive.serde2.thrift.ColumnBuffer;
-import org.apache.hadoop.hive.serde2.thrift.Type;
-import org.apache.hive.service.rpc.thrift.TColumn;
-import org.apache.hive.service.rpc.thrift.TRow;
-import org.apache.hive.service.rpc.thrift.TRowSet;
-import org.apache.thrift.TException;
-import org.apache.thrift.protocol.TCompactProtocol;
-import org.apache.thrift.protocol.TProtocol;
-import org.apache.thrift.transport.TIOStreamTransport;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * ColumnBasedSet.
- */
-public class ColumnBasedSet implements RowSet {
-
- private long startOffset;
-
- private final TypeDescriptor[] descriptors; // non-null only for writing (server-side)
- private final List<ColumnBuffer> columns;
- private byte[] blob;
- private boolean isBlobBased = false;
- public static final Logger LOG = LoggerFactory.getLogger(ColumnBasedSet.class);
-
- public ColumnBasedSet(TableSchema schema) {
- descriptors = schema.toTypeDescriptors();
- columns = new ArrayList<ColumnBuffer>();
- for (ColumnDescriptor colDesc : schema.getColumnDescriptors()) {
- columns.add(new ColumnBuffer(colDesc.getType()));
- }
- }
-
- public ColumnBasedSet(TRowSet tRowSet) throws TException {
- descriptors = null;
- columns = new ArrayList<ColumnBuffer>();
- // Use TCompactProtocol to read serialized TColumns
- if (tRowSet.isSetBinaryColumns()) {
- TProtocol protocol =
- new TCompactProtocol(new TIOStreamTransport(new ByteArrayInputStream(
- tRowSet.getBinaryColumns())));
- // Read from the stream using the protocol for each column in final schema
- for (int i = 0; i < tRowSet.getColumnCount(); i++) {
- TColumn tvalue = new TColumn();
- try {
- tvalue.read(protocol);
- } catch (TException e) {
- LOG.error(e.getMessage(), e);
- throw new TException("Error reading column value from the row set blob", e);
- }
- columns.add(new ColumnBuffer(tvalue));
- }
- }
- else {
- if (tRowSet.getColumns() != null) {
- for (TColumn tvalue : tRowSet.getColumns()) {
- columns.add(new ColumnBuffer(tvalue));
- }
- }
- }
- startOffset = tRowSet.getStartRowOffset();
- }
-
- public ColumnBasedSet(TypeDescriptor[] descriptors, List<ColumnBuffer> columns, long startOffset) {
- this.descriptors = descriptors;
- this.columns = columns;
- this.startOffset = startOffset;
- }
-
- public ColumnBasedSet(TableSchema schema, boolean isBlobBased) {
- this(schema);
- this.isBlobBased = isBlobBased;
- }
-
- @Override
- public ColumnBasedSet addRow(Object[] fields) {
- if (isBlobBased) {
- this.blob = (byte[]) fields[0];
- } else {
- for (int i = 0; i < fields.length; i++) {
- TypeDescriptor descriptor = descriptors[i];
- Object field = fields[i];
- if (field != null && descriptor.getType() == Type.DECIMAL_TYPE) {
- int scale = descriptor.getDecimalDigits();
- field = ((HiveDecimal) field).toFormatString(scale);
- }
- columns.get(i).addValue(descriptor.getType(), field);
- }
- }
- return this;
- }
-
- public List<ColumnBuffer> getColumns() {
- return columns;
- }
-
- @Override
- public int numColumns() {
- return columns.size();
- }
-
- @Override
- public int numRows() {
- return columns.isEmpty() ? 0 : columns.get(0).size();
- }
-
- @Override
- public ColumnBasedSet extractSubset(int maxRows) {
- int numRows = Math.min(numRows(), maxRows);
-
- List<ColumnBuffer> subset = new ArrayList<ColumnBuffer>();
- for (int i = 0; i < columns.size(); i++) {
- subset.add(columns.get(i).extractSubset(numRows));
- }
- ColumnBasedSet result = new ColumnBasedSet(descriptors, subset, startOffset);
- startOffset += numRows;
- return result;
- }
-
- @Override
- public long getStartOffset() {
- return startOffset;
- }
-
- @Override
- public void setStartOffset(long startOffset) {
- this.startOffset = startOffset;
- }
-
- public TRowSet toTRowSet() {
- TRowSet tRowSet = new TRowSet(startOffset, new ArrayList<TRow>());
- if (isBlobBased) {
- tRowSet.setColumns(null);
- tRowSet.setBinaryColumns(blob);
- tRowSet.setColumnCount(numColumns());
- } else {
- for (int i = 0; i < columns.size(); i++) {
- tRowSet.addToColumns(columns.get(i).toTColumn());
- }
- }
- return tRowSet;
- }
-
- @Override
- public Iterator<Object[]> iterator() {
- return new Iterator<Object[]>() {
-
- private int index;
- private final Object[] convey = new Object[numColumns()];
-
- @Override
- public boolean hasNext() {
- return index < numRows();
- }
-
- @Override
- public Object[] next() {
- for (int i = 0; i < columns.size(); i++) {
- convey[i] = columns.get(i).get(index);
- }
- index++;
- return convey;
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException("remove");
- }
- };
- }
-
- public Object[] fill(int index, Object[] convey) {
- for (int i = 0; i < columns.size(); i++) {
- convey[i] = columns.get(i).get(index);
- }
- return convey;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-livy/blob/47d3ee6b/thriftserver/server/src/main/java/org/apache/hive/service/cli/JobProgressUpdate.java
----------------------------------------------------------------------
diff --git a/thriftserver/server/src/main/java/org/apache/hive/service/cli/JobProgressUpdate.java b/thriftserver/server/src/main/java/org/apache/hive/service/cli/JobProgressUpdate.java
deleted file mode 100644
index 5c3d8ce..0000000
--- a/thriftserver/server/src/main/java/org/apache/hive/service/cli/JobProgressUpdate.java
+++ /dev/null
@@ -1,55 +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.hive.service.cli;
-
-import org.apache.hadoop.hive.common.log.ProgressMonitor;
-
-import java.util.List;
-
-public class JobProgressUpdate {
- public final double progressedPercentage;
- public final String footerSummary;
- public final long startTimeMillis;
- private final List<String> headers;
- private final List<List<String>> rows;
- public final String status;
-
-
- public JobProgressUpdate(ProgressMonitor monitor) {
- this(monitor.headers(), monitor.rows(), monitor.footerSummary(), monitor.progressedPercentage(),
- monitor.startTime(), monitor.executionStatus());
- }
-
- private JobProgressUpdate(List<String> headers, List<List<String>> rows, String footerSummary,
- double progressedPercentage, long startTimeMillis, String status) {
- this.progressedPercentage = progressedPercentage;
- this.footerSummary = footerSummary;
- this.startTimeMillis = startTimeMillis;
- this.headers = headers;
- this.rows = rows;
- this.status = status;
- }
-
- public List<String> headers() {
- return headers;
- }
-
- public List<List<String>> rows() {
- return rows;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-livy/blob/47d3ee6b/thriftserver/server/src/main/java/org/apache/hive/service/cli/OperationStatus.java
----------------------------------------------------------------------
diff --git a/thriftserver/server/src/main/java/org/apache/hive/service/cli/OperationStatus.java b/thriftserver/server/src/main/java/org/apache/hive/service/cli/OperationStatus.java
deleted file mode 100644
index 663be4b..0000000
--- a/thriftserver/server/src/main/java/org/apache/hive/service/cli/OperationStatus.java
+++ /dev/null
@@ -1,75 +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.hive.service.cli;
-
-/**
- * OperationStatus
- *
- */
-public class OperationStatus {
-
- private final OperationState state;
- private final String taskStatus;
- private final long operationStarted;
- private final long operationCompleted;
- private final boolean hasResultSet;
- private final HiveSQLException operationException;
- private JobProgressUpdate jobProgressUpdate;
-
- public OperationStatus(OperationState state, String taskStatus, long operationStarted, long operationCompleted, boolean hasResultSet, HiveSQLException operationException) {
- this.state = state;
- this.taskStatus = taskStatus;
- this.operationStarted = operationStarted;
- this.operationCompleted = operationCompleted;
- this.hasResultSet = hasResultSet;
- this.operationException = operationException;
- }
-
- public OperationState getState() {
- return state;
- }
-
- public String getTaskStatus() {
- return taskStatus;
- }
-
- public long getOperationStarted() {
- return operationStarted;
- }
-
- public long getOperationCompleted() {
- return operationCompleted;
- }
-
- public boolean getHasResultSet() {
- return hasResultSet;
- }
-
- public HiveSQLException getOperationException() {
- return operationException;
- }
-
- public void setJobProgressUpdate(JobProgressUpdate jobProgressUpdate){
- this.jobProgressUpdate = jobProgressUpdate;
- }
-
- public JobProgressUpdate jobProgressUpdate(){
- return jobProgressUpdate;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-livy/blob/47d3ee6b/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/GetCatalogsOperation.java
----------------------------------------------------------------------
diff --git a/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/GetCatalogsOperation.java b/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/GetCatalogsOperation.java
deleted file mode 100644
index 02b7bf3..0000000
--- a/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/GetCatalogsOperation.java
+++ /dev/null
@@ -1,80 +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.hive.service.cli.operation;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-import org.apache.hive.service.cli.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * GetCatalogsOperation.
- *
- */
-public class GetCatalogsOperation extends MetadataOperation {
-
- private static final Logger LOG = LoggerFactory.getLogger(GetCatalogsOperation.class.getName());
-
- private static final TableSchema RESULT_SET_SCHEMA = new TableSchema()
- .addStringColumn("TABLE_CAT", "Catalog name. NULL if not applicable.");
-
- private final RowSet rowSet;
-
- public GetCatalogsOperation(SessionHandle sessionHandle) {
- super(sessionHandle, OperationType.GET_CATALOGS);
- rowSet = RowSetFactory.create(RESULT_SET_SCHEMA, getProtocolVersion(), false);
- LOG.info("Starting GetCatalogsOperation");
- }
-
- @Override
- public void runInternal() throws HiveSQLException {
- setState(OperationState.RUNNING);
- try {
- // catalogs are actually not supported in hive, so this is a no-op
- setState(OperationState.FINISHED);
- LOG.info("Fetching catalog metadata has been successfully finished");
- } catch (HiveSQLException e) {
- setState(OperationState.ERROR);
- throw e;
- }
- }
-
- /* (non-Javadoc)
- * @see org.apache.hive.service.cli.Operation#getResultSetSchema()
- */
- @Override
- public TableSchema getResultSetSchema() throws HiveSQLException {
- return RESULT_SET_SCHEMA;
- }
-
- /* (non-Javadoc)
- * @see org.apache.hive.service.cli.Operation#getNextRowSet(org.apache.hive.service.cli.FetchOrientation, long)
- */
- @Override
- public RowSet getNextRowSet(FetchOrientation orientation, long maxRows) throws HiveSQLException {
- assertState(new ArrayList<OperationState>(Arrays.asList(OperationState.FINISHED)));
- validateDefaultFetchOrientation(orientation);
- if (orientation.equals(FetchOrientation.FETCH_FIRST)) {
- rowSet.setStartOffset(0);
- }
- return rowSet.extractSubset((int)maxRows);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-livy/blob/47d3ee6b/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/GetTableTypesOperation.java
----------------------------------------------------------------------
diff --git a/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/GetTableTypesOperation.java b/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/GetTableTypesOperation.java
deleted file mode 100644
index 0f3cc24..0000000
--- a/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/GetTableTypesOperation.java
+++ /dev/null
@@ -1,101 +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.hive.service.cli.operation;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-import org.apache.hadoop.hive.conf.HiveConf;
-import org.apache.hadoop.hive.metastore.TableType;
-import org.apache.hive.service.cli.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.livy.thriftserver.LivyThriftServer$;
-
-/**
- * GetTableTypesOperation.
- *
- */
-public class GetTableTypesOperation extends MetadataOperation {
-
- private static final Logger LOG = LoggerFactory.getLogger(GetTableTypesOperation.class.getName());
-
- protected static TableSchema RESULT_SET_SCHEMA = new TableSchema()
- .addStringColumn("TABLE_TYPE", "Table type name.");
-
- private final RowSet rowSet;
- private final TableTypeMapping tableTypeMapping;
-
- public GetTableTypesOperation(SessionHandle sessionHandle) {
- super(sessionHandle, OperationType.GET_TABLE_TYPES);
- String tableMappingStr = LivyThriftServer$.MODULE$.getInstance().get().getHiveConf()
- .getVar(HiveConf.ConfVars.HIVE_SERVER2_TABLE_TYPE_MAPPING);
- tableTypeMapping = TableTypeMappingFactory.getTableTypeMapping(tableMappingStr);
- rowSet = RowSetFactory.create(RESULT_SET_SCHEMA, getProtocolVersion(), false);
- LOG.info("Starting GetTableTypesOperation");
- }
-
- @Override
- public void runInternal() throws HiveSQLException {
- setState(OperationState.RUNNING);
- LOG.info("Fetching table type metadata");
- try {
- for (TableType type : TableType.values()) {
- String tableType = tableTypeMapping.mapToClientType(type.toString());
- rowSet.addRow(new String[] {tableType});
- if (LOG.isDebugEnabled()) {
- String debugMessage = getDebugMessage("table type", RESULT_SET_SCHEMA);
- LOG.debug(debugMessage, tableType);
- }
- }
- if (LOG.isDebugEnabled() && rowSet.numRows() == 0) {
- LOG.debug("No table type metadata has been returned.");
- }
- setState(OperationState.FINISHED);
- LOG.info("Fetching table type metadata has been successfully finished");
- } catch (Exception e) {
- setState(OperationState.ERROR);
- throw new HiveSQLException(e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.apache.hive.service.cli.Operation#getResultSetSchema()
- */
- @Override
- public TableSchema getResultSetSchema() throws HiveSQLException {
- assertState(new ArrayList<OperationState>(Arrays.asList(OperationState.FINISHED)));
- return RESULT_SET_SCHEMA;
- }
-
- /* (non-Javadoc)
- * @see org.apache.hive.service.cli.Operation#getNextRowSet(org.apache.hive.service.cli.FetchOrientation, long)
- */
- @Override
- public RowSet getNextRowSet(FetchOrientation orientation, long maxRows) throws HiveSQLException {
- assertState(new ArrayList<OperationState>(Arrays.asList(OperationState.FINISHED)));
- validateDefaultFetchOrientation(orientation);
- if (orientation.equals(FetchOrientation.FETCH_FIRST)) {
- rowSet.setStartOffset(0);
- }
- return rowSet.extractSubset((int)maxRows);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-livy/blob/47d3ee6b/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/GetTypeInfoOperation.java
----------------------------------------------------------------------
diff --git a/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/GetTypeInfoOperation.java b/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/GetTypeInfoOperation.java
deleted file mode 100644
index 501a2a9..0000000
--- a/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/GetTypeInfoOperation.java
+++ /dev/null
@@ -1,147 +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.hive.service.cli.operation;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-import org.apache.hadoop.hive.serde2.thrift.Type;
-import org.apache.hive.service.cli.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * GetTypeInfoOperation.
- *
- */
-public class GetTypeInfoOperation extends MetadataOperation {
-
- private static final Logger LOG = LoggerFactory.getLogger(GetTypeInfoOperation.class.getName());
-
- private final static TableSchema RESULT_SET_SCHEMA = new TableSchema()
- .addPrimitiveColumn("TYPE_NAME", Type.STRING_TYPE,
- "Type name")
- .addPrimitiveColumn("DATA_TYPE", Type.INT_TYPE,
- "SQL data type from java.sql.Types")
- .addPrimitiveColumn("PRECISION", Type.INT_TYPE,
- "Maximum precision")
- .addPrimitiveColumn("LITERAL_PREFIX", Type.STRING_TYPE,
- "Prefix used to quote a literal (may be null)")
- .addPrimitiveColumn("LITERAL_SUFFIX", Type.STRING_TYPE,
- "Suffix used to quote a literal (may be null)")
- .addPrimitiveColumn("CREATE_PARAMS", Type.STRING_TYPE,
- "Parameters used in creating the type (may be null)")
- .addPrimitiveColumn("NULLABLE", Type.SMALLINT_TYPE,
- "Can you use NULL for this type")
- .addPrimitiveColumn("CASE_SENSITIVE", Type.BOOLEAN_TYPE,
- "Is it case sensitive")
- .addPrimitiveColumn("SEARCHABLE", Type.SMALLINT_TYPE,
- "Can you use \"WHERE\" based on this type")
- .addPrimitiveColumn("UNSIGNED_ATTRIBUTE", Type.BOOLEAN_TYPE,
- "Is it unsigned")
- .addPrimitiveColumn("FIXED_PREC_SCALE", Type.BOOLEAN_TYPE,
- "Can it be a money value")
- .addPrimitiveColumn("AUTO_INCREMENT", Type.BOOLEAN_TYPE,
- "Can it be used for an auto-increment value")
- .addPrimitiveColumn("LOCAL_TYPE_NAME", Type.STRING_TYPE,
- "Localized version of type name (may be null)")
- .addPrimitiveColumn("MINIMUM_SCALE", Type.SMALLINT_TYPE,
- "Minimum scale supported")
- .addPrimitiveColumn("MAXIMUM_SCALE", Type.SMALLINT_TYPE,
- "Maximum scale supported")
- .addPrimitiveColumn("SQL_DATA_TYPE", Type.INT_TYPE,
- "Unused")
- .addPrimitiveColumn("SQL_DATETIME_SUB", Type.INT_TYPE,
- "Unused")
- .addPrimitiveColumn("NUM_PREC_RADIX", Type.INT_TYPE,
- "Usually 2 or 10");
-
- private final RowSet rowSet;
-
- public GetTypeInfoOperation(SessionHandle sessionHandle) {
- super(sessionHandle, OperationType.GET_TYPE_INFO);
- rowSet = RowSetFactory.create(RESULT_SET_SCHEMA, getProtocolVersion(), false);
- LOG.info("Starting GetTypeInfoOperation");
- }
-
- @Override
- public void runInternal() throws HiveSQLException {
- setState(OperationState.RUNNING);
- LOG.info("Fetching type info metadata");
- try {
- for (Type type : Type.values()) {
- Object[] rowData = new Object[] {
- type.getName(), // TYPE_NAME
- type.toJavaSQLType(), // DATA_TYPE
- type.getMaxPrecision(), // PRECISION
- type.getLiteralPrefix(), // LITERAL_PREFIX
- type.getLiteralSuffix(), // LITERAL_SUFFIX
- type.getCreateParams(), // CREATE_PARAMS
- type.getNullable(), // NULLABLE
- type.isCaseSensitive(), // CASE_SENSITIVE
- type.getSearchable(), // SEARCHABLE
- type.isUnsignedAttribute(), // UNSIGNED_ATTRIBUTE
- type.isFixedPrecScale(), // FIXED_PREC_SCALE
- type.isAutoIncrement(), // AUTO_INCREMENT
- type.getLocalizedName(), // LOCAL_TYPE_NAME
- type.getMinimumScale(), // MINIMUM_SCALE
- type.getMaximumScale(), // MAXIMUM_SCALE
- null, // SQL_DATA_TYPE, unused
- null, // SQL_DATETIME_SUB, unused
- type.getNumPrecRadix() //NUM_PREC_RADIX
- };
- rowSet.addRow(rowData);
- if (LOG.isDebugEnabled()) {
- String debugMessage = getDebugMessage("type info", RESULT_SET_SCHEMA);
- LOG.debug(debugMessage, rowData);
- }
- }
- if (LOG.isDebugEnabled() && rowSet.numRows() == 0) {
- LOG.debug("No type info metadata has been returned.");
- }
- setState(OperationState.FINISHED);
- LOG.info("Fetching type info metadata has been successfully finished");
- } catch (Exception e) {
- setState(OperationState.ERROR);
- throw new HiveSQLException(e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.apache.hive.service.cli.Operation#getResultSetSchema()
- */
- @Override
- public TableSchema getResultSetSchema() throws HiveSQLException {
- assertState(new ArrayList<OperationState>(Arrays.asList(OperationState.FINISHED)));
- return RESULT_SET_SCHEMA;
- }
-
- /* (non-Javadoc)
- * @see org.apache.hive.service.cli.Operation#getNextRowSet(org.apache.hive.service.cli.FetchOrientation, long)
- */
- @Override
- public RowSet getNextRowSet(FetchOrientation orientation, long maxRows) throws HiveSQLException {
- assertState(new ArrayList<OperationState>(Arrays.asList(OperationState.FINISHED)));
- validateDefaultFetchOrientation(orientation);
- if (orientation.equals(FetchOrientation.FETCH_FIRST)) {
- rowSet.setStartOffset(0);
- }
- return rowSet.extractSubset((int)maxRows);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-livy/blob/47d3ee6b/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/HiveTableTypeMapping.java
----------------------------------------------------------------------
diff --git a/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/HiveTableTypeMapping.java b/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/HiveTableTypeMapping.java
deleted file mode 100644
index 6bf2507..0000000
--- a/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/HiveTableTypeMapping.java
+++ /dev/null
@@ -1,61 +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.hive.service.cli.operation;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.hadoop.hive.metastore.TableType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * HiveTableTypeMapping.
- * Default table type mapping
- *
- */
-public class HiveTableTypeMapping implements TableTypeMapping {
-
- private static final Logger LOG = LoggerFactory.getLogger(HiveTableTypeMapping.class);
-
- @Override
- public String[] mapToHiveType(String clientTypeName) {
- return new String[] {mapToClientType(clientTypeName)};
- }
-
- @Override
- public String mapToClientType(String hiveTypeName) {
- try {
- TableType hiveType = TableType.valueOf(hiveTypeName.toUpperCase());
- return hiveType.name();
- } catch (IllegalArgumentException e) {
- LOG.warn("Invalid hive table type " + hiveTypeName);
- return hiveTypeName;
- }
- }
-
- @Override
- public Set<String> getTableTypeNames() {
- Set<String> typeNameSet = new HashSet<String>();
- for (TableType typeNames : TableType.values()) {
- typeNameSet.add(typeNames.name());
- }
- return typeNameSet;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-livy/blob/47d3ee6b/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/MetadataOperation.java
----------------------------------------------------------------------
diff --git a/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/MetadataOperation.java b/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/MetadataOperation.java
deleted file mode 100644
index 553a283..0000000
--- a/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/MetadataOperation.java
+++ /dev/null
@@ -1,133 +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.hive.service.cli.operation;
-
-import org.apache.hive.service.cli.ColumnDescriptor;
-import org.apache.hive.service.cli.HiveSQLException;
-import org.apache.hive.service.cli.OperationState;
-import org.apache.hive.service.cli.OperationType;
-import org.apache.hive.service.cli.SessionHandle;
-import org.apache.hive.service.cli.TableSchema;
-
-/**
- * MetadataOperation.
- *
- */
-public abstract class MetadataOperation extends Operation {
-
- protected static final String DEFAULT_HIVE_CATALOG = "";
-
- protected MetadataOperation(SessionHandle sessionHandle, OperationType opType) {
- super(sessionHandle, opType);
- setHasResultSet(true);
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.hive.service.cli.Operation#close()
- */
- @Override
- public void close() throws HiveSQLException {
- setState(OperationState.CLOSED);
- }
-
- /**
- * Convert wildchars and escape sequence from JDBC format to datanucleous/regex
- */
- protected String convertIdentifierPattern(final String pattern, boolean datanucleusFormat) {
- if (pattern == null) {
- return convertPattern("%", true);
- } else {
- return convertPattern(pattern, datanucleusFormat);
- }
- }
-
- /**
- * Convert wildchars and escape sequence of schema pattern from JDBC format to datanucleous/regex
- * The schema pattern treats empty string also as wildchar
- */
- protected String convertSchemaPattern(final String pattern) {
- if ((pattern == null) || pattern.isEmpty()) {
- return convertPattern("%", true);
- } else {
- return convertPattern(pattern, true);
- }
- }
-
- /**
- * Convert a pattern containing JDBC catalog search wildcards into
- * Java regex patterns.
- *
- * @param pattern input which may contain '%' or '_' wildcard characters, or
- * these characters escaped using {@link #getSearchStringEscape()}.
- * @return replace %/_ with regex search characters, also handle escaped
- * characters.
- *
- * The datanucleus module expects the wildchar as '*'. The columns search on the
- * other hand is done locally inside the hive code and that requires the regex wildchar
- * format '.*' This is driven by the datanucleusFormat flag.
- */
- private String convertPattern(String pattern, boolean datanucleusFormat) {
- String wStr;
- if (datanucleusFormat) {
- wStr = "*";
- } else {
- wStr = ".*";
- }
- pattern = replaceAll(pattern, "([^\\\\])%", "$1" + wStr);
- pattern = replaceAll(pattern, "\\\\%", "%");
- pattern = replaceAll(pattern, "^%", wStr);
- pattern = replaceAll(pattern, "([^\\\\])_", "$1.");
- pattern = replaceAll(pattern, "\\\\_", "_");
- pattern = replaceAll(pattern, "^_", ".");
- return pattern;
- }
-
- private String replaceAll(String input, final String pattern, final String replace) {
- while (true) {
- String replaced = input.replaceAll(pattern, replace);
- if (replaced.equals(input)) {
- return replaced;
- }
- input = replaced;
- }
- }
-
- @Override
- public void cancel(OperationState stateAfterCancel) throws HiveSQLException {
- throw new UnsupportedOperationException("MetadataOperation.cancel()");
- }
-
- protected String getDebugMessage(final String type, final TableSchema resultSetSchema) {
- StringBuilder debugMessage = new StringBuilder();
- debugMessage.append("Returning ");
- debugMessage.append(type);
- debugMessage.append(" metadata: ");
- boolean firstColumn = true;
- for (ColumnDescriptor column : resultSetSchema.getColumnDescriptors()) {
- if (!firstColumn) {
- debugMessage.append(", ");
- }
- debugMessage.append(column.getName());
- debugMessage.append("={}");
- firstColumn = false;
- }
- return debugMessage.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-livy/blob/47d3ee6b/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/Operation.java
----------------------------------------------------------------------
diff --git a/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/Operation.java b/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/Operation.java
deleted file mode 100644
index 9a3b516..0000000
--- a/thriftserver/server/src/main/java/org/apache/hive/service/cli/operation/Operation.java
+++ /dev/null
@@ -1,290 +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.hive.service.cli.operation;
-
-import java.util.EnumSet;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.hadoop.hive.conf.HiveConf;
-import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse;
-import org.apache.hive.service.cli.FetchOrientation;
-import org.apache.hive.service.cli.HiveSQLException;
-import org.apache.hive.service.cli.OperationHandle;
-import org.apache.hive.service.cli.OperationState;
-import org.apache.hive.service.cli.OperationStatus;
-import org.apache.hive.service.cli.OperationType;
-import org.apache.hive.service.cli.RowSet;
-import org.apache.hive.service.cli.SessionHandle;
-import org.apache.hive.service.cli.TableSchema;
-import org.apache.hive.service.rpc.thrift.TProtocolVersion;
-import org.apache.livy.thriftserver.LivyThriftServer$;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class Operation {
- protected final SessionHandle sessionHandle;
- private volatile OperationState state = OperationState.INITIALIZED;
- private final OperationHandle opHandle;
- public static final FetchOrientation DEFAULT_FETCH_ORIENTATION = FetchOrientation.FETCH_NEXT;
- public static final Logger LOG = LoggerFactory.getLogger(Operation.class.getName());
- protected boolean hasResultSet;
- protected volatile HiveSQLException operationException;
- protected volatile Future<?> backgroundHandle;
- private ScheduledExecutorService scheduledExecutorService;
-
- private long operationTimeout;
- private volatile long lastAccessTime;
- private final long beginTime;
-
- protected long operationStart;
- protected long operationComplete;
-
- protected static final EnumSet<FetchOrientation> DEFAULT_FETCH_ORIENTATION_SET =
- EnumSet.of(FetchOrientation.FETCH_NEXT,FetchOrientation.FETCH_FIRST);
-
-
- protected Operation(SessionHandle sessionHandle, OperationType opType) {
- this(sessionHandle, null, opType);
- }
-
- protected Operation(SessionHandle sessionHandle,
- Map<String, String> confOverlay, OperationType opType) {
- this.sessionHandle = sessionHandle;
- this.opHandle = new OperationHandle(opType, sessionHandle.getProtocolVersion());
- beginTime = System.currentTimeMillis();
- lastAccessTime = beginTime;
- HiveConf conf = LivyThriftServer$.MODULE$.getInstance().get().getHiveConf();
- operationTimeout = HiveConf.getTimeVar(conf,
- HiveConf.ConfVars.HIVE_SERVER2_IDLE_OPERATION_TIMEOUT, TimeUnit.MILLISECONDS);
- scheduledExecutorService = Executors.newScheduledThreadPool(1);
-
- }
-
- public Future<?> getBackgroundHandle() {
- return backgroundHandle;
- }
-
- protected void setBackgroundHandle(Future<?> backgroundHandle) {
- this.backgroundHandle = backgroundHandle;
- }
-
- public boolean shouldRunAsync() {
- return false; // Most operations cannot run asynchronously.
- }
-
- public SessionHandle getSessionHandle() {
- return sessionHandle;
- }
-
- public OperationHandle getHandle() {
- return opHandle;
- }
-
- public TProtocolVersion getProtocolVersion() {
- return opHandle.getProtocolVersion();
- }
-
- public OperationType getType() {
- return opHandle.getOperationType();
- }
-
- public OperationStatus getStatus() {
- String taskStatus = null;
- try {
- taskStatus = getTaskStatus();
- } catch (HiveSQLException sqlException) {
- LOG.error("Error getting task status for " + opHandle.toString(), sqlException);
- }
- return new OperationStatus(state, taskStatus, operationStart, operationComplete, hasResultSet, operationException);
- }
-
- public boolean hasResultSet() {
- return hasResultSet;
- }
-
- protected void setHasResultSet(boolean hasResultSet) {
- this.hasResultSet = hasResultSet;
- opHandle.setHasResultSet(hasResultSet);
- }
-
- protected final OperationState setState(OperationState newState) throws HiveSQLException {
- state.validateTransition(newState);
- OperationState prevState = state;
- this.state = newState;
- onNewState(state, prevState);
- this.lastAccessTime = System.currentTimeMillis();
- return this.state;
- }
-
- public boolean isTimedOut(long current) {
- if (operationTimeout == 0) {
- return false;
- }
- if (operationTimeout > 0) {
- // check only when it's in terminal state
- return state.isTerminal() && lastAccessTime + operationTimeout <= current;
- }
- return lastAccessTime + -operationTimeout <= current;
- }
-
- public long getLastAccessTime() {
- return lastAccessTime;
- }
-
- public long getOperationTimeout() {
- return operationTimeout;
- }
-
- public void setOperationTimeout(long operationTimeout) {
- this.operationTimeout = operationTimeout;
- }
-
- protected void setOperationException(HiveSQLException operationException) {
- this.operationException = operationException;
- }
-
- protected final void assertState(List<OperationState> states) throws HiveSQLException {
- if (!states.contains(state)) {
- throw new HiveSQLException("Expected states: " + states.toString() + ", but found "
- + this.state);
- }
- this.lastAccessTime = System.currentTimeMillis();
- }
-
- public boolean isDone() {
- return state.isTerminal();
- }
-
- /**
- * Invoked before runInternal().
- * Set up some preconditions, or configurations.
- */
- protected void beforeRun() {
- // For Livy operations, this currently does nothing
- }
-
- /**
- * Invoked after runInternal(), even if an exception is thrown in runInternal().
- * Clean up resources, which was set up in beforeRun().
- */
- protected void afterRun() {
- // For Livy operations, this currently does nothing
- }
-
- /**
- * Implemented by subclass of Operation class to execute specific behaviors.
- * @throws HiveSQLException
- */
- protected abstract void runInternal() throws HiveSQLException;
-
- public void run() throws HiveSQLException {
- beforeRun();
- try {
- runInternal();
- } finally {
- afterRun();
- }
- }
-
- public abstract void cancel(OperationState stateAfterCancel) throws HiveSQLException;
-
- public abstract void close() throws HiveSQLException;
-
- public abstract TableSchema getResultSetSchema() throws HiveSQLException;
-
- public abstract RowSet getNextRowSet(FetchOrientation orientation, long maxRows) throws HiveSQLException;
-
- public String getTaskStatus() throws HiveSQLException {
- return null;
- }
-
- /**
- * Verify if the given fetch orientation is part of the default orientation types.
- * @param orientation
- * @throws HiveSQLException
- */
- protected void validateDefaultFetchOrientation(FetchOrientation orientation)
- throws HiveSQLException {
- validateFetchOrientation(orientation, DEFAULT_FETCH_ORIENTATION_SET);
- }
-
- /**
- * Verify if the given fetch orientation is part of the supported orientation types.
- * @param orientation
- * @param supportedOrientations
- * @throws HiveSQLException
- */
- protected void validateFetchOrientation(FetchOrientation orientation,
- EnumSet<FetchOrientation> supportedOrientations) throws HiveSQLException {
- if (!supportedOrientations.contains(orientation)) {
- throw new HiveSQLException("The fetch type " + orientation.toString() +
- " is not supported for this resultset", "HY106");
- }
- }
-
- protected HiveSQLException toSQLException(String prefix, CommandProcessorResponse response) {
- HiveSQLException ex = new HiveSQLException(prefix + ": " + response.getErrorMessage(),
- response.getSQLState(), response.getResponseCode());
- if (response.getException() != null) {
- ex.initCause(response.getException());
- }
- return ex;
- }
-
- public long getBeginTime() {
- return beginTime;
- }
-
- protected OperationState getState() {
- return state;
- }
-
- protected void onNewState(OperationState state, OperationState prevState) {
- switch(state) {
- case RUNNING:
- markOperationStartTime();
- break;
- case ERROR:
- case FINISHED:
- case CANCELED:
- markOperationCompletedTime();
- break;
- }
- }
-
- public long getOperationComplete() {
- return operationComplete;
- }
-
- public long getOperationStart() {
- return operationStart;
- }
-
- protected void markOperationStartTime() {
- operationStart = System.currentTimeMillis();
- }
-
- protected void markOperationCompletedTime() {
- operationComplete = System.currentTimeMillis();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-livy/blob/47d3ee6b/thriftserver/server/src/main/java/org/apache/hive/service/cli/thrift/ThriftBinaryCLIService.java
----------------------------------------------------------------------
diff --git a/thriftserver/server/src/main/java/org/apache/hive/service/cli/thrift/ThriftBinaryCLIService.java b/thriftserver/server/src/main/java/org/apache/hive/service/cli/thrift/ThriftBinaryCLIService.java
deleted file mode 100644
index 7873e33..0000000
--- a/thriftserver/server/src/main/java/org/apache/hive/service/cli/thrift/ThriftBinaryCLIService.java
+++ /dev/null
@@ -1,167 +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.hive.service.cli.thrift;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.SynchronousQueue;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.hadoop.hive.common.auth.HiveAuthUtils;
-import org.apache.hadoop.hive.conf.HiveConf;
-import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
-import org.apache.hadoop.hive.shims.ShimLoader;
-import org.apache.hive.service.auth.HiveAuthFactory;
-import org.apache.hive.service.cli.HiveSQLException;
-import org.apache.hive.service.cli.ICLIService;
-import org.apache.hive.service.cli.SessionHandle;
-import org.apache.hive.service.server.ThreadFactoryWithGarbageCleanup;
-import org.apache.thrift.TProcessorFactory;
-import org.apache.thrift.protocol.TBinaryProtocol;
-import org.apache.thrift.protocol.TProtocol;
-import org.apache.thrift.server.ServerContext;
-import org.apache.thrift.server.TServer;
-import org.apache.thrift.server.TServerEventHandler;
-import org.apache.thrift.server.TThreadPoolServer;
-import org.apache.thrift.transport.TServerSocket;
-import org.apache.thrift.transport.TTransport;
-import org.apache.thrift.transport.TTransportFactory;
-
-
-public class ThriftBinaryCLIService extends ThriftCLIService {
- private final Runnable oomHook;
- protected TServer server;
-
- public ThriftBinaryCLIService(ICLIService cliService, Runnable oomHook) {
- super(cliService, ThriftBinaryCLIService.class.getSimpleName());
- this.oomHook = oomHook;
- }
-
- @Override
- protected void initServer() {
- try {
- // Server thread pool
- String threadPoolName = "HiveServer2-Handler-Pool";
- ExecutorService executorService = new ThreadPoolExecutorWithOomHook(minWorkerThreads, maxWorkerThreads,
- workerKeepAliveTime, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
- new ThreadFactoryWithGarbageCleanup(threadPoolName), oomHook);
-
- // Thrift configs
- hiveAuthFactory = new HiveAuthFactory(hiveConf);
- TTransportFactory transportFactory = hiveAuthFactory.getAuthTransFactory();
- TProcessorFactory processorFactory = hiveAuthFactory.getAuthProcFactory(this);
- TServerSocket serverSocket = null;
- List<String> sslVersionBlacklist = new ArrayList<String>();
- for (String sslVersion : hiveConf.getVar(ConfVars.HIVE_SSL_PROTOCOL_BLACKLIST).split(",")) {
- sslVersionBlacklist.add(sslVersion);
- }
- if (!hiveConf.getBoolVar(ConfVars.HIVE_SERVER2_USE_SSL)) {
- serverSocket = HiveAuthUtils.getServerSocket(hiveHost, portNum);
- } else {
- String keyStorePath = hiveConf.getVar(ConfVars.HIVE_SERVER2_SSL_KEYSTORE_PATH).trim();
- if (keyStorePath.isEmpty()) {
- throw new IllegalArgumentException(
- ConfVars.HIVE_SERVER2_SSL_KEYSTORE_PATH.varname + " Not configured for SSL connection");
- }
- String keyStorePassword = ShimLoader.getHadoopShims().getPassword(hiveConf,
- HiveConf.ConfVars.HIVE_SERVER2_SSL_KEYSTORE_PASSWORD.varname);
- serverSocket = HiveAuthUtils.getServerSSLSocket(hiveHost, portNum, keyStorePath, keyStorePassword,
- sslVersionBlacklist);
- }
-
- // Server args
- int maxMessageSize = hiveConf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_MAX_MESSAGE_SIZE);
- int requestTimeout = (int) hiveConf.getTimeVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_LOGIN_TIMEOUT,
- TimeUnit.SECONDS);
- int beBackoffSlotLength = (int) hiveConf
- .getTimeVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_LOGIN_BEBACKOFF_SLOT_LENGTH, TimeUnit.MILLISECONDS);
- TThreadPoolServer.Args sargs = new TThreadPoolServer.Args(serverSocket).processorFactory(processorFactory)
- .transportFactory(transportFactory).protocolFactory(new TBinaryProtocol.Factory())
- .inputProtocolFactory(new TBinaryProtocol.Factory(true, true, maxMessageSize, maxMessageSize))
- .requestTimeout(requestTimeout).requestTimeoutUnit(TimeUnit.SECONDS).beBackoffSlotLength(beBackoffSlotLength)
- .beBackoffSlotLengthUnit(TimeUnit.MILLISECONDS).executorService(executorService);
-
- // TCP Server
- server = new TThreadPoolServer(sargs);
- server.setServerEventHandler(new TServerEventHandler() {
- @Override
- public ServerContext createContext(TProtocol input, TProtocol output) {
- return new ThriftCLIServerContext();
- }
-
- @Override
- public void deleteContext(ServerContext serverContext, TProtocol input, TProtocol output) {
- ThriftCLIServerContext context = (ThriftCLIServerContext) serverContext;
- SessionHandle sessionHandle = context.getSessionHandle();
- if (sessionHandle != null) {
- LOG.info("Session disconnected without closing properly. ");
- try {
- boolean close = hiveConf.getBoolVar(ConfVars.HIVE_SERVER2_CLOSE_SESSION_ON_DISCONNECT);
- LOG.info("Closing the session: " + sessionHandle);
- if (close) {
- cliService.closeSession(sessionHandle);
- }
- } catch (HiveSQLException e) {
- LOG.warn("Failed to close session: " + e, e);
- }
- }
- }
-
- @Override
- public void preServe() {
- }
-
- @Override
- public void processContext(ServerContext serverContext, TTransport input, TTransport output) {
- currentServerContext.set(serverContext);
- }
- });
- String msg = "Starting " + ThriftBinaryCLIService.class.getSimpleName() + " on port " + portNum + " with "
- + minWorkerThreads + "..." + maxWorkerThreads + " worker threads";
- LOG.info(msg);
- } catch (Exception e) {
- throw new RuntimeException("Failed to init thrift server", e);
- }
- }
-
- @Override
- public void run() {
- try {
- server.serve();
- } catch (Throwable t) {
- if (t instanceof InterruptedException) {
- // This is likely a shutdown
- LOG.info("Caught " + t.getClass().getSimpleName() + ". Shutting down.");
- } else {
- LOG.error("Exception caught by " + this.getClass().getSimpleName() +
- ". Exiting.", t);
- }
- System.exit(-1);
- }
- }
-
- @Override
- protected void stopServer() {
- server.stop();
- server = null;
- LOG.info("Thrift server has stopped");
- }
-
-}