Skip to content

Commit 4fcace9

Browse files
author
slfan1989
committed
YARN-11342. Fix CheckStyle.
1 parent 59a41ac commit 4fcace9

File tree

6 files changed

+75
-16
lines changed

6 files changed

+75
-16
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4117,6 +4117,14 @@ public static boolean isAclEnabled(Configuration conf) {
41174117
ROUTER_PREFIX + "submit.retry";
41184118
public static final int DEFAULT_ROUTER_CLIENTRM_SUBMIT_RETRY = 3;
41194119

4120+
/**
4121+
* GetNewApplication and SubmitApplication request retry interval time.
4122+
*/
4123+
public static final String ROUTER_CLIENTRM_SUBMIT_INTERVAL_TIME =
4124+
ROUTER_PREFIX + "submit.interval.time";
4125+
public static final long DEFAULT_CLIENTRM_SUBMIT_INTERVAL_TIME =
4126+
TimeUnit.MILLISECONDS.toMillis(10);
4127+
41204128
/**
41214129
* The interceptor class used in FederationClientInterceptor should return
41224130
* partial ApplicationReports.

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5047,4 +5047,13 @@
50475047
</description>
50485048
</property>
50495049

5050+
<property>
5051+
<name>yarn.router.submit.interval.time</name>
5052+
<value>10</value>
5053+
<description>
5054+
The interval Time between calling different subCluster requests.
5055+
Default is 10ms.
5056+
</description>
5057+
</property>
5058+
50505059
</configuration>

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,24 @@ public static void logFailure(String user, String operation, String perm,
196196
}
197197
}
198198

199+
/**
200+
* Create a readable and parsable audit log string for a failed event.
201+
*
202+
* @param user User who made the service request.
203+
* @param operation Operation requested by the user.
204+
* @param perm Target permissions.
205+
* @param target The target on which the operation is being performed.
206+
* @param description Some additional information as to why the operation failed.
207+
* @param subClusterId SubCluster Id in which operation was performed.
208+
*/
209+
public static void logFailure(String user, String operation, String perm,
210+
String target, String description, SubClusterId subClusterId) {
211+
if (LOG.isInfoEnabled()) {
212+
LOG.info(createFailureLog(user, operation, perm, target, description, null,
213+
subClusterId));
214+
}
215+
}
216+
199217
/**
200218
* A helper api for creating an audit log for a failure event.
201219
*/

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@
3737

3838
import java.lang.reflect.InvocationTargetException;
3939
import java.lang.reflect.Method;
40-
import java.util.*;
40+
import java.util.ArrayList;
41+
import java.util.Collection;
42+
import java.util.List;
43+
import java.util.Map;
44+
import java.util.Random;
4145
import java.io.IOException;
4246

4347
/**
@@ -458,21 +462,33 @@ public static void validateContainerId(String containerId)
458462
*
459463
* @param activeSubClusters List of active subClusters.
460464
* @param blackList blacklist.
461-
* @return Active SubClusterId
465+
* @return Active SubClusterId.
466+
* @throws YarnException When there is no Active SubCluster,
467+
* an exception will be thrown (No active SubCluster available to submit the request.)
462468
*/
463469
public static SubClusterId getRandomActiveSubCluster(
464470
Map<SubClusterId, SubClusterInfo> activeSubClusters, List<SubClusterId> blackList)
465471
throws YarnException {
472+
473+
// Check if activeSubClusters is empty, if it is empty, we need to throw an exception
466474
if (MapUtils.isEmpty(activeSubClusters)) {
467475
logAndThrowException(FederationPolicyUtils.NO_ACTIVE_SUBCLUSTER_AVAILABLE, null);
468476
}
469-
List<SubClusterId> list = new ArrayList<>(activeSubClusters.keySet());
477+
478+
// Change activeSubClusters to List
479+
List<SubClusterId> subClusterIds = new ArrayList<>(activeSubClusters.keySet());
480+
481+
// If the blacklist is not empty, we need to remove all the subClusters in the blacklist
470482
if (CollectionUtils.isNotEmpty(blackList)) {
471-
list.removeAll(blackList);
483+
subClusterIds.removeAll(blackList);
472484
}
473-
if (CollectionUtils.isEmpty(list)) {
485+
486+
// Check there are still active subcluster after removing the blacklist
487+
if (CollectionUtils.isEmpty(subClusterIds)) {
474488
logAndThrowException(FederationPolicyUtils.NO_ACTIVE_SUBCLUSTER_AVAILABLE, null);
475489
}
476-
return list.get(rand.nextInt(list.size()));
490+
491+
// Randomly choose a SubCluster
492+
return subClusterIds.get(rand.nextInt(subClusterIds.size()));
477493
}
478494
}

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: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ public class FederationClientInterceptor
178178
private ThreadPoolExecutor executorService;
179179
private final Clock clock = new MonotonicClock();
180180
private boolean returnPartialReport;
181+
private long submitIntervalTime;
181182

182183
@Override
183184
public void init(String userName) {
@@ -209,6 +210,10 @@ public void init(String userName) {
209210
YarnConfiguration.ROUTER_CLIENTRM_SUBMIT_RETRY,
210211
YarnConfiguration.DEFAULT_ROUTER_CLIENTRM_SUBMIT_RETRY);
211212

213+
submitIntervalTime = conf.getTimeDuration(
214+
YarnConfiguration.ROUTER_CLIENTRM_SUBMIT_INTERVAL_TIME,
215+
YarnConfiguration.DEFAULT_CLIENTRM_SUBMIT_INTERVAL_TIME, TimeUnit.MILLISECONDS);
216+
212217
clientRMProxies = new ConcurrentHashMap<>();
213218
routerMetrics = RouterMetrics.getMetrics();
214219

@@ -315,7 +320,7 @@ public GetNewApplicationResponse getNewApplication(
315320
GetNewApplicationResponse response =
316321
((FederationActionRetry<GetNewApplicationResponse>) (retryCount) ->
317322
invokeGetNewApplication(subClustersActive, blacklist, request, retryCount)).
318-
runWithRetries(actualRetryNums, 100);
323+
runWithRetries(actualRetryNums, submitIntervalTime);
319324

320325
if (response != null) {
321326
long stopTime = clock.getTime();
@@ -343,8 +348,8 @@ public GetNewApplicationResponse getNewApplication(
343348
* @param retryCount number of retries.
344349
* @return Get NewApplicationResponse response, If the response is empty, the request fails,
345350
* if the response is not empty, the request is successful.
346-
* @throws YarnException
347-
* @throws IOException
351+
* @throws YarnException yarn exception.
352+
* @throws IOException io error.
348353
*/
349354
private GetNewApplicationResponse invokeGetNewApplication(
350355
Map<SubClusterId, SubClusterInfo> subClustersActive,
@@ -358,10 +363,12 @@ private GetNewApplicationResponse invokeGetNewApplication(
358363
GetNewApplicationResponse response = clientRMProxy.getNewApplication(request);
359364
if (response != null) {
360365
RouterAuditLogger.logSuccess(user.getShortUserName(), GET_NEW_APP,
361-
TARGET_CLIENT_RM_SERVICE, response.getApplicationId());
366+
TARGET_CLIENT_RM_SERVICE, response.getApplicationId(), subClusterId);
362367
return response;
363368
}
364369
} catch (Exception e) {
370+
RouterAuditLogger.logFailure(user.getShortUserName(), GET_NEW_APP, UNKNOWN,
371+
TARGET_CLIENT_RM_SERVICE, e.getMessage(), subClusterId);
365372
LOG.warn("Unable to create a new ApplicationId in SubCluster {}.", subClusterId.getId(), e);
366373
blackList.add(subClusterId);
367374
throw e;
@@ -469,7 +476,7 @@ public SubmitApplicationResponse submitApplication(
469476
SubmitApplicationResponse response =
470477
((FederationActionRetry<SubmitApplicationResponse>) (retryCount) ->
471478
invokeSubmitApplication(blacklist, request, retryCount)).
472-
runWithRetries(actualRetryNums, 100);
479+
runWithRetries(actualRetryNums, submitIntervalTime);
473480

474481
if (response != null) {
475482
long stopTime = clock.getTime();

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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.apache.hadoop.yarn.api.records.Priority;
3838
import org.apache.hadoop.yarn.conf.YarnConfiguration;
3939
import org.apache.hadoop.yarn.exceptions.YarnException;
40-
import org.apache.hadoop.yarn.server.federation.policies.FederationPolicyUtils;
4140
import org.apache.hadoop.yarn.server.federation.policies.manager.UniformBroadcastPolicyManager;
4241
import org.apache.hadoop.yarn.server.federation.store.impl.MemoryFederationStateStore;
4342
import org.apache.hadoop.yarn.server.federation.store.records.ApplicationHomeSubCluster;
@@ -53,6 +52,8 @@
5352
import org.slf4j.Logger;
5453
import org.slf4j.LoggerFactory;
5554

55+
import static org.apache.hadoop.yarn.server.federation.policies.FederationPolicyUtils.NO_ACTIVE_SUBCLUSTER_AVAILABLE;
56+
5657
/**
5758
* Extends the {@code BaseRouterClientRMTest} and overrides methods in order to
5859
* use the {@code RouterClientRMService} pipeline test cases for testing the
@@ -169,7 +170,7 @@ public void testGetNewApplicationOneBadSC()
169170
setupCluster(Arrays.asList(bad2));
170171

171172
GetNewApplicationRequest request = GetNewApplicationRequest.newInstance();
172-
LambdaTestUtils.intercept(YarnException.class, FederationPolicyUtils.NO_ACTIVE_SUBCLUSTER_AVAILABLE,
173+
LambdaTestUtils.intercept(YarnException.class, NO_ACTIVE_SUBCLUSTER_AVAILABLE,
173174
() -> interceptor.getNewApplication(request));
174175
}
175176

@@ -184,7 +185,7 @@ public void testGetNewApplicationTwoBadSCs()
184185
setupCluster(Arrays.asList(bad1, bad2));
185186

186187
GetNewApplicationRequest request = GetNewApplicationRequest.newInstance();
187-
LambdaTestUtils.intercept(YarnException.class, FederationPolicyUtils.NO_ACTIVE_SUBCLUSTER_AVAILABLE,
188+
LambdaTestUtils.intercept(YarnException.class, NO_ACTIVE_SUBCLUSTER_AVAILABLE,
188189
() -> interceptor.getNewApplication(request));
189190
}
190191

@@ -221,7 +222,7 @@ public void testSubmitApplicationOneBadSC()
221222
ApplicationId.newInstance(System.currentTimeMillis(), 1);
222223

223224
final SubmitApplicationRequest request = mockSubmitApplicationRequest(appId);
224-
LambdaTestUtils.intercept(YarnException.class, FederationPolicyUtils.NO_ACTIVE_SUBCLUSTER_AVAILABLE,
225+
LambdaTestUtils.intercept(YarnException.class, NO_ACTIVE_SUBCLUSTER_AVAILABLE,
225226
() -> interceptor.submitApplication(request));
226227
}
227228

@@ -253,7 +254,7 @@ public void testSubmitApplicationTwoBadSCs()
253254
ApplicationId.newInstance(System.currentTimeMillis(), 1);
254255

255256
final SubmitApplicationRequest request = mockSubmitApplicationRequest(appId);
256-
LambdaTestUtils.intercept(YarnException.class, FederationPolicyUtils.NO_ACTIVE_SUBCLUSTER_AVAILABLE,
257+
LambdaTestUtils.intercept(YarnException.class, NO_ACTIVE_SUBCLUSTER_AVAILABLE,
257258
() -> interceptor.submitApplication(request));
258259
}
259260

0 commit comments

Comments
 (0)