Skip to content

Commit

Permalink
YARN-11239. Fix CheckStyle.
Browse files Browse the repository at this point in the history
  • Loading branch information
slfan1989 committed Apr 3, 2023
1 parent decf5d9 commit 94b7edf
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public static class AuditConstants {
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";
public static final String MOVE_APPLICATION_ACROSS_QUEUES = "Move ApplicationAcrossQueues";
public static final String GET_NEW_RESERVATION = "Get NewReservation";
public static final String SUBMIT_RESERVATION = "Submit Reservation";
public static final String LIST_RESERVATIONS = "List Reservations";
public static final String UPDATE_RESERVATION = "Update Reservation";
public static final String DELETE_RESERVATION = "Delete Reservation";
public static final String GET_NODETOLABELS = "Get NodeToLabels";
public static final String GET_LABELSTONODES = "Get LabelsToNodes";
public static final String GET_CLUSTERNODELABELS = "Get ClusterNodeLabels";
}

public static void logSuccess(String user, String operation, String target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.GET_APPLICATIONS;
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.GET_CLUSTERMETRICS;
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.GET_QUEUEINFO;
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.MOVE_APPLICATION_ACROSS_QUEUES;
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.GET_NEW_RESERVATION;
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.SUBMIT_RESERVATION;
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.LIST_RESERVATIONS;
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.UPDATE_RESERVATION;
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.DELETE_RESERVATION;
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.GET_NODETOLABELS;
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.GET_LABELSTONODES;
import static org.apache.hadoop.yarn.server.router.RouterAuditLogger.AuditConstants.GET_CLUSTERNODELABELS;

/**
* Extends the {@code AbstractRequestInterceptorClient} class and provides an
Expand Down Expand Up @@ -957,7 +966,7 @@ public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(
routerMetrics.incrMoveApplicationAcrossQueuesFailedRetrieved();
String msg = "Missing moveApplicationAcrossQueues request or " +
"applicationId or target queue.";
RouterAuditLogger.logFailure(user.getShortUserName(), GET_QUEUE_USER_ACLS, UNKNOWN,
RouterAuditLogger.logFailure(user.getShortUserName(), MOVE_APPLICATION_ACROSS_QUEUES, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, msg);
RouterServerUtil.logAndThrowException(msg);
}
Expand All @@ -972,7 +981,7 @@ public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(
} catch (YarnException e) {
routerMetrics.incrMoveApplicationAcrossQueuesFailedRetrieved();
String errMsgFormat = "Application %s does not exist in FederationStateStore.";
RouterAuditLogger.logFailure(user.getShortUserName(), GET_QUEUE_USER_ACLS, UNKNOWN,
RouterAuditLogger.logFailure(user.getShortUserName(), MOVE_APPLICATION_ACROSS_QUEUES, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, String.format(errMsgFormat, applicationId));
RouterServerUtil.logAndThrowException(e, errMsgFormat, applicationId);
}
Expand All @@ -995,7 +1004,7 @@ public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(
}

long stopTime = clock.getTime();
RouterAuditLogger.logSuccess(user.getShortUserName(), GET_QUEUE_USER_ACLS,
RouterAuditLogger.logSuccess(user.getShortUserName(), MOVE_APPLICATION_ACROSS_QUEUES,
TARGET_CLIENT_RM_SERVICE, applicationId, subClusterId);
routerMetrics.succeededMoveApplicationAcrossQueuesRetrieved(stopTime - startTime);
return response;
Expand All @@ -1008,6 +1017,8 @@ public GetNewReservationResponse getNewReservation(
if (request == null) {
routerMetrics.incrGetNewReservationFailedRetrieved();
String errMsg = "Missing getNewReservation request.";
RouterAuditLogger.logFailure(user.getShortUserName(), GET_NEW_RESERVATION, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, errMsg);
RouterServerUtil.logAndThrowException(errMsg, null);
}

Expand All @@ -1023,16 +1034,23 @@ public GetNewReservationResponse getNewReservation(
if (response != null) {
long stopTime = clock.getTime();
routerMetrics.succeededGetNewReservationRetrieved(stopTime - startTime);
RouterAuditLogger.logSuccess(user.getShortUserName(), GET_NEW_RESERVATION,
TARGET_CLIENT_RM_SERVICE);
return response;
}
} catch (Exception e) {
LOG.warn("Unable to create a new Reservation in SubCluster {}.", subClusterId.getId(), e);
String logFormatted = "Unable to create a new Reservation in SubCluster {}.";
LOG.warn(logFormatted, subClusterId.getId(), e);
RouterAuditLogger.logFailure(user.getShortUserName(), GET_NEW_RESERVATION, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, logFormatted, subClusterId.getId());
subClustersActive.remove(subClusterId);
}
}

routerMetrics.incrGetNewReservationFailedRetrieved();
String errMsg = "Failed to create a new reservation.";
RouterAuditLogger.logFailure(user.getShortUserName(), GET_NEW_RESERVATION, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, errMsg);
throw new YarnException(errMsg);
}

Expand All @@ -1043,9 +1061,11 @@ public ReservationSubmissionResponse submitReservation(
if (request == null || request.getReservationId() == null
|| request.getReservationDefinition() == null || request.getQueue() == null) {
routerMetrics.incrSubmitReservationFailedRetrieved();
RouterServerUtil.logAndThrowException(
"Missing submitReservation request or reservationId " +
"or reservation definition or queue.", null);
String msg = "Missing submitReservation request or reservationId " +
"or reservation definition or queue.";
RouterAuditLogger.logFailure(user.getShortUserName(), SUBMIT_RESERVATION, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, msg);
RouterServerUtil.logAndThrowException(msg, null);
}

long startTime = clock.getTime();
Expand Down Expand Up @@ -1082,6 +1102,8 @@ public ReservationSubmissionResponse submitReservation(
LOG.info("Reservation {} submitted on subCluster {}.", reservationId, subClusterId);
long stopTime = clock.getTime();
routerMetrics.succeededSubmitReservationRetrieved(stopTime - startTime);
RouterAuditLogger.logSuccess(user.getShortUserName(), SUBMIT_RESERVATION,
TARGET_CLIENT_RM_SERVICE);
return response;
}
} catch (Exception e) {
Expand All @@ -1091,6 +1113,8 @@ public ReservationSubmissionResponse submitReservation(

routerMetrics.incrSubmitReservationFailedRetrieved();
String msg = String.format("Reservation %s failed to be submitted.", reservationId);
RouterAuditLogger.logFailure(user.getShortUserName(), SUBMIT_RESERVATION, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, msg);
throw new YarnException(msg);
}

Expand All @@ -1099,7 +1123,10 @@ public ReservationListResponse listReservations(
ReservationListRequest request) throws YarnException, IOException {
if (request == null || request.getReservationId() == null) {
routerMetrics.incrListReservationsFailedRetrieved();
RouterServerUtil.logAndThrowException("Missing listReservations request.", null);
String msg = "Missing listReservations request.";
RouterAuditLogger.logFailure(user.getShortUserName(), LIST_RESERVATIONS, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, msg);
RouterServerUtil.logAndThrowException(msg, null);
}
long startTime = clock.getTime();
ClientMethod remoteMethod = new ClientMethod("listReservations",
Expand All @@ -1108,12 +1135,16 @@ public ReservationListResponse listReservations(
try {
listResponses = invokeConcurrent(remoteMethod, ReservationListResponse.class);
} catch (Exception ex) {
String msg = "Unable to list reservations node due to exception.";
routerMetrics.incrListReservationsFailedRetrieved();
RouterServerUtil.logAndThrowException(
"Unable to list reservations node due to exception.", ex);
RouterAuditLogger.logFailure(user.getShortUserName(), LIST_RESERVATIONS, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, msg);
RouterServerUtil.logAndThrowException(msg, ex);
}
long stopTime = clock.getTime();
routerMetrics.succeededListReservationsRetrieved(stopTime - startTime);
RouterAuditLogger.logSuccess(user.getShortUserName(), LIST_RESERVATIONS,
TARGET_CLIENT_RM_SERVICE);
// Merge the ReservationListResponse
return RouterYarnClientUtils.mergeReservationsList(listResponses);
}
Expand All @@ -1125,8 +1156,10 @@ public ReservationUpdateResponse updateReservation(
if (request == null || request.getReservationId() == null
|| request.getReservationDefinition() == null) {
routerMetrics.incrUpdateReservationFailedRetrieved();
RouterServerUtil.logAndThrowException(
"Missing updateReservation request or reservationId or reservation definition.", null);
String msg = "Missing updateReservation request or reservationId or reservation definition.";
RouterAuditLogger.logFailure(user.getShortUserName(), UPDATE_RESERVATION, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, msg);
RouterServerUtil.logAndThrowException(msg, null);
}

long startTime = clock.getTime();
Expand All @@ -1139,16 +1172,22 @@ public ReservationUpdateResponse updateReservation(
if (response != null) {
long stopTime = clock.getTime();
routerMetrics.succeededUpdateReservationRetrieved(stopTime - startTime);
RouterAuditLogger.logSuccess(user.getShortUserName(), UPDATE_RESERVATION,
TARGET_CLIENT_RM_SERVICE);
return response;
}
} catch (Exception ex) {
routerMetrics.incrUpdateReservationFailedRetrieved();
RouterServerUtil.logAndThrowException(
"Unable to reservation update due to exception.", ex);
String msg = "Unable to reservation update due to exception.";
RouterAuditLogger.logFailure(user.getShortUserName(), UPDATE_RESERVATION, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, msg);
RouterServerUtil.logAndThrowException(msg, ex);
}

routerMetrics.incrUpdateReservationFailedRetrieved();
String msg = String.format("Reservation %s failed to be update.", reservationId);
RouterAuditLogger.logFailure(user.getShortUserName(), UPDATE_RESERVATION, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, msg);
throw new YarnException(msg);
}

Expand All @@ -1157,8 +1196,10 @@ public ReservationDeleteResponse deleteReservation(
ReservationDeleteRequest request) throws YarnException, IOException {
if (request == null || request.getReservationId() == null) {
routerMetrics.incrDeleteReservationFailedRetrieved();
RouterServerUtil.logAndThrowException(
"Missing deleteReservation request or reservationId.", null);
String msg = "Missing deleteReservation request or reservationId.";
RouterServerUtil.logAndThrowException(msg, null);
RouterAuditLogger.logFailure(user.getShortUserName(), DELETE_RESERVATION, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, msg);
}

long startTime = clock.getTime();
Expand All @@ -1172,16 +1213,22 @@ public ReservationDeleteResponse deleteReservation(
federationFacade.deleteReservationHomeSubCluster(reservationId);
long stopTime = clock.getTime();
routerMetrics.succeededDeleteReservationRetrieved(stopTime - startTime);
RouterAuditLogger.logSuccess(user.getShortUserName(), DELETE_RESERVATION,
TARGET_CLIENT_RM_SERVICE);
return response;
}
} catch (Exception ex) {
routerMetrics.incrUpdateReservationFailedRetrieved();
RouterServerUtil.logAndThrowException(
"Unable to reservation delete due to exception.", ex);
String msg = "Unable to reservation delete due to exception.";
RouterAuditLogger.logFailure(user.getShortUserName(), DELETE_RESERVATION, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, msg);
RouterServerUtil.logAndThrowException(msg, ex);
}

routerMetrics.incrDeleteReservationFailedRetrieved();
String msg = String.format("Reservation %s failed to be delete.", reservationId);
RouterAuditLogger.logFailure(user.getShortUserName(), DELETE_RESERVATION, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, msg);
throw new YarnException(msg);
}

Expand All @@ -1190,20 +1237,28 @@ public GetNodesToLabelsResponse getNodeToLabels(
GetNodesToLabelsRequest request) throws YarnException, IOException {
if (request == null) {
routerMetrics.incrNodeToLabelsFailedRetrieved();
RouterServerUtil.logAndThrowException("Missing getNodesToLabels request.", null);
String msg = "Missing getNodesToLabels request.";
RouterServerUtil.logAndThrowException(msg, null);
RouterAuditLogger.logFailure(user.getShortUserName(), GET_NODETOLABELS, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, msg);
}
long startTime = clock.getTime();
ClientMethod remoteMethod = new ClientMethod("getNodeToLabels",
new Class[] {GetNodesToLabelsRequest.class}, new Object[] {request});
new Class[] {GetNodesToLabelsRequest.class}, new Object[] {request});
Collection<GetNodesToLabelsResponse> clusterNodes = null;
try {
clusterNodes = invokeConcurrent(remoteMethod, GetNodesToLabelsResponse.class);
} catch (Exception ex) {
routerMetrics.incrNodeToLabelsFailedRetrieved();
RouterServerUtil.logAndThrowException("Unable to get node label due to exception.", ex);
String msg = "Unable to get node label due to exception.";
RouterAuditLogger.logFailure(user.getShortUserName(), GET_NODETOLABELS, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, msg);
RouterServerUtil.logAndThrowException(msg, ex);
}
long stopTime = clock.getTime();
routerMetrics.succeededGetNodeToLabelsRetrieved(stopTime - startTime);
RouterAuditLogger.logSuccess(user.getShortUserName(), GET_NODETOLABELS,
TARGET_CLIENT_RM_SERVICE);
// Merge the NodesToLabelsResponse
return RouterYarnClientUtils.mergeNodesToLabelsResponse(clusterNodes);
}
Expand All @@ -1213,7 +1268,10 @@ public GetLabelsToNodesResponse getLabelsToNodes(
GetLabelsToNodesRequest request) throws YarnException, IOException {
if (request == null) {
routerMetrics.incrLabelsToNodesFailedRetrieved();
RouterServerUtil.logAndThrowException("Missing getLabelsToNodes request.", null);
String msg = "Missing getNodesToLabels request.";
RouterAuditLogger.logFailure(user.getShortUserName(), GET_LABELSTONODES, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, msg);
RouterServerUtil.logAndThrowException(msg, null);
}
long startTime = clock.getTime();
ClientMethod remoteMethod = new ClientMethod("getLabelsToNodes",
Expand All @@ -1223,10 +1281,15 @@ public GetLabelsToNodesResponse getLabelsToNodes(
labelNodes = invokeConcurrent(remoteMethod, GetLabelsToNodesResponse.class);
} catch (Exception ex) {
routerMetrics.incrLabelsToNodesFailedRetrieved();
RouterServerUtil.logAndThrowException("Unable to get label node due to exception.", ex);
String msg = "Unable to get label node due to exception.";
RouterAuditLogger.logFailure(user.getShortUserName(), GET_LABELSTONODES, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, msg);
RouterServerUtil.logAndThrowException(msg, ex);
}
long stopTime = clock.getTime();
routerMetrics.succeededGetLabelsToNodesRetrieved(stopTime - startTime);
RouterAuditLogger.logSuccess(user.getShortUserName(), GET_LABELSTONODES,
TARGET_CLIENT_RM_SERVICE);
// Merge the LabelsToNodesResponse
return RouterYarnClientUtils.mergeLabelsToNodes(labelNodes);
}
Expand All @@ -1236,7 +1299,10 @@ public GetClusterNodeLabelsResponse getClusterNodeLabels(
GetClusterNodeLabelsRequest request) throws YarnException, IOException {
if (request == null) {
routerMetrics.incrClusterNodeLabelsFailedRetrieved();
RouterServerUtil.logAndThrowException("Missing getClusterNodeLabels request.", null);
String msg = "Missing getClusterNodeLabels request.";
RouterAuditLogger.logFailure(user.getShortUserName(), GET_CLUSTERNODELABELS, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, msg);
RouterServerUtil.logAndThrowException(msg, null);
}
long startTime = clock.getTime();
ClientMethod remoteMethod = new ClientMethod("getClusterNodeLabels",
Expand All @@ -1246,8 +1312,10 @@ public GetClusterNodeLabelsResponse getClusterNodeLabels(
nodeLabels = invokeConcurrent(remoteMethod, GetClusterNodeLabelsResponse.class);
} catch (Exception ex) {
routerMetrics.incrClusterNodeLabelsFailedRetrieved();
RouterServerUtil.logAndThrowException("Unable to get cluster nodeLabels due to exception.",
ex);
String msg = "Unable to get cluster nodeLabels due to exception.";
RouterAuditLogger.logFailure(user.getShortUserName(), GET_CLUSTERNODELABELS, UNKNOWN,
TARGET_CLIENT_RM_SERVICE, msg);
RouterServerUtil.logAndThrowException(msg, ex);
}
long stopTime = clock.getTime();
routerMetrics.succeededGetClusterNodeLabelsRetrieved(stopTime - startTime);
Expand Down

0 comments on commit 94b7edf

Please sign in to comment.