@@ -130,7 +130,7 @@ public void init(String userName) {
130130 ThreadFactory threadFactory = new ThreadFactoryBuilder ()
131131 .setNameFormat ("RPC Router RMAdminClient-" + userName + "-%d " ).build ();
132132
133- BlockingQueue <Runnable > workQueue = new LinkedBlockingQueue <Runnable >();
133+ BlockingQueue <Runnable > workQueue = new LinkedBlockingQueue <>();
134134 this .executorService = new ThreadPoolExecutor (numThreads , numThreads ,
135135 0L , TimeUnit .MILLISECONDS , workQueue , threadFactory );
136136
@@ -1032,7 +1032,7 @@ public QueryFederationQueuePoliciesResponse listFederationQueuePolicies(
10321032 }
10331033
10341034 try {
1035- QueryFederationQueuePoliciesResponse response = null ;
1035+ QueryFederationQueuePoliciesResponse response ;
10361036
10371037 long startTime = clock .getTime ();
10381038 String queue = request .getQueue ();
@@ -1056,9 +1056,15 @@ public QueryFederationQueuePoliciesResponse listFederationQueuePolicies(
10561056 // We filter by pagination.
10571057 response = filterPoliciesConfigurationsByQueues (queues , policiesConfigurations ,
10581058 pageSize , currentPage );
1059+ } else {
1060+ // If we don't have any filtering criteria, we should also support paginating the results.
1061+ response = filterPoliciesConfigurations (policiesConfigurations , pageSize , currentPage );
10591062 }
10601063 long stopTime = clock .getTime ();
10611064 routerMetrics .succeededListFederationQueuePoliciesRetrieved (stopTime - startTime );
1065+ if (response == null ) {
1066+ response = QueryFederationQueuePoliciesResponse .newInstance ();
1067+ }
10621068 return response ;
10631069 } catch (Exception e ) {
10641070 routerMetrics .incrListFederationQueuePoliciesFailedRetrieved ();
@@ -1137,12 +1143,75 @@ private QueryFederationQueuePoliciesResponse filterPoliciesConfigurationsByQueue
11371143 }
11381144 }
11391145
1146+ // Step3. To paginate the returned results.
1147+ return queryFederationQueuePoliciesPagination (federationQueueWeights , pageSize , currentPage );
1148+ }
1149+
1150+ /**
1151+ * Filter PoliciesConfigurations, and we paginate Policies within this method.
1152+ *
1153+ * @param policiesConfigurations policy configurations.
1154+ * @param pageSize Items per page.
1155+ * @param currentPage The number of pages to be queried.
1156+ * @return federation queue policies response.
1157+ * @throws YarnException indicates exceptions from yarn servers.
1158+ */
1159+ private QueryFederationQueuePoliciesResponse filterPoliciesConfigurations (
1160+ Map <String , SubClusterPolicyConfiguration > policiesConfigurations ,
1161+ int pageSize , int currentPage ) throws YarnException {
1162+
1163+ // Step1. Check the parameters, if the policy list is empty, return empty directly.
1164+ if (MapUtils .isEmpty (policiesConfigurations )) {
1165+ return null ;
1166+ }
1167+
1168+ // Step2. Traverse policiesConfigurations and obtain the FederationQueueWeight list.
1169+ List <FederationQueueWeight > federationQueueWeights = new ArrayList <>();
1170+ for (Map .Entry <String , SubClusterPolicyConfiguration > entry :
1171+ policiesConfigurations .entrySet ()) {
1172+ String queue = entry .getKey ();
1173+ SubClusterPolicyConfiguration policyConf = entry .getValue ();
1174+ if (policyConf == null ) {
1175+ continue ;
1176+ }
1177+ FederationQueueWeight federationQueueWeight = parseFederationQueueWeight (queue , policyConf );
1178+ if (federationQueueWeight != null ) {
1179+ federationQueueWeights .add (federationQueueWeight );
1180+ }
1181+ }
1182+
1183+ // Step3. To paginate the returned results.
1184+ return queryFederationQueuePoliciesPagination (federationQueueWeights , pageSize , currentPage );
1185+ }
1186+
1187+ /**
1188+ * Pagination for FederationQueuePolicies.
1189+ *
1190+ * @param queueWeights List Of FederationQueueWeight.
1191+ * @param pageSize Items per page.
1192+ * @param currentPage The number of pages to be queried.
1193+ * @return federation queue policies response.
1194+ * @throws YarnException indicates exceptions from yarn servers.
1195+ */
1196+ private QueryFederationQueuePoliciesResponse queryFederationQueuePoliciesPagination (
1197+ List <FederationQueueWeight > queueWeights , int pageSize , int currentPage )
1198+ throws YarnException {
1199+ if (CollectionUtils .isEmpty (queueWeights )) {
1200+ return null ;
1201+ }
1202+
11401203 int startIndex = (currentPage - 1 ) * pageSize ;
1141- int endIndex = Math .min (startIndex + pageSize , federationQueueWeights .size ());
1204+ int endIndex = Math .min (startIndex + pageSize , queueWeights .size ());
1205+
1206+ if (startIndex > endIndex ) {
1207+ throw new YarnException ("The index of the records to be retrieved " +
1208+ "has exceeded the maximum index." );
1209+ }
1210+
11421211 List <FederationQueueWeight > subFederationQueueWeights =
1143- federationQueueWeights .subList (startIndex , endIndex );
1212+ queueWeights .subList (startIndex , endIndex );
11441213
1145- int totalSize = federationQueueWeights .size ();
1214+ int totalSize = queueWeights .size ();
11461215 int totalPage =
11471216 (totalSize % pageSize == 0 ) ? totalSize / pageSize : (totalSize / pageSize ) + 1 ;
11481217
0 commit comments