HDFS-14449. Expose total number of DT in JMX for Namenode. Contributed by Fengnan Li.

This commit is contained in:
Inigo Goiri 2019-07-30 13:45:27 -07:00
parent e68d8446c4
commit 7849bdcf70
4 changed files with 41 additions and 1 deletions

View File

@ -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");

View File

@ -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.
*

View File

@ -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();
}

View File

@ -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;
@ -154,6 +156,26 @@ public class TestDelegationToken {
}
}
@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");