157157import static org .apache .hadoop .yarn .server .router .RouterAuditLogger .AuditConstants .GET_APPLICATIONS ;
158158import static org .apache .hadoop .yarn .server .router .RouterAuditLogger .AuditConstants .GET_CLUSTERMETRICS ;
159159import static org .apache .hadoop .yarn .server .router .RouterAuditLogger .AuditConstants .GET_QUEUEINFO ;
160+ import static org .apache .hadoop .yarn .server .router .RouterAuditLogger .AuditConstants .MOVE_APPLICATION_ACROSS_QUEUES ;
161+ import static org .apache .hadoop .yarn .server .router .RouterAuditLogger .AuditConstants .GET_NEW_RESERVATION ;
162+ import static org .apache .hadoop .yarn .server .router .RouterAuditLogger .AuditConstants .SUBMIT_RESERVATION ;
163+ import static org .apache .hadoop .yarn .server .router .RouterAuditLogger .AuditConstants .LIST_RESERVATIONS ;
164+ import static org .apache .hadoop .yarn .server .router .RouterAuditLogger .AuditConstants .UPDATE_RESERVATION ;
165+ import static org .apache .hadoop .yarn .server .router .RouterAuditLogger .AuditConstants .DELETE_RESERVATION ;
166+ import static org .apache .hadoop .yarn .server .router .RouterAuditLogger .AuditConstants .GET_NODETOLABELS ;
167+ import static org .apache .hadoop .yarn .server .router .RouterAuditLogger .AuditConstants .GET_LABELSTONODES ;
168+ import static org .apache .hadoop .yarn .server .router .RouterAuditLogger .AuditConstants .GET_CLUSTERNODELABELS ;
160169
161170/**
162171 * Extends the {@code AbstractRequestInterceptorClient} class and provides an
@@ -957,7 +966,7 @@ public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(
957966 routerMetrics .incrMoveApplicationAcrossQueuesFailedRetrieved ();
958967 String msg = "Missing moveApplicationAcrossQueues request or " +
959968 "applicationId or target queue." ;
960- RouterAuditLogger .logFailure (user .getShortUserName (), GET_QUEUE_USER_ACLS , UNKNOWN ,
969+ RouterAuditLogger .logFailure (user .getShortUserName (), MOVE_APPLICATION_ACROSS_QUEUES , UNKNOWN ,
961970 TARGET_CLIENT_RM_SERVICE , msg );
962971 RouterServerUtil .logAndThrowException (msg );
963972 }
@@ -972,7 +981,7 @@ public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(
972981 } catch (YarnException e ) {
973982 routerMetrics .incrMoveApplicationAcrossQueuesFailedRetrieved ();
974983 String errMsgFormat = "Application %s does not exist in FederationStateStore." ;
975- RouterAuditLogger .logFailure (user .getShortUserName (), GET_QUEUE_USER_ACLS , UNKNOWN ,
984+ RouterAuditLogger .logFailure (user .getShortUserName (), MOVE_APPLICATION_ACROSS_QUEUES , UNKNOWN ,
976985 TARGET_CLIENT_RM_SERVICE , String .format (errMsgFormat , applicationId ));
977986 RouterServerUtil .logAndThrowException (e , errMsgFormat , applicationId );
978987 }
@@ -995,7 +1004,7 @@ public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(
9951004 }
9961005
9971006 long stopTime = clock .getTime ();
998- RouterAuditLogger .logSuccess (user .getShortUserName (), GET_QUEUE_USER_ACLS ,
1007+ RouterAuditLogger .logSuccess (user .getShortUserName (), MOVE_APPLICATION_ACROSS_QUEUES ,
9991008 TARGET_CLIENT_RM_SERVICE , applicationId , subClusterId );
10001009 routerMetrics .succeededMoveApplicationAcrossQueuesRetrieved (stopTime - startTime );
10011010 return response ;
@@ -1008,6 +1017,8 @@ public GetNewReservationResponse getNewReservation(
10081017 if (request == null ) {
10091018 routerMetrics .incrGetNewReservationFailedRetrieved ();
10101019 String errMsg = "Missing getNewReservation request." ;
1020+ RouterAuditLogger .logFailure (user .getShortUserName (), GET_NEW_RESERVATION , UNKNOWN ,
1021+ TARGET_CLIENT_RM_SERVICE , errMsg );
10111022 RouterServerUtil .logAndThrowException (errMsg , null );
10121023 }
10131024
@@ -1023,16 +1034,23 @@ public GetNewReservationResponse getNewReservation(
10231034 if (response != null ) {
10241035 long stopTime = clock .getTime ();
10251036 routerMetrics .succeededGetNewReservationRetrieved (stopTime - startTime );
1037+ RouterAuditLogger .logSuccess (user .getShortUserName (), GET_NEW_RESERVATION ,
1038+ TARGET_CLIENT_RM_SERVICE );
10261039 return response ;
10271040 }
10281041 } catch (Exception e ) {
1029- LOG .warn ("Unable to create a new Reservation in SubCluster {}." , subClusterId .getId (), e );
1042+ String logFormatted = "Unable to create a new Reservation in SubCluster {}." ;
1043+ LOG .warn (logFormatted , subClusterId .getId (), e );
1044+ RouterAuditLogger .logFailure (user .getShortUserName (), GET_NEW_RESERVATION , UNKNOWN ,
1045+ TARGET_CLIENT_RM_SERVICE , logFormatted , subClusterId .getId ());
10301046 subClustersActive .remove (subClusterId );
10311047 }
10321048 }
10331049
10341050 routerMetrics .incrGetNewReservationFailedRetrieved ();
10351051 String errMsg = "Failed to create a new reservation." ;
1052+ RouterAuditLogger .logFailure (user .getShortUserName (), GET_NEW_RESERVATION , UNKNOWN ,
1053+ TARGET_CLIENT_RM_SERVICE , errMsg );
10361054 throw new YarnException (errMsg );
10371055 }
10381056
@@ -1043,9 +1061,11 @@ public ReservationSubmissionResponse submitReservation(
10431061 if (request == null || request .getReservationId () == null
10441062 || request .getReservationDefinition () == null || request .getQueue () == null ) {
10451063 routerMetrics .incrSubmitReservationFailedRetrieved ();
1046- RouterServerUtil .logAndThrowException (
1047- "Missing submitReservation request or reservationId " +
1048- "or reservation definition or queue." , null );
1064+ String msg = "Missing submitReservation request or reservationId " +
1065+ "or reservation definition or queue." ;
1066+ RouterAuditLogger .logFailure (user .getShortUserName (), SUBMIT_RESERVATION , UNKNOWN ,
1067+ TARGET_CLIENT_RM_SERVICE , msg );
1068+ RouterServerUtil .logAndThrowException (msg , null );
10491069 }
10501070
10511071 long startTime = clock .getTime ();
@@ -1082,6 +1102,8 @@ public ReservationSubmissionResponse submitReservation(
10821102 LOG .info ("Reservation {} submitted on subCluster {}." , reservationId , subClusterId );
10831103 long stopTime = clock .getTime ();
10841104 routerMetrics .succeededSubmitReservationRetrieved (stopTime - startTime );
1105+ RouterAuditLogger .logSuccess (user .getShortUserName (), SUBMIT_RESERVATION ,
1106+ TARGET_CLIENT_RM_SERVICE );
10851107 return response ;
10861108 }
10871109 } catch (Exception e ) {
@@ -1091,6 +1113,8 @@ public ReservationSubmissionResponse submitReservation(
10911113
10921114 routerMetrics .incrSubmitReservationFailedRetrieved ();
10931115 String msg = String .format ("Reservation %s failed to be submitted." , reservationId );
1116+ RouterAuditLogger .logFailure (user .getShortUserName (), SUBMIT_RESERVATION , UNKNOWN ,
1117+ TARGET_CLIENT_RM_SERVICE , msg );
10941118 throw new YarnException (msg );
10951119 }
10961120
@@ -1099,7 +1123,10 @@ public ReservationListResponse listReservations(
10991123 ReservationListRequest request ) throws YarnException , IOException {
11001124 if (request == null || request .getReservationId () == null ) {
11011125 routerMetrics .incrListReservationsFailedRetrieved ();
1102- RouterServerUtil .logAndThrowException ("Missing listReservations request." , null );
1126+ String msg = "Missing listReservations request." ;
1127+ RouterAuditLogger .logFailure (user .getShortUserName (), LIST_RESERVATIONS , UNKNOWN ,
1128+ TARGET_CLIENT_RM_SERVICE , msg );
1129+ RouterServerUtil .logAndThrowException (msg , null );
11031130 }
11041131 long startTime = clock .getTime ();
11051132 ClientMethod remoteMethod = new ClientMethod ("listReservations" ,
@@ -1108,12 +1135,16 @@ public ReservationListResponse listReservations(
11081135 try {
11091136 listResponses = invokeConcurrent (remoteMethod , ReservationListResponse .class );
11101137 } catch (Exception ex ) {
1138+ String msg = "Unable to list reservations node due to exception." ;
11111139 routerMetrics .incrListReservationsFailedRetrieved ();
1112- RouterServerUtil .logAndThrowException (
1113- "Unable to list reservations node due to exception." , ex );
1140+ RouterAuditLogger .logFailure (user .getShortUserName (), LIST_RESERVATIONS , UNKNOWN ,
1141+ TARGET_CLIENT_RM_SERVICE , msg );
1142+ RouterServerUtil .logAndThrowException (msg , ex );
11141143 }
11151144 long stopTime = clock .getTime ();
11161145 routerMetrics .succeededListReservationsRetrieved (stopTime - startTime );
1146+ RouterAuditLogger .logSuccess (user .getShortUserName (), LIST_RESERVATIONS ,
1147+ TARGET_CLIENT_RM_SERVICE );
11171148 // Merge the ReservationListResponse
11181149 return RouterYarnClientUtils .mergeReservationsList (listResponses );
11191150 }
@@ -1125,8 +1156,10 @@ public ReservationUpdateResponse updateReservation(
11251156 if (request == null || request .getReservationId () == null
11261157 || request .getReservationDefinition () == null ) {
11271158 routerMetrics .incrUpdateReservationFailedRetrieved ();
1128- RouterServerUtil .logAndThrowException (
1129- "Missing updateReservation request or reservationId or reservation definition." , null );
1159+ String msg = "Missing updateReservation request or reservationId or reservation definition." ;
1160+ RouterAuditLogger .logFailure (user .getShortUserName (), UPDATE_RESERVATION , UNKNOWN ,
1161+ TARGET_CLIENT_RM_SERVICE , msg );
1162+ RouterServerUtil .logAndThrowException (msg , null );
11301163 }
11311164
11321165 long startTime = clock .getTime ();
@@ -1139,16 +1172,22 @@ public ReservationUpdateResponse updateReservation(
11391172 if (response != null ) {
11401173 long stopTime = clock .getTime ();
11411174 routerMetrics .succeededUpdateReservationRetrieved (stopTime - startTime );
1175+ RouterAuditLogger .logSuccess (user .getShortUserName (), UPDATE_RESERVATION ,
1176+ TARGET_CLIENT_RM_SERVICE );
11421177 return response ;
11431178 }
11441179 } catch (Exception ex ) {
11451180 routerMetrics .incrUpdateReservationFailedRetrieved ();
1146- RouterServerUtil .logAndThrowException (
1147- "Unable to reservation update due to exception." , ex );
1181+ String msg = "Unable to reservation update due to exception." ;
1182+ RouterAuditLogger .logFailure (user .getShortUserName (), UPDATE_RESERVATION , UNKNOWN ,
1183+ TARGET_CLIENT_RM_SERVICE , msg );
1184+ RouterServerUtil .logAndThrowException (msg , ex );
11481185 }
11491186
11501187 routerMetrics .incrUpdateReservationFailedRetrieved ();
11511188 String msg = String .format ("Reservation %s failed to be update." , reservationId );
1189+ RouterAuditLogger .logFailure (user .getShortUserName (), UPDATE_RESERVATION , UNKNOWN ,
1190+ TARGET_CLIENT_RM_SERVICE , msg );
11521191 throw new YarnException (msg );
11531192 }
11541193
@@ -1157,8 +1196,10 @@ public ReservationDeleteResponse deleteReservation(
11571196 ReservationDeleteRequest request ) throws YarnException , IOException {
11581197 if (request == null || request .getReservationId () == null ) {
11591198 routerMetrics .incrDeleteReservationFailedRetrieved ();
1160- RouterServerUtil .logAndThrowException (
1161- "Missing deleteReservation request or reservationId." , null );
1199+ String msg = "Missing deleteReservation request or reservationId." ;
1200+ RouterServerUtil .logAndThrowException (msg , null );
1201+ RouterAuditLogger .logFailure (user .getShortUserName (), DELETE_RESERVATION , UNKNOWN ,
1202+ TARGET_CLIENT_RM_SERVICE , msg );
11621203 }
11631204
11641205 long startTime = clock .getTime ();
@@ -1172,16 +1213,22 @@ public ReservationDeleteResponse deleteReservation(
11721213 federationFacade .deleteReservationHomeSubCluster (reservationId );
11731214 long stopTime = clock .getTime ();
11741215 routerMetrics .succeededDeleteReservationRetrieved (stopTime - startTime );
1216+ RouterAuditLogger .logSuccess (user .getShortUserName (), DELETE_RESERVATION ,
1217+ TARGET_CLIENT_RM_SERVICE );
11751218 return response ;
11761219 }
11771220 } catch (Exception ex ) {
11781221 routerMetrics .incrUpdateReservationFailedRetrieved ();
1179- RouterServerUtil .logAndThrowException (
1180- "Unable to reservation delete due to exception." , ex );
1222+ String msg = "Unable to reservation delete due to exception." ;
1223+ RouterAuditLogger .logFailure (user .getShortUserName (), DELETE_RESERVATION , UNKNOWN ,
1224+ TARGET_CLIENT_RM_SERVICE , msg );
1225+ RouterServerUtil .logAndThrowException (msg , ex );
11811226 }
11821227
11831228 routerMetrics .incrDeleteReservationFailedRetrieved ();
11841229 String msg = String .format ("Reservation %s failed to be delete." , reservationId );
1230+ RouterAuditLogger .logFailure (user .getShortUserName (), DELETE_RESERVATION , UNKNOWN ,
1231+ TARGET_CLIENT_RM_SERVICE , msg );
11851232 throw new YarnException (msg );
11861233 }
11871234
@@ -1190,20 +1237,28 @@ public GetNodesToLabelsResponse getNodeToLabels(
11901237 GetNodesToLabelsRequest request ) throws YarnException , IOException {
11911238 if (request == null ) {
11921239 routerMetrics .incrNodeToLabelsFailedRetrieved ();
1193- RouterServerUtil .logAndThrowException ("Missing getNodesToLabels request." , null );
1240+ String msg = "Missing getNodesToLabels request." ;
1241+ RouterServerUtil .logAndThrowException (msg , null );
1242+ RouterAuditLogger .logFailure (user .getShortUserName (), GET_NODETOLABELS , UNKNOWN ,
1243+ TARGET_CLIENT_RM_SERVICE , msg );
11941244 }
11951245 long startTime = clock .getTime ();
11961246 ClientMethod remoteMethod = new ClientMethod ("getNodeToLabels" ,
1197- new Class [] {GetNodesToLabelsRequest .class }, new Object [] {request });
1247+ new Class [] {GetNodesToLabelsRequest .class }, new Object [] {request });
11981248 Collection <GetNodesToLabelsResponse > clusterNodes = null ;
11991249 try {
12001250 clusterNodes = invokeConcurrent (remoteMethod , GetNodesToLabelsResponse .class );
12011251 } catch (Exception ex ) {
12021252 routerMetrics .incrNodeToLabelsFailedRetrieved ();
1203- RouterServerUtil .logAndThrowException ("Unable to get node label due to exception." , ex );
1253+ String msg = "Unable to get node label due to exception." ;
1254+ RouterAuditLogger .logFailure (user .getShortUserName (), GET_NODETOLABELS , UNKNOWN ,
1255+ TARGET_CLIENT_RM_SERVICE , msg );
1256+ RouterServerUtil .logAndThrowException (msg , ex );
12041257 }
12051258 long stopTime = clock .getTime ();
12061259 routerMetrics .succeededGetNodeToLabelsRetrieved (stopTime - startTime );
1260+ RouterAuditLogger .logSuccess (user .getShortUserName (), GET_NODETOLABELS ,
1261+ TARGET_CLIENT_RM_SERVICE );
12071262 // Merge the NodesToLabelsResponse
12081263 return RouterYarnClientUtils .mergeNodesToLabelsResponse (clusterNodes );
12091264 }
@@ -1213,7 +1268,10 @@ public GetLabelsToNodesResponse getLabelsToNodes(
12131268 GetLabelsToNodesRequest request ) throws YarnException , IOException {
12141269 if (request == null ) {
12151270 routerMetrics .incrLabelsToNodesFailedRetrieved ();
1216- RouterServerUtil .logAndThrowException ("Missing getLabelsToNodes request." , null );
1271+ String msg = "Missing getNodesToLabels request." ;
1272+ RouterAuditLogger .logFailure (user .getShortUserName (), GET_LABELSTONODES , UNKNOWN ,
1273+ TARGET_CLIENT_RM_SERVICE , msg );
1274+ RouterServerUtil .logAndThrowException (msg , null );
12171275 }
12181276 long startTime = clock .getTime ();
12191277 ClientMethod remoteMethod = new ClientMethod ("getLabelsToNodes" ,
@@ -1223,10 +1281,15 @@ public GetLabelsToNodesResponse getLabelsToNodes(
12231281 labelNodes = invokeConcurrent (remoteMethod , GetLabelsToNodesResponse .class );
12241282 } catch (Exception ex ) {
12251283 routerMetrics .incrLabelsToNodesFailedRetrieved ();
1226- RouterServerUtil .logAndThrowException ("Unable to get label node due to exception." , ex );
1284+ String msg = "Unable to get label node due to exception." ;
1285+ RouterAuditLogger .logFailure (user .getShortUserName (), GET_LABELSTONODES , UNKNOWN ,
1286+ TARGET_CLIENT_RM_SERVICE , msg );
1287+ RouterServerUtil .logAndThrowException (msg , ex );
12271288 }
12281289 long stopTime = clock .getTime ();
12291290 routerMetrics .succeededGetLabelsToNodesRetrieved (stopTime - startTime );
1291+ RouterAuditLogger .logSuccess (user .getShortUserName (), GET_LABELSTONODES ,
1292+ TARGET_CLIENT_RM_SERVICE );
12301293 // Merge the LabelsToNodesResponse
12311294 return RouterYarnClientUtils .mergeLabelsToNodes (labelNodes );
12321295 }
@@ -1236,7 +1299,10 @@ public GetClusterNodeLabelsResponse getClusterNodeLabels(
12361299 GetClusterNodeLabelsRequest request ) throws YarnException , IOException {
12371300 if (request == null ) {
12381301 routerMetrics .incrClusterNodeLabelsFailedRetrieved ();
1239- RouterServerUtil .logAndThrowException ("Missing getClusterNodeLabels request." , null );
1302+ String msg = "Missing getClusterNodeLabels request." ;
1303+ RouterAuditLogger .logFailure (user .getShortUserName (), GET_CLUSTERNODELABELS , UNKNOWN ,
1304+ TARGET_CLIENT_RM_SERVICE , msg );
1305+ RouterServerUtil .logAndThrowException (msg , null );
12401306 }
12411307 long startTime = clock .getTime ();
12421308 ClientMethod remoteMethod = new ClientMethod ("getClusterNodeLabels" ,
@@ -1246,8 +1312,10 @@ public GetClusterNodeLabelsResponse getClusterNodeLabels(
12461312 nodeLabels = invokeConcurrent (remoteMethod , GetClusterNodeLabelsResponse .class );
12471313 } catch (Exception ex ) {
12481314 routerMetrics .incrClusterNodeLabelsFailedRetrieved ();
1249- RouterServerUtil .logAndThrowException ("Unable to get cluster nodeLabels due to exception." ,
1250- ex );
1315+ String msg = "Unable to get cluster nodeLabels due to exception." ;
1316+ RouterAuditLogger .logFailure (user .getShortUserName (), GET_CLUSTERNODELABELS , UNKNOWN ,
1317+ TARGET_CLIENT_RM_SERVICE , msg );
1318+ RouterServerUtil .logAndThrowException (msg , ex );
12511319 }
12521320 long stopTime = clock .getTime ();
12531321 routerMetrics .succeededGetClusterNodeLabelsRetrieved (stopTime - startTime );
0 commit comments