|
@@ -23,6 +23,7 @@ import java.io.IOException;
|
|
|
import java.lang.reflect.UndeclaredThrowableException;
|
|
|
import java.net.ConnectException;
|
|
|
import java.net.HttpURLConnection;
|
|
|
+import java.net.InetSocketAddress;
|
|
|
import java.net.URI;
|
|
|
import java.net.URL;
|
|
|
import java.net.URLConnection;
|
|
@@ -44,6 +45,7 @@ import org.apache.commons.logging.LogFactory;
|
|
|
import org.apache.hadoop.classification.InterfaceAudience.Private;
|
|
|
import org.apache.hadoop.classification.InterfaceStability.Unstable;
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
+import org.apache.hadoop.security.SecurityUtil;
|
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
|
import org.apache.hadoop.security.authentication.client.AuthenticationException;
|
|
|
import org.apache.hadoop.security.authentication.client.ConnectionConfigurator;
|
|
@@ -362,6 +364,12 @@ public class TimelineClientImpl extends TimelineClient {
|
|
|
public long renewDelegationToken(
|
|
|
final Token<TimelineDelegationTokenIdentifier> timelineDT)
|
|
|
throws IOException, YarnException {
|
|
|
+ final boolean isTokenServiceAddrEmpty =
|
|
|
+ timelineDT.getService().toString().isEmpty();
|
|
|
+ final String scheme = isTokenServiceAddrEmpty ? null
|
|
|
+ : (YarnConfiguration.useHttps(this.getConfig()) ? "https" : "http");
|
|
|
+ final InetSocketAddress address = isTokenServiceAddrEmpty ? null
|
|
|
+ : SecurityUtil.getTokenServiceAddr(timelineDT);
|
|
|
PrivilegedExceptionAction<Long> renewDTAction =
|
|
|
new PrivilegedExceptionAction<Long>() {
|
|
|
|
|
@@ -377,6 +385,11 @@ public class TimelineClientImpl extends TimelineClient {
|
|
|
DelegationTokenAuthenticatedURL authUrl =
|
|
|
new DelegationTokenAuthenticatedURL(authenticator,
|
|
|
connConfigurator);
|
|
|
+ // If the token service address is not available, fall back to use
|
|
|
+ // the configured service address.
|
|
|
+ final URI serviceURI = isTokenServiceAddrEmpty ? resURI
|
|
|
+ : new URI(scheme, null, address.getHostName(),
|
|
|
+ address.getPort(), RESOURCE_URI_STR, null, null);
|
|
|
return authUrl
|
|
|
.renewDelegationToken(resURI.toURL(), token, doAsUser);
|
|
|
}
|
|
@@ -389,6 +402,12 @@ public class TimelineClientImpl extends TimelineClient {
|
|
|
public void cancelDelegationToken(
|
|
|
final Token<TimelineDelegationTokenIdentifier> timelineDT)
|
|
|
throws IOException, YarnException {
|
|
|
+ final boolean isTokenServiceAddrEmpty =
|
|
|
+ timelineDT.getService().toString().isEmpty();
|
|
|
+ final String scheme = isTokenServiceAddrEmpty ? null
|
|
|
+ : (YarnConfiguration.useHttps(this.getConfig()) ? "https" : "http");
|
|
|
+ final InetSocketAddress address = isTokenServiceAddrEmpty ? null
|
|
|
+ : SecurityUtil.getTokenServiceAddr(timelineDT);
|
|
|
PrivilegedExceptionAction<Void> cancelDTAction =
|
|
|
new PrivilegedExceptionAction<Void>() {
|
|
|
|
|
@@ -404,7 +423,12 @@ public class TimelineClientImpl extends TimelineClient {
|
|
|
DelegationTokenAuthenticatedURL authUrl =
|
|
|
new DelegationTokenAuthenticatedURL(authenticator,
|
|
|
connConfigurator);
|
|
|
- authUrl.cancelDelegationToken(resURI.toURL(), token, doAsUser);
|
|
|
+ // If the token service address is not available, fall back to use
|
|
|
+ // the configured service address.
|
|
|
+ final URI serviceURI = isTokenServiceAddrEmpty ? resURI
|
|
|
+ : new URI(scheme, null, address.getHostName(),
|
|
|
+ address.getPort(), RESOURCE_URI_STR, null, null);
|
|
|
+ authUrl.cancelDelegationToken(serviceURI.toURL(), token, doAsUser);
|
|
|
return null;
|
|
|
}
|
|
|
};
|