diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index fef8cca3b2f..0d3b33086cd 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -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 diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/impl/pb/GetApplicationsRequestPBImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/impl/pb/GetApplicationsRequestPBImpl.java index cd58f711f9c..4fd49bcee8d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/impl/pb/GetApplicationsRequestPBImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/protocolrecords/impl/pb/GetApplicationsRequestPBImpl.java @@ -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 users = null; Set queues = null; long limit = Long.MAX_VALUE; - LongRange start = null, finish = null; + LongRange start = null; + LongRange finish = null; private Set 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 iterable = - new Iterable() { - + builder.addAllApplicationStates(Iterables.transform(applicationStates, + new Function() { @Override - public Iterator iterator() { - return new Iterator() { - - Iterator 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() { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestGetApplicationsRequest.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestGetApplicationsRequest.java index 3b95d87f3fb..3d95a0fb573 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestGetApplicationsRequest.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestGetApplicationsRequest.java @@ -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",