4949import org .apache .hadoop .yarn .api .records .AMCommand ;
5050import org .apache .hadoop .yarn .api .records .ApplicationAttemptId ;
5151import org .apache .hadoop .yarn .api .records .ApplicationId ;
52+ import org .apache .hadoop .yarn .api .records .ApplicationSubmissionContext ;
5253import org .apache .hadoop .yarn .api .records .Container ;
5354import org .apache .hadoop .yarn .api .records .ContainerId ;
5455import org .apache .hadoop .yarn .api .records .NMToken ;
@@ -254,13 +255,13 @@ public RegisterApplicationMasterResponse registerApplicationMaster(
254255 if (hasApplicationMasterRegistered (applicationAttemptId )) {
255256 String message =
256257 "Application Master is already registered : "
257- + applicationAttemptId . getApplicationId () ;
258+ + appID ;
258259 LOG .warn (message );
259260 RMAuditLogger .logFailure (
260261 this .rmContext .getRMApps ()
261- .get (applicationAttemptId . getApplicationId () ).getUser (),
262+ .get (appID ).getUser (),
262263 AuditConstants .REGISTER_AM , "" , "ApplicationMasterService" , message ,
263- applicationAttemptId . getApplicationId () , applicationAttemptId );
264+ appID , applicationAttemptId );
264265 throw new InvalidApplicationMasterRequestException (message );
265266 }
266267
@@ -340,6 +341,7 @@ public FinishApplicationMasterResponse finishApplicationMaster(
340341
341342 ApplicationAttemptId applicationAttemptId =
342343 authorizeRequest ().getApplicationAttemptId ();
344+ ApplicationId appId = applicationAttemptId .getApplicationId ();
343345
344346 AllocateResponseLock lock = responseMap .get (applicationAttemptId );
345347 if (lock == null ) {
@@ -351,21 +353,21 @@ public FinishApplicationMasterResponse finishApplicationMaster(
351353 if (!hasApplicationMasterRegistered (applicationAttemptId )) {
352354 String message =
353355 "Application Master is trying to unregister before registering for: "
354- + applicationAttemptId . getApplicationId () ;
356+ + appId ;
355357 LOG .error (message );
356358 RMAuditLogger .logFailure (
357359 this .rmContext .getRMApps ()
358- .get (applicationAttemptId . getApplicationId () ).getUser (),
360+ .get (appId ).getUser (),
359361 AuditConstants .UNREGISTER_AM , "" , "ApplicationMasterService" ,
360- message , applicationAttemptId . getApplicationId () ,
362+ message , appId ,
361363 applicationAttemptId );
362364 throw new ApplicationMasterNotRegisteredException (message );
363365 }
364366
365367 this .amLivelinessMonitor .receivedPing (applicationAttemptId );
366368
367369 RMApp rmApp =
368- rmContext .getRMApps ().get (applicationAttemptId . getApplicationId () );
370+ rmContext .getRMApps ().get (appId );
369371
370372 if (rmApp .isAppFinalStateStored ()) {
371373 return FinishApplicationMasterResponse .newInstance (true );
@@ -418,6 +420,7 @@ public AllocateResponse allocate(AllocateRequest request)
418420
419421 ApplicationAttemptId appAttemptId =
420422 amrmTokenIdentifier .getApplicationAttemptId ();
423+ ApplicationId applicationId = appAttemptId .getApplicationId ();
421424
422425 this .amLivelinessMonitor .receivedPing (appAttemptId );
423426
@@ -432,14 +435,14 @@ public AllocateResponse allocate(AllocateRequest request)
432435 if (!hasApplicationMasterRegistered (appAttemptId )) {
433436 String message =
434437 "Application Master is not registered for known application: "
435- + appAttemptId . getApplicationId ()
438+ + applicationId
436439 + ". Let AM resync." ;
437440 LOG .info (message );
438441 RMAuditLogger .logFailure (
439- this .rmContext .getRMApps ().get (appAttemptId . getApplicationId () )
442+ this .rmContext .getRMApps ().get (applicationId )
440443 .getUser (), AuditConstants .REGISTER_AM , "" ,
441444 "ApplicationMasterService" , message ,
442- appAttemptId . getApplicationId () ,
445+ applicationId ,
443446 appAttemptId );
444447 return resync ;
445448 }
@@ -481,11 +484,22 @@ public AllocateResponse allocate(AllocateRequest request)
481484 List <String > blacklistRemovals =
482485 (blacklistRequest != null ) ?
483486 blacklistRequest .getBlacklistRemovals () : Collections .EMPTY_LIST ;
484-
487+ RMApp app =
488+ this .rmContext .getRMApps ().get (applicationId );
489+
490+ // set label expression for Resource Requests
491+ ApplicationSubmissionContext asc = app .getApplicationSubmissionContext ();
492+ for (ResourceRequest req : ask ) {
493+ if (null == req .getNodeLabelExpression ()) {
494+ req .setNodeLabelExpression (asc .getNodeLabelExpression ());
495+ }
496+ }
497+
485498 // sanity check
486499 try {
487500 RMServerUtils .validateResourceRequests (ask ,
488- rScheduler .getMaximumResourceCapability ());
501+ rScheduler .getMaximumResourceCapability (), app .getQueue (),
502+ rScheduler );
489503 } catch (InvalidResourceRequestException e ) {
490504 LOG .warn ("Invalid resource ask by application " + appAttemptId , e );
491505 throw e ;
@@ -498,8 +512,6 @@ public AllocateResponse allocate(AllocateRequest request)
498512 throw e ;
499513 }
500514
501- RMApp app =
502- this .rmContext .getRMApps ().get (appAttemptId .getApplicationId ());
503515 // In the case of work-preserving AM restart, it's possible for the
504516 // AM to release containers from the earlier attempt.
505517 if (!app .getApplicationSubmissionContext ()
@@ -582,7 +594,7 @@ public AllocateResponse allocate(AllocateRequest request)
582594 .toString (), amrmToken .getPassword (), amrmToken .getService ()
583595 .toString ()));
584596 LOG .info ("The AMRMToken has been rolled-over. Send new AMRMToken back"
585- + " to application: " + appAttemptId . getApplicationId () );
597+ + " to application: " + applicationId );
586598 }
587599
588600 /*
0 commit comments