Repository: sqoop Updated Branches: refs/heads/trunk 7966f1966 -> 391091768
SQOOP-1684: Use pre-existing HBase delegation token (Abraham Elmahrek via Jarek Jarcec Cecho) Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/39109176 Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/39109176 Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/39109176 Branch: refs/heads/trunk Commit: 391091768651178126e93e52b198ed19ebedf220 Parents: 7966f19 Author: Jarek Jarcec Cecho <[email protected]> Authored: Sun Nov 9 20:28:35 2014 -0800 Committer: Jarek Jarcec Cecho <[email protected]> Committed: Sun Nov 9 20:28:35 2014 -0800 ---------------------------------------------------------------------- .../apache/sqoop/mapreduce/HBaseImportJob.java | 99 ++++++++++++-------- 1 file changed, 60 insertions(+), 39 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sqoop/blob/39109176/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 d10050d..a93114f 100644 --- a/src/java/org/apache/sqoop/mapreduce/HBaseImportJob.java +++ b/src/java/org/apache/sqoop/mapreduce/HBaseImportJob.java @@ -120,6 +120,25 @@ public class HBaseImportJob extends DataDrivenImportJob { conf.set(HBasePutProcessor.ROW_KEY_COLUMN_KEY, rowKeyCol); } + /** + * Hope for an existing authentication token. + * Test with basic metadata operation. + * Log exception if credentials exist, otherwise rethrow exception. + */ + private boolean isAuthenticated(HBaseAdmin admin) { + try { + LOG.info("Checking for previous credentials by performing a metadata query."); + admin.tableExists("TEST"); + LOG.info("Previous authentication credentials detected, so the job will use them."); + } catch (IOException e) { + LOG.info("No previous credentials found. Will attempt to authenticate."); + LOG.debug("Exception found when performing metadata query to check credentials.", e); + return false; + } + + return true; + } + @Override /** Create the target HBase table before running the job. */ protected void jobSetup(Job job) throws IOException, ImportException { @@ -143,50 +162,52 @@ 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 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); + if (!isAuthenticated(admin)) { + // 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); } - } catch(InterruptedException ex) { - throw new ImportException("Can't get authentication token", ex); - } - */ - try { - // Get method isSecurityEnabled - Method isHBaseSecurityEnabled = User.class.getMethod( - "isHBaseSecurityEnabled", Configuration.class); + */ + try { + // Get method isSecurityEnabled + Method isHBaseSecurityEnabled = User.class.getMethod( + "isHBaseSecurityEnabled", Configuration.class); - // Get method obtainAuthTokenForJob - Method obtainAuthTokenForJob = User.class.getMethod( - "obtainAuthTokenForJob", Configuration.class, Job.class); + // Get method obtainAuthTokenForJob + Method obtainAuthTokenForJob = User.class.getMethod( + "obtainAuthTokenForJob", Configuration.class, Job.class); - // Get current user - User user = User.getCurrent(); + // Get current user + User user = User.getCurrent(); - // Obtain security token if needed - if ((Boolean)isHBaseSecurityEnabled.invoke(null, conf)) { - obtainAuthTokenForJob.invoke(user, conf, job); + // Obtain security token if needed + if ((Boolean)isHBaseSecurityEnabled.invoke(null, conf)) { + 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); } - } 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.
