diff --git a/hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseStorageHandler.java b/hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseStorageHandler.java index f4b41bb7b6cc41e604335ee3f688425bc2847702..53d913435cd43c96f044cf8668461fc686817ef4 100644 --- a/hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseStorageHandler.java +++ b/hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseStorageHandler.java @@ -37,6 +37,8 @@ import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.client.HBaseAdmin; +import org.apache.hadoop.hbase.client.HConnection; +import org.apache.hadoop.hbase.client.HConnectionManager; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.mapred.TableOutputFormat; import org.apache.hadoop.hbase.mapreduce.TableInputFormatBase; @@ -65,6 +67,7 @@ import org.apache.hadoop.hive.serde2.SerDe; import org.apache.hadoop.hive.shims.ShimLoader; import org.apache.hadoop.io.Text; +import org.apache.hadoop.hbase.security.token.TokenUtil; import org.apache.hadoop.mapred.InputFormat; import org.apache.hadoop.mapred.JobConf; import org.apache.hadoop.mapred.OutputFormat; @@ -468,35 +471,17 @@ private void addHBaseResources(Configuration jobConf, private void addHBaseDelegationToken(Configuration conf) throws IOException { if (User.isHBaseSecurityEnabled(conf)) { + HConnection conn = HConnectionManager.createConnection(conf); try { User curUser = User.getCurrent(); - Token authToken = getAuthToken(conf, curUser); Job job = new Job(conf); - if (authToken == null) { - curUser.obtainAuthTokenForJob(conf,job); - } else { - job.getCredentials().addToken(authToken.getService(), authToken); - } + TokenUtil.addTokenForJob(conn, curUser, job); } catch (InterruptedException e) { throw new IOException("Error while obtaining hbase delegation token", e); } - } - } - - /** - * Get the authentication token of the user for the cluster specified in the configuration - * @return null if the user does not have the token, otherwise the auth token for the cluster. - */ - private static Token getAuthToken(Configuration conf, User user) - throws IOException, InterruptedException { - ZooKeeperWatcher zkw = new ZooKeeperWatcher(conf, "mr-init-credentials", null); - try { - String clusterId = ZKClusterId.readClusterIdZNode(zkw); - return new AuthenticationTokenSelector().selectToken(new Text(clusterId), user.getUGI().getTokens()); - } catch (KeeperException e) { - throw new IOException(e); - } finally { - zkw.close(); + finally { + conn.close(); + } } } diff --git a/pom.xml b/pom.xml index f23a99c8ca0a9af284ac040569b6eef269cbe5c1..f302524a27d5a960fe83d0a8ed7a74869acec576 100644 --- a/pom.xml +++ b/pom.xml @@ -121,8 +121,8 @@ 1.2.1 2.6.0 ${basedir}/${hive.path.to.root}/testutils/hadoop - 0.98.3-hadoop1 - 0.98.3-hadoop2 + 0.98.9-hadoop1 + 0.98.9-hadoop2 4.2.5 4.2.5