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;
}
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());
}
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");
}
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);
}
}
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);
}
}
Aggregations