Community Articles
Find and share helpful community-sourced technical articles
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.
Labels (1)
Expert Contributor

Below are the high level requirements which are needed to connect to Secure Hbase cluster

- hbase-client

- Hbase config file

- Kerberos config files and keytab for user

Pom file and Sample Code are given below:

Java Class: (Change Paths for config files and kerberos related parameters):

package com.hortonworks.hbase;import java.io.IOException;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.Path;import org.apache.hadoop.hbase.HBaseConfiguration;import org.apache.hadoop.hbase.TableName;import org.apache.hadoop.hbase.client.Connection;import org.apache.hadoop.hbase.client.ConnectionFactory;import org.apache.hadoop.hbase.client.ResultScanner;import org.apache.hadoop.hbase.client.Scan;import org.apache.hadoop.hbase.client.Table;import org.apache.hadoop.security.UserGroupInformation;public class HBaseConnection {  public
static void main(String ar[]) throws IOException {  //
System Properties (Change Path/Properties according to env)  //
copy krb5.conf from cluster  System.setProperty("java.security.krb5.conf",
"/Users/schhabra/krb5.conf");  System.setProperty("javax.security.auth.useSubjectCredsOnly",
"true");  //
Configuration (Change Path/Properties according to env)  Configuration
configuration = HBaseConfiguration.create();  configuration.set("hadoop.security.authentication",
"Kerberos");  //
copy hbase-site.xml and hdfs-site.xml from cluster and set paths  configuration.addResource(new
Path("file:///Users/schhabra/hbase-site.xml"));  configuration.addResource(new
Path("file:///Users/schhabra/hdfs-site.xml"));  UserGroupInformation.setConfiguration(configuration);  //
User information (Change Path/Properties according to env)  UserGroupInformation.loginUserFromKeytab("ambari-qa-c1201@HWX.COM",    "/Users/schhabra/smokeuser.headless.keytab");  //
Connection  Connection
connection =
ConnectionFactory.createConnection(HBaseConfiguration.create(configuration));   System.out.println(connection.getAdmin().isTableAvailable(TableName.valueOf("SYSTEM.STATS")));  Scan
scan1 = new Scan();  Table
table = connection.getTable(TableName.valueOf("test"));  ResultScanner
scanner = table.getScanner(scan1);  }}

POM: (Dependencies)

<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hortonworks</groupId>
<artifactId>hbase</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>hbase</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>HDP</id>
<name>HDP Releases</name>
<!--url>http://repo.hortonworks.com/content/repositories/releases/</url-->
<url>http://repo.hortonworks.com/content/groups/public</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>1.1.2.2.5.0.0-1245</version>
</dependency>
</dependencies>
</project>
54 Views
0 Kudos
Don't have an account?
Coming from Hortonworks? Activate your account here
Version history
Revision #:
1 of 1
Last update:
‎08-09-2018 05:59 AM
Updated by:
 
Contributors
Top Kudoed Authors