HDFS-8721. Add a metric for number of encryption zones. Contributed by Rakesh R.

(cherry picked from commit cb03768b1b)
(cherry picked from commit 57d55d40dd)
This commit is contained in:
cnauroth 2015-07-21 13:55:58 -07:00 committed by Zhe Zhang
parent 5fe29062eb
commit a1d8e421f6
6 changed files with 30 additions and 0 deletions

View File

@ -215,6 +215,7 @@ Each metrics record contains tags such as HAState and Hostname as additional inf
| `TotalLoad` | Current number of connections |
| `SnapshottableDirectories` | Current number of snapshottable directories |
| `Snapshots` | Current number of snapshots |
| `NumEncryptionZones` | Current number of encryption zones |
| `BlocksTotal` | Current number of allocated blocks in the system |
| `FilesTotal` | Current number of files and directories |
| `PendingReplicationBlocks` | Current number of blocks pending to be replicated |

View File

@ -386,6 +386,13 @@ public class EncryptionZoneManager {
return new BatchedListEntries<EncryptionZone>(zones, hasMore);
}
/**
* @return number of encryption zones.
*/
public int getNumEncryptionZones() {
return encryptionZones.size();
}
/**
* @return Whether there has been any attempt to create an encryption zone in
* the cluster at all. If not, it is safe to quickly return null when

View File

@ -4930,6 +4930,12 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
return JSON.toString(info);
}
@Override // FSNamesystemMBean
@Metric({ "NumEncryptionZones", "The number of encryption zones" })
public int getNumEncryptionZones() {
return dir.ezManager.getNumEncryptionZones();
}
int getNumberOfDatanodes(DatanodeReportType type) {
readLock();
try {

View File

@ -184,4 +184,9 @@ public interface FSNamesystemMBean {
* @return JSON string
*/
public String getTopUserOpCounts();
/**
* Return the number of encryption zones in the system.
*/
int getNumEncryptionZones();
}

View File

@ -100,6 +100,8 @@ import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyString;
import static org.apache.hadoop.hdfs.DFSTestUtil.verifyFilesEqual;
import static org.apache.hadoop.test.GenericTestUtils.assertExceptionContains;
import static org.apache.hadoop.test.MetricsAsserts.assertGauge;
import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@ -123,6 +125,7 @@ public class TestEncryptionZones {
protected DistributedFileSystem fs;
private File testRootDir;
protected final String TEST_KEY = "test_key";
private static final String NS_METRICS = "FSNamesystem";
protected FileSystemTestWrapper fsWrapper;
protected FileContextTestWrapper fcWrapper;
@ -361,6 +364,9 @@ public class TestEncryptionZones {
fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
cluster.restartNameNode(true);
assertNumZones(numZones);
assertEquals("Unexpected number of encryption zones!", numZones, cluster
.getNamesystem().getNumEncryptionZones());
assertGauge("NumEncryptionZones", numZones, getMetrics(NS_METRICS));
assertZonePresent(null, zone1.toString());
// Verify newly added ez is present after restarting the NameNode

View File

@ -117,6 +117,11 @@ public class TestFSNamesystemMBean {
"PendingDeletionBlocks");
assertNotNull(pendingDeletionBlocks);
assertTrue(pendingDeletionBlocks instanceof Long);
Object encryptionZones = mbs.getAttribute(mxbeanName,
"NumEncryptionZones");
assertNotNull(encryptionZones);
assertTrue(encryptionZones instanceof Integer);
} finally {
if (cluster != null) {
cluster.shutdown();