slfan1989 commented on code in PR #5146:
URL: https://github.com/apache/hadoop/pull/5146#discussion_r1030951556
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/rmadmin/RMAdminProtocolMethod.java:
##########
@@ -129,4 +135,49 @@ protected <R> Collection<R> invokeConcurrent(Class<R>
clazz) throws YarnExceptio
// return result
return results.values();
}
+
+ /**
+ * Call the method in the protocol according to the subClusterId.
+ *
+ * @param clazz return type
+ * @param subClusterId subCluster Id
+ * @param <R> Generic R
+ * @return response collection.
+ * @throws YarnException yarn exception.
+ */
+ protected <R> Collection<R> invoke(Class<R> clazz, String subClusterId)
throws YarnException {
+
+ // Get the method name to call
+ String methodName =
Thread.currentThread().getStackTrace()[3].getMethodName();
+ this.setMethodName(methodName);
+
+ // Get Active SubClusters
+ Map<SubClusterId, SubClusterInfo> subClusterInfoMap =
+ federationFacade.getSubClusters(true);
+
+ // According to subCluster of string type, convert to SubClusterId type
+ SubClusterId subClusterIdKey = SubClusterId.newInstance(subClusterId);
+
+ // If the provided subCluster is not Active or does not exist,
+ // an exception will be returned directly.
+ if (!subClusterInfoMap.containsKey(subClusterIdKey)) {
+ throw new YarnException("subClusterId = " + subClusterId + " is not an
active subCluster.");
+ }
+
+ // Call the method in the protocol and convert it according to clazz.
+ try {
+ ResourceManagerAdministrationProtocol protocol =
+ rmAdminInterceptor.getAdminRMProxyForSubCluster(subClusterIdKey);
+ Class<?>[] types = this.getTypes();
+ Object[] params = this.getParams();
+ Method method =
ResourceManagerAdministrationProtocol.class.getMethod(methodName, types);
+ Object result = method.invoke(protocol, params);
+ if (result != null) {
+ return Collections.singletonList(clazz.cast(result));
+ }
+ } catch (Exception e) {
+ throw new YarnException("invoke Failed.", e);
+ }
+ throw new YarnException("invoke Failed.");
Review Comment:
I will refactor this part of code.
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/rmadmin/FederationRMAdminInterceptor.java:
##########
@@ -172,19 +190,68 @@ public RefreshQueuesResponse
refreshQueues(RefreshQueuesRequest request)
routerMetrics.succeededRefreshQueuesRetrieved(stopTime - startTime);
return RefreshQueuesResponse.newInstance();
}
- } catch (Exception e) {
+ } catch (YarnException e) {
routerMetrics.incrRefreshQueuesFailedRetrieved();
- RouterServerUtil.logAndThrowException("Unable to refreshQueue to
exception.", e);
+ throw e;
}
routerMetrics.incrRefreshQueuesFailedRetrieved();
- throw new YarnException("Unable to refreshQueue.");
+ throw new YarnException("Unable to refreshQueue to exception.");
}
+ /**
+ * Refresh node requests.
+ *
+ * The Router supports refreshing all SubCluster nodes at once,
+ * and also supports refreshing node by SubCluster.
+ *
+ * @param request RefreshNodesRequest, If subClusterId is not empty,
+ * it means that we want to refresh the node of the specified subClusterId.
+ * If subClusterId is empty, it means we want to refresh all nodes.
+ *
+ * @return RefreshNodesResponse, There is no specific information in the
response,
+ * as long as it is not empty, it means that the request is successful.
+ *
+ * @throws StandbyException exception thrown by non-active server.
+ * @throws YarnException indicates exceptions from yarn servers.
+ * @throws IOException io error occurs.
+ */
@Override
public RefreshNodesResponse refreshNodes(RefreshNodesRequest request)
throws StandbyException, YarnException, IOException {
- throw new NotImplementedException();
+
+ // parameter verification.
+ // We will not check whether the DecommissionType is empty,
+ // because this parameter has a default value at the proto level.
+ if (request == null) {
+ routerMetrics.incrRefreshNodesFailedRetrieved();
+ RouterServerUtil.logAndThrowException(
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: [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]