YARN-2088. Fixed a bug in GetApplicationsRequestPBImpl#mergeLocalToBuilder. Contributed by Binglin Chang

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1609584 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jian He 2014-07-10 22:36:13 +00:00
parent 9f1768fba2
commit 50be8561a7
3 changed files with 33 additions and 55 deletions

View File

@ -83,6 +83,9 @@ Release 2.5.0 - UNRELEASED
YARN-2181. Added preemption info to logs and RM web UI. (Wangda Tan via YARN-2181. Added preemption info to logs and RM web UI. (Wangda Tan via
jianhe) jianhe)
YARN-2088. Fixed a bug in GetApplicationsRequestPBImpl#mergeLocalToBuilder.
(Binglin Chang via jianhe)
IMPROVEMENTS IMPROVEMENTS
YARN-1479. Invalid NaN values in Hadoop REST API JSON response (Chen He via YARN-1479. Invalid NaN values in Hadoop REST API JSON response (Chen He via

View File

@ -20,7 +20,6 @@
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -35,6 +34,8 @@
import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetApplicationsRequestProto; import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetApplicationsRequestProto;
import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetApplicationsRequestProtoOrBuilder; import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetApplicationsRequestProtoOrBuilder;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.protobuf.TextFormat; import com.google.protobuf.TextFormat;
@Private @Private
@ -49,7 +50,8 @@ public class GetApplicationsRequestPBImpl extends GetApplicationsRequest {
Set<String> users = null; Set<String> users = null;
Set<String> queues = null; Set<String> queues = null;
long limit = Long.MAX_VALUE; long limit = Long.MAX_VALUE;
LongRange start = null, finish = null; LongRange start = null;
LongRange finish = null;
private Set<String> applicationTags; private Set<String> applicationTags;
private ApplicationsRequestScope scope; private ApplicationsRequestScope scope;
@ -78,76 +80,46 @@ private void mergeLocalToProto() {
} }
private void mergeLocalToBuilder() { private void mergeLocalToBuilder() {
if (this.applicationTypes != null) { if (applicationTypes != null && !applicationTypes.isEmpty()) {
addLocalApplicationTypesToProto(); builder.clearApplicationTypes();
builder.addAllApplicationTypes(applicationTypes);
} }
if (this.applicationStates != null) { if (applicationStates != null && !applicationStates.isEmpty()) {
maybeInitBuilder();
builder.clearApplicationStates(); builder.clearApplicationStates();
Iterable<YarnApplicationStateProto> iterable = builder.addAllApplicationStates(Iterables.transform(applicationStates,
new Iterable<YarnApplicationStateProto>() { new Function<YarnApplicationState, YarnApplicationStateProto>() {
@Override @Override
public Iterator<YarnApplicationStateProto> iterator() { public YarnApplicationStateProto apply(YarnApplicationState input) {
return new Iterator<YarnApplicationStateProto>() { return ProtoUtils.convertToProtoFormat(input);
Iterator<YarnApplicationState> iter = applicationStates
.iterator();
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public YarnApplicationStateProto next() {
return ProtoUtils.convertToProtoFormat(iter.next());
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
} }
}; }));
builder.addAllApplicationStates(iterable);
} }
if (this.applicationTags != null && !this.applicationTags.isEmpty()) { if (applicationTags != null && !applicationTags.isEmpty()) {
builder.clearApplicationTags();
builder.addAllApplicationTags(this.applicationTags); builder.addAllApplicationTags(this.applicationTags);
} }
if (this.scope != null) { if (scope != null) {
builder.setScope(ProtoUtils.convertToProtoFormat(scope)); builder.setScope(ProtoUtils.convertToProtoFormat(scope));
} }
if (this.start != null) { if (start != null) {
builder.setStartBegin(start.getMinimumLong()); builder.setStartBegin(start.getMinimumLong());
builder.setStartEnd(start.getMaximumLong()); builder.setStartEnd(start.getMaximumLong());
} }
if (finish != null) {
if (this.finish != null) {
builder.setFinishBegin(finish.getMinimumLong()); builder.setFinishBegin(finish.getMinimumLong());
builder.setFinishEnd(finish.getMaximumLong()); builder.setFinishEnd(finish.getMaximumLong());
} }
if (limit != Long.MAX_VALUE) {
builder.setLimit(limit); builder.setLimit(limit);
if (this.users != null && !this.users.isEmpty()) {
builder.addAllUsers(this.users);
} }
if (users != null && !users.isEmpty()) {
if (this.queues != null && !this.queues.isEmpty()) { builder.clearUsers();
builder.addAllQueues(this.queues); builder.addAllUsers(users);
}
if (queues != null && !queues.isEmpty()) {
builder.clearQueues();
builder.addAllQueues(queues);
} }
}
private void addLocalApplicationTypesToProto() {
maybeInitBuilder();
builder.clearApplicationTypes();
if (this.applicationTypes == null)
return;
builder.addAllApplicationTypes(applicationTypes);
} }
private void maybeInitBuilder() { private void maybeInitBuilder() {

View File

@ -72,6 +72,9 @@ public void testGetApplicationsRequest(){
GetApplicationsRequest requestFromProto = new GetApplicationsRequestPBImpl( GetApplicationsRequest requestFromProto = new GetApplicationsRequestPBImpl(
((GetApplicationsRequestPBImpl)request).getProto()); ((GetApplicationsRequestPBImpl)request).getProto());
// verify the whole record equals with original record
Assert.assertEquals(requestFromProto, request);
// verify all properties are the same as original request // verify all properties are the same as original request
Assert.assertEquals( Assert.assertEquals(
"ApplicationStates from proto is not the same with original request", "ApplicationStates from proto is not the same with original request",