diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java b/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java index b3dd0ae..3f64ecb 100644 --- a/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java +++ b/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java @@ -24,6 +24,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; +import java.nio.ByteBuffer; import java.security.KeyStore; import java.security.SecureRandom; import java.sql.Array; @@ -58,6 +59,10 @@ import javax.security.sasl.Sasl; import javax.security.sasl.SaslException; +import org.apache.hive.service.cli.GetInfoValue; +import org.apache.hive.service.cli.HandleIdentifier; +import org.apache.hive.service.cli.HiveSQLException; +import org.apache.hive.service.cli.thrift.*; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.protocol.HttpContext; import org.apache.commons.logging.Log; @@ -68,19 +73,6 @@ import org.apache.hive.service.auth.KerberosSaslHelper; import org.apache.hive.service.auth.PlainSaslHelper; import org.apache.hive.service.auth.SaslQOP; -import org.apache.hive.service.cli.thrift.EmbeddedThriftBinaryCLIService; -import org.apache.hive.service.cli.thrift.TCLIService; -import org.apache.hive.service.cli.thrift.TCancelDelegationTokenReq; -import org.apache.hive.service.cli.thrift.TCancelDelegationTokenResp; -import org.apache.hive.service.cli.thrift.TCloseSessionReq; -import org.apache.hive.service.cli.thrift.TGetDelegationTokenReq; -import org.apache.hive.service.cli.thrift.TGetDelegationTokenResp; -import org.apache.hive.service.cli.thrift.TOpenSessionReq; -import org.apache.hive.service.cli.thrift.TOpenSessionResp; -import org.apache.hive.service.cli.thrift.TProtocolVersion; -import org.apache.hive.service.cli.thrift.TRenewDelegationTokenReq; -import org.apache.hive.service.cli.thrift.TRenewDelegationTokenResp; -import org.apache.hive.service.cli.thrift.TSessionHandle; import org.apache.http.HttpRequestInterceptor; import org.apache.http.HttpResponse; import org.apache.http.client.CookieStore; @@ -158,12 +150,24 @@ public HiveConnection(String uri, Properties info) throws SQLException { } } + // add supported protocols + supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V1); + supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V2); + supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V3); + supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V4); + supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V5); + supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V6); + supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V7); + supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8); + supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9); + isEmbeddedMode = connParams.isEmbeddedMode(); if (isEmbeddedMode) { EmbeddedThriftBinaryCLIService embeddedClient = new EmbeddedThriftBinaryCLIService(); embeddedClient.init(new HiveConf()); client = embeddedClient; + openSession(); } else { // extract user/password from JDBC connection properties if its not supplied in the // connection URL @@ -176,71 +180,71 @@ public HiveConnection(String uri, Properties info) throws SQLException { if (info.containsKey(JdbcConnectionParams.AUTH_TYPE)) { sessConfMap.put(JdbcConnectionParams.AUTH_TYPE, info.getProperty(JdbcConnectionParams.AUTH_TYPE)); } - // open the client transport - openTransport(); - // set up the client - client = new TCLIService.Client(new TBinaryProtocol(transport)); - } - // add supported protocols - supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V1); - supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V2); - supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V3); - supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V4); - supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V5); - supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V6); - supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V7); - supportedProtocols.add(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8); - // open client session - openSession(); + do { + try { + // open the client transport + openTransport(); + + // set up the client + client = new TCLIService.Client(new TBinaryProtocol(transport)); + + // open client session + openSession(); + + break; + } catch(Exception e) { + LOG.info("Could not open client transport with JDBC Uri: " + jdbcUriString); + + // We'll retry till we exhaust all HiveServer2 nodes from ZooKeeper + if ((sessConfMap.get(JdbcConnectionParams.SERVICE_DISCOVERY_MODE) != null) + && (JdbcConnectionParams.SERVICE_DISCOVERY_MODE_ZOOKEEPER.equalsIgnoreCase(sessConfMap + .get(JdbcConnectionParams.SERVICE_DISCOVERY_MODE)))) { + try { + // Update jdbcUriString, host & port variables in connParams + // Throw an exception if all HiveServer2 nodes have been exhausted, + // or if we're unable to connect to ZooKeeper. + Utils.updateConnParamsFromZooKeeper(connParams); + } catch (ZooKeeperHiveClientException ze) { + LOG.info("Last exception from HiveServer2: " + e.getMessage()); + throw new SQLException( + "Could not open client transport for any of the Server URI's in ZooKeeper: " + + ze.getMessage(), " 08S01", ze); + } + // Update with new values + jdbcUriString = connParams.getJdbcUriString(); + host = connParams.getHost(); + port = connParams.getPort(); + + transport = null; + client = null; + LOG.info("Will retry opening client transport"); + } else { + LOG.info("Transport Used for JDBC connection: " + + sessConfMap.get(JdbcConnectionParams.TRANSPORT_MODE)); + throw new SQLException("Could not open client transport with JDBC Uri: " + jdbcUriString + + ": " + e.getMessage(), " 08S01", e); + } + } + } while(true); + } // Wrap the client with a thread-safe proxy to serialize the RPC calls client = newSynchronizedClient(client); } - private void openTransport() throws SQLException { - while (true) { - try { - assumeSubject = - JdbcConnectionParams.AUTH_KERBEROS_AUTH_TYPE_FROM_SUBJECT.equals(sessConfMap - .get(JdbcConnectionParams.AUTH_KERBEROS_AUTH_TYPE)); - transport = isHttpTransportMode() ? createHttpTransport() : createBinaryTransport(); - if (!transport.isOpen()) { - LOG.info("Will try to open client transport with JDBC Uri: " + jdbcUriString); - transport.open(); - } - break; - } catch (TTransportException e) { - LOG.info("Could not open client transport with JDBC Uri: " + jdbcUriString); - // We'll retry till we exhaust all HiveServer2 nodes from ZooKeeper - if ((sessConfMap.get(JdbcConnectionParams.SERVICE_DISCOVERY_MODE) != null) - && (JdbcConnectionParams.SERVICE_DISCOVERY_MODE_ZOOKEEPER.equalsIgnoreCase(sessConfMap - .get(JdbcConnectionParams.SERVICE_DISCOVERY_MODE)))) { - try { - // Update jdbcUriString, host & port variables in connParams - // Throw an exception if all HiveServer2 nodes have been exhausted, - // or if we're unable to connect to ZooKeeper. - Utils.updateConnParamsFromZooKeeper(connParams); - } catch (ZooKeeperHiveClientException ze) { - throw new SQLException( - "Could not open client transport for any of the Server URI's in ZooKeeper: " - + ze.getMessage(), " 08S01", ze); - } - // Update with new values - jdbcUriString = connParams.getJdbcUriString(); - host = connParams.getHost(); - port = connParams.getPort(); - LOG.info("Will retry opening client transport"); - } else { - LOG.info("Transport Used for JDBC connection: " + - sessConfMap.get(JdbcConnectionParams.TRANSPORT_MODE)); - throw new SQLException("Could not open client transport with JDBC Uri: " + jdbcUriString - + ": " + e.getMessage(), " 08S01", e); - } - } + private void openTransport() throws SQLException, TTransportException { + assumeSubject = + JdbcConnectionParams.AUTH_KERBEROS_AUTH_TYPE_FROM_SUBJECT.equals(sessConfMap + .get(JdbcConnectionParams.AUTH_KERBEROS_AUTH_TYPE)); + transport = isHttpTransportMode() ? createHttpTransport() : createBinaryTransport(); + if (!transport.isOpen()) { + LOG.info("Will try to open client transport with JDBC Uri: " + jdbcUriString); + transport.open(); } } + private String getServerHttpUrl(boolean useSsl) { // Create the http/https url // JDBC driver will set up an https url if ssl is enabled, otherwise http @@ -263,15 +267,6 @@ private TTransport createHttpTransport() throws SQLException, TTransportExceptio httpClient = getHttpClient(useSsl); try { transport = new THttpClient(getServerHttpUrl(useSsl), httpClient); - // We'll call an open/close here to send a test HTTP message to the server. Any - // TTransportException caused by trying to connect to a non-available peer are thrown here. - // Bubbling them up the call hierarchy so that a retry can happen in openTransport, - // if dynamic service discovery is configured. - TCLIService.Iface client = new TCLIService.Client(new TBinaryProtocol(transport)); - TOpenSessionResp openResp = client.OpenSession(new TOpenSessionReq()); - if (openResp != null) { - client.CloseSession(new TCloseSessionReq(openResp.getSessionHandle())); - } } catch (TException e) { LOG.info("JDBC Connection Parameters used : useSSL = " + useSsl + " , httpPath = " + diff --git a/service/src/gen/thrift/gen-javabean/org/apache/hive/service/cli/thrift/TOpenSessionReq.java b/service/src/gen/thrift/gen-javabean/org/apache/hive/service/cli/thrift/TOpenSessionReq.java index c048161..98ca923 100644 --- a/service/src/gen/thrift/gen-javabean/org/apache/hive/service/cli/thrift/TOpenSessionReq.java +++ b/service/src/gen/thrift/gen-javabean/org/apache/hive/service/cli/thrift/TOpenSessionReq.java @@ -141,7 +141,7 @@ public String getFieldName() { } public TOpenSessionReq() { - this.client_protocol = org.apache.hive.service.cli.thrift.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8; + this.client_protocol = org.apache.hive.service.cli.thrift.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9; } @@ -188,7 +188,7 @@ public TOpenSessionReq deepCopy() { @Override public void clear() { - this.client_protocol = org.apache.hive.service.cli.thrift.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8; + this.client_protocol = org.apache.hive.service.cli.thrift.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9; this.username = null; this.password = null; diff --git a/service/src/gen/thrift/gen-javabean/org/apache/hive/service/cli/thrift/TOpenSessionResp.java b/service/src/gen/thrift/gen-javabean/org/apache/hive/service/cli/thrift/TOpenSessionResp.java index 351f78b..115d929 100644 --- a/service/src/gen/thrift/gen-javabean/org/apache/hive/service/cli/thrift/TOpenSessionResp.java +++ b/service/src/gen/thrift/gen-javabean/org/apache/hive/service/cli/thrift/TOpenSessionResp.java @@ -141,7 +141,7 @@ public String getFieldName() { } public TOpenSessionResp() { - this.serverProtocolVersion = org.apache.hive.service.cli.thrift.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8; + this.serverProtocolVersion = org.apache.hive.service.cli.thrift.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9; } @@ -191,7 +191,7 @@ public TOpenSessionResp deepCopy() { @Override public void clear() { this.status = null; - this.serverProtocolVersion = org.apache.hive.service.cli.thrift.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8; + this.serverProtocolVersion = org.apache.hive.service.cli.thrift.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9; this.sessionHandle = null; this.configuration = null; diff --git a/service/src/gen/thrift/gen-javabean/org/apache/hive/service/cli/thrift/TProtocolVersion.java b/service/src/gen/thrift/gen-javabean/org/apache/hive/service/cli/thrift/TProtocolVersion.java index a4279d2..f960338 100644 --- a/service/src/gen/thrift/gen-javabean/org/apache/hive/service/cli/thrift/TProtocolVersion.java +++ b/service/src/gen/thrift/gen-javabean/org/apache/hive/service/cli/thrift/TProtocolVersion.java @@ -19,7 +19,8 @@ HIVE_CLI_SERVICE_PROTOCOL_V5(4), HIVE_CLI_SERVICE_PROTOCOL_V6(5), HIVE_CLI_SERVICE_PROTOCOL_V7(6), - HIVE_CLI_SERVICE_PROTOCOL_V8(7); + HIVE_CLI_SERVICE_PROTOCOL_V8(7), + HIVE_CLI_SERVICE_PROTOCOL_V9(8); private final int value; @@ -56,6 +57,8 @@ public static TProtocolVersion findByValue(int value) { return HIVE_CLI_SERVICE_PROTOCOL_V7; case 7: return HIVE_CLI_SERVICE_PROTOCOL_V8; + case 8: + return HIVE_CLI_SERVICE_PROTOCOL_V9; default: return null; }