Accessing MapR DB without installing MapR Client

Document created by snayeem Employee on Feb 27, 2016
Version 1Show Document
  • View in full screen mode

Author: Sanjamala Nayeem

Original Publication Date: April 15, 2015

 

Env:

  • MapR v3.1.1+ latest EBF patch (mapr-patch-3.1.1.26113.GA-31296 onwards)
  • MapR v4.0.2

Goal:

To access MapR DB from application without installing MapR client for un-secure cluster.

Solutions:

To achieve this MapR has provided following configuration parameter to set cluster details at run time which allows to connect to that cluster.

conf.set("dfs.nameservices", clusterName); 
conf.set("dfs.ha.namenodes." + clusterName, "cldb1,cldb2,cldb3");
conf.set("dfs.namenode.rpc-address." + clusterName + ".cldb1",cldb1node + ":7222");
  • In above snippet, we need to provide cluster name against dfs.nameservices.
  • Need to specify how many CLDB do we have, if we have HA implemented for CLDB and in this example we are having three cldbs, configured as cldb1,cldb2.cldb3. and against dfs.namenodes.<clustername>
  • Hostname of CLDB or IP addresses of CLDB with port  7222 need to be set against dfs.namenode.rpc-address.<clustername>.<cldbno>

 

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HColumnDescriptor;

import org.apache.hadoop.hbase.HTableDescriptor;

import org.apache.hadoop.hbase.client.HBaseAdmin;

import org.apache.hadoop.hbase.client.HTable;

import org.apache.hadoop.hbase.client.Put;

 

public class SampleAccessMDB {

 

public static void main(String[] args) {

Configuration conf = new Configuration();

String clusterName = "gauth";

String cldb1node = "10.10.70.1";

String cldb2node = "10.10.70.2";

String cldb3node = "10.10.70.3";

 

conf.setBoolean("fs.mapr.impl.clustername.unique", true);

 

conf.set("dfs.nameservices", clusterName);

conf.set("dfs.ha.namenodes." + clusterName, "cldb1,cldb2,cldb3");

conf.set("dfs.namenode.rpc-address." + clusterName + ".cldb1",cldb1node + ":7222");

conf.set("dfs.namenode.rpc-address." + clusterName + ".cldb2",cldb2node + ":7222");

conf.set("dfs.namenode.rpc-address." + clusterName + ".cldb3",cldb3node + ":7222");

 

  System.out.println("Check for Tables");

  String tableName = "/mapr/gauth/myTable"+System.currentTimeMillis();

  System.out.println("Table name: " + tableName);

  try{

HBaseAdmin admin = new HBaseAdmin(conf);

HTableDescriptor des = new HTableDescriptor(tableName.getBytes());

des.setName(tableName.getBytes());

des.addFamily(new HColumnDescriptor("cf1".getBytes()));

admin.createTable(des);

 

Put put = new Put("r1".getBytes());

put.add("cf1".getBytes(),"c1".getBytes(),"val1".getBytes());

HTable table = new HTable(conf,tableName);

table.put(put);

  }catch(Exception ex){

  ex.printStackTrace();

  }

}

}

  • In the above sample we are trying to create table /mapr/gauth/myTable"+ Current timestamp in this path is /mapr/gauth and table name is myTable+time-in-millis.
2 people found this helpful

Attachments

    Outcomes