Search in sources :

Example 1 with StateChangeRequestInfo

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

the class TestRMHA method testTransitionsWhenAutomaticFailoverEnabled.

@Test
public void testTransitionsWhenAutomaticFailoverEnabled() throws Exception {
    final String ERR_UNFORCED_REQUEST = "User request succeeded even when " + "automatic failover is enabled";
    Configuration conf = new YarnConfiguration(configuration);
    rm = new MockRM(conf);
    rm.init(conf);
    rm.start();
    StateChangeRequestInfo requestInfo = new StateChangeRequestInfo(HAServiceProtocol.RequestSource.REQUEST_BY_USER);
    // Transition to standby
    try {
        rm.adminService.transitionToStandby(requestInfo);
        fail(ERR_UNFORCED_REQUEST);
    } catch (AccessControlException e) {
    // expected
    }
    checkMonitorHealth();
    checkStandbyRMFunctionality();
    // Transition to active
    try {
        rm.adminService.transitionToActive(requestInfo);
        fail(ERR_UNFORCED_REQUEST);
    } catch (AccessControlException e) {
    // expected
    }
    checkMonitorHealth();
    checkStandbyRMFunctionality();
    final String ERR_FORCED_REQUEST = "Forced request by user should work " + "even if automatic failover is enabled";
    requestInfo = new StateChangeRequestInfo(HAServiceProtocol.RequestSource.REQUEST_BY_USER_FORCED);
    // Transition to standby
    try {
        rm.adminService.transitionToStandby(requestInfo);
    } catch (AccessControlException e) {
        fail(ERR_FORCED_REQUEST);
    }
    checkMonitorHealth();
    checkStandbyRMFunctionality();
    // Transition to active
    try {
        rm.adminService.transitionToActive(requestInfo);
    } catch (AccessControlException e) {
        fail(ERR_FORCED_REQUEST);
    }
    checkMonitorHealth();
    checkActiveRMFunctionality();
}
Also used : YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) AccessControlException(org.apache.hadoop.security.AccessControlException) StateChangeRequestInfo(org.apache.hadoop.ha.HAServiceProtocol.StateChangeRequestInfo) Test(org.junit.Test)

Example 2 with StateChangeRequestInfo

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

the class TestRMHA method testFailoverClearsRMContext.

@Test
public void testFailoverClearsRMContext() throws Exception {
    configuration.setBoolean(YarnConfiguration.AUTO_FAILOVER_ENABLED, false);
    configuration.setBoolean(YarnConfiguration.RECOVERY_ENABLED, true);
    Configuration conf = new YarnConfiguration(configuration);
    MemoryRMStateStore memStore = new MemoryRMStateStore();
    memStore.init(conf);
    // 1. start RM
    rm = new MockRM(conf, memStore);
    rm.init(conf);
    rm.start();
    StateChangeRequestInfo requestInfo = new StateChangeRequestInfo(HAServiceProtocol.RequestSource.REQUEST_BY_USER);
    checkMonitorHealth();
    checkStandbyRMFunctionality();
    // 2. Transition to active
    rm.adminService.transitionToActive(requestInfo);
    checkMonitorHealth();
    checkActiveRMFunctionality();
    verifyClusterMetrics(1, 1, 1, 1, 2048, 1);
    assertEquals(1, rm.getRMContext().getRMNodes().size());
    assertEquals(1, rm.getRMContext().getRMApps().size());
    // 3. Create new RM
    rm = new MockRM(conf, memStore) {

        @Override
        protected ResourceTrackerService createResourceTrackerService() {
            return new ResourceTrackerService(this.rmContext, this.nodesListManager, this.nmLivelinessMonitor, this.rmContext.getContainerTokenSecretManager(), this.rmContext.getNMTokenSecretManager()) {

                @Override
                protected void serviceStart() throws Exception {
                    throw new Exception("ResourceTracker service failed");
                }
            };
        }
    };
    rm.init(conf);
    rm.start();
    checkMonitorHealth();
    checkStandbyRMFunctionality();
    // 4. Try Transition to active, throw exception
    try {
        rm.adminService.transitionToActive(requestInfo);
        Assert.fail("Transitioned to Active should throw exception.");
    } catch (Exception e) {
        assertTrue("Error when transitioning to Active mode".contains(e.getMessage()));
    }
    // 5. Clears the metrics
    verifyClusterMetrics(0, 0, 0, 0, 0, 0);
    assertEquals(0, rm.getRMContext().getRMNodes().size());
    assertEquals(0, rm.getRMContext().getRMApps().size());
}
Also used : MemoryRMStateStore(org.apache.hadoop.yarn.server.resourcemanager.recovery.MemoryRMStateStore) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) StateChangeRequestInfo(org.apache.hadoop.ha.HAServiceProtocol.StateChangeRequestInfo) StoreFencedException(org.apache.hadoop.yarn.server.resourcemanager.recovery.StoreFencedException) ServiceFailedException(org.apache.hadoop.ha.ServiceFailedException) HealthCheckFailedException(org.apache.hadoop.ha.HealthCheckFailedException) IOException(java.io.IOException) YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) JSONException(org.codehaus.jettison.json.JSONException) AccessControlException(org.apache.hadoop.security.AccessControlException) Test(org.junit.Test)

