slfan1989 commented on code in PR #6121:
URL: https://github.com/apache/hadoop/pull/6121#discussion_r1338877982
##########
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:
Thanks for your suggestion! 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]