slfan1989 commented on code in PR #4656: URL: https://github.com/apache/hadoop/pull/4656#discussion_r933440496
########## hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/policies/RouterPolicyFacade.java: ########## @@ -262,4 +219,92 @@ public synchronized void reset() { } + /** + * This method provides a wrapper of all policy functionalities for routing a + * reservation. Internally it manages configuration changes, and policy + * init/reinit. + * + * @param request the reservation to route. + * + * @return the id of the subcluster that will be the "home" for this + * reservation. + * + * @throws YarnException if there are issues initializing policies, or no + * valid sub-cluster id could be found for this reservation. + */ + public SubClusterId getReservationHomeSubCluster( + ReservationSubmissionRequest request) throws YarnException { + + // the maps are concurrent, but we need to protect from reset() + // reinitialization mid-execution by creating a new reference local to this + // method. + Map<String, SubClusterPolicyConfiguration> cachedConfs = globalConfMap; + Map<String, FederationRouterPolicy> policyMap = globalPolicyMap; + + if (request == null) { + throw new FederationPolicyException( + "The ReservationSubmissionRequest cannot be null."); + } + + String queue = request.getQueue(); + FederationRouterPolicy policy = getFederationRouterPolicy(cachedConfs, policyMap, queue); + + if (policy == null) { + // this should never happen, as the to maps are updated together + throw new FederationPolicyException("No FederationRouterPolicy found " + + "for queue: " + request.getQueue() + " (while routing " + + "reservation: " + request.getReservationId() + ") " + + "and no default specified."); + } + + return policy.getReservationHomeSubcluster(request); + } + + private FederationRouterPolicy getFederationRouterPolicy( + Map<String, SubClusterPolicyConfiguration> cachedConfiguration, + Map<String, FederationRouterPolicy> policyMap, String queue) + throws FederationPolicyInitializationException { + + // the facade might cache this request, based on its parameterization + SubClusterPolicyConfiguration configuration = null; + String copyQueue = queue; + + try { + configuration = federationFacade.getPolicyConfiguration(copyQueue); + } catch (YarnException e) { + LOG.warn("There is no policy configured for the queue: {}, " + + "falling back to defaults.", copyQueue, e); + } + + // If there is no policy configured for this queue, fallback to the baseline + // policy that is configured either in the store or via XML config (and + // cached) + if (configuration == null) { + final String policyKey = YarnConfiguration.DEFAULT_FEDERATION_POLICY_KEY; + LOG.warn("There is no policies configured for queue: {} " + + "we fallback to default policy for: {}. ", copyQueue, policyKey); + copyQueue = YarnConfiguration.DEFAULT_FEDERATION_POLICY_KEY; + try { + configuration = federationFacade.getPolicyConfiguration(copyQueue); + } catch (YarnException e) { + LOG.warn("Cannot retrieve policy configured for the queue: {}, " + + "falling back to defaults.", copyQueue, e); + } + } + + // the fallback is not configure via store, but via XML, using + // previously loaded configuration. + if (configuration == null) { + configuration = cachedConfiguration.get(YarnConfiguration.DEFAULT_FEDERATION_POLICY_KEY); + } + + // if the configuration has changed since last loaded, reinit the policy + // based on current configuration + if (!cachedConfiguration.containsKey(copyQueue) Review Comment: I will fix it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org