HDFS-13869. RBF: Handle NPE for NamenodeBeanMetrics#getFederationMetrics. Contributed by Ranith Sardar.
This commit is contained in:
parent
01b4126b4e
commit
bbe859177d
@ -168,8 +168,12 @@ public void close() {
|
||||
}
|
||||
}
|
||||
|
||||
private FederationMetrics getFederationMetrics() {
|
||||
return this.router.getMetrics();
|
||||
private FederationMetrics getFederationMetrics() throws IOException {
|
||||
FederationMetrics metrics = getRouter().getMetrics();
|
||||
if (metrics == null) {
|
||||
throw new IOException("Federated metrics is not initialized");
|
||||
}
|
||||
return metrics;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
@ -188,22 +192,42 @@ public String getSoftwareVersion() {
|
||||
|
||||
@Override
|
||||
public long getUsed() {
|
||||
try {
|
||||
return getFederationMetrics().getUsedCapacity();
|
||||
} catch (IOException e) {
|
||||
LOG.debug("Failed to get the used capacity", e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getFree() {
|
||||
try {
|
||||
return getFederationMetrics().getRemainingCapacity();
|
||||
} catch (IOException e) {
|
||||
LOG.debug("Failed to get remaining capacity", e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTotal() {
|
||||
try {
|
||||
return getFederationMetrics().getTotalCapacity();
|
||||
} catch (IOException e) {
|
||||
LOG.debug("Failed to Get total capacity", e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getProvidedCapacity() {
|
||||
try {
|
||||
return getFederationMetrics().getProvidedSpace();
|
||||
} catch (IOException e) {
|
||||
LOG.debug("Failed to get provided capacity", e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -261,39 +285,79 @@ public float getPercentBlockPoolUsed() {
|
||||
|
||||
@Override
|
||||
public long getTotalBlocks() {
|
||||
try {
|
||||
return getFederationMetrics().getNumBlocks();
|
||||
} catch (IOException e) {
|
||||
LOG.debug("Failed to get number of blocks", e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getNumberOfMissingBlocks() {
|
||||
try {
|
||||
return getFederationMetrics().getNumOfMissingBlocks();
|
||||
} catch (IOException e) {
|
||||
LOG.debug("Failed to get number of missing blocks", e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public long getPendingReplicationBlocks() {
|
||||
try {
|
||||
return getFederationMetrics().getNumOfBlocksPendingReplication();
|
||||
} catch (IOException e) {
|
||||
LOG.debug("Failed to get number of blocks pending replica",
|
||||
e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPendingReconstructionBlocks() {
|
||||
try {
|
||||
return getFederationMetrics().getNumOfBlocksPendingReplication();
|
||||
} catch (IOException e) {
|
||||
LOG.debug("Failed to get number of blocks pending replica",
|
||||
e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public long getUnderReplicatedBlocks() {
|
||||
try {
|
||||
return getFederationMetrics().getNumOfBlocksUnderReplicated();
|
||||
} catch (IOException e) {
|
||||
LOG.debug("Failed to get number of blocks under replicated",
|
||||
e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLowRedundancyBlocks() {
|
||||
try {
|
||||
return getFederationMetrics().getNumOfBlocksUnderReplicated();
|
||||
} catch (IOException e) {
|
||||
LOG.debug("Failed to get number of blocks under replicated",
|
||||
e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPendingDeletionBlocks() {
|
||||
try {
|
||||
return getFederationMetrics().getNumOfBlocksPendingDeletion();
|
||||
} catch (IOException e) {
|
||||
LOG.debug("Failed to get number of blocks pending deletion",
|
||||
e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -471,7 +535,12 @@ public String getJournalTransactionInfo() {
|
||||
|
||||
@Override
|
||||
public long getNNStartedTimeInMillis() {
|
||||
return this.router.getStartTime();
|
||||
try {
|
||||
return getRouter().getStartTime();
|
||||
} catch (IOException e) {
|
||||
LOG.debug("Failed to get the router startup time", e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -527,7 +596,12 @@ public long getProvidedCapacityTotal() {
|
||||
|
||||
@Override
|
||||
public long getFilesTotal() {
|
||||
try {
|
||||
return getFederationMetrics().getNumFiles();
|
||||
} catch (IOException e) {
|
||||
LOG.debug("Failed to get number of files", e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -537,12 +611,22 @@ public int getTotalLoad() {
|
||||
|
||||
@Override
|
||||
public int getNumLiveDataNodes() {
|
||||
return this.router.getMetrics().getNumLiveNodes();
|
||||
try {
|
||||
return getFederationMetrics().getNumLiveNodes();
|
||||
} catch (IOException e) {
|
||||
LOG.debug("Failed to get number of live nodes", e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumDeadDataNodes() {
|
||||
return this.router.getMetrics().getNumDeadNodes();
|
||||
try {
|
||||
return getFederationMetrics().getNumDeadNodes();
|
||||
} catch (IOException e) {
|
||||
LOG.debug("Failed to get number of dead nodes", e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -552,17 +636,35 @@ public int getNumStaleDataNodes() {
|
||||
|
||||
@Override
|
||||
public int getNumDecomLiveDataNodes() {
|
||||
return this.router.getMetrics().getNumDecomLiveNodes();
|
||||
try {
|
||||
return getFederationMetrics().getNumDecomLiveNodes();
|
||||
} catch (IOException e) {
|
||||
LOG.debug("Failed to get the number of live decommissioned datanodes",
|
||||
e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumDecomDeadDataNodes() {
|
||||
return this.router.getMetrics().getNumDecomDeadNodes();
|
||||
try {
|
||||
return getFederationMetrics().getNumDecomDeadNodes();
|
||||
} catch (IOException e) {
|
||||
LOG.debug("Failed to get the number of dead decommissioned datanodes",
|
||||
e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumDecommissioningDataNodes() {
|
||||
return this.router.getMetrics().getNumDecommissioningNodes();
|
||||
try {
|
||||
return getFederationMetrics().getNumDecommissioningNodes();
|
||||
} catch (IOException e) {
|
||||
LOG.debug("Failed to get number of decommissioning nodes",
|
||||
e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -702,4 +804,11 @@ public int getNumEncryptionZones() {
|
||||
public String getVerifyECWithTopologyResult() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Router getRouter() throws IOException {
|
||||
if (this.router == null) {
|
||||
throw new IOException("Router is not initialized");
|
||||
}
|
||||
return this.router;
|
||||
}
|
||||
}
|
||||
|
@ -586,11 +586,11 @@ public FederationMetrics getMetrics() {
|
||||
*
|
||||
* @return Namenode metrics.
|
||||
*/
|
||||
public NamenodeBeanMetrics getNamenodeMetrics() {
|
||||
if (this.metrics != null) {
|
||||
return this.metrics.getNamenodeMetrics();
|
||||
public NamenodeBeanMetrics getNamenodeMetrics() throws IOException {
|
||||
if (this.metrics == null) {
|
||||
throw new IOException("Namenode metrics is not initialized");
|
||||
}
|
||||
return null;
|
||||
return this.metrics.getNamenodeMetrics();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -203,4 +203,18 @@ public void testRouterIDInRouterRpcClient() throws Exception {
|
||||
router.stop();
|
||||
router.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRouterMetricsWhenDisabled() throws Exception {
|
||||
|
||||
Router router = new Router();
|
||||
router.init(new RouterConfigBuilder(conf).rpc().build());
|
||||
router.start();
|
||||
|
||||
intercept(IOException.class, "Namenode metrics is not initialized",
|
||||
() -> router.getNamenodeMetrics().getCacheCapacity());
|
||||
|
||||
router.stop();
|
||||
router.close();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user