4545
4646import org .apache .commons .lang3 .NotImplementedException ;
4747import org .apache .commons .lang3 .StringUtils ;
48- import org .apache .commons .lang3 .tuple .Pair ;
4948import org .apache .hadoop .conf .Configuration ;
5049import org .apache .hadoop .io .Text ;
5150import org .apache .hadoop .security .UserGroupInformation ;
123122import org .apache .hadoop .yarn .server .router .security .RouterDelegationTokenSecretManager ;
124123import org .apache .hadoop .yarn .server .router .webapp .cache .RouterAppInfoCacheKey ;
125124import org .apache .hadoop .yarn .server .router .webapp .dao .FederationRMQueueAclInfo ;
125+ import org .apache .hadoop .yarn .server .router .webapp .dao .SubClusterResult ;
126126import org .apache .hadoop .yarn .server .router .webapp .dao .FederationSchedulerTypeInfo ;
127127import org .apache .hadoop .yarn .server .utils .BuilderUtils ;
128128import org .apache .hadoop .yarn .server .webapp .dao .AppAttemptInfo ;
@@ -2532,7 +2532,7 @@ private <R> Map<SubClusterInfo, R> invokeConcurrent(Collection<SubClusterInfo> c
25322532 // If there is a sub-cluster access error,
25332533 // we should choose whether to throw exception information according to user configuration.
25342534 // Send the requests in parallel.
2535- CompletionService <Pair < R , Exception >> compSvc = new ExecutorCompletionService <>(threadpool );
2535+ CompletionService <SubClusterResult < R >> compSvc = new ExecutorCompletionService <>(threadpool );
25362536
25372537 // This part of the code should be able to expose the accessed Exception information.
25382538 // We use Pair to store related information. The left value of the Pair is the response,
@@ -2548,36 +2548,41 @@ private <R> Map<SubClusterInfo, R> invokeConcurrent(Collection<SubClusterInfo> c
25482548 getMethod (request .getMethodName (), request .getTypes ());
25492549 Object retObj = method .invoke (interceptor , request .getParams ());
25502550 R ret = clazz .cast (retObj );
2551- return Pair . of ( ret , null );
2551+ return new SubClusterResult <>( info , ret , null );
25522552 } catch (Exception e ) {
25532553 LOG .error ("SubCluster {} failed to call {} method." ,
25542554 info .getSubClusterId (), request .getMethodName (), e );
2555- return Pair . of ( null , e );
2555+ return new SubClusterResult <>( info , null , e );
25562556 }
25572557 });
25582558 }
25592559
2560- clusterIds .stream ().forEach (clusterId -> {
2560+ for (int i = 0 ; i < clusterIds .size (); i ++) {
2561+ SubClusterInfo subClusterInfo = null ;
25612562 try {
2562- Future <Pair <R , Exception >> future = compSvc .take ();
2563- Pair <R , Exception > pair = future .get ();
2564- R response = pair .getKey ();
2563+ Future <SubClusterResult <R >> future = compSvc .take ();
2564+ SubClusterResult <R > result = future .get ();
2565+ subClusterInfo = result .getSubClusterInfo ();
2566+
2567+ R response = result .getResponse ();
25652568 if (response != null ) {
2566- results .put (clusterId , response );
2569+ results .put (subClusterInfo , response );
25672570 }
2568- Exception exception = pair .getValue ();
2571+
2572+ Exception exception = result .getException ();
2573+
25692574 // If allowPartialResult=false, it means that if an exception occurs in a subCluster,
25702575 // an exception will be thrown directly.
25712576 if (!allowPartialResult && exception != null ) {
25722577 throw exception ;
25732578 }
25742579 } catch (Throwable e ) {
2575- String msg = String . format ( "SubCluster %s failed to %s report." ,
2576- clusterId .getSubClusterId (), request . getMethodName ()) ;
2577- LOG .error (msg , e );
2580+ String subClusterId = subClusterInfo != null ?
2581+ subClusterInfo .getSubClusterId (). getId () : "UNKNOWN" ;
2582+ LOG .error ("SubCluster {} failed to {} report." , subClusterId , request . getMethodName () , e );
25782583 throw new YarnRuntimeException (e .getCause ().getMessage (), e );
25792584 }
2580- });
2585+ }
25812586
25822587 return results ;
25832588 }
@@ -2648,4 +2653,16 @@ public Map<SubClusterId, DefaultRequestInterceptorREST> getInterceptors() {
26482653 public void setAllowPartialResult (boolean allowPartialResult ) {
26492654 this .allowPartialResult = allowPartialResult ;
26502655 }
2656+
2657+ @ VisibleForTesting
2658+ public Map <SubClusterInfo , NodesInfo > invokeConcurrentGetNodeLabel ()
2659+ throws IOException , YarnException {
2660+ Map <SubClusterId , SubClusterInfo > subClustersActive = getActiveSubclusters ();
2661+ Class [] argsClasses = new Class []{String .class };
2662+ Object [] args = new Object []{null };
2663+ ClientMethod remoteMethod = new ClientMethod ("getNodes" , argsClasses , args );
2664+ Map <SubClusterInfo , NodesInfo > nodesMap =
2665+ invokeConcurrent (subClustersActive .values (), remoteMethod , NodesInfo .class );
2666+ return nodesMap ;
2667+ }
26512668}
0 commit comments