137137
138138import org .apache .hadoop .classification .VisibleForTesting ;
139139
140+ import static org .apache .hadoop .yarn .server .router .RouterAuditLogger .AuditConstants .GET_NEW_APP ;
141+ import static org .apache .hadoop .yarn .server .router .RouterAuditLogger .AuditConstants .SUBMIT_NEW_APP ;
142+ import static org .apache .hadoop .yarn .server .router .RouterAuditLogger .AuditConstants .GET_APP_REPORT ;
143+ import static org .apache .hadoop .yarn .server .router .RouterAuditLogger .AuditConstants .FORCE_KILL_APP ;
144+ import static org .apache .hadoop .yarn .server .router .RouterAuditLogger .AuditConstants .TARGET_CLIENT_RM_SERVICE ;
145+ import static org .apache .hadoop .yarn .server .router .RouterAuditLogger .AuditConstants .UNKNOWN ;
146+
140147/**
141148 * Extends the {@code AbstractRequestInterceptorClient} class and provides an
142149 * implementation for federation of YARN RM and scaling an application across
@@ -277,9 +284,8 @@ public GetNewApplicationResponse getNewApplication(
277284 if (request == null ) {
278285 routerMetrics .incrAppsFailedCreated ();
279286 String errMsg = "Missing getNewApplication request." ;
280- RouterAuditLogger .logFailure (user .getShortUserName (),
281- RouterAuditLogger .AuditConstants .GET_NEW_APP , "UNKNOWN" ,
282- "RouterClientRMService" , errMsg );
287+ RouterAuditLogger .logFailure (user .getShortUserName (), GET_NEW_APP , UNKNOWN ,
288+ TARGET_CLIENT_RM_SERVICE , errMsg );
283289 RouterServerUtil .logAndThrowException (errMsg , null );
284290 }
285291
@@ -291,7 +297,7 @@ public GetNewApplicationResponse getNewApplication(
291297
292298 for (int i = 0 ; i < numSubmitRetries ; ++i ) {
293299 SubClusterId subClusterId = getRandomActiveSubCluster (subClustersActive );
294- LOG .info ("getNewApplication try #{} on SubCluster {}" , i , subClusterId );
300+ LOG .info ("getNewApplication try #{} on SubCluster {}. " , i , subClusterId );
295301 ApplicationClientProtocol clientRMProxy = getClientRMProxyForSubCluster (subClusterId );
296302 response = null ;
297303 try {
@@ -304,18 +310,16 @@ public GetNewApplicationResponse getNewApplication(
304310 if (response != null ) {
305311 long stopTime = clock .getTime ();
306312 routerMetrics .succeededAppsCreated (stopTime - startTime );
307- RouterAuditLogger .logSuccess (user .getShortUserName (),
308- RouterAuditLogger .AuditConstants .GET_NEW_APP ,
309- "RouterClientRMService" , response .getApplicationId ());
313+ RouterAuditLogger .logSuccess (user .getShortUserName (), GET_NEW_APP ,
314+ TARGET_CLIENT_RM_SERVICE , response .getApplicationId ());
310315 return response ;
311316 }
312317 }
313318
314319 routerMetrics .incrAppsFailedCreated ();
315320 String errMsg = "Failed to create a new application." ;
316- RouterAuditLogger .logFailure (user .getShortUserName (),
317- RouterAuditLogger .AuditConstants .GET_NEW_APP , "UNKNOWN" ,
318- "RouterClientRMService" , errMsg );
321+ RouterAuditLogger .logFailure (user .getShortUserName (), GET_NEW_APP , UNKNOWN ,
322+ TARGET_CLIENT_RM_SERVICE , errMsg );
319323 RouterServerUtil .logAndThrowException (errMsg , null );
320324 return response ;
321325 }
@@ -394,12 +398,13 @@ public SubmitApplicationResponse submitApplication(
394398 routerMetrics .incrAppsFailedSubmitted ();
395399 String errMsg =
396400 "Missing submitApplication request or applicationSubmissionContext information." ;
397- RouterAuditLogger .logFailure (user .getShortUserName (),
398- RouterAuditLogger .AuditConstants .SUBMIT_NEW_APP , "UNKNOWN" ,
399- "RouterClientRMService" , errMsg );
401+ RouterAuditLogger .logFailure (user .getShortUserName (), SUBMIT_NEW_APP , UNKNOWN ,
402+ TARGET_CLIENT_RM_SERVICE , errMsg );
400403 RouterServerUtil .logAndThrowException (errMsg , null );
401404 }
402405
406+ SubmitApplicationResponse response = null ;
407+
403408 long startTime = clock .getTime ();
404409
405410 ApplicationId applicationId =
@@ -429,9 +434,8 @@ public SubmitApplicationResponse submitApplication(
429434 String message =
430435 String .format ("Unable to insert the ApplicationId %s into the FederationStateStore." ,
431436 applicationId );
432- RouterAuditLogger .logFailure (user .getShortUserName (),
433- RouterAuditLogger .AuditConstants .SUBMIT_NEW_APP , "UNKNOWN" ,
434- "RouterClientRMService" , message , applicationId , subClusterId );
437+ RouterAuditLogger .logFailure (user .getShortUserName (), SUBMIT_NEW_APP , UNKNOWN ,
438+ TARGET_CLIENT_RM_SERVICE , message , applicationId , subClusterId );
435439 RouterServerUtil .logAndThrowException (message , e );
436440 }
437441 } else {
@@ -450,9 +454,8 @@ public SubmitApplicationResponse submitApplication(
450454 applicationId , subClusterId );
451455 } else {
452456 routerMetrics .incrAppsFailedSubmitted ();
453- RouterAuditLogger .logFailure (user .getShortUserName (),
454- RouterAuditLogger .AuditConstants .SUBMIT_NEW_APP , "UNKNOWN" ,
455- "RouterClientRMService" , message , applicationId , subClusterId );
457+ RouterAuditLogger .logFailure (user .getShortUserName (), SUBMIT_NEW_APP , UNKNOWN ,
458+ TARGET_CLIENT_RM_SERVICE , message , applicationId , subClusterId );
456459 RouterServerUtil .logAndThrowException (message , e );
457460 }
458461 }
@@ -461,7 +464,6 @@ public SubmitApplicationResponse submitApplication(
461464 ApplicationClientProtocol clientRMProxy =
462465 getClientRMProxyForSubCluster (subClusterId );
463466
464- SubmitApplicationResponse response = null ;
465467 try {
466468 response = clientRMProxy .submitApplication (request );
467469 } catch (Exception e ) {
@@ -475,9 +477,8 @@ public SubmitApplicationResponse submitApplication(
475477 applicationId , subClusterId );
476478 long stopTime = clock .getTime ();
477479 routerMetrics .succeededAppsSubmitted (stopTime - startTime );
478- RouterAuditLogger .logSuccess (user .getShortUserName (),
479- RouterAuditLogger .AuditConstants .SUBMIT_NEW_APP ,
480- "RouterClientRMService" , applicationId , subClusterId );
480+ RouterAuditLogger .logSuccess (user .getShortUserName (), SUBMIT_NEW_APP ,
481+ TARGET_CLIENT_RM_SERVICE , applicationId , subClusterId );
481482 return response ;
482483 } else {
483484 // Empty response from the ResourceManager.
@@ -487,12 +488,12 @@ public SubmitApplicationResponse submitApplication(
487488 }
488489
489490 routerMetrics .incrAppsFailedSubmitted ();
490- String errMsg = String .format ("Application %s with appId %s failed to be submitted." ,
491+ String msg = String .format ("Application %s with appId %s failed to be submitted." ,
491492 request .getApplicationSubmissionContext ().getApplicationName (), applicationId );
492- RouterAuditLogger .logFailure (user .getShortUserName (),
493- RouterAuditLogger . AuditConstants . SUBMIT_NEW_APP , "UNKNOWN" ,
494- "RouterClientRMService" , errMsg , applicationId );
495- throw new YarnException ( errMsg ) ;
493+ RouterAuditLogger .logFailure (user .getShortUserName (), SUBMIT_NEW_APP , UNKNOWN ,
494+ TARGET_CLIENT_RM_SERVICE , msg , applicationId );
495+ RouterServerUtil . logAndThrowException ( msg , null );
496+ return response ;
496497 }
497498
498499 /**
@@ -515,16 +516,16 @@ public SubmitApplicationResponse submitApplication(
515516 public KillApplicationResponse forceKillApplication (
516517 KillApplicationRequest request ) throws YarnException , IOException {
517518
518- long startTime = clock .getTime ();
519-
520519 if (request == null || request .getApplicationId () == null ) {
521520 routerMetrics .incrAppsFailedKilled ();
522- String message = "Missing forceKillApplication request or ApplicationId." ;
523- RouterAuditLogger .logFailure (user .getShortUserName (),
524- RouterAuditLogger .AuditConstants .FORCE_KILL_APP , "UNKNOWN" ,
525- "RouterClientRMService" , message );
526- throw new YarnException (message );
521+ String msg = "Missing forceKillApplication request or ApplicationId." ;
522+ RouterAuditLogger .logFailure (user .getShortUserName (), FORCE_KILL_APP , UNKNOWN ,
523+ TARGET_CLIENT_RM_SERVICE , msg );
524+ RouterServerUtil .logAndThrowException (msg , null );
527525 }
526+
527+ long startTime = clock .getTime ();
528+
528529 ApplicationId applicationId = request .getApplicationId ();
529530 SubClusterId subClusterId = null ;
530531
@@ -533,12 +534,11 @@ public KillApplicationResponse forceKillApplication(
533534 .getApplicationHomeSubCluster (request .getApplicationId ());
534535 } catch (YarnException e ) {
535536 routerMetrics .incrAppsFailedKilled ();
536- String msg = "Application " + applicationId
537- + " does not exist in FederationStateStore" ;
538- RouterAuditLogger .logFailure (user .getShortUserName (),
539- RouterAuditLogger .AuditConstants .FORCE_KILL_APP , "UNKNOWN" ,
540- "RouterClientRMService" , msg , applicationId );
541- throw new YarnException (msg , e );
537+ String msg =
538+ String .format ("Application %s does not exist in FederationStateStore." , applicationId );
539+ RouterAuditLogger .logFailure (user .getShortUserName (), FORCE_KILL_APP , UNKNOWN ,
540+ TARGET_CLIENT_RM_SERVICE , msg , applicationId );
541+ RouterServerUtil .logAndThrowException (msg , e );
542542 }
543543
544544 ApplicationClientProtocol clientRMProxy =
@@ -550,23 +550,21 @@ public KillApplicationResponse forceKillApplication(
550550 response = clientRMProxy .forceKillApplication (request );
551551 } catch (Exception e ) {
552552 routerMetrics .incrAppsFailedKilled ();
553- RouterAuditLogger .logFailure (user .getShortUserName (),
554- RouterAuditLogger .AuditConstants .FORCE_KILL_APP , "UNKNOWN" ,
555- "RouterClientRMService" , "Unable to kill the application report" ,
556- applicationId , subClusterId );
557- throw e ;
553+ String msg = "Unable to kill the application report." ;
554+ RouterAuditLogger .logFailure (user .getShortUserName (), FORCE_KILL_APP , UNKNOWN ,
555+ TARGET_CLIENT_RM_SERVICE , msg , applicationId , subClusterId );
556+ RouterServerUtil .logAndThrowException (msg , e );
558557 }
559558
560559 if (response == null ) {
561- LOG .error ("No response when attempting to kill the application "
562- + applicationId + " to SubCluster " + subClusterId .getId ());
560+ LOG .error ("No response when attempting to kill the application {} to SubCluster {}." ,
561+ applicationId , subClusterId .getId ());
563562 }
564563
565564 long stopTime = clock .getTime ();
566565 routerMetrics .succeededAppsKilled (stopTime - startTime );
567- RouterAuditLogger .logSuccess (user .getShortUserName (),
568- RouterAuditLogger .AuditConstants .FORCE_KILL_APP ,
569- "RouterClientRMService" , applicationId );
566+ RouterAuditLogger .logSuccess (user .getShortUserName (), FORCE_KILL_APP ,
567+ TARGET_CLIENT_RM_SERVICE , applicationId );
570568 return response ;
571569 }
572570
@@ -590,61 +588,53 @@ public KillApplicationResponse forceKillApplication(
590588 public GetApplicationReportResponse getApplicationReport (
591589 GetApplicationReportRequest request ) throws YarnException , IOException {
592590
593- long startTime = clock .getTime ();
594-
595591 if (request == null || request .getApplicationId () == null ) {
596592 routerMetrics .incrAppsFailedRetrieved ();
597- String errMsg =
598- "Missing getApplicationReport request or applicationId information." ;
599- RouterAuditLogger .logFailure (user .getShortUserName (),
600- RouterAuditLogger .AuditConstants .GET_APP_REPORT , "UNKNOWN" ,
601- "RouterClientRMService" , errMsg );
602- throw new YarnException (errMsg );
593+ String errMsg = "Missing getApplicationReport request or applicationId information." ;
594+ RouterAuditLogger .logFailure (user .getShortUserName (), GET_APP_REPORT , UNKNOWN ,
595+ TARGET_CLIENT_RM_SERVICE , errMsg );
596+ RouterServerUtil .logAndThrowException (errMsg , null );
603597 }
604598
599+ long startTime = clock .getTime ();
605600 SubClusterId subClusterId = null ;
606601
607602 try {
608603 subClusterId = federationFacade
609604 .getApplicationHomeSubCluster (request .getApplicationId ());
610605 } catch (YarnException e ) {
611606 routerMetrics .incrAppsFailedRetrieved ();
612- String errMsg = "Application " + request .getApplicationId ()
613- + " does not exist in FederationStateStore" ;
614- RouterAuditLogger .logFailure (user .getShortUserName (),
615- RouterAuditLogger .AuditConstants .GET_APP_REPORT , "UNKNOWN" ,
616- "RouterClientRMService" , errMsg , request .getApplicationId ());
617- throw new YarnException (errMsg , e );
607+ String errMsg = String .format ("Application %s does not exist in FederationStateStore." ,
608+ request .getApplicationId ());
609+ RouterAuditLogger .logFailure (user .getShortUserName (), GET_APP_REPORT , UNKNOWN ,
610+ TARGET_CLIENT_RM_SERVICE , errMsg , request .getApplicationId ());
611+ RouterServerUtil .logAndThrowException (errMsg , e );
618612 }
619613
620614 ApplicationClientProtocol clientRMProxy =
621615 getClientRMProxyForSubCluster (subClusterId );
622-
623616 GetApplicationReportResponse response = null ;
617+
624618 try {
625619 response = clientRMProxy .getApplicationReport (request );
626620 } catch (Exception e ) {
627621 routerMetrics .incrAppsFailedRetrieved ();
628- String errMsg = "Unable to get the application report for " + request
629- .getApplicationId () + "to SubCluster " + subClusterId .getId ();
630- RouterAuditLogger .logFailure (user .getShortUserName (),
631- RouterAuditLogger .AuditConstants .GET_APP_REPORT , "UNKNOWN" ,
632- "RouterClientRMService" , errMsg , request .getApplicationId (),
633- subClusterId );
634- throw e ;
622+ String errMsg = String .format ("Unable to get the application report for %s to SubCluster %s." ,
623+ request .getApplicationId (), subClusterId .getId ());
624+ RouterAuditLogger .logFailure (user .getShortUserName (), GET_APP_REPORT , UNKNOWN ,
625+ TARGET_CLIENT_RM_SERVICE , errMsg , request .getApplicationId (), subClusterId );
626+ RouterServerUtil .logAndThrowException (errMsg , e );
635627 }
636628
637629 if (response == null ) {
638630 LOG .error ("No response when attempting to retrieve the report of "
639631 + "the application {} to SubCluster {}." ,
640632 request .getApplicationId (), subClusterId .getId ());
641633 }
642-
643634 long stopTime = clock .getTime ();
644635 routerMetrics .succeededAppsRetrieved (stopTime - startTime );
645- RouterAuditLogger .logSuccess (user .getShortUserName (),
646- RouterAuditLogger .AuditConstants .GET_APP_REPORT ,
647- "RouterClientRMService" , request .getApplicationId ());
636+ RouterAuditLogger .logSuccess (user .getShortUserName (), GET_APP_REPORT ,
637+ TARGET_CLIENT_RM_SERVICE , request .getApplicationId ());
648638 return response ;
649639 }
650640
@@ -672,21 +662,17 @@ public GetApplicationsResponse getApplications(GetApplicationsRequest request)
672662 throws YarnException , IOException {
673663 if (request == null ) {
674664 routerMetrics .incrMultipleAppsFailedRetrieved ();
675- RouterServerUtil .logAndThrowException (
676- "Missing getApplications request." ,
677- null );
665+ RouterServerUtil .logAndThrowException ("Missing getApplications request." , null );
678666 }
679667 long startTime = clock .getTime ();
680668 Map <SubClusterId , SubClusterInfo > subclusters =
681669 federationFacade .getSubClusters (true );
682670 ClientMethod remoteMethod = new ClientMethod ("getApplications" ,
683671 new Class [] {GetApplicationsRequest .class }, new Object [] {request });
684672 Map <SubClusterId , GetApplicationsResponse > applications ;
685-
686673 try {
687674 applications = invokeConcurrent (subclusters .keySet (), remoteMethod ,
688675 GetApplicationsResponse .class );
689-
690676 } catch (Exception ex ) {
691677 routerMetrics .incrMultipleAppsFailedRetrieved ();
692678 LOG .error ("Unable to get applications due to exception." , ex );
@@ -695,8 +681,7 @@ public GetApplicationsResponse getApplications(GetApplicationsRequest request)
695681 long stopTime = clock .getTime ();
696682 routerMetrics .succeededMultipleAppsRetrieved (stopTime - startTime );
697683 // Merge the Application Reports
698- return RouterYarnClientUtils .mergeApplications (applications .values (),
699- returnPartialReport );
684+ return RouterYarnClientUtils .mergeApplications (applications .values (), returnPartialReport );
700685 }
701686
702687 @ Override
0 commit comments