Search in sources :

Example 1 with HealthCheckFailedException

use of org.apache.hadoop.ha.HealthCheckFailedException in project hadoop by apache.

the class TestDFSHAAdmin method testCheckHealth.

@Test
public void testCheckHealth() throws Exception {
    assertEquals(0, runTool("-checkHealth", "nn1"));
    Mockito.verify(mockProtocol).monitorHealth();
    Mockito.doThrow(new HealthCheckFailedException("fake health check failure")).when(mockProtocol).monitorHealth();
    assertEquals(-1, runTool("-checkHealth", "nn1"));
    assertOutputContains("Health check failed: fake health check failure");
}
Also used : HealthCheckFailedException(org.apache.hadoop.ha.HealthCheckFailedException) Test(org.junit.Test)

Example 2 with HealthCheckFailedException

use of org.apache.hadoop.ha.HealthCheckFailedException in project hadoop by apache.

the class TestNNHealthCheck method doNNHealthCheckTest.

private void doNNHealthCheckTest() throws IOException {
    MockNameNodeResourceChecker mockResourceChecker = new MockNameNodeResourceChecker(conf);
    cluster.getNameNode(0).getNamesystem().setNNResourceChecker(mockResourceChecker);
    NNHAServiceTarget haTarget = new NNHAServiceTarget(conf, DFSUtil.getNamenodeNameServiceId(conf), "nn1");
    final String expectedTargetString;
    if (conf.get(DFS_NAMENODE_LIFELINE_RPC_ADDRESS_KEY + "." + DFSUtil.getNamenodeNameServiceId(conf) + ".nn1") != null) {
        expectedTargetString = haTarget.getHealthMonitorAddress().toString();
    } else {
        expectedTargetString = haTarget.getAddress().toString();
    }
    assertTrue("Expected haTarget " + haTarget + " containing " + expectedTargetString, haTarget.toString().contains(expectedTargetString));
    HAServiceProtocol rpc = haTarget.getHealthMonitorProxy(conf, conf.getInt(HA_HM_RPC_TIMEOUT_KEY, HA_HM_RPC_TIMEOUT_DEFAULT));
    // Should not throw error, which indicates healthy.
    rpc.monitorHealth();
    mockResourceChecker.setResourcesAvailable(false);
    try {
        // Should throw error - NN is unhealthy.
        rpc.monitorHealth();
        fail("Should not have succeeded in calling monitorHealth");
    } catch (HealthCheckFailedException hcfe) {
        GenericTestUtils.assertExceptionContains("The NameNode has no resources available", hcfe);
    } catch (RemoteException re) {
        GenericTestUtils.assertExceptionContains("The NameNode has no resources available", re.unwrapRemoteException(HealthCheckFailedException.class));
    }
}
Also used : MockNameNodeResourceChecker(org.apache.hadoop.hdfs.server.namenode.MockNameNodeResourceChecker) HAServiceProtocol(org.apache.hadoop.ha.HAServiceProtocol) NNHAServiceTarget(org.apache.hadoop.hdfs.tools.NNHAServiceTarget) RemoteException(org.apache.hadoop.ipc.RemoteException) HealthCheckFailedException(org.apache.hadoop.ha.HealthCheckFailedException)

Aggregations

HealthCheckFailedException (org.apache.hadoop.ha.HealthCheckFailedException)2 HAServiceProtocol (org.apache.hadoop.ha.HAServiceProtocol)1 MockNameNodeResourceChecker (org.apache.hadoop.hdfs.server.namenode.MockNameNodeResourceChecker)1 NNHAServiceTarget (org.apache.hadoop.hdfs.tools.NNHAServiceTarget)1 RemoteException (org.apache.hadoop.ipc.RemoteException)1 Test (org.junit.Test)1