@Override public void becomeActive() throws ServiceFailedException { try { rmContext.getRMAdminService().transitionToActive(req); } catch (Exception e) { throw new ServiceFailedException("RM could not transition to Active", e); } }
@Override public synchronized void transitionToStandby( HAServiceProtocol.StateChangeRequestInfo reqInfo) throws IOException { // call refreshAdminAcls before HA state transition // 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", "RMHAProtocolService"); } catch (Exception e) { RMAuditLogger.logFailure(user.getShortUserName(), "transitionToStandby", "", "RMHAProtocolService", "Exception transitioning to standby"); throw new ServiceFailedException( "Error when transitioning to Standby mode", e); } }
@VisibleForTesting void refreshAll() throws ServiceFailedException { try { checkAcls("refreshAll"); if (isSchedulerMutable()) { try { ((MutableConfScheduler) rm.getRMContext().getScheduler()) .getMutableConfProvider().reloadConfigurationFromStore(); } catch (Exception e) { throw new IOException("Failed to refresh configuration:", e); } } refreshQueues(); refreshNodes(); refreshSuperUserGroupsConfiguration(); refreshUserToGroupsMappings(); if (getConfig().getBoolean( CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, false)) { refreshServiceAcls(); } refreshClusterMaxPriority(); } catch (Exception ex) { throw new ServiceFailedException("RefreshAll operation failed", ex); } }
@VisibleForTesting void refreshAll() throws ServiceFailedException { try { checkAcls("refreshAll"); refreshQueues(); refreshNodes(); refreshSuperUserGroupsConfiguration(); refreshUserToGroupsMappings(); if (getConfig().getBoolean( CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, false)) { refreshServiceAcls(); } } catch (Exception ex) { throw new ServiceFailedException(ex.getMessage()); } }
private void refreshServiceAcls() throws IOException, YarnException { PolicyProvider policyProvider = RMPolicyProvider.getInstance(); Configuration conf = getConfiguration(new Configuration(false), YarnConfiguration.HADOOP_POLICY_CONFIGURATION_FILE); refreshServiceAcls(conf, policyProvider); }
@Override public RefreshUserToGroupsMappingsResponse refreshUserToGroupsMappings( RefreshUserToGroupsMappingsRequest request) throws YarnException, IOException { final String operation = "refreshUserToGroupsMappings"; UserGroupInformation user = checkAcls(operation); checkRMStatus(user.getShortUserName(), operation, "refresh user-groups."); refreshUserToGroupsMappings(); RMAuditLogger.logSuccess(user.getShortUserName(), operation, "AdminService"); return recordFactory.newRecordInstance( RefreshUserToGroupsMappingsResponse.class); }
/** * Helper method to test that neutral mode plays well with an active * transition. * * @param as the admin service * @param ees the embedded elector service * @throws IOException if there's an issue transitioning * @throws InterruptedException if interrupted * @throws TimeoutException if waitFor timeout reached */ private void testCallbackSynchronizationActive(AdminService as, ActiveStandbyElectorBasedElectorService ees) throws IOException, InterruptedException, TimeoutException { ees.becomeActive(); GenericTestUtils.waitFor( () -> transitionToActiveCounter.get() >= 1, 500, 10 * 1000); verify(as, times(1)).transitionToActive(any()); verify(as, never()).transitionToStandby(any()); }
public synchronized void transitionToActive( HAServiceProtocol.StateChangeRequestInfo reqInfo) throws IOException { if (isRMActive()) { return; refreshAdminAcls(false); } catch (YarnException ex) { throw new ServiceFailedException("Can not execute refreshAdminAcls", ex); UserGroupInformation user = checkAccess("transitionToActive"); checkHaStateChange(reqInfo); refreshAll(); } catch (Exception e) { LOG.error("RefreshAll failed so firing fatal event", e);
.getServiceStatus().getState()); assertFalse("RM is ready to become active before being started", rm.adminService.getServiceStatus().isReadyToBecomeActive()); checkMonitorHealth(); rm.adminService.transitionToActive(requestInfo); rm.adminService.transitionToStandby(requestInfo); checkStandbyRMFunctionality(); rm.stop();
== HAServiceState.STANDBY); rm1.adminService.transitionToActive(requestInfo); Assert.assertTrue(rm1.getRMContext().getHAServiceState() == HAServiceState.ACTIVE); uploadConfiguration(csConf, "capacity-scheduler.xml"); rm1.adminService.refreshQueues(RefreshQueuesRequest.newInstance()); rm1.adminService.transitionToStandby(requestInfo); rm2.adminService.transitionToActive(requestInfo); Assert.assertTrue(rm1.getRMContext().getHAServiceState() == HAServiceState.STANDBY);
@Override public RefreshServiceAclsResponse refreshServiceAcls( RefreshServiceAclsRequest request) throws YarnException, IOException { if (!getConfig().getBoolean( CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, false)) { throw RPCUtil.getRemoteException( new IOException("Service Authorization (" + CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION + ") not enabled.")); } final String operation = "refreshServiceAcls"; UserGroupInformation user = checkAcls(operation); checkRMStatus(user.getShortUserName(), operation, "refresh Service ACLs."); refreshServiceAcls(); refreshActiveServicesAcls(); RMAuditLogger.logSuccess(user.getShortUserName(), operation, "AdminService"); return recordFactory.newRecordInstance(RefreshServiceAclsResponse.class); }
.getServiceStatus().getState()); assertFalse("RM is ready to become active before being started", rm.adminService.getServiceStatus().isReadyToBecomeActive()); checkMonitorHealth(); rm.adminService.transitionToActive(requestInfo); Assert.fail("Transitioned to Active should throw exception."); } catch (Exception e) { rm.adminService.transitionToActive(requestInfo); checkMonitorHealth(); checkActiveRMFunctionality();
@Override public RefreshServiceAclsResponse refreshServiceAcls( RefreshServiceAclsRequest request) throws YarnException, IOException { if (!getConfig().getBoolean( CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, false)) { throw RPCUtil.getRemoteException( new IOException("Service Authorization (" + CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION + ") not enabled.")); } String argName = "refreshServiceAcls"; UserGroupInformation user = checkAcls(argName); checkRMStatus(user.getShortUserName(), argName, "refresh Service ACLs."); PolicyProvider policyProvider = RMPolicyProvider.getInstance(); Configuration conf = getConfiguration(new Configuration(false), YarnConfiguration.HADOOP_POLICY_CONFIGURATION_FILE); refreshServiceAcls(conf, policyProvider); rmContext.getClientRMService().refreshServiceAcls(conf, policyProvider); rmContext.getApplicationMasterService().refreshServiceAcls( conf, policyProvider); rmContext.getResourceTrackerService().refreshServiceAcls( conf, policyProvider); RMAuditLogger.logSuccess(user.getShortUserName(), argName, "AdminService"); return recordFactory.newRecordInstance(RefreshServiceAclsResponse.class); }
@Override public RefreshQueuesResponse refreshQueues(RefreshQueuesRequest request) throws YarnException, StandbyException { String argName = "refreshQueues"; final String msg = "refresh queues."; UserGroupInformation user = checkAcls(argName); checkRMStatus(user.getShortUserName(), argName, msg); RefreshQueuesResponse response = recordFactory.newRecordInstance(RefreshQueuesResponse.class); try { refreshQueues(); RMAuditLogger.logSuccess(user.getShortUserName(), argName, "AdminService"); return response; } catch (IOException ioe) { throw logAndWrapException(ioe, user.getShortUserName(), argName, msg); } }
protected void startServer() throws Exception { Configuration conf = getConfig(); YarnRPC rpc = YarnRPC.create(conf); this.server = (Server) rpc.getServer( CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, false)) { refreshServiceAcls( getConfiguration(conf, YarnConfiguration.HADOOP_POLICY_CONFIGURATION_FILE), RMPolicyProvider.getInstance());
@Override public RefreshSuperUserGroupsConfigurationResponse refreshSuperUserGroupsConfiguration( RefreshSuperUserGroupsConfigurationRequest request) throws YarnException, IOException { String argName = "refreshSuperUserGroupsConfiguration"; UserGroupInformation user = checkAcls(argName); checkRMStatus(user.getShortUserName(), argName, "refresh super-user-groups."); refreshSuperUserGroupsConfiguration(); RMAuditLogger.logSuccess(user.getShortUserName(), argName, "AdminService"); return recordFactory.newRecordInstance( RefreshSuperUserGroupsConfigurationResponse.class); }
@Override public void becomeStandby() { try { rmContext.getRMAdminService().transitionToStandby(req); } catch (Exception e) { LOG.error("RM could not transition to Standby", e); } }
@Test public void testAdminAclsWithFileSystemBasedConfigurationProvider() throws IOException, YarnException { configuration.set(YarnConfiguration.RM_CONFIGURATION_PROVIDER_CLASS, "org.apache.hadoop.yarn.FileSystemBasedConfigurationProvider"); //upload default configurations uploadDefaultConfiguration(); try { rm = new MockRM(configuration); rm.init(configuration); rm.start(); } catch(Exception ex) { fail("Should not get any exceptions"); } String aclStringBefore = rm.adminService.getAccessControlList().getAclString().trim(); YarnConfiguration yarnConf = new YarnConfiguration(); yarnConf.set(YarnConfiguration.YARN_ADMIN_ACL, "world:anyone:rwcda"); uploadConfiguration(yarnConf, "yarn-site.xml"); rm.adminService.refreshAdminAcls(RefreshAdminAclsRequest.newInstance()); String aclStringAfter = rm.adminService.getAccessControlList().getAclString().trim(); Assert.assertTrue(!aclStringAfter.equals(aclStringBefore)); Assert.assertEquals(aclStringAfter, "world:anyone:rwcda," + UserGroupInformation.getCurrentUser().getShortUserName()); }
@Test public void testAdminRefreshQueuesWithMutableSchedulerConfiguration() { configuration.set(YarnConfiguration.SCHEDULER_CONFIGURATION_STORE_CLASS, YarnConfiguration.MEMORY_CONFIGURATION_STORE); try { rm = new MockRM(configuration); rm.init(configuration); rm.start(); } catch (Exception ex) { fail("Should not get any exceptions"); } try { rm.adminService.refreshQueues(RefreshQueuesRequest.newInstance()); fail("Expected exception while calling refreshQueues when scheduler" + " configuration is mutable."); } catch (Exception ex) { assertTrue(ex.getMessage().endsWith("Scheduler configuration is " + "mutable. refreshQueues is not allowed in this scenario.")); } }
@Override public Boolean get() { try { return rm.getAdminService().getServiceStatus().getState() .equals(state); } catch (IOException e) { } return false; } }, 2000, 15000);