Community Articles

Find and share helpful community-sourced technical articles.
Announcements
Welcome to the upgraded Community! Read this blog to see What’s New!
Labels (1)
avatar
Cloudera Employee

The following link has some sample code to connect to a secure Hive Server2 via the default connection string and via knox.

https://github.com/vspw/hiveJDBC

It uses the following Jar files:-

commons-configuration-xx.jar (UGI set configurations and metrics)
commons-logging-xx.jar (*Not mandatory)
hadoop-auth-xx.jar
hadoop-common-xx.jar (UGI stuff, hadoop configurations)
hive-jdbc-1.2xx-standalone.jar
log4j-xx-api-xx.jar (for log4j)
log4j-api-xx.jar (for log4j)
log4j-core.xx.jar (for log4j)
xercesImpl-xx.jar

It also reads a bunch of properties like "keytabLocationWindows", "jdbcConnStringDirect", "hiveQuery" etc. from a properties file and logging is enabled with log4j2.xml.

The class: "HiveJDBCKnox" , has some instructions to make knox connectivity work on windows platform as well.

3,268 Views
Comments
avatar
New Contributor

Failing with the below error . what is the reason ?

Exception in thread "main" java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://<<HOST>>:10000/default;principal=<<Principle_NAME>>;ssl=true;transportMode=http;httpPath=gateway/default/hive: Could not create http connection to jdbc:hive2://<<HOST>>:10000/default;principal=hive/_HOST@DEVAD.DOMAIN.COM;ssl=true;transportMode=http;httpPath=gateway/default/hive. org.apache.http.client.ClientProtocolException at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:210) at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:156) at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at com.hwx.hive.HiveJDBCKnox.main(HiveJDBCKnox.java:80) Caused by: org.apache.thrift.transport.TTransportException: Could not create http connection to jdbc:hive2://<<HOST>>:10000/default;principal=hive/_HOST@DEVAD.DOMAIN.COM;ssl=true;transportMode=http;httpPath=gateway/default/hive. org.apache.http.client.ClientProtocolException at org.apache.hive.jdbc.HiveConnection.createHttpTransport(HiveConnection.java:255) at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:183) ... 5 more Caused by: org.apache.thrift.transport.TTransportException: org.apache.http.client.ClientProtocolException at org.apache.thrift.transport.THttpClient.flushUsingHttpClient(THttpClient.java:297) at org.apache.thrift.transport.THttpClient.flush(THttpClient.java:313) at org.apache.thrift.TServiceClient.sendBase(TServiceClient.java:65) at org.apache.hive.service.cli.thrift.TCLIService$Client.send_OpenSession(TCLIService.java:154) at org.apache.hive.service.cli.thrift.TCLIService$Client.OpenSession(TCLIService.java:146) at org.apache.hive.jdbc.HiveConnection.createHttpTransport(HiveConnection.java:244) ... 6 more Caused by: org.apache.http.client.ClientProtocolException at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:117) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55) at org.apache.thrift.transport.THttpClient.flushUsingHttpClient(THttpClient.java:251) ... 11 more Caused by: org.apache.http.HttpException at org.apache.hive.jdbc.HttpRequestInterceptorBase.process(HttpRequestInterceptorBase.java:86) at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:132) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:182) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) at org.apache.http.impl.execchain.ServiceUnavailableRetryExec.execute(ServiceUnavailableRetryExec.java:84) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) ... 14 more Caused by: org.apache.http.HttpException at org.apache.hive.jdbc.HttpKerberosRequestInterceptor.addHttpAuthHeader(HttpKerberosRequestInterceptor.java:68) at org.apache.hive.jdbc.HttpRequestInterceptorBase.process(HttpRequestInterceptorBase.java:74) ... 20 more Caused by: java.lang.reflect.UndeclaredThrowableException at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1713) at org.apache.hive.service.auth.HttpAuthUtils.getKerberosServiceTicket(HttpAuthUtils.java:83) at org.apache.hive.jdbc.HttpKerberosRequestInterceptor.addHttpAuthHeader(HttpKerberosRequestInterceptor.java:62) ... 21 more Caused by: GSSException: No valid credentials provided (Mechanism level: Failed to find any Kerberos tgt) at sun.security.jgss.krb5.Krb5InitCredential.getInstance(Krb5InitCredential.java:147) at sun.security.jgss.krb5.Krb5MechFactory.getCredentialElement(Krb5MechFactory.java:122) at sun.security.jgss.krb5.Krb5MechFactory.getMechanismContext(Krb5MechFactory.java:187) at sun.security.jgss.GSSManagerImpl.getMechanismContext(GSSManagerImpl.java:224) at sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:212) at sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:179) at org.apache.hive.service.auth.HttpAuthUtils$HttpKerberosClientAction.run(HttpAuthUtils.java:183) at org.apache.hive.service.auth.HttpAuthUtils$HttpKerberosClientAction.run(HttpAuthUtils.java:151) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:422) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1698) ... 23 more

Labels
Version history
Last update:
‎10-01-2017 02:21 AM
Updated by:
Contributors