Skip to content

Commit 94a01ab

Browse files
committed
YARN-11515. [Federation] Improve DefaultRequestInterceptor#init Code.
1 parent 6042d59 commit 94a01ab

File tree

4 files changed

+34
-52
lines changed

4 files changed

+34
-52
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
9999

100100
import org.apache.hadoop.classification.VisibleForTesting;
101+
import org.slf4j.Logger;
102+
import org.slf4j.LoggerFactory;
101103

102104
/**
103105
* Extends the {@code AbstractRequestInterceptorClient} class and provides an
@@ -107,25 +109,26 @@
107109
*/
108110
public class DefaultClientRequestInterceptor
109111
extends AbstractClientRequestInterceptor {
112+
private static final Logger LOG =
113+
LoggerFactory.getLogger(DefaultClientRequestInterceptor.class);
110114
private ApplicationClientProtocol clientRMProxy;
111115

112116
@Override
113117
public void init(String userName) {
114118
super.init(userName);
115-
116-
final Configuration conf = this.getConf();
117119
try {
118-
clientRMProxy =
119-
user.doAs(new PrivilegedExceptionAction<ApplicationClientProtocol>() {
120-
@Override
121-
public ApplicationClientProtocol run() throws Exception {
122-
return ClientRMProxy.createRMProxy(conf,
123-
ApplicationClientProtocol.class);
124-
}
125-
});
120+
final Configuration conf = this.getConf();
121+
clientRMProxy = user.doAs(
122+
(PrivilegedExceptionAction<ApplicationClientProtocol>) () ->
123+
ClientRMProxy.createRMProxy(conf, ApplicationClientProtocol.class));
126124
} catch (Exception e) {
127-
throw new YarnRuntimeException(
128-
"Unable to create the interface to reach the YarnRM", e);
125+
StringBuilder message = new StringBuilder();
126+
message.append("Error while creating Router RMClient Service");
127+
if (user != null) {
128+
message.append(", user: " + user);
129+
}
130+
LOG.error(message.toString(), e);
131+
throw new YarnRuntimeException(message.toString(), e);
129132
}
130133
}
131134

@@ -355,6 +358,5 @@ public GetNodesToAttributesResponse getNodesToAttributes(
355358
@VisibleForTesting
356359
public void setRMClient(ApplicationClientProtocol clientRM) {
357360
this.clientRMProxy = clientRM;
358-
359361
}
360362
}

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

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -80,38 +80,18 @@ public class DefaultRMAdminRequestInterceptor
8080
public void init(String userName) {
8181
super.init(userName);
8282
try {
83-
// Do not create a proxy user if user name matches the user name on
84-
// current UGI
85-
if (UserGroupInformation.isSecurityEnabled()) {
86-
user = UserGroupInformation.createProxyUser(userName, UserGroupInformation.getLoginUser());
87-
} else if (userName.equalsIgnoreCase(UserGroupInformation.getCurrentUser().getUserName())) {
88-
user = UserGroupInformation.getCurrentUser();
89-
} else {
90-
user = UserGroupInformation.createProxyUser(userName,
91-
UserGroupInformation.getCurrentUser());
92-
}
93-
9483
final Configuration conf = this.getConf();
95-
9684
rmAdminProxy = user.doAs(
97-
new PrivilegedExceptionAction<ResourceManagerAdministrationProtocol>() {
98-
@Override
99-
public ResourceManagerAdministrationProtocol run()
100-
throws Exception {
101-
return ClientRMProxy.createRMProxy(conf,
102-
ResourceManagerAdministrationProtocol.class);
103-
}
104-
});
105-
} catch (IOException e) {
106-
String message = "Error while creating Router RMAdmin Service for user:";
85+
(PrivilegedExceptionAction<ResourceManagerAdministrationProtocol>) () ->
86+
ClientRMProxy.createRMProxy(conf, ResourceManagerAdministrationProtocol.class));
87+
} catch (Exception e) {
88+
StringBuilder message = new StringBuilder();
89+
message.append("Error while creating Router RMAdmin Service");
10790
if (user != null) {
108-
message += ", user: " + user;
91+
message.append(", user: " + user);
10992
}
110-
111-
LOG.info(message);
112-
throw new YarnRuntimeException(message, e);
113-
} catch (Exception e) {
114-
throw new YarnRuntimeException(e);
93+
LOG.error(message.toString(), e);
94+
throw new YarnRuntimeException(message.toString(), e);
11595
}
11696
}
11797

