-
Notifications
You must be signed in to change notification settings - Fork 9.2k
YARN-11235. Refactor Policy Code and Define getReservationHomeSubcluster #4656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
aeea18b
YARN-11235. Refactor Policy Code and Define getReservationHomeSubclus…
63c3696
YARN-11235. Fix CheckStyle.
5412975
YARN-11235. Fix CheckStyle.
b258c9a
YARN-11235. Fix CheckStyle.
1ce3194
YARN-11235. Fix CheckStyle.
fd81fc1
YARN-11235. Fix CheckStyle.
10ddb9f
Merge branch 'apache:trunk' into YARN-11235
slfan1989 22db7c6
YARN-11235. Fix CheckStyle.
28b10e9
Merge remote-tracking branch 'origin/YARN-11235' into YARN-11235
62dd3a1
YARN-11235. Fix Junit Test.
slfan1989 874c9c5
YARN-11235. Fix CheckStyle.
0ea9490
Revert "YARN-11235. Fix CheckStyle."
6dd7d05
YARN-11235. Fix CheckStyle.
371801d
YARN-11235. Fix CodeStyle.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,15 +18,23 @@ | |
|
|
||
| package org.apache.hadoop.yarn.server.federation.policies.router; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.apache.hadoop.yarn.api.protocolrecords.ReservationSubmissionRequest; | ||
| import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext; | ||
| import org.apache.hadoop.yarn.api.records.ReservationId; | ||
| import org.apache.hadoop.yarn.conf.YarnConfiguration; | ||
| import org.apache.hadoop.yarn.exceptions.YarnException; | ||
| import org.apache.hadoop.yarn.server.federation.policies.AbstractConfigurableFederationPolicy; | ||
| import org.apache.hadoop.yarn.server.federation.policies.FederationPolicyUtils; | ||
| import org.apache.hadoop.yarn.server.federation.policies.dao.WeightedPolicyInfo; | ||
| import org.apache.hadoop.yarn.server.federation.policies.exceptions.FederationPolicyException; | ||
| import org.apache.hadoop.yarn.server.federation.policies.exceptions.FederationPolicyInitializationException; | ||
| import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId; | ||
| import org.apache.hadoop.yarn.server.federation.store.records.SubClusterIdInfo; | ||
| import org.apache.hadoop.yarn.server.federation.store.records.SubClusterInfo; | ||
|
|
||
| /** | ||
| * Base abstract class for {@link FederationRouterPolicy} implementations, that | ||
|
|
@@ -63,4 +71,108 @@ 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("The ReservationSubmissionRequest cannot be null."); | ||
| } | ||
|
|
||
| if (request.getQueue() == null) { | ||
| request.setQueue(YarnConfiguration.DEFAULT_QUEUE_NAME); | ||
| } | ||
|
|
||
| // apply filtering based on reservation location and active sub-clusters | ||
| Map<SubClusterId, SubClusterInfo> filteredSubClusters = prefilterSubClusters( | ||
| request.getReservationId(), getActiveSubclusters()); | ||
|
|
||
| // pick the chosen subCluster from the active ones | ||
| return chooseSubCluster(request.getQueue(), filteredSubClusters); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can rearrange so the string is a single line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix it.