RBFMetrics implements RouterMBean, FederationMBean { @Override public String getMountTable() { final List<Map<String, Object>> info = new LinkedList<>(); if (mountTableStore == null) { return "[]"; } try { GetMountTableEntriesRequest request = GetMountTableEntriesRequest.newInstance("/"); GetMountTableEntriesResponse response = mountTableStore.getMountTableEntries(request); final List<MountTable> mounts = response.getEntries(); List<MountTable> orderedMounts = new ArrayList<>(mounts); Collections.sort(orderedMounts, MountTable.SOURCE_COMPARATOR); for (MountTable entry : orderedMounts) { Set<String> nameservices = new LinkedHashSet<>(); Set<String> paths = new LinkedHashSet<>(); for (RemoteLocation location : entry.getDestinations()) { nameservices.add(location.getNameserviceId()); paths.add(location.getDest()); } Map<String, Object> map = getJson(entry); map.put("dateCreated", getDateString(entry.getDateCreated())); map.put("dateModified", getDateString(entry.getDateModified())); Map<String, Object> innerInfo = new HashMap<>(); innerInfo.putAll(map); innerInfo.put("nameserviceId", StringUtils.join(",", nameservices)); innerInfo.put("path", StringUtils.join(",", paths)); if (nameservices.size() > 1) { innerInfo.put("order", entry.getDestOrder().toString()); } else { innerInfo.put("order", ""); } innerInfo.put("readonly", entry.isReadOnly()); innerInfo.put("faulttolerant", entry.isFaultTolerant()); info.add(Collections.unmodifiableMap(innerInfo)); } } catch (IOException e) { LOG.error( "Cannot generate JSON of mount table from store: {}", e.getMessage()); return "[]"; } return JSON.toString(info); } RBFMetrics(Router router); void close(); @Override String getNamenodes(); @Override String getNameservices(); @Override String getMountTable(); @Override String getRouters(); @Override long getTotalCapacity(); @Override long getRemainingCapacity(); @Override long getProvidedSpace(); @Override long getUsedCapacity(); @Override int getNumNameservices(); @Override int getNumNamenodes(); @Override int getNumExpiredNamenodes(); @Override int getNumLiveNodes(); @Override int getNumDeadNodes(); @Override int getNumStaleNodes(); @Override int getNumDecommissioningNodes(); @Override int getNumDecomLiveNodes(); @Override int getNumDecomDeadNodes(); @Override int getNumInMaintenanceLiveDataNodes(); @Override int getNumInMaintenanceDeadDataNodes(); @Override int getNumEnteringMaintenanceDataNodes(); @Override // NameNodeMXBean String getNodeUsage(); @Override long getNumBlocks(); @Override long getNumOfMissingBlocks(); @Override long getNumOfBlocksPendingReplication(); @Override long getNumOfBlocksUnderReplicated(); @Override long getNumOfBlocksPendingDeletion(); @Override long getNumFiles(); @Override String getRouterStarted(); @Override String getVersion(); @Override String getCompiledDate(); @Override String getCompileInfo(); @Override String getHostAndPort(); @Override String getRouterId(); @Override String getClusterId(); @Override String getBlockPoolId(); @Override String getRouterStatus(); @Override long getCurrentTokensCount(); @Override String getTopTokenRealOwners(); @Override boolean isSecurityEnabled(); @Override int getCorruptFilesCount(); @Override long getScheduledReplicationBlocks(); @Override long getNumberOfMissingBlocksWithReplicationFactorOne(); @Override long getHighestPriorityLowRedundancyReplicatedBlocks(); @Override long getHighestPriorityLowRedundancyECBlocks(); @Override String getSafemode();  }
@Test public void testMountTableStatsDataSource() throws IOException, JSONException { RBFMetrics metrics = getRouter().getMetrics(); String jsonString = metrics.getMountTable(); JSONArray jsonArray = new JSONArray(jsonString); assertEquals(jsonArray.length(), getMockMountTable().size()); int match = 0; for (int i = 0; i < jsonArray.length(); i++) { JSONObject json = jsonArray.getJSONObject(i); String src = json.getString("sourcePath"); for (MountTable entry : getMockMountTable()) { if (entry.getSourcePath().equals(src)) { assertEquals(entry.getDefaultLocation().getNameserviceId(), json.getString("nameserviceId")); assertEquals(entry.getDefaultLocation().getDest(), json.getString("path")); assertEquals(entry.getOwnerName(), json.getString("ownerName")); assertEquals(entry.getGroupName(), json.getString("groupName")); assertEquals(entry.getMode().toString(), json.getString("mode")); assertEquals(entry.getQuota().toString(), json.getString("quota")); assertNotNullAndNotEmpty(json.getString("dateCreated")); assertNotNullAndNotEmpty(json.getString("dateModified")); match++; } } } assertEquals(match, getMockMountTable().size()); }