mirror of
https://github.com/apache/sqoop.git
synced 2025-05-04 20:42:20 +08:00
SQOOP-599: Import to HBase is not working on secure cluster
This commit is contained in:
parent
2a2596b7d5
commit
3fee25eb8f
@ -174,7 +174,7 @@
|
|||||||
<!-- testing with JUnit -->
|
<!-- testing with JUnit -->
|
||||||
<property name="test.junit.output.format" value="plain"/>
|
<property name="test.junit.output.format" value="plain"/>
|
||||||
<property name="test.output" value="no"/>
|
<property name="test.output" value="no"/>
|
||||||
<property name="test.timeout" value="300000"/>
|
<property name="test.timeout" value="600000"/>
|
||||||
|
|
||||||
<!-- static analysis -->
|
<!-- static analysis -->
|
||||||
<property name="findbugs.out.dir" value="${build.dir}/findbugs" />
|
<property name="findbugs.out.dir" value="${build.dir}/findbugs" />
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
package org.apache.sqoop.mapreduce;
|
package org.apache.sqoop.mapreduce;
|
||||||
|
|
||||||
import java.io.IOException;
|
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.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
@ -28,6 +31,7 @@
|
|||||||
import org.apache.hadoop.hbase.client.HBaseAdmin;
|
import org.apache.hadoop.hbase.client.HBaseAdmin;
|
||||||
import org.apache.hadoop.hbase.client.HTable;
|
import org.apache.hadoop.hbase.client.HTable;
|
||||||
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
|
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.hbase.util.Bytes;
|
||||||
import org.apache.hadoop.io.NullWritable;
|
import org.apache.hadoop.io.NullWritable;
|
||||||
import org.apache.hadoop.mapreduce.Job;
|
import org.apache.hadoop.mapreduce.Job;
|
||||||
@ -138,6 +142,44 @@ protected void jobSetup(Job job) throws IOException, ImportException {
|
|||||||
|
|
||||||
HBaseAdmin admin = new HBaseAdmin(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 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.
|
// Check to see if the table exists.
|
||||||
HTableDescriptor tableDesc = new HTableDescriptor(tableName);
|
HTableDescriptor tableDesc = new HTableDescriptor(tableName);
|
||||||
byte [] familyBytes = Bytes.toBytes(familyName);
|
byte [] familyBytes = Bytes.toBytes(familyName);
|
||||||
|
Loading…
Reference in New Issue
Block a user