Configuration conf = job.getConfiguration();
String tableName = conf.get(HBasePutProcessor.TABLE_NAME_KEY);
String familyName = conf.get(HBasePutProcessor.COL_FAMILY_KEY);
if (null == tableName) {
throw new ImportException(
"Import to HBase error: Table name not specified");
}
if (null == familyName) {
throw new ImportException(
"Import to HBase error: Column family not specified");
}
// Add HBase configuration files to this conf object.
HBaseConfiguration.addHbaseResources(conf);
HBaseAdmin admin = new HBaseAdmin(conf);
// Add authentication token to the job if we're running on secure cluster.
//
// We're currently supporting HBase version 0.90 that do not have security
// patches which means that it do not have required methods
// "isSecurityEnabled" and "obtainAuthTokenForJob".
//
// We're using reflection API to see if those methods are available and call
// them only if they are present.
//
// After we will remove support for HBase 0.90 we can simplify the code to
// following code fragment:
/*
try {
if (User.isSecurityEnabled()) {
User user = User.getCurrent();
user.obtainAuthTokenForJob(conf, job);
}
} catch(InterruptedException ex) {
throw new ImportException("Can't get authentication token", ex);
}
*/
try {
// Get method isSecurityEnabled
Method isSecurityEnabled = User.class.getMethod("isSecurityEnabled");
// Get method obtainAuthTokenForJob
Method obtainAuthTokenForJob = User.class.getMethod(
"obtainAuthTokenForJob", Configuration.class, Job.class);
// Get current user
User user = User.getCurrent();
// Obtain security token if needed
if ((Boolean)isSecurityEnabled.invoke(null)) {
obtainAuthTokenForJob.invoke(user, conf, job);
}
} catch (NoSuchMethodException e) {
LOG.info("It seems that we're running on HBase without security"
+ " additions. Security additions will not be used during this job.");
} catch (InvocationTargetException e) {
throw new ImportException("Can't get authentication token", e);
} catch (IllegalAccessException e) {
throw new ImportException("Can't get authentication token", e);
}
// Check to see if the table exists.
HTableDescriptor tableDesc = null;
byte [] familyBytes = Bytes.toBytes(familyName);