@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"; if (!isRMActive()) { RMAuditLogger.logFailure( UserGroupInformation.getCurrentUser().getShortUserName(), argName, adminAcl.toString(), "AdminService", "ResourceManager is not active. Can not refresh Service ACLs."); throwStandbyException(); } 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); return recordFactory.newRecordInstance(RefreshServiceAclsResponse.class); }
private RMAppImpl createAndPopulateNewRMApp( ApplicationSubmissionContext submissionContext, long submitTime, String user) throws YarnException { ApplicationId applicationId = submissionContext.getApplicationId(); validateResourceRequest(submissionContext); // Create RMApp RMAppImpl application = new RMAppImpl( applicationId, rmContext, this.conf, submissionContext.getApplicationName(), user, submissionContext.getQueue(), submissionContext, this.scheduler, this.masterService, submitTime, submissionContext.getApplicationType(), submissionContext.getApplicationTags()); // Concurrent app submissions with same applicationId will fail here // Concurrent app submissions with different applicationIds will not // influence each other if (rmContext.getRMApps().putIfAbsent(applicationId, application) != null) { String message = "Application with id " + applicationId + " is already present! Cannot add a duplicate!"; LOG.warn(message); throw RPCUtil.getRemoteException(message); } // Inform the ACLs Manager this.applicationACLsManager.addApplication( applicationId, submissionContext.getAMContainerSpec().getApplicationACLs()); return application; }
@Override public RefreshNodesResponse refreshNodes(RefreshNodesRequest request) throws YarnException, StandbyException { String argName = "refreshNodes"; UserGroupInformation user = checkAcls("refreshNodes"); if (!isRMActive()) { RMAuditLogger.logFailure( user.getShortUserName(), argName, adminAcl.toString(), "AdminService", "ResourceManager is not active. Can not refresh nodes."); throwStandbyException(); } try { Configuration conf = getConfiguration( new Configuration(false), YarnConfiguration.YARN_SITE_CONFIGURATION_FILE); rmContext.getNodesListManager().refreshNodes(conf); RMAuditLogger.logSuccess(user.getShortUserName(), argName, "AdminService"); return recordFactory.newRecordInstance(RefreshNodesResponse.class); } catch (IOException ioe) { LOG.info("Exception refreshing nodes ", ioe); RMAuditLogger.logFailure( user.getShortUserName(), argName, adminAcl.toString(), "AdminService", "Exception refreshing nodes"); throw RPCUtil.getRemoteException(ioe); } }
@Override public RefreshQueuesResponse refreshQueues(RefreshQueuesRequest request) throws YarnException, StandbyException { String argName = "refreshQueues"; UserGroupInformation user = checkAcls(argName); if (!isRMActive()) { RMAuditLogger.logFailure( user.getShortUserName(), argName, adminAcl.toString(), "AdminService", "ResourceManager is not active. Can not refresh queues."); throwStandbyException(); } RefreshQueuesResponse response = recordFactory.newRecordInstance(RefreshQueuesResponse.class); try { rmContext.getScheduler().reinitialize(getConfig(), this.rmContext); RMAuditLogger.logSuccess(user.getShortUserName(), argName, "AdminService"); return response; } catch (IOException ioe) { LOG.info("Exception refreshing queues ", ioe); RMAuditLogger.logFailure( user.getShortUserName(), argName, adminAcl.toString(), "AdminService", "Exception refreshing queues"); throw RPCUtil.getRemoteException(ioe); } }
private UserGroupInformation checkAcls(String method) throws YarnException { try { return checkAccess(method); } catch (IOException ioe) { throw RPCUtil.getRemoteException(ioe); } }
@Override public UpdateNodeResourceResponse updateNodeResource(UpdateNodeResourceRequest request) throws YarnException, IOException { Map<NodeId, ResourceOption> nodeResourceMap = request.getNodeResourceMap(); Set<NodeId> nodeIds = nodeResourceMap.keySet(); // verify nodes are all valid first. // if any invalid nodes, throw exception instead of partially updating // valid nodes. for (NodeId nodeId : nodeIds) { RMNode node = this.rmContext.getActiveRMNodes().get(nodeId); if (node == null) { LOG.error( "Resource update get failed on all nodes due to change " + "resource on an unrecognized node: " + nodeId); throw RPCUtil.getRemoteException( "Resource update get failed on all nodes due to change resource " + "on an unrecognized node: " + nodeId); } } // do resource update on each node. // Notice: it is still possible to have invalid NodeIDs as nodes decommission // may happen just at the same time. This time, only log and skip absent // nodes without throwing any exceptions. for (Map.Entry<NodeId, ResourceOption> entry : nodeResourceMap.entrySet()) { ResourceOption newResourceOption = entry.getValue(); NodeId nodeId = entry.getKey(); RMNode node = this.rmContext.getActiveRMNodes().get(nodeId); if (node == null) { LOG.warn("Resource update get failed on an unrecognized node: " + nodeId); } else { node.setResourceOption(newResourceOption); LOG.info( "Update resource successfully on node(" + node.getNodeID() + ") with resource(" + newResourceOption.toString() + ")"); } } UpdateNodeResourceResponse response = recordFactory.newRecordInstance(UpdateNodeResourceResponse.class); return response; }
@SuppressWarnings("unchecked") protected void submitApplication( ApplicationSubmissionContext submissionContext, long submitTime, String user) throws YarnException { ApplicationId applicationId = submissionContext.getApplicationId(); RMAppImpl application = createAndPopulateNewRMApp(submissionContext, submitTime, user, false); ApplicationId appId = submissionContext.getApplicationId(); Credentials credentials = null; try { credentials = parseCredentials(submissionContext); if (UserGroupInformation.isSecurityEnabled()) { this.rmContext .getDelegationTokenRenewer() .addApplicationAsync( appId, credentials, submissionContext.getCancelTokensWhenComplete(), application.getUser()); } else { // Dispatcher is not yet started at this time, so these START events // enqueued should be guaranteed to be first processed when dispatcher // gets started. this.rmContext .getDispatcher() .getEventHandler() .handle(new RMAppEvent(applicationId, RMAppEventType.START)); } } catch (Exception e) { LOG.warn("Unable to parse credentials.", e); // Sending APP_REJECTED is fine, since we assume that the // RMApp is in NEW state and thus we haven't yet informed the // scheduler about the existence of the application assert application.getState() == RMAppState.NEW; this.rmContext .getDispatcher() .getEventHandler() .handle(new RMAppRejectedEvent(applicationId, e.getMessage())); throw RPCUtil.getRemoteException(e); } }