[
https://issues.apache.org/jira/browse/YARN-11222?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17690959#comment-17690959
]
ASF GitHub Bot commented on YARN-11222:
---------------------------------------
slfan1989 commented on code in PR #5328:
URL: https://github.com/apache/hadoop/pull/5328#discussion_r1111366488
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/FederationInterceptorREST.java:
##########
@@ -1580,16 +1582,115 @@ public NodeLabelsInfo
getClusterNodeLabels(HttpServletRequest hsr)
throw new RuntimeException("getClusterNodeLabels Failed.");
}
+ /**
+ * This method adds specific node labels for specific nodes, and it is
+ * reachable by using {@link RMWSConsts#ADD_NODE_LABELS}.
+ *
+ * @see ResourceManagerAdministrationProtocol#addToClusterNodeLabels
+ * @param newNodeLabels the node labels to add. It is a content param.
+ * @param hsr the servlet request
+ * @return Response containing the status code
+ * @throws Exception in case of bad request
+ */
@Override
public Response addToClusterNodeLabels(NodeLabelsInfo newNodeLabels,
HttpServletRequest hsr) throws Exception {
- throw new NotImplementedException("Code is not implemented");
+
+ if (newNodeLabels == null) {
+ routerMetrics.incrAddToClusterNodeLabelsFailedRetrieved();
+ throw new IllegalArgumentException("Parameter error, the newNodeLabels
is null.");
+ }
+
+ List<NodeLabelInfo> nodeLabelInfos = newNodeLabels.getNodeLabelsInfo();
+ if (CollectionUtils.isEmpty(nodeLabelInfos)) {
+ routerMetrics.incrAddToClusterNodeLabelsFailedRetrieved();
+ throw new IllegalArgumentException("Parameter error, the nodeLabelsInfo
is null or empty.");
+ }
+
+ try {
+ long startTime = clock.getTime();
+ Map<SubClusterId, SubClusterInfo> subClustersActive =
getActiveSubclusters();
+ final HttpServletRequest hsrCopy = clone(hsr);
+ Class[] argsClasses = new Class[]{NodeLabelsInfo.class,
HttpServletRequest.class};
+ Object[] args = new Object[]{newNodeLabels, hsrCopy};
+ ClientMethod remoteMethod = new ClientMethod("addToClusterNodeLabels",
argsClasses, args);
+ Map<SubClusterInfo, Response> responseInfoMap =
+ invokeConcurrent(subClustersActive.values(), remoteMethod,
Response.class);
+ StringBuffer buffer = new StringBuffer();
+ responseInfoMap.forEach((subClusterInfo, response) -> {
+ SubClusterId subClusterId = subClusterInfo.getSubClusterId();
+ if (response != null) {
+ buffer.append("SubCluster=" + subClusterId.getId() + ",SUCCESS#");
+ } else {
+ buffer.append("SubCluster=" + subClusterId.getId() + ",FAILED#");
+ }
+ });
+ long stopTime = clock.getTime();
+ routerMetrics.succeededAddToClusterNodeLabelsRetrieved((stopTime -
startTime));
+ return Response.status(Status.OK).entity(buffer.toString()).build();
+ } catch (NotFoundException e) {
+ routerMetrics.incrAddToClusterNodeLabelsFailedRetrieved();
+ RouterServerUtil.logAndThrowIOException("get all active sub cluster(s)
error.", e);
+ } catch (YarnException e) {
+ routerMetrics.incrAddToClusterNodeLabelsFailedRetrieved();
+ RouterServerUtil.logAndThrowIOException("addToClusterNodeLabels with
yarn error.", e);
+ }
+
+ routerMetrics.incrAddToClusterNodeLabelsFailedRetrieved();
+ throw new RuntimeException("addToClusterNodeLabels Failed.");
}
+ /**
+ * This method removes all the node labels for specific nodes, and it is
+ * reachable by using {@link RMWSConsts#REMOVE_NODE_LABELS}.
+ *
+ * @see ResourceManagerAdministrationProtocol#removeFromClusterNodeLabels
+ * @param oldNodeLabels the node labels to remove. It is a QueryParam.
+ * @param hsr the servlet request
+ * @return Response containing the status code
+ * @throws Exception in case of bad request
+ */
@Override
public Response removeFromClusterNodeLabels(Set<String> oldNodeLabels,
HttpServletRequest hsr) throws Exception {
- throw new NotImplementedException("Code is not implemented");
+
+ if (CollectionUtils.isEmpty(oldNodeLabels)) {
+ routerMetrics.incrRemoveFromClusterNodeLabelsFailedRetrieved();
+ throw new IllegalArgumentException("Parameter error, the oldNodeLabels
is null or empty.");
+ }
+
+ try {
+ long startTime = clock.getTime();
+ Map<SubClusterId, SubClusterInfo> subClustersActive =
getActiveSubclusters();
+ final HttpServletRequest hsrCopy = clone(hsr);
+ Class[] argsClasses = new Class[]{Set.class, HttpServletRequest.class};
+ Object[] args = new Object[]{oldNodeLabels, hsrCopy};
+ ClientMethod remoteMethod =
+ new ClientMethod("removeFromClusterNodeLabels", argsClasses, args);
+ Map<SubClusterInfo, Response> responseInfoMap =
+ invokeConcurrent(subClustersActive.values(), remoteMethod,
Response.class);
+ StringBuffer buffer = new StringBuffer();
+ responseInfoMap.forEach((subClusterInfo, response) -> {
+ SubClusterId subClusterId = subClusterInfo.getSubClusterId();
+ if (response != null) {
Review Comment:
Thanks for your suggestion, I will refactor this part of the code.
> [Federation] Add addToClusterNodeLabels, removeFromClusterNodeLabels REST
> APIs for Router
> -----------------------------------------------------------------------------------------
>
> Key: YARN-11222
> URL: https://issues.apache.org/jira/browse/YARN-11222
> Project: Hadoop YARN
> Issue Type: Sub-task
> Components: federation
> Affects Versions: 3.4.0, 3.3.4
> Reporter: Shilun Fan
> Assignee: Shilun Fan
> Priority: Major
> Labels: pull-request-available
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]