Skip to content

Commit c94e669

Browse files
author
slfan1989
committed
YARN-11509. Fix CheckStyle.
1 parent f348585 commit c94e669

File tree

3 files changed

+79
-5
lines changed

3 files changed

+79
-5
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/FederationInterceptor.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,9 +1281,11 @@ private List<SubClusterId> registerAndAllocateWithNewSubClusters(
12811281

12821282
// LaunchUAM And RegisterApplicationMaster
12831283
try {
1284-
TokenAndRegisterResponse result = ((FederationActionRetry<TokenAndRegisterResponse>)
1285-
(retryCount) -> launchUAMAndRegisterApplicationMaster(config, subClusterId, applicationId)).
1286-
runWithRetries(3, 100);
1284+
1285+
TokenAndRegisterResponse result =
1286+
((FederationActionRetry<TokenAndRegisterResponse>) (retryCount) ->
1287+
launchUAMAndRegisterApplicationMaster(config, subClusterId, applicationId)).
1288+
runWithRetries(3, 1);
12871289

12881290
token = result.getToken();
12891291
uamResponse = result.getResponse();
@@ -1340,8 +1342,8 @@ protected TokenAndRegisterResponse launchUAMAndRegisterApplicationMaster(
13401342
String queue = amRegistrationResponse.getQueue();
13411343

13421344
// For appNameSuffix, use subClusterId of the home sub-cluster
1343-
Token<AMRMTokenIdentifier> token = uamPool.launchUAM(subClusterId, config, applicationId, queue, submitter,
1344-
homeRM, true, subClusterId, originalSubmissionContext);
1345+
Token<AMRMTokenIdentifier> token = uamPool.launchUAM(subClusterId, config, applicationId,
1346+
queue, submitter, homeRM, true, subClusterId, originalSubmissionContext);
13451347

13461348
// Set the relationship between SubCluster and AMRMClientRelayer.
13471349
secondaryRelayers.put(subClusterId, uamPool.getAMRMClientRelayer(subClusterId));

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/TestFederationInterceptor.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,4 +1432,52 @@ private void finishApplication() throws IOException, YarnException {
14321432
Assert.assertNotNull(finishResponse);
14331433
Assert.assertTrue(finishResponse.getIsUnregistered());
14341434
}
1435+
1436+
@Test
1437+
public void testLaunchUAMAndRegisterApplicationMasterRetry() throws Exception {
1438+
1439+
UserGroupInformation ugi = interceptor.getUGIWithToken(interceptor.getAttemptId());
1440+
interceptor.setRetryCount(2);
1441+
1442+
ugi.doAs((PrivilegedExceptionAction<Object>) () -> {
1443+
// Register the application
1444+
RegisterApplicationMasterRequest registerReq = Records.newRecord(RegisterApplicationMasterRequest.class);
1445+
registerReq.setHost(Integer.toString(testAppId));
1446+
registerReq.setRpcPort(0);
1447+
registerReq.setTrackingUrl("");
1448+
1449+
RegisterApplicationMasterResponse registerResponse =
1450+
interceptor.registerApplicationMaster(registerReq);
1451+
Assert.assertNotNull(registerResponse);
1452+
lastResponseId = 0;
1453+
1454+
Assert.assertEquals(0, interceptor.getUnmanagedAMPoolSize());
1455+
1456+
// Allocate the first batch of containers, with sc1 active
1457+
registerSubCluster(SubClusterId.newInstance("SC-1"));
1458+
1459+
int numberOfContainers = 3;
1460+
List<Container> containers = getContainersAndAssert(numberOfContainers, numberOfContainers);
1461+
Assert.assertEquals(1, interceptor.getUnmanagedAMPoolSize());
1462+
1463+
// Release all containers
1464+
releaseContainersAndAssert(containers);
1465+
1466+
// Finish the application
1467+
FinishApplicationMasterRequest finishReq =
1468+
Records.newRecord(FinishApplicationMasterRequest.class);
1469+
finishReq.setDiagnostics("");
1470+
finishReq.setTrackingUrl("");
1471+
finishReq.setFinalApplicationStatus(FinalApplicationStatus.SUCCEEDED);
1472+
1473+
FinishApplicationMasterResponse finishResponse =
1474+
interceptor.finishApplicationMaster(finishReq);
1475+
Assert.assertNotNull(finishResponse);
1476+
Assert.assertEquals(true, finishResponse.getIsUnregistered());
1477+
1478+
return null;
1479+
});
1480+
1481+
Assert.assertEquals(0, interceptor.getRetryCount());
1482+
}
14351483
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/amrmproxy/TestableFederationInterceptor.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@
2020

2121
import java.io.IOException;
2222
import java.security.PrivilegedExceptionAction;
23+
import java.util.List;
24+
import java.util.Map;
2325
import java.util.concurrent.ConcurrentHashMap;
2426
import java.util.concurrent.ExecutorService;
2527
import java.util.concurrent.atomic.AtomicInteger;
2628

2729
import org.apache.hadoop.conf.Configuration;
2830
import org.apache.hadoop.security.UserGroupInformation;
2931
import org.apache.hadoop.security.token.Token;
32+
import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest;
33+
import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse;
3034
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
3135
import org.apache.hadoop.yarn.api.records.ApplicationId;
3236
import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
@@ -36,6 +40,7 @@
3640
import org.apache.hadoop.yarn.server.AMHeartbeatRequestHandler;
3741
import org.apache.hadoop.yarn.server.AMRMClientRelayer;
3842
import org.apache.hadoop.yarn.server.MockResourceManagerFacade;
43+
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
3944
import org.apache.hadoop.yarn.server.uam.UnmanagedAMPoolManager;
4045
import org.apache.hadoop.yarn.server.uam.UnmanagedApplicationManager;
4146
import org.slf4j.Logger;
@@ -55,6 +60,7 @@ public class TestableFederationInterceptor extends FederationInterceptor {
5560
private MockResourceManagerFacade mockRm;
5661

5762
private boolean isClientRPC = false;
63+
private int retryCount = 0;
5864

5965
public TestableFederationInterceptor() {
6066
}
@@ -258,6 +264,24 @@ protected <T> T createRMProxy(Class<T> protocol, Configuration config,
258264
}
259265
}
260266

267+
@Override
268+
protected TokenAndRegisterResponse launchUAMAndRegisterApplicationMaster(YarnConfiguration config,
269+
String subClusterId, ApplicationId applicationId) throws IOException, YarnException {
270+
if (retryCount > 0) {
271+
retryCount--;
272+
throw new YarnException("launchUAMAndRegisterApplicationMaster will retry");
273+
}
274+
return super.launchUAMAndRegisterApplicationMaster(config, subClusterId, applicationId);
275+
}
276+
277+
public void setRetryCount(int retryCount) {
278+
this.retryCount = retryCount;
279+
}
280+
281+
public int getRetryCount() {
282+
return retryCount;
283+
}
284+
261285
/**
262286
* Wrap the handler thread, so it calls from the same user.
263287
*/

0 commit comments

Comments
 (0)