Example 3 with StateChangeRequestInfo

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

the class TestRMHA method testFailoverWhenTransitionToActiveThrowException.

@Test(timeout = 30000)
public void testFailoverWhenTransitionToActiveThrowException() throws Exception {
    configuration.setBoolean(YarnConfiguration.AUTO_FAILOVER_ENABLED, false);
    Configuration conf = new YarnConfiguration(configuration);
    MemoryRMStateStore memStore = new MemoryRMStateStore() {

        int count = 0;

        @Override
        public synchronized void startInternal() throws Exception {
            // first time throw exception
            if (count++ == 0) {
                throw new Exception("Session Expired");
            }
        }
    };
    // start RM
    memStore.init(conf);
    rm = new MockRM(conf, memStore);
    rm.init(conf);
    StateChangeRequestInfo requestInfo = new StateChangeRequestInfo(HAServiceProtocol.RequestSource.REQUEST_BY_USER);
    assertEquals(STATE_ERR, HAServiceState.INITIALIZING, rm.adminService.getServiceStatus().getState());
    assertFalse("RM is ready to become active before being started", rm.adminService.getServiceStatus().isReadyToBecomeActive());
    checkMonitorHealth();
    rm.start();
    checkMonitorHealth();
    checkStandbyRMFunctionality();
    // 2. Try Transition to active, throw exception
    try {
        rm.adminService.transitionToActive(requestInfo);
        Assert.fail("Transitioned to Active should throw exception.");
    } catch (Exception e) {
        assertTrue("Error when transitioning to Active mode".contains(e.getMessage()));
    }
    // 3. Transition to active, success
    rm.adminService.transitionToActive(requestInfo);
    checkMonitorHealth();
    checkActiveRMFunctionality();
}
Also used : MemoryRMStateStore(org.apache.hadoop.yarn.server.resourcemanager.recovery.MemoryRMStateStore) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) StateChangeRequestInfo(org.apache.hadoop.ha.HAServiceProtocol.StateChangeRequestInfo) StoreFencedException(org.apache.hadoop.yarn.server.resourcemanager.recovery.StoreFencedException) ServiceFailedException(org.apache.hadoop.ha.ServiceFailedException) HealthCheckFailedException(org.apache.hadoop.ha.HealthCheckFailedException) IOException(java.io.IOException) YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) JSONException(org.codehaus.jettison.json.JSONException) AccessControlException(org.apache.hadoop.security.AccessControlException) Test(org.junit.Test)

Example 4 with StateChangeRequestInfo

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

the class TestRMStoreCommands method testRemoveApplicationFromStateStoreCmdForZK.

