Skip to content

Commit a431fdb

Browse files
committed
svn merge -c 1335567 FIXES: MAPREDUCE-4162. Correctly set token service (Daryn Sharp via bobby)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1335569 13f79535-47bb-0310-9956-ffa450edef68
1 parent 16ed3d3 commit a431fdb

File tree

24 files changed

+147
-108
lines changed

24 files changed

+147
-108
lines changed

hadoop-mapreduce-project/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ Release 0.23.3 - UNRELEASED
212212

213213
MAPREDUCE-4210. Expose listener address for WebApp (Daryn Sharp via bobby)
214214

215+
MAPREDUCE-4162. Correctly set token service (Daryn Sharp via bobby)
216+
215217
OPTIMIZATIONS
216218

217219
BUG FIXES

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapred/YarnChild.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
5050
import org.apache.hadoop.mapreduce.security.token.JobTokenSecretManager;
5151
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
5252
import org.apache.hadoop.metrics2.source.JvmMetrics;
53+
import org.apache.hadoop.net.NetUtils;
5354
import org.apache.hadoop.security.Credentials;
55+
import org.apache.hadoop.security.SecurityUtil;
5456
import org.apache.hadoop.security.UserGroupInformation;
5557
import org.apache.hadoop.security.token.Token;
5658
import org.apache.hadoop.security.token.TokenIdentifier;
@@ -77,7 +79,8 @@ public static void main(String[] args) throws Throwable {
7779

7880
String host = args[0];
7981
int port = Integer.parseInt(args[1]);
80-
final InetSocketAddress address = new InetSocketAddress(host, port);
82+
final InetSocketAddress address =
83+
NetUtils.createSocketAddrForHost(host, port);
8184
final TaskAttemptID firstTaskid = TaskAttemptID.forName(args[2]);
8285
int jvmIdInt = Integer.parseInt(args[3]);
8386
JVMId jvmId = new JVMId(firstTaskid.getJobID(),
@@ -214,8 +217,7 @@ private static Token<JobTokenIdentifier> loadCredentials(JobConf conf,
214217
LOG.debug("loading token. # keys =" +credentials.numberOfSecretKeys() +
215218
"; from file=" + jobTokenFile);
216219
Token<JobTokenIdentifier> jt = TokenCache.getJobToken(credentials);
217-
jt.setService(new Text(address.getAddress().getHostAddress() + ":"
218-
+ address.getPort()));
220+
SecurityUtil.setTokenService(jt, address);
219221
UserGroupInformation current = UserGroupInformation.getCurrentUser();
220222
current.addToken(jt);
221223
for (Token<? extends TokenIdentifier> tok : credentials.getAllTokens()) {

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/client/MRClientService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ class MRClientProtocolHandler implements MRClientProtocol {
180180
private RecordFactory recordFactory =
181181
RecordFactoryProvider.getRecordFactory(null);
182182

183+
@Override
184+
public InetSocketAddress getConnectAddress() {
185+
return getBindAddress();
186+
}
187+
183188
private Job verifyAndGetJob(JobId jobID,
184189
boolean modifyAccess) throws YarnRemoteException {
185190
Job job = appContext.getJob(jobID);

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/launcher/ContainerLauncherImpl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.hadoop.mapreduce.v2.app.launcher;
2020

2121
import java.io.IOException;
22+
import java.net.InetSocketAddress;
2223
import java.nio.ByteBuffer;
2324
import java.security.PrivilegedAction;
2425
import java.util.HashSet;
@@ -34,7 +35,6 @@
3435
import org.apache.commons.logging.LogFactory;
3536
import org.apache.hadoop.conf.Configuration;
3637
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
37-
import org.apache.hadoop.io.Text;
3838
import org.apache.hadoop.mapred.ShuffleHandler;
3939
import org.apache.hadoop.mapreduce.MRJobConfig;
4040
import org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId;
@@ -58,6 +58,7 @@
5858
import org.apache.hadoop.yarn.ipc.YarnRPC;
5959
import org.apache.hadoop.yarn.security.ContainerTokenIdentifier;
6060
import org.apache.hadoop.yarn.service.AbstractService;
61+
import org.apache.hadoop.yarn.util.ProtoUtils;
6162
import org.apache.hadoop.yarn.util.Records;
6263

6364
import com.google.common.util.concurrent.ThreadFactoryBuilder;
@@ -321,13 +322,13 @@ protected ContainerManager getCMProxy(ContainerId containerID,
321322
final String containerManagerBindAddr, ContainerToken containerToken)
322323
throws IOException {
323324

325+
final InetSocketAddress cmAddr =
326+
NetUtils.createSocketAddr(containerManagerBindAddr);
324327
UserGroupInformation user = UserGroupInformation.getCurrentUser();
325328

326329
if (UserGroupInformation.isSecurityEnabled()) {
327-
Token<ContainerTokenIdentifier> token = new Token<ContainerTokenIdentifier>(
328-
containerToken.getIdentifier().array(), containerToken
329-
.getPassword().array(), new Text(containerToken.getKind()),
330-
new Text(containerToken.getService()));
330+
Token<ContainerTokenIdentifier> token =
331+
ProtoUtils.convertFromProtoFormat(containerToken, cmAddr);
331332
// the user in createRemoteUser in this context has to be ContainerID
332333
user = UserGroupInformation.createRemoteUser(containerID.toString());
333334
user.addToken(token);
@@ -338,8 +339,7 @@ protected ContainerManager getCMProxy(ContainerId containerID,
338339
@Override
339340
public ContainerManager run() {
340341
return (ContainerManager) rpc.getProxy(ContainerManager.class,
341-
NetUtils.createSocketAddr(containerManagerBindAddr),
342-
getConfig());
342+
cmAddr, getConfig());
343343
}
344344
});
345345
return proxy;

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/rm/RMCommunicator.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.hadoop.mapreduce.v2.app.client.ClientService;
3737
import org.apache.hadoop.mapreduce.v2.app.job.Job;
3838
import org.apache.hadoop.mapreduce.v2.jobhistory.JobHistoryUtils;
39+
import org.apache.hadoop.security.SecurityUtil;
3940
import org.apache.hadoop.security.UserGroupInformation;
4041
import org.apache.hadoop.security.token.Token;
4142
import org.apache.hadoop.security.token.TokenIdentifier;
@@ -133,15 +134,14 @@ protected float getApplicationProgress() {
133134

134135
protected void register() {
135136
//Register
136-
String host = clientService.getBindAddress().getAddress()
137-
.getCanonicalHostName();
137+
InetSocketAddress serviceAddr = clientService.getBindAddress();
138138
try {
139139
RegisterApplicationMasterRequest request =
140140
recordFactory.newRecordInstance(RegisterApplicationMasterRequest.class);
141141
request.setApplicationAttemptId(applicationAttemptId);
142-
request.setHost(host);
143-
request.setRpcPort(clientService.getBindAddress().getPort());
144-
request.setTrackingUrl(host + ":" + clientService.getHttpPort());
142+
request.setHost(serviceAddr.getHostName());
143+
request.setRpcPort(serviceAddr.getPort());
144+
request.setTrackingUrl(serviceAddr.getHostName() + ":" + clientService.getHttpPort());
145145
RegisterApplicationMasterResponse response =
146146
scheduler.registerApplicationMaster(request);
147147
minContainerCapability = response.getMinimumResourceCapability();
@@ -262,9 +262,6 @@ protected AMRMProtocol createSchedulerProxy() {
262262
if (UserGroupInformation.isSecurityEnabled()) {
263263
String tokenURLEncodedStr = System.getenv().get(
264264
ApplicationConstants.APPLICATION_MASTER_TOKEN_ENV_NAME);
265-
if (LOG.isDebugEnabled()) {
266-
LOG.debug("AppMasterToken is " + tokenURLEncodedStr);
267-
}
268265
Token<? extends TokenIdentifier> token = new Token<TokenIdentifier>();
269266

270267
try {
@@ -273,6 +270,10 @@ protected AMRMProtocol createSchedulerProxy() {
273270
throw new YarnException(e);
274271
}
275272

273+
SecurityUtil.setTokenService(token, serviceAddr);
274+
if (LOG.isDebugEnabled()) {
275+
LOG.debug("AppMasterToken is " + token);
276+
}
276277
currentUser.addToken(token);
277278
}
278279

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/api/MRClientProtocol.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
package org.apache.hadoop.mapreduce.v2.api;
2020

21+
import java.net.InetSocketAddress;
22+
2123
import org.apache.hadoop.mapreduce.v2.api.protocolrecords.FailTaskAttemptRequest;
2224
import org.apache.hadoop.mapreduce.v2.api.protocolrecords.FailTaskAttemptResponse;
2325
import org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetCountersRequest;
@@ -45,6 +47,11 @@
4547
import org.apache.hadoop.yarn.exceptions.YarnRemoteException;
4648

4749
public interface MRClientProtocol {
50+
/**
51+
* Address to which the client is connected
52+
* @return InetSocketAddress
53+
*/
54+
public InetSocketAddress getConnectAddress();
4855
public GetJobReportResponse getJobReport(GetJobReportRequest request) throws YarnRemoteException;
4956
public GetTaskReportResponse getTaskReport(GetTaskReportRequest request) throws YarnRemoteException;
5057
public GetTaskAttemptReportResponse getTaskAttemptReport(GetTaskAttemptReportRequest request) throws YarnRemoteException;

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/api/impl/pb/client/MRClientProtocolPBClientImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ public MRClientProtocolPBClientImpl(long clientVersion, InetSocketAddress addr,
104104
MRClientProtocolPB.class, clientVersion, addr, conf);
105105
}
106106

107+
@Override
108+
public InetSocketAddress getConnectAddress() {
109+
return RPC.getServerAddress(proxy);
110+
}
111+
107112
@Override
108113
public GetJobReportResponse getJobReport(GetJobReportRequest request)
109114
throws YarnRemoteException {

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/test/java/org/apache/hadoop/mapreduce/v2/TestRPCFactories.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ private void testPbClientFactory() {
122122

123123
public class MRClientProtocolTestImpl implements MRClientProtocol {
124124

125+
@Override
126+
public InetSocketAddress getConnectAddress() {
127+
return null;
128+
}
129+
125130
@Override
126131
public GetJobReportResponse getJobReport(GetJobReportRequest request)
127132
throws YarnRemoteException {

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Cluster.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@
3535
import org.apache.hadoop.io.Text;
3636
import org.apache.hadoop.ipc.RemoteException;
3737
import org.apache.hadoop.mapred.JobConf;
38-
import org.apache.hadoop.mapred.Master;
3938
import org.apache.hadoop.mapreduce.protocol.ClientProtocol;
4039
import org.apache.hadoop.mapreduce.protocol.ClientProtocolProvider;
4140
import org.apache.hadoop.mapreduce.security.token.delegation.DelegationTokenIdentifier;
4241
import org.apache.hadoop.mapreduce.util.ConfigUtil;
4342
import org.apache.hadoop.mapreduce.v2.LogParams;
44-
import org.apache.hadoop.net.NetUtils;
4543
import org.apache.hadoop.security.AccessControlException;
4644
import org.apache.hadoop.security.UserGroupInformation;
4745
import org.apache.hadoop.security.token.SecretManager.InvalidToken;
@@ -388,21 +386,8 @@ public long getTaskTrackerExpiryInterval() throws IOException,
388386
*/
389387
public Token<DelegationTokenIdentifier>
390388
getDelegationToken(Text renewer) throws IOException, InterruptedException{
391-
Token<DelegationTokenIdentifier> result =
392-
client.getDelegationToken(renewer);
393-
394-
if (result == null) {
395-
return result;
396-
}
397-
398-
InetSocketAddress addr = Master.getMasterAddress(conf);
399-
StringBuilder service = new StringBuilder();
400-
service.append(NetUtils.normalizeHostName(addr.getAddress().
401-
getHostAddress()));
402-
service.append(':');
403-
service.append(addr.getPort());
404-
result.setService(new Text(service.toString()));
405-
return result;
389+
// client has already set the service
390+
return client.getDelegationToken(renewer);
406391
}
407392

408393
/**

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/HistoryClientService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ private class HSClientProtocolHandler implements HSClientProtocol {
178178

179179
private RecordFactory recordFactory = RecordFactoryProvider.getRecordFactory(null);
180180

181+
public InetSocketAddress getConnectAddress() {
182+
return getBindAddress();
183+
}
184+
181185
private Job verifyAndGetJob(final JobId jobID) throws YarnRemoteException {
182186
UserGroupInformation loginUgi = null;
183187
Job job = null;
@@ -335,8 +339,7 @@ public GetDelegationTokenResponse getDelegationToken(
335339
jhsDTSecretManager);
336340
DelegationToken mrDToken = BuilderUtils.newDelegationToken(
337341
realJHSToken.getIdentifier(), realJHSToken.getKind().toString(),
338-
realJHSToken.getPassword(), bindAddress.getAddress().getHostAddress()
339-
+ ":" + bindAddress.getPort());
342+
realJHSToken.getPassword(), realJHSToken.getService().toString());
340343
response.setDelegationToken(mrDToken);
341344
return response;
342345
} catch (IOException i) {

0 commit comments

Comments
 (0)