Search in sources :

Example 1 with ServiceFailedException

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

the class NameNode method getServiceStatus.

synchronized HAServiceStatus getServiceStatus() throws ServiceFailedException, AccessControlException {
    namesystem.checkSuperuserPrivilege();
    if (!haEnabled) {
        throw new ServiceFailedException("HA for namenode is not enabled");
    }
    if (state == null) {
        return new HAServiceStatus(HAServiceState.INITIALIZING);
    }
    HAServiceState retState = state.getServiceState();
    HAServiceStatus ret = new HAServiceStatus(retState);
    if (retState == HAServiceState.STANDBY) {
        if (namesystem.isInSafeMode()) {
            ret.setNotReadyToBecomeActive("The NameNode is in safemode. " + namesystem.getSafeModeTip());
        } else {
            ret.setReadyToBecomeActive();
        }
    } else if (retState == HAServiceState.ACTIVE) {
        ret.setReadyToBecomeActive();
    } else {
        ret.setNotReadyToBecomeActive("State is " + state);
    }
    return ret;
}
Also used : HAServiceState(org.apache.hadoop.ha.HAServiceProtocol.HAServiceState) HAServiceStatus(org.apache.hadoop.ha.HAServiceStatus) ServiceFailedException(org.apache.hadoop.ha.ServiceFailedException)

Example 2 with ServiceFailedException

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

the class TestRMHA method testTransitionedToActiveRefreshFail.

@Test(timeout = 9000000)
public void testTransitionedToActiveRefreshFail() throws Exception {
    configuration.setBoolean(YarnConfiguration.AUTO_FAILOVER_ENABLED, false);
    rm = new MockRM(configuration) {

        @Override
        protected AdminService createAdminService() {
            return new AdminService(this, getRMContext()) {

                int counter = 0;

                @Override
                protected void setConfig(Configuration conf) {
                    super.setConfig(configuration);
                }

                @Override
                protected void refreshAll() throws ServiceFailedException {
                    if (counter == 0) {
                        counter++;
                        throw new ServiceFailedException("Simulate RefreshFail");
                    } else {
                        super.refreshAll();
                    }
                }
            };
        }

        @Override
        protected Dispatcher createDispatcher() {
            return new FailFastDispatcher();
        }
    };
    rm.init(configuration);
    rm.start();
    final StateChangeRequestInfo requestInfo = new StateChangeRequestInfo(HAServiceProtocol.RequestSource.REQUEST_BY_USER);
    FailFastDispatcher dispatcher = ((FailFastDispatcher) rm.rmContext.getDispatcher());
    // Verify transition to transitionToStandby
    rm.adminService.transitionToStandby(requestInfo);
    assertEquals("Fatal Event should be 0", 0, dispatcher.getEventCount());
    assertEquals("HA state should be in standBy State", HAServiceState.STANDBY, rm.getRMContext().getHAServiceState());
    try {
        // Verify refreshAll call failure and check fail Event is dispatched
        rm.adminService.transitionToActive(requestInfo);
        Assert.fail("Transition to Active should have failed for refreshAll()");
    } catch (Exception e) {
        assertTrue("Service fail Exception expected", e instanceof ServiceFailedException);
    }
    // Since refreshAll failed we are expecting fatal event to be send
    // Then fatal event is send RM will shutdown
    dispatcher.await();
    assertEquals("Fatal Event to be received", 1, dispatcher.getEventCount());
    // Check of refreshAll success HA can be active
    rm.adminService.transitionToActive(requestInfo);
    assertEquals(HAServiceState.ACTIVE, rm.getRMContext().getHAServiceState());
    rm.adminService.transitionToStandby(requestInfo);
    assertEquals(HAServiceState.STANDBY, rm.getRMContext().getHAServiceState());
}
Also used : YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) StateChangeRequestInfo(org.apache.hadoop.ha.HAServiceProtocol.StateChangeRequestInfo) ServiceFailedException(org.apache.hadoop.ha.ServiceFailedException) Dispatcher(org.apache.hadoop.yarn.event.Dispatcher) DrainDispatcher(org.apache.hadoop.yarn.event.DrainDispatcher) 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 ServiceFailedException

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

the class AdminService method transitionToActive.

