Skip to content

Commit

Permalink
YARN-11239. Optimize FederationClientInterceptor audit log.
Browse files Browse the repository at this point in the history
  • Loading branch information
slfan1989 committed Nov 12, 2022
1 parent 5bb11ce commit 92e37b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public static class AuditConstants {
public static final String GET_APP_REPORT = "Get Application Report";
public static final String TARGET_CLIENT_RM_SERVICE = "RouterClientRMService";
public static final String UNKNOWN = "UNKNOWN";
public static final String GET_APPLICATIONS = "Get Applications";
public static final String GET_CLUSTERMETRICS = "Get ClusterMetrics";
public static final String GET_CLUSTERNODES = "Get ClusterNodes";
public static final String GET_QUEUEINFO = "Get QueueInfo";
public static final String GET_QUEUE_USER_ACLS = "Get QueueUserAcls";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,7 @@

import org.apache.hadoop.classification.VisibleForTesting;

import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.GET_NEW_APP;
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.SUBMIT_NEW_APP;
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.GET_APP_REPORT;
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.FORCE_KILL_APP;
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.TARGET_CLIENT_RM_SERVICE;
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.UNKNOWN;
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.*;

/**
* Extends the {@code AbstractRequestInterceptorClient} class and provides an
Expand Down Expand Up @@ -811,6 +806,8 @@ public GetApplicationsResponse getApplications(GetApplicationsRequest request)
throws YarnException, IOException {
if (request == null) {
routerMetrics.incrMultipleAppsFailedRetrieved();
RouterAuditLogger.logFailure(user.getShortUserName(), GET_APPLICATIONS, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, "Missing getApplications request.");
RouterServerUtil.logAndThrowException("Missing getApplications request.", null);
}
long startTime = clock.getTime();
Expand All @@ -834,6 +831,8 @@ public GetClusterMetricsResponse getClusterMetrics(
GetClusterMetricsRequest request) throws YarnException, IOException {
if (request == null) {
routerMetrics.incrGetClusterMetricsFailedRetrieved();
RouterAuditLogger.logFailure(user.getShortUserName(), GET_CLUSTERMETRICS, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, "Missing getApplications request.");
RouterServerUtil.logAndThrowException("Missing getClusterMetrics request.", null);
}
long startTime = clock.getTime();
Expand Down Expand Up @@ -888,7 +887,7 @@ <R> Collection<R> invokeConcurrent(ClientMethod request, Class<R> clazz)
results.put(subClusterId, clazz.cast(result));
} catch (InterruptedException | ExecutionException e) {
Throwable cause = e.getCause();
LOG.error("Cannot execute {} on {}: {}", request.getMethodName(),
LOG.error("Cannot execute {} on {} : {}", request.getMethodName(),
subClusterId.getId(), cause.getMessage());
exceptions.put(subClusterId, e);
}
Expand All @@ -914,6 +913,8 @@ public GetClusterNodesResponse getClusterNodes(GetClusterNodesRequest request)
throws YarnException, IOException {
if (request == null) {
routerMetrics.incrClusterNodesFailedRetrieved();
RouterAuditLogger.logFailure(user.getShortUserName(), GET_CLUSTERNODES, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, "Missing getClusterNodes request.");
RouterServerUtil.logAndThrowException("Missing getClusterNodes request.", null);
}
long startTime = clock.getTime();
Expand All @@ -937,6 +938,8 @@ public GetQueueInfoResponse getQueueInfo(GetQueueInfoRequest request)
throws YarnException, IOException {
if (request == null || request.getQueueName() == null) {
routerMetrics.incrGetQueueInfoFailedRetrieved();
RouterAuditLogger.logFailure(user.getShortUserName(), GET_QUEUEINFO, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, "Missing getQueueInfo request or queueName.");
RouterServerUtil.logAndThrowException("Missing getQueueInfo request or queueName.", null);
}

Expand All @@ -962,6 +965,8 @@ public GetQueueUserAclsInfoResponse getQueueUserAcls(
GetQueueUserAclsInfoRequest request) throws YarnException, IOException {
if(request == null){
routerMetrics.incrQueueUserAclsFailedRetrieved();
RouterAuditLogger.logFailure(user.getShortUserName(), GET_QUEUE_USER_ACLS, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, "Missing getQueueUserAcls request.");
RouterServerUtil.logAndThrowException("Missing getQueueUserAcls request.", null);
}
long startTime = clock.getTime();
Expand All @@ -986,6 +991,9 @@ public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(
throws YarnException, IOException {
if (request == null || request.getApplicationId() == null || request.getTargetQueue() == null) {
routerMetrics.incrMoveApplicationAcrossQueuesFailedRetrieved();
RouterAuditLogger.logFailure(user.getShortUserName(), GET_QUEUE_USER_ACLS, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, "Missing moveApplicationAcrossQueues request or " +
"applicationId or target queue.");
RouterServerUtil.logAndThrowException("Missing moveApplicationAcrossQueues request or " +
"applicationId or target queue.", null);
}
Expand All @@ -999,8 +1007,8 @@ public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(
.getApplicationHomeSubCluster(applicationId);
} catch (YarnException e) {
routerMetrics.incrMoveApplicationAcrossQueuesFailedRetrieved();
RouterServerUtil.logAndThrowException("Application " +
applicationId + " does not exist in FederationStateStore.", e);
RouterServerUtil.logAndThrowException(e, "Application %s does not exist in FederationStateStore.",
applicationId);
}

ApplicationClientProtocol clientRMProxy = getClientRMProxyForSubCluster(subClusterId);
Expand All @@ -1009,8 +1017,9 @@ public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(
response = clientRMProxy.moveApplicationAcrossQueues(request);
} catch (Exception e) {
routerMetrics.incrMoveApplicationAcrossQueuesFailedRetrieved();
RouterServerUtil.logAndThrowException("Unable to moveApplicationAcrossQueues for " +
applicationId + " to SubCluster " + subClusterId.getId(), e);
RouterServerUtil.logAndThrowException(e,
"Unable to moveApplicationAcrossQueues for %s to SubCluster %s.", applicationId,
subClusterId.getId());
}

if (response == null) {
Expand Down

0 comments on commit 92e37b4

Please sign in to comment.