Skip to content

Commit d22b8ad

Browse files
author
slfan1989
committed
YARN-11342. Fix CheckStyle.
1 parent d7c5819 commit d22b8ad

File tree

2 files changed

+50
-71
lines changed

2 files changed

+50
-71
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public SubmitApplicationResponse submitApplication(
425425
// but if the number of Active SubClusters is less than this number at this time,
426426
// we should provide a high number of retry according to the number of Active SubClusters.
427427
int activeSubClustersCount = getActiveSubClustersCount();
428-
int actualRetryNums = Math.min(activeSubClustersCount, numSubmitRetries);
428+
int actualRetryNums = Math.min(activeSubClustersCount, numSubmitRetries) + 1;
429429

430430
// Try calling the SubmitApplication method
431431
SubmitApplicationResponse response =
@@ -476,7 +476,7 @@ public SubmitApplicationResponse submitApplication(
476476
*/
477477
private SubmitApplicationResponse invokeSubmitApplication(
478478
List<SubClusterId> blackList, SubmitApplicationRequest request, int retryCount)
479-
throws YarnException {
479+
throws YarnException, IOException {
480480

481481
// The request is not checked here,
482482
// because the request has been checked before the method is called.
@@ -520,12 +520,14 @@ private SubmitApplicationResponse invokeSubmitApplication(
520520
TARGET_CLIENT_RM_SERVICE, e.getMessage(), applicationId, subClusterId);
521521
LOG.warn("Unable to submitApplication appId {} try #{} on SubCluster {} error = {}.",
522522
applicationId, subClusterId, e);
523-
blackList.add(subClusterId);
523+
if (subClusterId != null) {
524+
blackList.add(subClusterId);
525+
}
526+
throw e;
524527
}
525528

526529
// If SubmitApplicationResponse is empty, the request fails.
527-
String msg = String.format("Application %s failed to be submitted SubCluster %s.",
528-
applicationId, subClusterId);
530+
String msg = String.format("Application %s failed to be submitted.", applicationId);
529531
throw new YarnException(msg);
530532
}
531533

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestFederationClientInterceptorRetry.java

Lines changed: 43 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
import java.util.Arrays;
2626
import java.util.List;
2727

28+
import org.apache.hadoop.test.LambdaTestUtils;
2829
import org.apache.hadoop.yarn.MockApps;
2930
import org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationRequest;
3031
import org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse;
3132
import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationRequest;
33+
import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationResponse;
3234
import org.apache.hadoop.yarn.api.records.ApplicationId;
3335
import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
3436
import org.apache.hadoop.yarn.api.records.ContainerLaunchContext;
@@ -38,7 +40,9 @@
3840
import org.apache.hadoop.yarn.server.federation.policies.FederationPolicyUtils;
3941
import org.apache.hadoop.yarn.server.federation.policies.manager.UniformBroadcastPolicyManager;
4042
import org.apache.hadoop.yarn.server.federation.store.impl.MemoryFederationStateStore;
43+
import org.apache.hadoop.yarn.server.federation.store.records.ApplicationHomeSubCluster;
4144
import org.apache.hadoop.yarn.server.federation.store.records.GetApplicationHomeSubClusterRequest;
45+
import org.apache.hadoop.yarn.server.federation.store.records.GetApplicationHomeSubClusterResponse;
4246
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
4347
import org.apache.hadoop.yarn.server.federation.utils.FederationStateStoreFacade;
4448
import org.apache.hadoop.yarn.server.federation.utils.FederationStateStoreTestUtil;
@@ -160,19 +164,13 @@ protected YarnConfiguration createConfiguration() {
160164
*/
161165
@Test
162166
public void testGetNewApplicationOneBadSC()
163-
throws YarnException, IOException, InterruptedException {
164-
165-
System.out.println("Test getNewApplication with one bad SubCluster");
167+
throws Exception {
168+
LOG.info("Test getNewApplication with one bad SubCluster");
166169
setupCluster(Arrays.asList(bad2));
167170

168-
try {
169-
interceptor.getNewApplication(GetNewApplicationRequest.newInstance());
170-
Assert.fail();
171-
} catch (Exception e) {
172-
System.out.println(e.toString());
173-
Assert.assertTrue(e.getMessage()
174-
.equals(FederationPolicyUtils.NO_ACTIVE_SUBCLUSTER_AVAILABLE));
175-
}
171+
GetNewApplicationRequest request = GetNewApplicationRequest.newInstance();
172+
LambdaTestUtils.intercept(YarnException.class, FederationPolicyUtils.NO_ACTIVE_SUBCLUSTER_AVAILABLE,
173+
() -> interceptor.getNewApplication(request));
176174
}
177175

178176
/**
@@ -181,18 +179,13 @@ public void testGetNewApplicationOneBadSC()
181179
*/
182180
@Test
183181
public void testGetNewApplicationTwoBadSCs()
184-
throws YarnException, IOException, InterruptedException {
185-
System.out.println("Test getNewApplication with two bad SubClusters");
182+
throws Exception {
183+
LOG.info("Test getNewApplication with two bad SubClusters");
186184
setupCluster(Arrays.asList(bad1, bad2));
187185

188-
try {
189-
interceptor.getNewApplication(GetNewApplicationRequest.newInstance());
190-
Assert.fail();
191-
} catch (Exception e) {
192-
System.out.println(e.toString());
193-
Assert.assertTrue(e.getMessage()
194-
.equals(FederationPolicyUtils.NO_ACTIVE_SUBCLUSTER_AVAILABLE));
195-
}
186+
GetNewApplicationRequest request = GetNewApplicationRequest.newInstance();
187+
LambdaTestUtils.intercept(YarnException.class, FederationPolicyUtils.NO_ACTIVE_SUBCLUSTER_AVAILABLE,
188+
() -> interceptor.getNewApplication(request));
196189
}
197190

198191
/**
@@ -201,16 +194,14 @@ public void testGetNewApplicationTwoBadSCs()
201194
*/
202195
@Test
203196
public void testGetNewApplicationOneBadOneGood()
204-
throws YarnException, IOException, InterruptedException {
205-
System.out.println("Test getNewApplication with one bad, one good SC");
197+
throws YarnException, IOException {
198+
199+
LOG.info("Test getNewApplication with one bad, one good SC");
206200
setupCluster(Arrays.asList(good, bad2));
207-
GetNewApplicationResponse response = null;
208-
try {
209-
response =
210-
interceptor.getNewApplication(GetNewApplicationRequest.newInstance());
211-
} catch (Exception e) {
212-
Assert.fail();
213-
}
201+
GetNewApplicationRequest request = GetNewApplicationRequest.newInstance();
202+
GetNewApplicationResponse response = interceptor.getNewApplication(request);
203+
204+
Assert.assertNotNull(response);
214205
Assert.assertEquals(ResourceManager.getClusterTimeStamp(),
215206
response.getApplicationId().getClusterTimestamp());
216207
}
@@ -221,24 +212,17 @@ public void testGetNewApplicationOneBadOneGood()
221212
*/
222213
@Test
223214
public void testSubmitApplicationOneBadSC()
224-
throws YarnException, IOException, InterruptedException {
215+
throws Exception {
225216

226-
System.out.println("Test submitApplication with one bad SubCluster");
217+
LOG.info("Test submitApplication with one bad SubCluster");
227218
setupCluster(Arrays.asList(bad2));
228219

229220
final ApplicationId appId =
230221
ApplicationId.newInstance(System.currentTimeMillis(), 1);
231222

232-
final SubmitApplicationRequest request = mockSubmitApplicationRequest(
233-
appId);
234-
try {
235-
interceptor.submitApplication(request);
236-
Assert.fail();
237-
} catch (Exception e) {
238-
System.out.println(e);
239-
Assert.assertTrue(e.getMessage()
240-
.equals(FederationPolicyUtils.NO_ACTIVE_SUBCLUSTER_AVAILABLE));
241-
}
223+
final SubmitApplicationRequest request = mockSubmitApplicationRequest(appId);
224+
LambdaTestUtils.intercept(YarnException.class, FederationPolicyUtils.NO_ACTIVE_SUBCLUSTER_AVAILABLE,
225+
() -> interceptor.submitApplication(request));
242226
}
243227

244228
private SubmitApplicationRequest mockSubmitApplicationRequest(
@@ -261,23 +245,16 @@ private SubmitApplicationRequest mockSubmitApplicationRequest(
261245
*/
262246
@Test
263247
public void testSubmitApplicationTwoBadSCs()
264-
throws YarnException, IOException, InterruptedException {
248+
throws Exception {
265249
System.out.println("Test submitApplication with two bad SubClusters");
266250
setupCluster(Arrays.asList(bad1, bad2));
267251

268252
final ApplicationId appId =
269253
ApplicationId.newInstance(System.currentTimeMillis(), 1);
270254

271-
final SubmitApplicationRequest request = mockSubmitApplicationRequest(
272-
appId);
273-
try {
274-
interceptor.submitApplication(request);
275-
Assert.fail();
276-
} catch (Exception e) {
277-
System.out.println(e.toString());
278-
Assert.assertTrue(e.getMessage()
279-
.equals(FederationPolicyUtils.NO_ACTIVE_SUBCLUSTER_AVAILABLE));
280-
}
255+
final SubmitApplicationRequest request = mockSubmitApplicationRequest(appId);
256+
LambdaTestUtils.intercept(YarnException.class, FederationPolicyUtils.NO_ACTIVE_SUBCLUSTER_AVAILABLE,
257+
() -> interceptor.submitApplication(request));
281258
}
282259

283260
/**
@@ -293,18 +270,18 @@ public void testSubmitApplicationOneBadOneGood()
293270
final ApplicationId appId =
294271
ApplicationId.newInstance(System.currentTimeMillis(), 1);
295272

296-
final SubmitApplicationRequest request = mockSubmitApplicationRequest(
297-
appId);
298-
try {
299-
interceptor.submitApplication(request);
300-
} catch (Exception e) {
301-
Assert.fail();
302-
}
303-
Assert.assertEquals(good,
304-
stateStore
305-
.getApplicationHomeSubCluster(
306-
GetApplicationHomeSubClusterRequest.newInstance(appId))
307-
.getApplicationHomeSubCluster().getHomeSubCluster());
308-
}
273+
final SubmitApplicationRequest request = mockSubmitApplicationRequest(appId);
274+
SubmitApplicationResponse response = interceptor.submitApplication(request);
275+
Assert.assertNotNull(response);
276+
277+
GetApplicationHomeSubClusterRequest getAppRequest =
278+
GetApplicationHomeSubClusterRequest.newInstance(appId);
279+
GetApplicationHomeSubClusterResponse getAppResponse =
280+
stateStore.getApplicationHomeSubCluster(getAppRequest);
281+
Assert.assertNotNull(getAppResponse);
309282

283+
ApplicationHomeSubCluster responseHomeSubCluster =
284+
getAppResponse.getApplicationHomeSubCluster();
285+
Assert.assertEquals(good,responseHomeSubCluster);
286+
}
310287
}

0 commit comments

Comments
 (0)