HDFS-14070. Refactor NameNodeWebHdfsMethods to allow better extensibility. Contributed by CR Hota
(cherry picked from commit e7b63baca1
)
This commit is contained in:
parent
359b1dd40b
commit
5e86641265
|
@ -337,9 +337,22 @@ public class NamenodeWebHdfsMethods {
|
||||||
throw new IOException("No active nodes contain this block");
|
throw new IOException("No active nodes contain this block");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Token<? extends TokenIdentifier> generateDelegationToken(
|
public long renewDelegationToken(Token<DelegationTokenIdentifier> token)
|
||||||
final NameNode namenode, final UserGroupInformation ugi,
|
throws IOException {
|
||||||
|
ClientProtocol cp = getRpcClientProtocol();
|
||||||
|
return cp.renewDelegationToken(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancelDelegationToken(Token<DelegationTokenIdentifier> token)
|
||||||
|
throws IOException {
|
||||||
|
ClientProtocol cp = getRpcClientProtocol();
|
||||||
|
cp.cancelDelegationToken(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Token<? extends TokenIdentifier> generateDelegationToken(
|
||||||
|
final UserGroupInformation ugi,
|
||||||
final String renewer) throws IOException {
|
final String renewer) throws IOException {
|
||||||
|
final NameNode namenode = (NameNode)context.getAttribute("name.node");
|
||||||
final Credentials c = DelegationTokenSecretManager.createCredentials(
|
final Credentials c = DelegationTokenSecretManager.createCredentials(
|
||||||
namenode, ugi, renewer != null? renewer: ugi.getShortUserName());
|
namenode, ugi, renewer != null? renewer: ugi.getShortUserName());
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
|
@ -384,7 +397,7 @@ public class NamenodeWebHdfsMethods {
|
||||||
} else {
|
} else {
|
||||||
//generate a token
|
//generate a token
|
||||||
final Token<? extends TokenIdentifier> t = generateDelegationToken(
|
final Token<? extends TokenIdentifier> t = generateDelegationToken(
|
||||||
namenode, ugi, null);
|
ugi, null);
|
||||||
delegationQuery = "&" + new DelegationParam(t.encodeToUrlString());
|
delegationQuery = "&" + new DelegationParam(t.encodeToUrlString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -705,7 +718,7 @@ public class NamenodeWebHdfsMethods {
|
||||||
validateOpParams(op, delegationTokenArgument);
|
validateOpParams(op, delegationTokenArgument);
|
||||||
final Token<DelegationTokenIdentifier> token = new Token<DelegationTokenIdentifier>();
|
final Token<DelegationTokenIdentifier> token = new Token<DelegationTokenIdentifier>();
|
||||||
token.decodeFromUrlString(delegationTokenArgument.getValue());
|
token.decodeFromUrlString(delegationTokenArgument.getValue());
|
||||||
final long expiryTime = cp.renewDelegationToken(token);
|
final long expiryTime = renewDelegationToken(token);
|
||||||
final String js = JsonUtil.toJsonString("long", expiryTime);
|
final String js = JsonUtil.toJsonString("long", expiryTime);
|
||||||
return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
|
return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
|
||||||
}
|
}
|
||||||
|
@ -714,7 +727,7 @@ public class NamenodeWebHdfsMethods {
|
||||||
validateOpParams(op, delegationTokenArgument);
|
validateOpParams(op, delegationTokenArgument);
|
||||||
final Token<DelegationTokenIdentifier> token = new Token<DelegationTokenIdentifier>();
|
final Token<DelegationTokenIdentifier> token = new Token<DelegationTokenIdentifier>();
|
||||||
token.decodeFromUrlString(delegationTokenArgument.getValue());
|
token.decodeFromUrlString(delegationTokenArgument.getValue());
|
||||||
cp.cancelDelegationToken(token);
|
cancelDelegationToken(token);
|
||||||
return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build();
|
return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build();
|
||||||
}
|
}
|
||||||
case MODIFYACLENTRIES: {
|
case MODIFYACLENTRIES: {
|
||||||
|
@ -1138,9 +1151,8 @@ public class NamenodeWebHdfsMethods {
|
||||||
throw new IllegalArgumentException(delegation.getName()
|
throw new IllegalArgumentException(delegation.getName()
|
||||||
+ " parameter is not null.");
|
+ " parameter is not null.");
|
||||||
}
|
}
|
||||||
final NameNode namenode = (NameNode)context.getAttribute("name.node");
|
|
||||||
final Token<? extends TokenIdentifier> token = generateDelegationToken(
|
final Token<? extends TokenIdentifier> token = generateDelegationToken(
|
||||||
namenode, ugi, renewer.getValue());
|
ugi, renewer.getValue());
|
||||||
|
|
||||||
final String setServiceName = tokenService.getValue();
|
final String setServiceName = tokenService.getValue();
|
||||||
final String setKind = tokenKind.getValue();
|
final String setKind = tokenKind.getValue();
|
||||||
|
|
Loading…
Reference in New Issue