@Test
public void testRemoveApplicationFromStateStoreCmdForZK() throws Exception {
    StateChangeRequestInfo req = new StateChangeRequestInfo(HAServiceProtocol.RequestSource.REQUEST_BY_USER);
    try (TestingServer curatorTestingServer = TestZKRMStateStore.setupCuratorServer();
        CuratorFramework curatorFramework = TestZKRMStateStore.setupCuratorFramework(curatorTestingServer)) {
        Configuration conf = TestZKRMStateStore.createHARMConf("rm1,rm2", "rm1", 1234, false, curatorTestingServer);
        ResourceManager rm = new MockRM(conf);
        rm.start();
        rm.getRMContext().getRMAdminService().transitionToActive(req);
        rm.close();
        String appId = ApplicationId.newInstance(System.currentTimeMillis(), 1).toString();
        String appRootPath = YarnConfiguration.DEFAULT_ZK_RM_STATE_STORE_PARENT_PATH + "/" + ZKRMStateStore.ROOT_ZNODE_NAME + "/" + RMStateStore.RM_APP_ROOT;
        String appIdPath = appRootPath + "/" + appId;
        curatorFramework.create().forPath(appIdPath);
        assertEquals("Application node for " + appId + "should exist", appId, curatorFramework.getChildren().forPath(appRootPath).get(0));
        try {
            ResourceManager.removeApplication(conf, appId);
        } catch (Exception e) {
            fail("Exception should not be thrown while removing app from " + "rm state store.");
        }
        assertTrue("After remove app from store there should be no child nodes" + " in app root path", curatorFramework.getChildren().forPath(appRootPath).isEmpty());
    }
}
Also used : TestingServer(org.apache.curator.test.TestingServer) CuratorFramework(org.apache.curator.framework.CuratorFramework) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) StateChangeRequestInfo(org.apache.hadoop.ha.HAServiceProtocol.StateChangeRequestInfo) Test(org.junit.Test)

Example 5 with StateChangeRequestInfo

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

the class TestRMAdminService method testRMHAWithFileSystemBasedConfiguration.

@Test
public void testRMHAWithFileSystemBasedConfiguration() throws IOException, YarnException {
    StateChangeRequestInfo requestInfo = new StateChangeRequestInfo(HAServiceProtocol.RequestSource.REQUEST_BY_USER);
    updateConfigurationForRMHA();
    Configuration conf1 = new Configuration(configuration);
    conf1.set(YarnConfiguration.RM_HA_ID, "rm1");
    Configuration conf2 = new Configuration(configuration);
    conf2.set(YarnConfiguration.RM_HA_ID, "rm2");
    // upload default configurations
    uploadDefaultConfiguration();
    MockRM rm1 = null;
    MockRM rm2 = null;
    try {
        rm1 = new MockRM(conf1);
        rm1.init(conf1);
        rm1.start();
        Assert.assertTrue(rm1.getRMContext().getHAServiceState() == HAServiceState.STANDBY);
        rm2 = new MockRM(conf2);
        rm2.init(conf1);
        rm2.start();
        Assert.assertTrue(rm2.getRMContext().getHAServiceState() == HAServiceState.STANDBY);
        rm1.adminService.transitionToActive(requestInfo);
        Assert.assertTrue(rm1.getRMContext().getHAServiceState() == HAServiceState.ACTIVE);
        CapacitySchedulerConfiguration csConf = new CapacitySchedulerConfiguration();
        csConf.set(CapacitySchedulerConfiguration.MAXIMUM_SYSTEM_APPLICATIONS, "5000");
        uploadConfiguration(csConf, "capacity-scheduler.xml");
        rm1.adminService.refreshQueues(RefreshQueuesRequest.newInstance());
        int maxApps = ((CapacityScheduler) rm1.getRMContext().getScheduler()).getConfiguration().getMaximumSystemApplications();
        Assert.assertEquals(maxApps, 5000);
        // Before failover happens, the maxApps is
        // still the default value on the standby rm : rm2
        int maxAppsBeforeFailOver = ((CapacityScheduler) rm2.getRMContext().getScheduler()).getConfiguration().getMaximumSystemApplications();
        Assert.assertEquals(maxAppsBeforeFailOver, 10000);
        // Do the failover
        rm1.adminService.transitionToStandby(requestInfo);
        rm2.adminService.transitionToActive(requestInfo);
        Assert.assertTrue(rm1.getRMContext().getHAServiceState() == HAServiceState.STANDBY);
        Assert.assertTrue(rm2.getRMContext().getHAServiceState() == HAServiceState.ACTIVE);
        int maxAppsAfter = ((CapacityScheduler) rm2.getRMContext().getScheduler()).getConfiguration().getMaximumSystemApplications();
        Assert.assertEquals(maxAppsAfter, 5000);
    } finally {
        if (rm1 != null) {
            rm1.stop();
        }
        if (rm2 != null) {
            rm2.stop();
        }
    }
}
Also used : CapacitySchedulerConfiguration(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration) Configuration(org.apache.hadoop.conf.Configuration) DynamicResourceConfiguration(org.apache.hadoop.yarn.server.resourcemanager.resource.DynamicResourceConfiguration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) StateChangeRequestInfo(org.apache.hadoop.ha.HAServiceProtocol.StateChangeRequestInfo) CapacitySchedulerConfiguration(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration) 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