Search in sources :

Example 16 with StateChangeRequestInfo

use of org.apache.hadoop.ha.HAServiceProtocol.StateChangeRequestInfo in project hadoop by apache.

the class TestHASafeMode method testEnterSafeModeInANNShouldNotThrowNPE.

/**
   * Test case for enter safemode in active namenode, when it is already in startup safemode.
   * It is a regression test for HDFS-2747.
   */
@Test
public void testEnterSafeModeInANNShouldNotThrowNPE() throws Exception {
    banner("Restarting active");
    DFSTestUtil.createFile(fs, new Path("/test"), 3 * BLOCK_SIZE, (short) 3, 1L);
    restartActive();
    nn0.getRpcServer().transitionToActive(new StateChangeRequestInfo(RequestSource.REQUEST_BY_USER));
    FSNamesystem namesystem = nn0.getNamesystem();
    String status = namesystem.getSafemode();
    assertTrue("Bad safemode status: '" + status + "'", status.startsWith("Safe mode is ON."));
    NameNodeAdapter.enterSafeMode(nn0, false);
    assertTrue("Failed to enter into safemode in active", namesystem.isInSafeMode());
    NameNodeAdapter.enterSafeMode(nn0, false);
    assertTrue("Failed to enter into safemode in active", namesystem.isInSafeMode());
}
Also used : Path(org.apache.hadoop.fs.Path) StateChangeRequestInfo(org.apache.hadoop.ha.HAServiceProtocol.StateChangeRequestInfo) FSNamesystem(org.apache.hadoop.hdfs.server.namenode.FSNamesystem) Test(org.junit.Test)

Example 17 with StateChangeRequestInfo

use of org.apache.hadoop.ha.HAServiceProtocol.StateChangeRequestInfo in project hadoop by apache.

the class TestDFSHAAdmin method testMutativeOperationsWithAutoHaEnabled.

/**
   * Test that, if automatic HA is enabled, none of the mutative operations
   * will succeed, unless the -forcemanual flag is specified.
   * @throws Exception
   */
@Test
public void testMutativeOperationsWithAutoHaEnabled() throws Exception {
    Mockito.doReturn(STANDBY_READY_RESULT).when(mockProtocol).getServiceStatus();
    // Turn on auto-HA in the config
    HdfsConfiguration conf = getHAConf();
    conf.setBoolean(DFSConfigKeys.DFS_HA_AUTO_FAILOVER_ENABLED_KEY, true);
    conf.set(DFSConfigKeys.DFS_HA_FENCE_METHODS_KEY, getFencerTrueCommand());
    tool.setConf(conf);
    // Should fail without the forcemanual flag
    assertEquals(-1, runTool("-transitionToActive", "nn1"));
    assertTrue(errOutput.contains("Refusing to manually manage"));
    assertEquals(-1, runTool("-transitionToStandby", "nn1"));
    assertTrue(errOutput.contains("Refusing to manually manage"));
    Mockito.verify(mockProtocol, Mockito.never()).transitionToActive(anyReqInfo());
    Mockito.verify(mockProtocol, Mockito.never()).transitionToStandby(anyReqInfo());
    // Force flag should bypass the check and change the request source
    // for the RPC
    setupConfirmationOnSystemIn();
    assertEquals(0, runTool("-transitionToActive", "-forcemanual", "nn1"));
    setupConfirmationOnSystemIn();
    assertEquals(0, runTool("-transitionToStandby", "-forcemanual", "nn1"));
    Mockito.verify(mockProtocol, Mockito.times(1)).transitionToActive(reqInfoCaptor.capture());
    Mockito.verify(mockProtocol, Mockito.times(1)).transitionToStandby(reqInfoCaptor.capture());
    // All of the RPCs should have had the "force" source
    for (StateChangeRequestInfo ri : reqInfoCaptor.getAllValues()) {
        assertEquals(RequestSource.REQUEST_BY_USER_FORCED, ri.getSource());
    }
}
Also used : StateChangeRequestInfo(org.apache.hadoop.ha.HAServiceProtocol.StateChangeRequestInfo) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) Test(org.junit.Test)

Aggregations

StateChangeRequestInfo (org.apache.hadoop.ha.HAServiceProtocol.StateChangeRequestInfo)17 Test (org.junit.Test)15 Configuration (org.apache.hadoop.conf.Configuration)12 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)12 AccessControlException (org.apache.hadoop.security.AccessControlException)5 IOException (java.io.IOException)4 HealthCheckFailedException (org.apache.hadoop.ha.HealthCheckFailedException)4 ServiceFailedException (org.apache.hadoop.ha.ServiceFailedException)4 YarnRuntimeException (org.apache.hadoop.yarn.exceptions.YarnRuntimeException)4 StoreFencedException (org.apache.hadoop.yarn.server.resourcemanager.recovery.StoreFencedException)4 JSONException (org.codehaus.jettison.json.JSONException)4 MemoryRMStateStore (org.apache.hadoop.yarn.server.resourcemanager.recovery.MemoryRMStateStore)3 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 TestingServer (org.apache.curator.test.TestingServer)2 Path (org.apache.hadoop.fs.Path)2 Dispatcher (org.apache.hadoop.yarn.event.Dispatcher)2 DrainDispatcher (org.apache.hadoop.yarn.event.DrainDispatcher)2 MockRM (org.apache.hadoop.yarn.server.resourcemanager.MockRM)2 ResourceManager (org.apache.hadoop.yarn.server.resourcemanager.ResourceManager)2 FileSystem (org.apache.hadoop.fs.FileSystem)1