goiri commented on code in PR #4618:
URL: https://github.com/apache/hadoop/pull/4618#discussion_r929101762
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java:
##########
@@ -280,47 +281,47 @@ private SubClusterId getRandomActiveSubCluster(
public GetNewApplicationResponse getNewApplication(
GetNewApplicationRequest request) throws YarnException, IOException {
- long startTime = clock.getTime();
+ if (request == null) {
+ routerMetrics.incrAppsFailedCreated();
+ String errMsg = "Missing getNewApplication request.";
+ RouterAuditLogger.logFailure(user.getShortUserName(), GET_NEW_APP,
UNKNOWN,
+ TARGET_CLIENT_RM_SERVICE, errMsg);
+ RouterServerUtil.logAndThrowException(errMsg, null);
+ }
+ long startTime = clock.getTime();
Map<SubClusterId, SubClusterInfo> subClustersActive =
federationFacade.getSubClusters(true);
+ GetNewApplicationResponse response = null;
Review Comment:
Why not leave the initialization where it was?
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java:
##########
@@ -227,35 +234,29 @@ protected ApplicationClientProtocol
getClientRMProxyForSubCluster(
ApplicationClientProtocol clientRMProxy = null;
try {
boolean serviceAuthEnabled = getConf().getBoolean(
- CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION, false);
+ CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION, false);
UserGroupInformation realUser = user;
if (serviceAuthEnabled) {
realUser = UserGroupInformation.createProxyUser(
- user.getShortUserName(), UserGroupInformation.getLoginUser());
+ user.getShortUserName(), UserGroupInformation.getLoginUser());
}
clientRMProxy = FederationProxyProviderUtil.createRMProxy(getConf(),
ApplicationClientProtocol.class, subClusterId, realUser);
} catch (Exception e) {
RouterServerUtil.logAndThrowException(
- "Unable to create the interface to reach the SubCluster "
- + subClusterId,
- e);
+ "Unable to create the interface to reach the SubCluster " +
subClusterId, e);
}
-
clientRMProxies.put(subClusterId, clientRMProxy);
return clientRMProxy;
}
private SubClusterId getRandomActiveSubCluster(
- Map<SubClusterId, SubClusterInfo> activeSubclusters)
- throws YarnException {
-
- if (activeSubclusters == null || activeSubclusters.size() < 1) {
+ Map<SubClusterId, SubClusterInfo> activeSubClusters) throws
YarnException {
+ if (activeSubClusters.isEmpty()) {
Review Comment:
Shouldn't we check for null?
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/clientrm/TestFederationClientInterceptor.java:
##########
@@ -293,17 +288,15 @@ public void testSubmitApplicationEmptyRequest()
interceptor.submitApplication(null);
Assert.fail();
Review Comment:
LambdaTestUtils#intercep
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java:
##########
@@ -489,13 +488,12 @@ public SubmitApplicationResponse submitApplication(
}
routerMetrics.incrAppsFailedSubmitted();
- String errMsg = "Application "
- + request.getApplicationSubmissionContext().getApplicationName()
- + " with appId " + applicationId + " failed to be submitted.";
- RouterAuditLogger.logFailure(user.getShortUserName(),
- RouterAuditLogger.AuditConstants.SUBMIT_NEW_APP, "UNKNOWN",
- "RouterClientRMService", errMsg, applicationId);
- throw new YarnException(errMsg);
+ String msg = String.format("Application %s with appId %s failed to be
submitted.",
+ request.getApplicationSubmissionContext().getApplicationName(),
applicationId);
+ RouterAuditLogger.logFailure(user.getShortUserName(), SUBMIT_NEW_APP,
UNKNOWN,
+ TARGET_CLIENT_RM_SERVICE, msg, applicationId);
+ RouterServerUtil.logAndThrowException(msg, null);
+ return response;
Review Comment:
This pattern is very weird.
There is no way to let know that we always throw the exception?
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java:
##########
@@ -280,47 +274,50 @@ private SubClusterId getRandomActiveSubCluster(
public GetNewApplicationResponse getNewApplication(
GetNewApplicationRequest request) throws YarnException, IOException {
- long startTime = clock.getTime();
+ if(request == null) {
+ routerMetrics.incrAppsFailedCreated();
+ String errMsg = "Missing getNewApplication request.";
+ RouterAuditLogger.logFailure(user.getShortUserName(),
+ RouterAuditLogger.AuditConstants.GET_NEW_APP, "UNKNOWN",
+ "RouterClientRMService", errMsg);
+ RouterServerUtil.logAndThrowException(errMsg, null);
+ }
+ long startTime = clock.getTime();
Map<SubClusterId, SubClusterInfo> subClustersActive =
federationFacade.getSubClusters(true);
+ GetNewApplicationResponse response = null;
+
for (int i = 0; i < numSubmitRetries; ++i) {
SubClusterId subClusterId = getRandomActiveSubCluster(subClustersActive);
- LOG.debug(
- "getNewApplication try #{} on SubCluster {}", i, subClusterId);
- ApplicationClientProtocol clientRMProxy =
- getClientRMProxyForSubCluster(subClusterId);
- GetNewApplicationResponse response = null;
+ LOG.info("getNewApplication try #{} on SubCluster {}", i, subClusterId);
+ ApplicationClientProtocol clientRMProxy =
getClientRMProxyForSubCluster(subClusterId);
+ response = null;
try {
response = clientRMProxy.getNewApplication(request);
} catch (Exception e) {
- LOG.warn("Unable to create a new ApplicationId in SubCluster "
- + subClusterId.getId(), e);
+ LOG.warn("Unable to create a new ApplicationId in SubCluster {}.",
subClusterId.getId(), e);
+ subClustersActive.remove(subClusterId);
}
if (response != null) {
-
long stopTime = clock.getTime();
routerMetrics.succeededAppsCreated(stopTime - startTime);
RouterAuditLogger.logSuccess(user.getShortUserName(),
RouterAuditLogger.AuditConstants.GET_NEW_APP,
"RouterClientRMService", response.getApplicationId());
return response;
- } else {
- // Empty response from the ResourceManager.
- // Blacklist this subcluster for this request.
- subClustersActive.remove(subClusterId);
Review Comment:
Isn't it safe to also remove if null?
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java:
##########
@@ -280,47 +281,47 @@ private SubClusterId getRandomActiveSubCluster(
public GetNewApplicationResponse getNewApplication(
GetNewApplicationRequest request) throws YarnException, IOException {
- long startTime = clock.getTime();
+ if (request == null) {
+ routerMetrics.incrAppsFailedCreated();
+ String errMsg = "Missing getNewApplication request.";
+ RouterAuditLogger.logFailure(user.getShortUserName(), GET_NEW_APP,
UNKNOWN,
+ TARGET_CLIENT_RM_SERVICE, errMsg);
+ RouterServerUtil.logAndThrowException(errMsg, null);
+ }
+ long startTime = clock.getTime();
Map<SubClusterId, SubClusterInfo> subClustersActive =
federationFacade.getSubClusters(true);
+ GetNewApplicationResponse response = null;
+
for (int i = 0; i < numSubmitRetries; ++i) {
SubClusterId subClusterId = getRandomActiveSubCluster(subClustersActive);
- LOG.debug(
- "getNewApplication try #{} on SubCluster {}", i, subClusterId);
- ApplicationClientProtocol clientRMProxy =
- getClientRMProxyForSubCluster(subClusterId);
- GetNewApplicationResponse response = null;
+ LOG.info("getNewApplication try #{} on SubCluster {}.", i, subClusterId);
+ ApplicationClientProtocol clientRMProxy =
getClientRMProxyForSubCluster(subClusterId);
+ response = null;
try {
response = clientRMProxy.getNewApplication(request);
} catch (Exception e) {
- LOG.warn("Unable to create a new ApplicationId in SubCluster "
- + subClusterId.getId(), e);
+ LOG.warn("Unable to create a new ApplicationId in SubCluster {}.",
subClusterId.getId(), e);
+ subClustersActive.remove(subClusterId);
}
if (response != null) {
-
long stopTime = clock.getTime();
routerMetrics.succeededAppsCreated(stopTime - startTime);
- RouterAuditLogger.logSuccess(user.getShortUserName(),
- RouterAuditLogger.AuditConstants.GET_NEW_APP,
- "RouterClientRMService", response.getApplicationId());
+ RouterAuditLogger.logSuccess(user.getShortUserName(), GET_NEW_APP,
+ TARGET_CLIENT_RM_SERVICE, response.getApplicationId());
return response;
- } else {
- // Empty response from the ResourceManager.
- // Blacklist this subcluster for this request.
- subClustersActive.remove(subClusterId);
}
-
}
routerMetrics.incrAppsFailedCreated();
- String errMsg = "Fail to create a new application.";
- RouterAuditLogger.logFailure(user.getShortUserName(),
- RouterAuditLogger.AuditConstants.GET_NEW_APP, "UNKNOWN",
- "RouterClientRMService", errMsg);
- throw new YarnException(errMsg);
+ String errMsg = "Failed to create a new application.";
+ RouterAuditLogger.logFailure(user.getShortUserName(), GET_NEW_APP, UNKNOWN,
+ TARGET_CLIENT_RM_SERVICE, errMsg);
+ RouterServerUtil.logAndThrowException(errMsg, null);
+ return response;
Review Comment:
return? Aren't we throwing the exception?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]