HBASE-23330: Fix delegation token fetch with MasterRegistry

Signed-off-by: Andrew Purtell <apurtell@apache.org>
This commit is contained in:
Bharath Vissapragada 2020-09-16 08:07:48 -07:00
parent 3e1450d8b3
commit 55cae10beb
No known key found for this signature in database
GPG Key ID: 18AE42A0B5A93FA7
5 changed files with 27 additions and 17 deletions

View File

@ -166,6 +166,11 @@ public interface Connection extends Abortable, Closeable {
*/
Admin getAdmin() throws IOException;
/**
* @return the cluster ID unique to this HBase cluster.
*/
String getClusterId() throws IOException;
@Override
public void close() throws IOException;

View File

@ -501,4 +501,9 @@ abstract class ConnectionAdapter implements ClusterConnection {
public RpcControllerFactory getRpcControllerFactory() {
return wrappedConnection.getRpcControllerFactory();
}
@Override
public String getClusterId() throws IOException {
return wrappedConnection.getClusterId();
}
}

View File

@ -824,6 +824,11 @@ class ConnectionManager {
return new HBaseAdmin(this);
}
@Override
public String getClusterId() throws IOException {
return registry.getClusterId();
}
@Override
public MetricsConnection getConnectionMetrics() {
return this.metrics;

View File

@ -305,7 +305,7 @@ public class TokenUtil {
public static void addTokenForJob(final Connection conn, final JobConf job, User user)
throws IOException, InterruptedException {
Token<AuthenticationTokenIdentifier> token = getAuthToken(conn.getConfiguration(), user);
Token<AuthenticationTokenIdentifier> token = getAuthToken(conn, user);
if (token == null) {
token = obtainToken(conn, user);
}
@ -324,7 +324,7 @@ public class TokenUtil {
*/
public static void addTokenForJob(final Connection conn, User user, Job job)
throws IOException, InterruptedException {
Token<AuthenticationTokenIdentifier> token = getAuthToken(conn.getConfiguration(), user);
Token<AuthenticationTokenIdentifier> token = getAuthToken(conn, user);
if (token == null) {
token = obtainToken(conn, user);
}
@ -343,7 +343,7 @@ public class TokenUtil {
*/
public static boolean addTokenIfMissing(Connection conn, User user)
throws IOException, InterruptedException {
Token<AuthenticationTokenIdentifier> token = getAuthToken(conn.getConfiguration(), user);
Token<AuthenticationTokenIdentifier> token = getAuthToken(conn, user);
if (token == null) {
token = obtainToken(conn, user);
user.getUGI().addToken(token.getService(), token);
@ -356,19 +356,9 @@ public class TokenUtil {
* 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<AuthenticationTokenIdentifier> getAuthToken(Configuration conf, User user)
throws IOException, InterruptedException {
ZooKeeperWatcher zkw = new ZooKeeperWatcher(conf, "TokenUtil-getAuthToken", null);
try {
String clusterId = ZKClusterId.readClusterIdZNode(zkw);
if (clusterId == null) {
throw new IOException("Failed to get cluster ID");
}
return new AuthenticationTokenSelector().selectToken(new Text(clusterId), user.getTokens());
} catch (KeeperException e) {
throw new IOException(e);
} finally {
zkw.close();
}
private static Token<AuthenticationTokenIdentifier> getAuthToken(Connection conn, User user)
throws IOException {
String clusterId = conn.getClusterId();
return new AuthenticationTokenSelector().selectToken(new Text(clusterId), user.getTokens());
}
}

View File

@ -81,6 +81,11 @@ public class TestMasterAddressRefresher {
return null;
}
@Override
public String getClusterId() throws IOException {
return null;
}
@Override
public void close() throws IOException {