From 32aa13d69a0449ff0149b5a48f8fe3c2df5170d8 Mon Sep 17 00:00:00 2001 From: slfan1989 Date: Sat, 28 Oct 2023 00:01:29 +0800 Subject: [PATCH] YARN-11011. Fix CheckStyle. --- .../yarn/server/router/RouterServerUtil.java | 2 +- .../clientrm/FederationClientInterceptor.java | 24 ++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/RouterServerUtil.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/RouterServerUtil.java index 096d8dac0a76c..deaff5c6ca310 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/RouterServerUtil.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/RouterServerUtil.java @@ -125,7 +125,7 @@ public static void logAndThrowException(Throwable t, String errMsgFormat, Object public static void logAndThrowException(String errMsg, Throwable t) throws YarnException { if (t != null) { - LOG.error(errMsg, t); + LOG.error(errMsg + "" + t.getMessage(), t); throw new YarnException(errMsg, t); } else { LOG.error(errMsg); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java index 1e043648dc7af..3ec4760c0f14b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java @@ -816,9 +816,9 @@ public GetClusterMetricsResponse getClusterMetrics( clusterMetrics = invokeConcurrent(remoteMethod, GetClusterMetricsResponse.class); } catch (Exception ex) { routerMetrics.incrGetClusterMetricsFailedRetrieved(); - String msg = "Unable to get cluster metrics due to exception. "; + String msg = "Unable to get cluster metrics due to exception."; RouterAuditLogger.logFailure(user.getShortUserName(), GET_CLUSTERMETRICS, UNKNOWN, - TARGET_CLIENT_RM_SERVICE, msg + ex.getMessage()); + TARGET_CLIENT_RM_SERVICE, msg); RouterServerUtil.logAndThrowException(msg, ex); } long stopTime = clock.getTime(); @@ -837,7 +837,7 @@ Collection invokeConcurrent(ClientMethod request, Class clazz) List>> callables = new ArrayList<>(); List>> futures = new ArrayList<>(); - List exceptions = new ArrayList<>(); + Map exceptions = new TreeMap<>(); // Generate parallel Callable tasks for (SubClusterId subClusterId : subClusterIds) { @@ -856,8 +856,9 @@ Collection invokeConcurrent(ClientMethod request, Class clazz) cause = cause.getCause(); } String errMsg = (cause.getMessage() != null) ? cause.getMessage() : "UNKNOWN"; - throw new YarnException(String.format("subClusterId %s exec %s error %s.", - subClusterId, request.getMethodName(), errMsg), e); + return Pair.of(subClusterId, new YarnException( + String.format("subClusterId %s exec %s error %s.", subClusterId, + request.getMethodName(), errMsg), e)); } }); } @@ -872,11 +873,15 @@ Collection invokeConcurrent(ClientMethod request, Class clazz) Pair pair = future.get(); subClusterId = pair.getKey(); Object result = pair.getValue(); + if(result instanceof YarnException) { + throw YarnException.class.cast(result); + } results.put(subClusterId, clazz.cast(result)); - } catch (InterruptedException | ExecutionException e) { + } catch (InterruptedException | ExecutionException | YarnException e) { Throwable cause = e.getCause(); - LOG.error(cause.getMessage(), e); - exceptions.add(cause.getMessage()); + LOG.error("Cannot execute {} on {} : {}", request.getMethodName(), + subClusterId.getId(), cause.getMessage()); + exceptions.put(subClusterId, e); } }); } catch (InterruptedException e) { @@ -886,7 +891,8 @@ Collection invokeConcurrent(ClientMethod request, Class clazz) // All sub-clusters return results to be considered successful, // otherwise an exception will be thrown. if (exceptions != null && !exceptions.isEmpty()) { - throw new YarnException("invokeConcurrent Failed = " + StringUtils.join(exceptions, ",")); + throw new YarnException("invokeConcurrent Failed = " + + StringUtils.join(exceptions.values(), ",")); } // return result