@@ -126,7 +106,6 @@ public void setNextInterceptor(RMAdminRequestInterceptor next) {
126106
@VisibleForTesting
127107
public void setRMAdmin(ResourceManagerAdministrationProtocol rmAdmin) {
128108
this.rmAdminProxy = rmAdmin;
129-
130109
}
131110

132111
@Override

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ protected SubClusterId getSubClusterId() {
103103

104104
@Override
105105
public void init(String user) {
106+
super.init(user);
106107
webAppAddress = WebAppUtils.getRMWebAppURLWithScheme(getConf());
107108
client = RouterWebServiceUtil.createJerseyClient(getConf());
108109
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/webapp/MockDefaultRequestInterceptorREST.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public Response createNewApplication(HttpServletRequest hsr)
211211
validateRunning();
212212

213213
ApplicationId applicationId =
214-
ApplicationId.newInstance(Integer.valueOf(getSubClusterId().getId()),
214+
ApplicationId.newInstance(Integer.parseInt(getSubClusterId().getId()),
215215
applicationCounter.incrementAndGet());
216216
NewApplication appId =
217217
new NewApplication(applicationId.toString(), new ResourceInfo());
@@ -275,7 +275,7 @@ public AppsInfo getApps(HttpServletRequest hsr, String stateQuery,
275275
AppInfo appInfo = new AppInfo();
276276

277277
appInfo.setAppId(
278-
ApplicationId.newInstance(Integer.valueOf(getSubClusterId().getId()),
278+
ApplicationId.newInstance(Integer.parseInt(getSubClusterId().getId()),
279279
applicationCounter.incrementAndGet()).toString());
280280
appInfo.setAMHostHttpAddress("http://i_am_the_AM:1234");
281281

@@ -316,7 +316,7 @@ public NodeInfo getNode(String nodeId) {
316316
if (nodeId.contains(subClusterId) || nodeId.contains("test")) {
317317
node = new NodeInfo();
318318
node.setId(nodeId);
319-
node.setLastHealthUpdate(Integer.valueOf(getSubClusterId().getId()));
319+
node.setLastHealthUpdate(Integer.parseInt(getSubClusterId().getId()));
320320
}
321321
return node;
322322
}
@@ -328,7 +328,7 @@ public NodesInfo getNodes(String states) {
328328
}
329329
NodeInfo node = new NodeInfo();
330330
node.setId("Node " + Integer.valueOf(getSubClusterId().getId()));
331-
node.setLastHealthUpdate(Integer.valueOf(getSubClusterId().getId()));
331+
node.setLastHealthUpdate(Integer.parseInt(getSubClusterId().getId()));
332332
NodesInfo nodes = new NodesInfo();
333333
nodes.add(node);
334334
return nodes;
@@ -350,12 +350,12 @@ public ClusterMetricsInfo getClusterMetricsInfo() {
350350
throw new RuntimeException("RM is stopped");
351351
}
352352
ClusterMetricsInfo metrics = new ClusterMetricsInfo();
353-
metrics.setAppsSubmitted(Integer.valueOf(getSubClusterId().getId()));
354-
metrics.setAppsCompleted(Integer.valueOf(getSubClusterId().getId()));
355-
metrics.setAppsPending(Integer.valueOf(getSubClusterId().getId()));
356-
metrics.setAppsRunning(Integer.valueOf(getSubClusterId().getId()));
357-
metrics.setAppsFailed(Integer.valueOf(getSubClusterId().getId()));
358-
metrics.setAppsKilled(Integer.valueOf(getSubClusterId().getId()));
353+
metrics.setAppsSubmitted(Integer.parseInt(getSubClusterId().getId()));
354+
metrics.setAppsCompleted(Integer.parseInt(getSubClusterId().getId()));
355+
metrics.setAppsPending(Integer.parseInt(getSubClusterId().getId()));
356+
metrics.setAppsRunning(Integer.parseInt(getSubClusterId().getId()));
357+
metrics.setAppsFailed(Integer.parseInt(getSubClusterId().getId()));
358+
metrics.setAppsKilled(Integer.parseInt(getSubClusterId().getId()));
359359

360360
return metrics;
361361
}

0 commit comments

Comments
 (0)