Updated Branches: refs/heads/trunk 2a2596b7d -> 3fee25eb8
SQOOP-599: Import to HBase is not working on secure cluster Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/3fee25eb Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/3fee25eb Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/3fee25eb Branch: refs/heads/trunk Commit: 3fee25eb8fa51362f3ec6ff220d223a4f62c69be Parents: 2a2596b Author: Bilung Lee <[email protected]> Authored: Tue Sep 11 17:56:56 2012 -0700 Committer: Bilung Lee <[email protected]> Committed: Tue Sep 11 17:56:56 2012 -0700 ---------------------------------------------------------------------- build.xml | 2 +- .../org/apache/sqoop/mapreduce/HBaseImportJob.java | 42 +++++++++++++++ 2 files changed, 43 insertions(+), 1 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sqoop/blob/3fee25eb/build.xml ---------------------------------------------------------------------- diff --git a/build.xml b/build.xml index edcda6e..17037ca 100644 --- a/build.xml +++ b/build.xml @@ -174,7 +174,7 @@ <!-- testing with JUnit --> <property name="test.junit.output.format" value="plain"/> <property name="test.output" value="no"/> - <property name="test.timeout" value="300000"/> + <property name="test.timeout" value="600000"/> <!-- static analysis --> <property name="findbugs.out.dir" value="${build.dir}/findbugs" /> http://git-wip-us.apache.org/repos/asf/sqoop/blob/3fee25eb/src/java/org/apache/sqoop/mapreduce/HBaseImportJob.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/sqoop/mapreduce/HBaseImportJob.java b/src/java/org/apache/sqoop/mapreduce/HBaseImportJob.java index 6a784d2..a2a167b 100644 --- a/src/java/org/apache/sqoop/mapreduce/HBaseImportJob.java +++ b/src/java/org/apache/sqoop/mapreduce/HBaseImportJob.java @@ -19,6 +19,9 @@ package org.apache.sqoop.mapreduce; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; @@ -28,6 +31,7 @@ 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.mapreduce.TableMapReduceUtil; +import org.apache.hadoop.hbase.security.User; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.io.NullWritable; import org.apache.hadoop.mapreduce.Job; @@ -138,6 +142,44 @@ public class HBaseImportJob extends DataDrivenImportJob { 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 method + // "obtainAuthTokenForJob". + // + // We're using reflection API to see if this method is available and call + // it only if it's present. + // + // After we will remove support for HBase 0.90 we can simplify the code to + // following code fragment: + /* + try { + User user = User.getCurrent(); + user.obtainAuthTokenForJob(conf, job); + } catch(InterruptedException ex) { + throw new ImportException("Can't get authentication token", ex); + } + */ + try { + // Get the method + Method obtainAuthTokenForJob = User.class.getMethod( + "obtainAuthTokenForJob", Configuration.class, Job.class); + + // Get current user + User user = User.getCurrent(); + + // Obtain security token if needed (it's no-op on non secure cluster) + 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 = new HTableDescriptor(tableName); byte [] familyBytes = Bytes.toBytes(familyName);
