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
jianhe)
YARN-2088. Fixed a bug in GetApplicationsRequestPBImpl#mergeLocalToBuilder.
(Binglin Chang via jianhe)
IMPROVEMENTS
YARN-1479. Invalid NaN values in Hadoop REST API JSON response (Chen He via

View File

@ -20,7 +20,6 @@ package org.apache.hadoop.yarn.api.protocolrecords.impl.pb;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@ -35,6 +34,8 @@ import org.apache.hadoop.yarn.proto.YarnProtos.YarnApplicationStateProto;
import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetApplicationsRequestProto;
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;
@Private
@ -49,7 +50,8 @@ public class GetApplicationsRequestPBImpl extends GetApplicationsRequest {
Set<String> users = null;
Set<String> queues = null;
long limit = Long.MAX_VALUE;
LongRange start = null, finish = null;
LongRange start = null;
LongRange finish = null;
private Set<String> applicationTags;
private ApplicationsRequestScope scope;
@ -78,76 +80,46 @@ public class GetApplicationsRequestPBImpl extends GetApplicationsRequest {
}
private void mergeLocalToBuilder() {
if (this.applicationTypes != null) {
addLocalApplicationTypesToProto();
if (applicationTypes != null && !applicationTypes.isEmpty()) {
builder.clearApplicationTypes();
builder.addAllApplicationTypes(applicationTypes);
}
if (this.applicationStates != null) {
maybeInitBuilder();
if (applicationStates != null && !applicationStates.isEmpty()) {
builder.clearApplicationStates();
Iterable<YarnApplicationStateProto> iterable =
new Iterable<YarnApplicationStateProto>() {
builder.addAllApplicationStates(Iterables.transform(applicationStates,
new Function<YarnApplicationState, YarnApplicationStateProto>() {
@Override
public Iterator<YarnApplicationStateProto> iterator() {
return new Iterator<YarnApplicationStateProto>() {
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();
}
};
public YarnApplicationStateProto apply(YarnApplicationState input) {
return ProtoUtils.convertToProtoFormat(input);
}
};
builder.addAllApplicationStates(iterable);
}));
}
if (this.applicationTags != null && !this.applicationTags.isEmpty()) {
if (applicationTags != null && !applicationTags.isEmpty()) {
builder.clearApplicationTags();
builder.addAllApplicationTags(this.applicationTags);
}
if (this.scope != null) {
if (scope != null) {
builder.setScope(ProtoUtils.convertToProtoFormat(scope));
}
if (this.start != null) {
if (start != null) {
builder.setStartBegin(start.getMinimumLong());
builder.setStartEnd(start.getMaximumLong());
}
if (this.finish != null) {
if (finish != null) {
builder.setFinishBegin(finish.getMinimumLong());
builder.setFinishEnd(finish.getMaximumLong());
}
builder.setLimit(limit);
if (this.users != null && !this.users.isEmpty()) {
builder.addAllUsers(this.users);
if (limit != Long.MAX_VALUE) {
builder.setLimit(limit);
}
if (this.queues != null && !this.queues.isEmpty()) {
builder.addAllQueues(this.queues);
if (users != null && !users.isEmpty()) {
builder.clearUsers();
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() {

View File

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