slfan1989 commented on code in PR #4656: URL: https://github.com/apache/hadoop/pull/4656#discussion_r933034630
########## hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/policies/router/AbstractRouterPolicy.java: ########## @@ -63,4 +71,109 @@ public void validate(ApplicationSubmissionContext appSubmissionContext) } } + /** + * This method is implemented by the specific policy, and it is used to route + * both reservations, and applications among a given set of + * sub-clusters. + * + * @param queue the queue for this application/reservation + * @param preSelectSubClusters a pre-filter set of sub-clusters + * @return the chosen sub-cluster + * + * @throws YarnException if the policy fails to choose a sub-cluster + */ + protected abstract SubClusterId chooseSubCluster(String queue, + Map<SubClusterId, SubClusterInfo> preSelectSubClusters) throws YarnException; + + /** + * Filter chosen SubCluster based on reservationId. + * + * @param reservationId the globally unique identifier for a reservation. + * @param activeSubClusters the map of ids to info for all active subclusters. + * @return the chosen sub-cluster + * @throws YarnException if the policy fails to choose a sub-cluster + */ + protected Map<SubClusterId, SubClusterInfo> prefilterSubClusters( + ReservationId reservationId, Map<SubClusterId, SubClusterInfo> activeSubClusters) + throws YarnException { + + // if a reservation exists limit scope to the sub-cluster this + // reservation is mapped to + // TODO: Implemented in YARN-11236 + return activeSubClusters; + } + + /** + * Simply picks from alphabetically-sorted active subclusters based on the + * hash of quey name. Jobs of the same queue will all be routed to the same + * sub-cluster, as far as the number of active sub-cluster and their names + * remain the same. + * + * @param appContext the {@link ApplicationSubmissionContext} that + * has to be routed to an appropriate subCluster for execution. + * + * @param blackLists the list of subClusters as identified by + * {@link SubClusterId} to blackList from the selection of the home + * subCluster. + * + * @return a hash-based chosen {@link SubClusterId} that will be the "home" + * for this application. + * + * @throws YarnException if there are no active subclusters. + */ + @Override + public SubClusterId getHomeSubcluster(ApplicationSubmissionContext appContext, + List<SubClusterId> blackLists) throws YarnException { + + // null checks and default-queue behavior + validate(appContext); + + // apply filtering based on reservation location and active sub-clusters + Map<SubClusterId, SubClusterInfo> filteredSubClusters = prefilterSubClusters( + appContext.getReservationID(), getActiveSubclusters()); + + FederationPolicyUtils.validateSubClusterAvailability( + new ArrayList<>(filteredSubClusters.keySet()), blackLists); + + // remove black SubCluster + if (blackLists != null) { + blackLists.forEach(filteredSubClusters::remove); + } + + // pick the chosen subCluster from the active ones + return chooseSubCluster(appContext.getQueue(), filteredSubClusters); + } + + /** + * 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. + */ + @Override + public SubClusterId getReservationHomeSubcluster(ReservationSubmissionRequest request) + throws YarnException { + if (request == null) { + throw new FederationPolicyException( 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