Skip to content

Commit d8c19bd

Browse files
author
slfan1989
committed
YARN-11239. Fix CheckStyle.
1 parent 92e37b4 commit d8c19bd

File tree

3 files changed

+56
-17
lines changed

3 files changed

+56
-17
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/RouterAuditLogger.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* Manages Router audit logs.
3131
* Audit log format is written as key=value pairs. Tab separated.
3232
*/
33-
public class RouterAuditLogger {
33+
public final class RouterAuditLogger {
3434
private static final Logger LOG =
3535
LoggerFactory.getLogger(RouterAuditLogger.class);
3636

@@ -151,6 +151,27 @@ public static void logFailure(String user, String operation, String perm,
151151
}
152152
}
153153

154+
/**
155+
* Create a readable and parseable audit log string for a failed event.
156+
*
157+
* @param user User who made the service request.
158+
* @param operation Operation requested by the user.
159+
* @param perm Target permissions.
160+
* @param target The target on which the operation is being performed.
161+
* @param descriptionFormat the description message format string.
162+
*
163+
* <br><br>
164+
* Note that the {@link RouterAuditLogger} uses tabs ('\t') as a key-val
165+
* delimiter and hence the value fields should not contains tabs ('\t').
166+
*/
167+
public static void logFailure(String user, String operation, String perm,
168+
String target, String descriptionFormat, Object... args) {
169+
if (LOG.isInfoEnabled()) {
170+
String description = String.format(descriptionFormat, args);
171+
LOG.info(createFailureLog(user, operation, perm, target, description, null, null));
172+
}
173+
}
174+
154175
/**
155176
* Create a readable and parseable audit log string for a failed event.
156177
*

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/RouterServerUtil.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,19 @@ public static void logAndThrowException(String errMsg, Throwable t)
111111
}
112112
}
113113

114+
/**
115+
* Throws an exception due to an error.
116+
*
117+
* @param errMsg the error message
118+
* @throws YarnException on failure
119+
*/
120+
@Public
121+
@Unstable
122+
public static void logAndThrowException(String errMsg) throws YarnException {
123+
LOG.error(errMsg);
124+
throw new YarnException(errMsg);
125+
}
126+
114127
public static <R> R createRequestInterceptorChain(Configuration conf, String pipeLineClassName,
115128
String interceptorClassName, Class<R> clazz) {
116129

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,10 @@ public GetApplicationsResponse getApplications(GetApplicationsRequest request)
806806
throws YarnException, IOException {
807807
if (request == null) {
808808
routerMetrics.incrMultipleAppsFailedRetrieved();
809+
String msg = "Missing getApplications request.";
809810
RouterAuditLogger.logFailure(user.getShortUserName(), GET_APPLICATIONS, UNKNOWN,
810-
TARGET_CLIENT_RM_SERVICE, "Missing getApplications request.");
811-
RouterServerUtil.logAndThrowException("Missing getApplications request.", null);
811+
TARGET_CLIENT_RM_SERVICE, msg);
812+
RouterServerUtil.logAndThrowException(msg, null);
812813
}
813814
long startTime = clock.getTime();
814815
ClientMethod remoteMethod = new ClientMethod("getApplications",
@@ -831,9 +832,10 @@ public GetClusterMetricsResponse getClusterMetrics(
831832
GetClusterMetricsRequest request) throws YarnException, IOException {
832833
if (request == null) {
833834
routerMetrics.incrGetClusterMetricsFailedRetrieved();
835+
String msg = "Missing getApplications request.";
834836
RouterAuditLogger.logFailure(user.getShortUserName(), GET_CLUSTERMETRICS, UNKNOWN,
835-
TARGET_CLIENT_RM_SERVICE, "Missing getApplications request.");
836-
RouterServerUtil.logAndThrowException("Missing getClusterMetrics request.", null);
837+
TARGET_CLIENT_RM_SERVICE, msg);
838+
RouterServerUtil.logAndThrowException(msg, null);
837839
}
838840
long startTime = clock.getTime();
839841
ClientMethod remoteMethod = new ClientMethod("getClusterMetrics",
@@ -913,9 +915,10 @@ public GetClusterNodesResponse getClusterNodes(GetClusterNodesRequest request)
913915
throws YarnException, IOException {
914916
if (request == null) {
915917
routerMetrics.incrClusterNodesFailedRetrieved();
918+
String msg = "Missing getClusterNodes request.";
916919
RouterAuditLogger.logFailure(user.getShortUserName(), GET_CLUSTERNODES, UNKNOWN,
917-
TARGET_CLIENT_RM_SERVICE, "Missing getClusterNodes request.");
918-
RouterServerUtil.logAndThrowException("Missing getClusterNodes request.", null);
920+
TARGET_CLIENT_RM_SERVICE, msg);
921+
RouterServerUtil.logAndThrowException(msg, null);
919922
}
920923
long startTime = clock.getTime();
921924
ClientMethod remoteMethod = new ClientMethod("getClusterNodes",
@@ -938,9 +941,10 @@ public GetQueueInfoResponse getQueueInfo(GetQueueInfoRequest request)
938941
throws YarnException, IOException {
939942
if (request == null || request.getQueueName() == null) {
940943
routerMetrics.incrGetQueueInfoFailedRetrieved();
944+
String msg = "Missing getQueueInfo request or queueName.";
941945
RouterAuditLogger.logFailure(user.getShortUserName(), GET_QUEUEINFO, UNKNOWN,
942-
TARGET_CLIENT_RM_SERVICE, "Missing getQueueInfo request or queueName.");
943-
RouterServerUtil.logAndThrowException("Missing getQueueInfo request or queueName.", null);
946+
TARGET_CLIENT_RM_SERVICE, msg);
947+
RouterServerUtil.logAndThrowException(msg, null);
944948
}
945949

946950
long startTime = clock.getTime();
@@ -965,9 +969,10 @@ public GetQueueUserAclsInfoResponse getQueueUserAcls(
965969
GetQueueUserAclsInfoRequest request) throws YarnException, IOException {
966970
if(request == null){
967971
routerMetrics.incrQueueUserAclsFailedRetrieved();
972+
String msg = "Missing getQueueUserAcls request.";
968973
RouterAuditLogger.logFailure(user.getShortUserName(), GET_QUEUE_USER_ACLS, UNKNOWN,
969-
TARGET_CLIENT_RM_SERVICE, "Missing getQueueUserAcls request.");
970-
RouterServerUtil.logAndThrowException("Missing getQueueUserAcls request.", null);
974+
TARGET_CLIENT_RM_SERVICE, msg);
975+
RouterServerUtil.logAndThrowException(msg);
971976
}
972977
long startTime = clock.getTime();
973978
ClientMethod remoteMethod = new ClientMethod("getQueueUserAcls",
@@ -991,11 +996,11 @@ public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(
991996
throws YarnException, IOException {
992997
if (request == null || request.getApplicationId() == null || request.getTargetQueue() == null) {
993998
routerMetrics.incrMoveApplicationAcrossQueuesFailedRetrieved();
999+
String msg = "Missing moveApplicationAcrossQueues request or " +
1000+
"applicationId or target queue.";
9941001
RouterAuditLogger.logFailure(user.getShortUserName(), GET_QUEUE_USER_ACLS, UNKNOWN,
995-
TARGET_CLIENT_RM_SERVICE, "Missing moveApplicationAcrossQueues request or " +
996-
"applicationId or target queue.");
997-
RouterServerUtil.logAndThrowException("Missing moveApplicationAcrossQueues request or " +
998-
"applicationId or target queue.", null);
1002+
TARGET_CLIENT_RM_SERVICE, msg);
1003+
RouterServerUtil.logAndThrowException(msg);
9991004
}
10001005

10011006
long startTime = clock.getTime();
@@ -1007,8 +1012,8 @@ public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(
10071012
.getApplicationHomeSubCluster(applicationId);
10081013
} catch (YarnException e) {
10091014
routerMetrics.incrMoveApplicationAcrossQueuesFailedRetrieved();
1010-
RouterServerUtil.logAndThrowException(e, "Application %s does not exist in FederationStateStore.",
1011-
applicationId);
1015+
String errMsgFormat = "Application %s does not exist in FederationStateStore.";
1016+
RouterServerUtil.logAndThrowException(e, errMsgFormat, applicationId);
10121017
}
10131018

10141019
ApplicationClientProtocol clientRMProxy = getClientRMProxyForSubCluster(subClusterId);

0 commit comments

Comments
 (0)