[
https://issues.apache.org/jira/browse/YARN-11537?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17769686#comment-17769686
]
ASF GitHub Bot commented on YARN-11537:
---------------------------------------
goiri commented on code in PR #6121:
URL: https://github.com/apache/hadoop/pull/6121#discussion_r1338846046
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/rmadmin/FederationRMAdminInterceptor.java:
##########
@@ -1137,18 +1143,81 @@ private QueryFederationQueuePoliciesResponse
filterPoliciesConfigurationsByQueue
}
}
+ // Step3. To paginate the returned results.
+ return queryFederationQueuePoliciesPagination(federationQueueWeights,
pageSize, currentPage);
+ }
+
+ /**
+ * Filter PoliciesConfigurations, and we paginate Policies within this
method.
+ *
+ * @param policiesConfigurations policy configurations.
+ * @param pageSize Items per page.
+ * @param currentPage The number of pages to be queried.
+ * @return federation queue policies response.
+ * @throws YarnException indicates exceptions from yarn servers.
+ */
+ private QueryFederationQueuePoliciesResponse filterPoliciesConfigurations(
+ Map<String, SubClusterPolicyConfiguration> policiesConfigurations,
+ int pageSize, int currentPage) throws YarnException {
+
+ // Step1. Check the parameters, if the policy list is empty, return empty
directly.
+ if (MapUtils.isEmpty(policiesConfigurations)) {
+ return null;
+ }
+
+ // Step2. Traverse policiesConfigurations and obtain the
FederationQueueWeight list.
+ List<FederationQueueWeight> federationQueueWeights = new ArrayList<>();
+ for (Map.Entry<String, SubClusterPolicyConfiguration> entry :
+ policiesConfigurations.entrySet()) {
+ String queue = entry.getKey();
+ SubClusterPolicyConfiguration policyConf = entry.getValue();
+ if(policyConf == null) {
+ continue;
+ }
+ FederationQueueWeight federationQueueWeight =
parseFederationQueueWeight(queue, policyConf);
+ if (federationQueueWeight != null) {
+ federationQueueWeights.add(federationQueueWeight);
+ }
+ }
+
+ // Step3. To paginate the returned results.
+ return queryFederationQueuePoliciesPagination(federationQueueWeights,
pageSize, currentPage);
+ }
+
+ /**
+ * Pagination for FederationQueuePolicies.
+ *
+ * @param queueWeights List Of FederationQueueWeight.
+ * @param pageSize Items per page.
+ * @param currentPage The number of pages to be queried.
+ * @return federation queue policies response.
+ * @throws YarnException indicates exceptions from yarn servers.
+ */
+ private QueryFederationQueuePoliciesResponse
queryFederationQueuePoliciesPagination(
+ List<FederationQueueWeight> queueWeights, int pageSize, int currentPage)
+ throws YarnException {
+ if (CollectionUtils.isEmpty(queueWeights)) {
+ return null;
+ }
+
int startIndex = (currentPage - 1) * pageSize;
- int endIndex = Math.min(startIndex + pageSize,
federationQueueWeights.size());
+ int endIndex = Math.min(startIndex + pageSize, queueWeights.size());
+
+ if (startIndex > endIndex) {
+ throw new YarnException("The index of the records to be retrieved " +
+ "has exceeded the maximum index.");
+ }
+
List<FederationQueueWeight> subFederationQueueWeights =
- federationQueueWeights.subList(startIndex, endIndex);
+ queueWeights.subList(startIndex, endIndex);
- int totalSize = federationQueueWeights.size();
+ int totalSize = queueWeights.size();
int totalPage =
(totalSize % pageSize == 0) ? totalSize / pageSize : (totalSize /
pageSize) + 1;
// Step3. Returns the Queue Policies result.
return QueryFederationQueuePoliciesResponse.newInstance(
- totalSize, totalPage, currentPage, pageSize,
subFederationQueueWeights);
+ totalSize, totalPage, currentPage, pageSize,
subFederationQueueWeights);
Review Comment:
Avoid
> [Federation] Router CLI Supports List SubClusterPolicyConfiguration Of Queues.
> ------------------------------------------------------------------------------
>
> Key: YARN-11537
> URL: https://issues.apache.org/jira/browse/YARN-11537
> Project: Hadoop YARN
> Issue Type: Sub-task
> Components: federation
> Affects Versions: 3.4.0
> Reporter: Shilun Fan
> Assignee: Shilun Fan
> Priority: Major
> Labels: pull-request-available
> Fix For: 3.4.0
>
>
> In this jira, we will support list SubClusterPolicyConfiguration information
> on the command line.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]