@SuppressWarnings("unchecked")
@Override
public synchronized void transitionToActive(HAServiceProtocol.StateChangeRequestInfo reqInfo) throws IOException {
    // for the case that adminAcls have been updated in previous active RM
    try {
        refreshAdminAcls(false);
    } catch (YarnException ex) {
        throw new ServiceFailedException("Can not execute refreshAdminAcls", ex);
    }
    UserGroupInformation user = checkAccess("transitionToActive");
    checkHaStateChange(reqInfo);
    try {
        // call all refresh*s for active RM to get the updated configurations.
        refreshAll();
    } catch (Exception e) {
        LOG.error("RefreshAll failed so firing fatal event", e);
        rmContext.getDispatcher().getEventHandler().handle(new RMFatalEvent(RMFatalEventType.TRANSITION_TO_ACTIVE_FAILED, e));
        throw new ServiceFailedException("Error on refreshAll during transition to Active", e);
    }
    try {
        rm.transitionToActive();
    } catch (Exception e) {
        RMAuditLogger.logFailure(user.getShortUserName(), "transitionToActive", "", "RM", "Exception transitioning to active");
        throw new ServiceFailedException("Error when transitioning to Active mode", e);
    }
    RMAuditLogger.logSuccess(user.getShortUserName(), "transitionToActive", "RM");
}
Also used : ServiceFailedException(org.apache.hadoop.ha.ServiceFailedException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) HealthCheckFailedException(org.apache.hadoop.ha.HealthCheckFailedException) StandbyException(org.apache.hadoop.ipc.StandbyException) ServiceFailedException(org.apache.hadoop.ha.ServiceFailedException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) AccessControlException(org.apache.hadoop.security.AccessControlException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 4 with ServiceFailedException

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

the class AdminService method refreshAll.

/*
   * Visibility could be private for test its made as default
   */
@VisibleForTesting
void refreshAll() throws ServiceFailedException {
    try {
        checkAcls("refreshAll");
        refreshQueues();
        refreshNodes();
        refreshSuperUserGroupsConfiguration();
        refreshUserToGroupsMappings();
        if (getConfig().getBoolean(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, false)) {
            refreshServiceAcls();
        }
        refreshClusterMaxPriority();
    } catch (Exception ex) {
        throw new ServiceFailedException("RefreshAll operation failed", ex);
    }
}
Also used : ServiceFailedException(org.apache.hadoop.ha.ServiceFailedException) HealthCheckFailedException(org.apache.hadoop.ha.HealthCheckFailedException) StandbyException(org.apache.hadoop.ipc.StandbyException) ServiceFailedException(org.apache.hadoop.ha.ServiceFailedException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) AccessControlException(org.apache.hadoop.security.AccessControlException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with ServiceFailedException

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

the class AdminService method transitionToStandby.

@Override
public synchronized void transitionToStandby(HAServiceProtocol.StateChangeRequestInfo reqInfo) throws IOException {
    // for the case that adminAcls have been updated in previous active RM
    try {
        refreshAdminAcls(false);
    } catch (YarnException ex) {
        throw new ServiceFailedException("Can not execute refreshAdminAcls", ex);
    }
    UserGroupInformation user = checkAccess("transitionToStandby");
    checkHaStateChange(reqInfo);
    try {
        rm.transitionToStandby(true);
        RMAuditLogger.logSuccess(user.getShortUserName(), "transitionToStandby", "RM");
    } catch (Exception e) {
        RMAuditLogger.logFailure(user.getShortUserName(), "transitionToStandby", "", "RM", "Exception transitioning to standby");
        throw new ServiceFailedException("Error when transitioning to Standby mode", e);
    }
}
Also used : ServiceFailedException(org.apache.hadoop.ha.ServiceFailedException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) HealthCheckFailedException(org.apache.hadoop.ha.HealthCheckFailedException) StandbyException(org.apache.hadoop.ipc.StandbyException) ServiceFailedException(org.apache.hadoop.ha.ServiceFailedException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) AccessControlException(org.apache.hadoop.security.AccessControlException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Aggregations

ServiceFailedException (org.apache.hadoop.ha.ServiceFailedException)5 IOException (java.io.IOException)4 HealthCheckFailedException (org.apache.hadoop.ha.HealthCheckFailedException)4 AccessControlException (org.apache.hadoop.security.AccessControlException)4 StandbyException (org.apache.hadoop.ipc.StandbyException)3 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)3 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Configuration (org.apache.hadoop.conf.Configuration)1 HAServiceState (org.apache.hadoop.ha.HAServiceProtocol.HAServiceState)1 StateChangeRequestInfo (org.apache.hadoop.ha.HAServiceProtocol.StateChangeRequestInfo)1 HAServiceStatus (org.apache.hadoop.ha.HAServiceStatus)1 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1 Dispatcher (org.apache.hadoop.yarn.event.Dispatcher)1 DrainDispatcher (org.apache.hadoop.yarn.event.DrainDispatcher)1 YarnRuntimeException (org.apache.hadoop.yarn.exceptions.YarnRuntimeException)1 StoreFencedException (org.apache.hadoop.yarn.server.resourcemanager.recovery.StoreFencedException)1 JSONException (org.codehaus.jettison.json.JSONException)1 Test (org.junit.Test)1