Support Questions

Find answers, ask questions, and share your expertise

How Do I Create A JDBC Connection to HiveServer2 That Is Kerberos-Enabled From An External Groovy-Grails Application?

avatar
Rising Star

I have included my following connection method, which just ends up outputting a stack trace of:

16/02/26 14:46:41 ERROR StackTrace: Full Stack Trace: java.net.SocketTimeoutException: Receive timed out at java.net.AbstractPlainDatagramSocketImpl.receive(AbstractPlainDatagramSocketImpl.java:146) at java.net.DatagramSocket.receive(DatagramSocket.java:817) at com.sun.security.auth.module.Krb5LoginModule.attemptAuthentication(Krb5LoginModule.java:735) at com.sun.security.auth.module.Krb5LoginModule.login(Krb5LoginModule.java:584) at javax.security.auth.login.LoginContext.invoke(LoginContext.java:762) at javax.security.auth.login.LoginContext.access$000(LoginContext.java:203) at javax.security.auth.login.LoginContext$4.run(LoginContext.java:690) at javax.security.auth.login.LoginContext$4.run(LoginContext.java:688) at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:687) at javax.security.auth.login.LoginContext.login(LoginContext.java:595) at org.apache.hadoop.security.UserGroupInformation.loginUserFromKeytab(UserGroupInformation.java:926) at com.zirous.alertsView.ETLService.getConnection(ETLService.groovy:419) at com.zirous.alertsView.ETLService.getRecentEtlByDate(ETLService.groovy:311) at com.zirous.etlView.ETLController.recent(ETLController.groovy:79) at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:198) at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745)

Does anyone have any experience with these kinds of connections or see an error in the way I am going about creating the connection?

 private static getConnection() {
  try {
      Configuration conf = new Configuration();
      conf.set("hadoop.security.authentication", "Kerberos");
      UserGroupInformation.setConfiguration(conf);
      UserGroupInformation.loginUserFromKeytab("<principal>", "<keytab location>");
      Class.forName("org.apache.hive.jdbc.HiveDriver");
      System.out.print("Getting Connection");
      Connection con = DriverManager.getConnection("jdbc:hive2://<hiveserver2_host>:10000/;principal=" +
            "<principal>;transportMode=http;httpPath=cliservice;auth=KERBEROS");
      return con
   } catch (Exception e) {
      e.printStackTrace()
      throw e
   }
}
1 ACCEPTED SOLUTION

avatar

@Colton Rodgers Can you try adding hive-site.xml as resource.

conf.addResource(new Path("/etc/hive/conf/hive-site.xml"));

View solution in original post

2 REPLIES 2

avatar

@Colton Rodgers Can you try adding hive-site.xml as resource.

conf.addResource(new Path("/etc/hive/conf/hive-site.xml"));

avatar
Rising Star

Thank you! That did it for me, the application host is separate from the HDP Cluster, so I had to scp the .xml over, but it then worked as planned.