HDFS-14449. Expose total number of DT in JMX for Namenode. Contributed by Fengnan Li.
This commit is contained in:
parent
e68d8446c4
commit
7849bdcf70
|
@ -838,6 +838,11 @@ public class NamenodeBeanMetrics
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCurrentTokensCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private Router getRouter() throws IOException {
|
||||
if (this.router == null) {
|
||||
throw new IOException("Router is not initialized");
|
||||
|
|
|
@ -4423,6 +4423,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|||
return dir.ezManager.getNumEncryptionZones();
|
||||
}
|
||||
|
||||
@Override // FSNamesystemMBean
|
||||
@Metric({ "CurrentTokensCount", "The number of delegation tokens"})
|
||||
public long getCurrentTokensCount() {
|
||||
return dtSecretManager != null ?
|
||||
dtSecretManager.getCurrentTokensSize() : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the wait Queue for the FSNameSystemLock.
|
||||
*
|
||||
|
|
|
@ -242,4 +242,10 @@ public interface FSNamesystemMBean {
|
|||
* @return Number of ENTERING_MAINTENANCE data nodes
|
||||
*/
|
||||
int getNumEnteringMaintenanceDataNodes();
|
||||
|
||||
/**
|
||||
* Get the current number of delegation tokens in memory.
|
||||
* @return number of DTs
|
||||
*/
|
||||
long getCurrentTokensCount();
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.hadoop.hdfs.security;
|
|||
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
@ -41,6 +42,7 @@ import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|||
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
|
||||
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenSecretManager;
|
||||
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
|
||||
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
|
||||
import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
||||
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
|
||||
import org.apache.hadoop.hdfs.server.namenode.web.resources.NamenodeWebHdfsMethods;
|
||||
|
@ -153,7 +155,27 @@ public class TestDelegationToken {
|
|||
// PASS
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDelegationTokenMetrics() throws Exception {
|
||||
FSNamesystem namesystem = cluster.getNamesystem();
|
||||
// should start with no token
|
||||
assertEquals(0, namesystem.getCurrentTokensCount());
|
||||
|
||||
// get token
|
||||
Token<DelegationTokenIdentifier> token = generateDelegationToken(
|
||||
"SomeUser", "JobTracker");
|
||||
assertEquals(1, namesystem.getCurrentTokensCount());
|
||||
|
||||
// Renew token shouldn't change the count of tokens
|
||||
dtSecretManager.renewToken(token, "JobTracker");
|
||||
assertEquals(1, namesystem.getCurrentTokensCount());
|
||||
|
||||
// Cancel token should remove the token from memory
|
||||
dtSecretManager.cancelToken(token, "JobTracker");
|
||||
assertEquals(0, namesystem.getCurrentTokensCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddDelegationTokensDFSApi() throws Exception {
|
||||
UserGroupInformation ugi = UserGroupInformation.createRemoteUser("JobTracker");
|
||||
|
|
Loading…
Reference in New Issue