Skip to content

Instantly share code, notes, and snippets.

@haoch
Created March 20, 2014 10:07
Show Gist options
  • Save haoch/9660735 to your computer and use it in GitHub Desktop.
Save haoch/9660735 to your computer and use it in GitHub Desktop.
require 'java'
import org.apache.hadoop.security.UserGroupInformation
import org.apache.hadoop.conf.Configuration
jruby_class_loader = JRuby.runtime.getJRubyClassLoader
Java::java.lang.Thread.currentThread.setContextClassLoader(jruby_class_loader)
#Parameters
#conf_dir = ENV['HADOOP_CONF_DIR'] #path to HADOOP_CONF_DIR
#principal = params['kerberos_principal'] #kerberos principal to use
#keytab_file = params['kerberos_keytab_file'] #path to the keytab file to use
conf_dir=ENV['HADOOP_CONF_DIR']
# klist -k -t ~/.keytabs/b_dpms.keytab
principal='b_dpms@CORP.EBAY.COM'
keytab_file='/export/home/b_dpms/.keytabs/b_dpms.keytab'
#Load Hadoop_CONF_DIR to make sure the .xml file are in the runtime path
unless $CLASSPATH.include? conf_dir
$CLASSPATH << conf_dir
end
core_site = jruby_class_loader.getResource("core-site.xml")
hdfs_site = jruby_class_loader.getResource("hdfs-site.xml")
#Construct conf object
conf = Configuration.new
conf.get('fs.default.name')
conf.set("hadoop.security.group.mapping",
"org.apache.hadoop.security.ShellBasedUnixGroupsMapping")
UserGroupInformation.setConfiguration(conf)
#Authenticate with kerberos
UserGroupInformation.loginUserFromKeytab(principal, keytab_file)
#Get a FileSystem object to interogate HDFS
fs=org.apache.hadoop.fs.FileSystem.get(conf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment