Skip to content

Commit 2839b73

Browse files
committed
Merge remote branch 'jvalkeal/SHDP-171'
SHDP-171 Prepare monitor,allocator and launcher. Tweaks and tidy up for concepts around monitoring, allocation and launching. This makes code base clean still leaving monitoring into a state which needs to be radically modify order to know real monitoring state. This is due to removal of container states from containers in yarn api. SHDP-171 Fixes for ClientRmTemplate Fixing template and re-enabling tests. SHDP-171 Clean and tweaks for AppmasterCmTemplate SHDP-171 Remove user and tidy up Remove user from yarn client because api doesn't use it anymore. Tidying up classes. SHDP-171 Fixing some tests for changes in CONTAINER_ID env variable AM_CONTAINER_ID is now CONTAINER_ID. Changes for this and tests which failed. SHDP-171 More changes due to removal of ApplicationAttemptId from api. Changes to internal apis, handling of connection authentication, etc. SHDP-171 ApplicationAttemptId not part of FinishApplicationMasterRequest anymore. SHDP-171 Fixing AbstractBatchAppmaster per changes in ContainerLauncherInterceptor SHDP-171 Modify ContainerLauncherInterceptor Adding Container into interceptor because previously it was part of the ContainerLaunchContext. That's not a case anymore and we need this info. SHDP-171 Saving work with first working unit test SHDP-171 first change set which compiles
1 parent 8566376 commit 2839b73

29 files changed

+310
-311
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ hd12HiveVersion = 0.11.0
2222
hd12PigVersion = 0.11.1
2323
hd12ThriftVersion = 0.9.0
2424

25-
## Hadoop20 Alpha
26-
hd20Version = 2.0.6-alpha
25+
## Hadoop20 GA
26+
hd20Version = 2.2.0
2727
hd20HbaseVersion = 0.94.6
2828
hd20HiveVersion = 0.10.0
2929
hd20PigVersion = 0.11.1

spring-yarn/spring-yarn-batch/src/main/java/org/springframework/yarn/batch/am/AbstractBatchAppmaster.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,14 @@ protected void onContainerCompleted(ContainerStatus status) {
203203
}
204204

205205
@Override
206-
public ContainerLaunchContext preLaunch(ContainerLaunchContext context) {
206+
public ContainerLaunchContext preLaunch(Container container, ContainerLaunchContext context) {
207207
AppmasterService service = getAppmasterService();
208208

209209
if(log.isDebugEnabled()) {
210210
log.debug("Intercept launch context: " + context);
211211
}
212212

213-
StepExecution stepExecution = containerToStepMap.get(context.getContainerId());
213+
StepExecution stepExecution = containerToStepMap.get(container.getId());
214214
String jobName = remoteStepNames.get(stepExecution);
215215

216216
if(service != null) {

spring-yarn/spring-yarn-core/src/main/java/org/springframework/yarn/YarnSystemException.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
*/
1616
package org.springframework.yarn;
1717

18+
import java.io.IOException;
19+
1820
import org.apache.hadoop.ipc.RemoteException;
19-
import org.apache.hadoop.yarn.YarnException;
20-
import org.apache.hadoop.yarn.exceptions.YarnRemoteException;
21+
import org.apache.hadoop.yarn.exceptions.YarnException;
22+
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
2123
import org.springframework.dao.UncategorizedDataAccessException;
2224

2325
/**
@@ -42,11 +44,11 @@ public YarnSystemException(YarnException e) {
4244
}
4345

4446
/**
45-
* Constructs YarnSystemException from {@link YarnRemoteException}.
47+
* Constructs YarnSystemException from {@link YarnRuntimeException}.
4648
*
47-
* @param e the {@link YarnRemoteException}
49+
* @param e the {@link YarnRuntimeException}
4850
*/
49-
public YarnSystemException(YarnRemoteException e) {
51+
public YarnSystemException(YarnRuntimeException e) {
5052
super(e.getMessage(), e);
5153
}
5254

@@ -55,9 +57,12 @@ public YarnSystemException(YarnRemoteException e) {
5557
*
5658
* @param e the {@link RemoteException}
5759
*/
58-
public YarnSystemException(RemoteException e) {
60+
public YarnSystemException(IOException e) {
5961
super(e.getMessage(), e);
6062
}
63+
// public YarnSystemException(RemoteException e) {
64+
// super(e.getMessage(), e);
65+
// }
6166

6267
/**
6368
* Constructs a general YarnSystemException.

spring-yarn/spring-yarn-core/src/main/java/org/springframework/yarn/am/AbstractAppmaster.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ protected RegisterApplicationMasterResponse registerAppmaster() {
349349
" trackUrl=" + trackUrl + " rpcHost=" + rpcHost + " rpcPort=" + rpcPort);
350350

351351
RegisterApplicationMasterResponse response =
352-
rmTemplate.registerApplicationMaster(applicationAttemptId, rpcHost, rpcPort, trackUrl);
352+
rmTemplate.registerApplicationMaster(rpcHost, rpcPort, trackUrl);
353353
applicationRegistered = true;
354354
return response;
355355
}
@@ -366,22 +366,26 @@ protected FinishApplicationMasterResponse finishAppmaster() {
366366
boolean clean = getResourceLocalizer().clean();
367367
log.info("Status of resource localizer clean operation is " + clean);
368368

369+
// starting from 2.1.x applicationAttemptId is part of the token and
370+
// doesn't exist in finish request. We still keep it around as per
371+
// old concept.
369372
Assert.notNull(applicationAttemptId, "applicationAttemptId must be set");
370373
if(!applicationRegistered) {
371374
log.warn("Not sending finish request because we're not registered");
372375
return null;
373376
}
374-
if(log.isDebugEnabled()) {
375-
log.debug("Sending finish request to resource manager: appAttemptId=" +
376-
applicationAttemptId + " status=" + FinalApplicationStatus.SUCCEEDED);
377-
}
378-
FinishApplicationMasterRequest finishReq = Records.newRecord(FinishApplicationMasterRequest.class);
379-
finishReq.setAppAttemptId(applicationAttemptId);
380377

378+
FinishApplicationMasterRequest finishReq = Records.newRecord(FinishApplicationMasterRequest.class);
381379
// assume succeed if not set
382380
FinalApplicationStatus status = finalApplicationStatus != null ?
383381
finalApplicationStatus : FinalApplicationStatus.SUCCEEDED;
384-
finishReq.setFinishApplicationStatus(status);
382+
383+
if(log.isDebugEnabled()) {
384+
log.debug("Sending finish request to resource manager. Current applicationAttemptId=" +
385+
applicationAttemptId + " with status=" + status);
386+
}
387+
388+
finishReq.setFinalApplicationStatus(status);
385389
return rmTemplate.finish(finishReq);
386390
}
387391

spring-yarn/spring-yarn-core/src/main/java/org/springframework/yarn/am/AbstractProcessingAppmaster.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void completed(List<ContainerStatus> completedContainers) {
8282
}
8383

8484
@Override
85-
public ContainerLaunchContext preLaunch(ContainerLaunchContext context) {
85+
public ContainerLaunchContext preLaunch(Container container, ContainerLaunchContext context) {
8686
return context;
8787
}
8888

spring-yarn/spring-yarn-core/src/main/java/org/springframework/yarn/am/AppmasterCmOperations.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616
package org.springframework.yarn.am;
1717

18-
import org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest;
19-
import org.apache.hadoop.yarn.api.protocolrecords.StartContainerResponse;
20-
import org.apache.hadoop.yarn.api.protocolrecords.StopContainerResponse;
18+
import org.apache.hadoop.yarn.api.protocolrecords.StartContainersRequest;
19+
import org.apache.hadoop.yarn.api.protocolrecords.StartContainersResponse;
20+
import org.apache.hadoop.yarn.api.protocolrecords.StopContainersResponse;
2121
import org.apache.hadoop.yarn.api.records.ContainerStatus;
2222

2323
/**
@@ -36,14 +36,14 @@ public interface AppmasterCmOperations {
3636
* @param request the request
3737
* @return the start container response
3838
*/
39-
StartContainerResponse startContainer(StartContainerRequest request);
39+
StartContainersResponse startContainers(StartContainersRequest request);
4040

4141
/**
4242
* Stop container.
4343
*
4444
* @return the stop container response
4545
*/
46-
StopContainerResponse stopContainer();
46+
StopContainersResponse stopContainers();
4747

4848
/**
4949
* Gets the container status.

spring-yarn/spring-yarn-core/src/main/java/org/springframework/yarn/am/AppmasterCmTemplate.java

Lines changed: 53 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -17,78 +17,87 @@
1717

1818
import java.io.IOException;
1919
import java.net.InetSocketAddress;
20+
import java.util.ArrayList;
2021

2122
import org.apache.hadoop.conf.Configuration;
22-
import org.apache.hadoop.io.Text;
2323
import org.apache.hadoop.net.NetUtils;
24-
import org.apache.hadoop.security.SecurityUtil;
2524
import org.apache.hadoop.security.UserGroupInformation;
26-
import org.apache.hadoop.security.token.Token;
27-
import org.apache.hadoop.security.token.TokenIdentifier;
28-
import org.apache.hadoop.yarn.api.ContainerManager;
29-
import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusRequest;
30-
import org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest;
31-
import org.apache.hadoop.yarn.api.protocolrecords.StartContainerResponse;
32-
import org.apache.hadoop.yarn.api.protocolrecords.StopContainerRequest;
33-
import org.apache.hadoop.yarn.api.protocolrecords.StopContainerResponse;
25+
import org.apache.hadoop.yarn.api.ContainerManagementProtocol;
26+
import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest;
27+
import org.apache.hadoop.yarn.api.protocolrecords.StartContainersRequest;
28+
import org.apache.hadoop.yarn.api.protocolrecords.StartContainersResponse;
29+
import org.apache.hadoop.yarn.api.protocolrecords.StopContainersRequest;
30+
import org.apache.hadoop.yarn.api.protocolrecords.StopContainersResponse;
3431
import org.apache.hadoop.yarn.api.records.Container;
32+
import org.apache.hadoop.yarn.api.records.ContainerId;
3533
import org.apache.hadoop.yarn.api.records.ContainerStatus;
36-
import org.apache.hadoop.yarn.api.records.ContainerToken;
37-
import org.apache.hadoop.yarn.api.records.DelegationToken;
38-
import org.apache.hadoop.yarn.exceptions.YarnRemoteException;
39-
import org.apache.hadoop.yarn.security.ContainerTokenIdentifier;
34+
import org.apache.hadoop.yarn.api.records.Token;
35+
import org.apache.hadoop.yarn.client.api.NMTokenCache;
36+
import org.apache.hadoop.yarn.exceptions.YarnException;
37+
import org.apache.hadoop.yarn.security.NMTokenIdentifier;
38+
import org.apache.hadoop.yarn.util.ConverterUtils;
4039
import org.apache.hadoop.yarn.util.Records;
4140
import org.springframework.yarn.rpc.YarnRpcAccessor;
4241
import org.springframework.yarn.rpc.YarnRpcCallback;
4342

4443
/**
4544
* Template implementation for {@link AppmasterCmOperations} wrapping
46-
* communication using {@link ContainerManager}. Methods for this
45+
* communication using {@link ContainerManagementProtocol}. Methods for this
4746
* template wraps possible exceptions into Spring Dao exception hierarchy.
4847
*
4948
* @author Janne Valkealahti
5049
*
5150
*/
52-
public class AppmasterCmTemplate extends YarnRpcAccessor<ContainerManager> implements AppmasterCmOperations {
51+
public class AppmasterCmTemplate extends YarnRpcAccessor<ContainerManagementProtocol> implements AppmasterCmOperations {
5352

5453
/** Container we're working for */
5554
private final Container container;
5655

56+
/**
57+
* Instantiates a new AppmasterCmTemplate.
58+
*
59+
* @param config the hadoop configation
60+
* @param container the {@link Container}
61+
*/
5762
public AppmasterCmTemplate(Configuration config, Container container) {
58-
super(ContainerManager.class, config);
63+
super(ContainerManagementProtocol.class, config);
5964
this.container = container;
6065
}
6166

6267
@Override
63-
public StartContainerResponse startContainer(final StartContainerRequest request) {
64-
return execute(new YarnRpcCallback<StartContainerResponse, ContainerManager>() {
68+
public StartContainersResponse startContainers(final StartContainersRequest request) {
69+
return execute(new YarnRpcCallback<StartContainersResponse, ContainerManagementProtocol>() {
6570
@Override
66-
public StartContainerResponse doInYarn(ContainerManager proxy) throws YarnRemoteException {
67-
return proxy.startContainer(request);
71+
public StartContainersResponse doInYarn(ContainerManagementProtocol proxy) throws YarnException, IOException {
72+
return proxy.startContainers(request);
6873
}
6974
});
7075
}
7176

7277
@Override
73-
public StopContainerResponse stopContainer() {
74-
return execute(new YarnRpcCallback<StopContainerResponse, ContainerManager>() {
78+
public StopContainersResponse stopContainers() {
79+
return execute(new YarnRpcCallback<StopContainersResponse, ContainerManagementProtocol>() {
7580
@Override
76-
public StopContainerResponse doInYarn(ContainerManager proxy) throws YarnRemoteException {
77-
StopContainerRequest request = Records.newRecord(StopContainerRequest.class);
78-
request.setContainerId(container.getId());
79-
return proxy.stopContainer(request);
81+
public StopContainersResponse doInYarn(ContainerManagementProtocol proxy) throws YarnException, IOException {
82+
StopContainersRequest request = Records.newRecord(StopContainersRequest.class);
83+
ArrayList<ContainerId> ids = new ArrayList<ContainerId>();
84+
ids.add(container.getId());
85+
request.setContainerIds(ids);
86+
return proxy.stopContainers(request);
8087
}
8188
});
8289
}
8390

8491
@Override
8592
public ContainerStatus getContainerStatus() {
86-
return execute(new YarnRpcCallback<ContainerStatus, ContainerManager>() {
93+
return execute(new YarnRpcCallback<ContainerStatus, ContainerManagementProtocol>() {
8794
@Override
88-
public ContainerStatus doInYarn(ContainerManager proxy) throws YarnRemoteException {
89-
GetContainerStatusRequest request = Records.newRecord(GetContainerStatusRequest.class);
90-
request.setContainerId(container.getId());
91-
return proxy.getContainerStatus(request).getStatus();
95+
public ContainerStatus doInYarn(ContainerManagementProtocol proxy) throws YarnException, IOException {
96+
GetContainerStatusesRequest request = Records.newRecord(GetContainerStatusesRequest.class);
97+
ArrayList<ContainerId> ids = new ArrayList<ContainerId>();
98+
ids.add(container.getId());
99+
request.setContainerIds(ids);
100+
return proxy.getContainerStatuses(request).getContainerStatuses().get(0);
92101
}
93102
});
94103
}
@@ -101,45 +110,19 @@ protected InetSocketAddress getRpcAddress(Configuration config) {
101110

102111
@Override
103112
protected UserGroupInformation getUser() {
104-
UserGroupInformation user = null;
105-
try {
106-
user = UserGroupInformation.getCurrentUser();
107-
if (UserGroupInformation.isSecurityEnabled()) {
108-
ContainerToken containerToken = container.getContainerToken();
109-
Token<ContainerTokenIdentifier> token = null;
110-
if (containerToken instanceof DelegationToken) {
111-
token = convertFromProtoFormat((DelegationToken) container.getContainerToken(),
112-
getRpcAddress(getConfiguration()));
113-
}
114-
// remote user needs to be a container id
115-
user = UserGroupInformation.createRemoteUser(container.getId().toString());
116-
user.addToken(token);
117-
}
118-
} catch (IOException e) {
119-
}
120-
return user;
121-
}
113+
InetSocketAddress rpcAddress = getRpcAddress(getConfiguration());
122114

123-
/**
124-
* Convert token identifier from a proto format.
125-
* <p>
126-
* This function is a copy for way it was pre hadoop-2.0.3. Helps
127-
* to work with api changes.
128-
*
129-
* @param <T> the generic type
130-
* @param protoToken the proto token
131-
* @param serviceAddr the service addr
132-
* @return the token identifier
133-
*/
134-
private static <T extends TokenIdentifier> Token<T> convertFromProtoFormat(DelegationToken protoToken,
135-
InetSocketAddress serviceAddr) {
136-
// TODO: remove this method when api's are compatible
137-
Token<T> token = new Token<T>(protoToken.getIdentifier().array(), protoToken.getPassword().array(),
138-
new Text(protoToken.getKind()), new Text(protoToken.getService()));
139-
if (serviceAddr != null) {
140-
SecurityUtil.setTokenService(token, serviceAddr);
141-
}
142-
return token;
115+
// TODO: at some point remove static cache
116+
Token token = NMTokenCache.getNMToken(container.getNodeId().toString());
117+
118+
// this is what node manager requires for auth
119+
UserGroupInformation user =
120+
UserGroupInformation.createRemoteUser(container.getId().getApplicationAttemptId().toString());
121+
org.apache.hadoop.security.token.Token<NMTokenIdentifier> nmToken =
122+
ConverterUtils.convertFromYarn(token, rpcAddress);
123+
user.addToken(nmToken);
124+
125+
return user;
143126
}
144127

145128
}

spring-yarn/spring-yarn-core/src/main/java/org/springframework/yarn/am/AppmasterRmOperations.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,26 @@
2020
import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterRequest;
2121
import org.apache.hadoop.yarn.api.protocolrecords.FinishApplicationMasterResponse;
2222
import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse;
23-
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
2423

2524
/**
2625
* Interface for appmaster to resource manager communication.
2726
*
2827
* @author Janne Valkealahti
2928
* @see org.springframework.yarn.am.AppmasterRmTemplate
30-
* @see org.apache.hadoop.yarn.api.AMRMProtocol
29+
* @see org.apache.hadoop.yarn.api.ApplicationMasterProtocol
3130
*
3231
*/
3332
public interface AppmasterRmOperations {
3433

3534
/**
3635
* Register application master.
3736
*
38-
* @param appAttemptId the app attempt id
3937
* @param host the host
4038
* @param rpcPort the rpc port
4139
* @param trackUrl the track url
42-
* @return the register application master response
40+
* @return the {@link RegisterApplicationMasterResponse}
4341
*/
44-
RegisterApplicationMasterResponse registerApplicationMaster(ApplicationAttemptId appAttemptId,
45-
String host, Integer rpcPort, String trackUrl);
42+
RegisterApplicationMasterResponse registerApplicationMaster(String host, Integer rpcPort, String trackUrl);
4643

4744
/**
4845
* Allocate container.
@@ -55,8 +52,8 @@ RegisterApplicationMasterResponse registerApplicationMaster(ApplicationAttemptId
5552
/**
5653
* Finish the application master.
5754
*
58-
* @param request the request
59-
* @return the finish application master response
55+
* @param request the {@link FinishApplicationMasterRequest}
56+
* @return the {@link FinishApplicationMasterResponse}
6057
*/
6158
FinishApplicationMasterResponse finish(FinishApplicationMasterRequest request);
6259

0 commit comments

Comments
 (0)