HDFS-14426. RBF: Add delegation token total count as one of the federation metrics. Contributed by Fengnan Li.
This commit is contained in:
parent
203664e6b2
commit
32841178ba
|
@ -244,4 +244,10 @@ public interface FederationMBean {
|
||||||
* @return String label for the current router state.
|
* @return String label for the current router state.
|
||||||
*/
|
*/
|
||||||
String getRouterStatus();
|
String getRouterStatus();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current number of delegation tokens in memory.
|
||||||
|
* @return number of DTs
|
||||||
|
*/
|
||||||
|
long getCurrentTokensCount();
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ import org.apache.hadoop.hdfs.server.federation.resolver.RemoteLocation;
|
||||||
import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys;
|
import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys;
|
||||||
import org.apache.hadoop.hdfs.server.federation.router.Router;
|
import org.apache.hadoop.hdfs.server.federation.router.Router;
|
||||||
import org.apache.hadoop.hdfs.server.federation.router.RouterRpcServer;
|
import org.apache.hadoop.hdfs.server.federation.router.RouterRpcServer;
|
||||||
|
import org.apache.hadoop.hdfs.server.federation.router.security.RouterSecurityManager;
|
||||||
import org.apache.hadoop.hdfs.server.federation.store.MembershipStore;
|
import org.apache.hadoop.hdfs.server.federation.store.MembershipStore;
|
||||||
import org.apache.hadoop.hdfs.server.federation.store.MountTableStore;
|
import org.apache.hadoop.hdfs.server.federation.store.MountTableStore;
|
||||||
import org.apache.hadoop.hdfs.server.federation.store.RouterStore;
|
import org.apache.hadoop.hdfs.server.federation.store.RouterStore;
|
||||||
|
@ -604,6 +605,16 @@ public class FederationMetrics implements FederationMBean {
|
||||||
return this.router.getRouterState().toString();
|
return this.router.getRouterState().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getCurrentTokensCount() {
|
||||||
|
RouterSecurityManager mgr =
|
||||||
|
this.router.getRpcServer().getRouterSecurityManager();
|
||||||
|
if (mgr != null && mgr.getSecretManager() != null) {
|
||||||
|
return mgr.getSecretManager().getCurrentTokensSize();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a set of unique values found in all namespaces.
|
* Build a set of unique values found in all namespaces.
|
||||||
*
|
*
|
||||||
|
|
|
@ -47,8 +47,13 @@ public class RouterHDFSContract extends HDFSContract {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createCluster(Configuration conf) throws IOException {
|
public static void createCluster(Configuration conf) throws IOException {
|
||||||
|
createCluster(true, 2, conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createCluster(
|
||||||
|
boolean ha, int numNameServices, Configuration conf) throws IOException {
|
||||||
try {
|
try {
|
||||||
cluster = new MiniRouterDFSCluster(true, 2, conf);
|
cluster = new MiniRouterDFSCluster(ha, numNameServices, conf);
|
||||||
|
|
||||||
// Start NNs and DNs and wait until ready
|
// Start NNs and DNs and wait until ready
|
||||||
cluster.startCluster(conf);
|
cluster.startCluster(conf);
|
||||||
|
|
|
@ -18,11 +18,18 @@
|
||||||
|
|
||||||
package org.apache.hadoop.fs.contract.router;
|
package org.apache.hadoop.fs.contract.router;
|
||||||
|
|
||||||
|
import static org.apache.hadoop.fs.contract.router.SecurityConfUtil.initSecurity;
|
||||||
|
import static org.apache.hadoop.hdfs.server.federation.metrics.TestFederationMetrics.FEDERATION_BEAN;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
import org.apache.hadoop.fs.contract.AbstractFSContract;
|
import org.apache.hadoop.fs.contract.AbstractFSContract;
|
||||||
import org.apache.hadoop.fs.contract.AbstractFSContractTestBase;
|
import org.apache.hadoop.fs.contract.AbstractFSContractTestBase;
|
||||||
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
|
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
|
||||||
|
import org.apache.hadoop.hdfs.server.federation.FederationTestUtils;
|
||||||
|
import org.apache.hadoop.hdfs.server.federation.metrics.FederationMBean;
|
||||||
import org.apache.hadoop.security.token.SecretManager;
|
import org.apache.hadoop.security.token.SecretManager;
|
||||||
import org.apache.hadoop.security.token.Token;
|
import org.apache.hadoop.security.token.Token;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
|
@ -31,9 +38,6 @@ import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import static org.apache.hadoop.fs.contract.router.SecurityConfUtil.initSecurity;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test to verify router contracts for delegation token operations.
|
* Test to verify router contracts for delegation token operations.
|
||||||
*/
|
*/
|
||||||
|
@ -42,7 +46,7 @@ public class TestRouterHDFSContractDelegationToken
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void createCluster() throws Exception {
|
public static void createCluster() throws Exception {
|
||||||
RouterHDFSContract.createCluster(initSecurity());
|
RouterHDFSContract.createCluster(false, 1, initSecurity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
|
@ -60,6 +64,10 @@ public class TestRouterHDFSContractDelegationToken
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRouterDelegationToken() throws Exception {
|
public void testRouterDelegationToken() throws Exception {
|
||||||
|
FederationMBean bean = FederationTestUtils.getBean(
|
||||||
|
FEDERATION_BEAN, FederationMBean.class);
|
||||||
|
// Initially there is no token in memory
|
||||||
|
assertEquals(0, bean.getCurrentTokensCount());
|
||||||
// Generate delegation token
|
// Generate delegation token
|
||||||
Token<DelegationTokenIdentifier> token =
|
Token<DelegationTokenIdentifier> token =
|
||||||
(Token<DelegationTokenIdentifier>) getFileSystem()
|
(Token<DelegationTokenIdentifier>) getFileSystem()
|
||||||
|
@ -81,6 +89,8 @@ public class TestRouterHDFSContractDelegationToken
|
||||||
assertTrue(sequenceNumber > 0);
|
assertTrue(sequenceNumber > 0);
|
||||||
long existingMaxTime = token.decodeIdentifier().getMaxDate();
|
long existingMaxTime = token.decodeIdentifier().getMaxDate();
|
||||||
assertTrue(identifier.getMaxDate() >= identifier.getIssueDate());
|
assertTrue(identifier.getMaxDate() >= identifier.getIssueDate());
|
||||||
|
// one token is expected after the generation
|
||||||
|
assertEquals(1, bean.getCurrentTokensCount());
|
||||||
|
|
||||||
// Renew delegation token
|
// Renew delegation token
|
||||||
long expiryTime = token.renew(initSecurity());
|
long expiryTime = token.renew(initSecurity());
|
||||||
|
@ -92,9 +102,11 @@ public class TestRouterHDFSContractDelegationToken
|
||||||
identifier = token.decodeIdentifier();
|
identifier = token.decodeIdentifier();
|
||||||
assertEquals(identifier.getMasterKeyId(), masterKeyId);
|
assertEquals(identifier.getMasterKeyId(), masterKeyId);
|
||||||
assertEquals(identifier.getSequenceNumber(), sequenceNumber);
|
assertEquals(identifier.getSequenceNumber(), sequenceNumber);
|
||||||
|
assertEquals(1, bean.getCurrentTokensCount());
|
||||||
|
|
||||||
// Cancel delegation token
|
// Cancel delegation token
|
||||||
token.cancel(initSecurity());
|
token.cancel(initSecurity());
|
||||||
|
assertEquals(0, bean.getCurrentTokensCount());
|
||||||
|
|
||||||
// Renew a cancelled token
|
// Renew a cancelled token
|
||||||
exceptionRule.expect(SecretManager.InvalidToken.class);
|
exceptionRule.expect(SecretManager.InvalidToken.class);
|
||||||
|
|
Loading…
Reference in New Issue