From 634485191ed024882cdce0cc081cc3fbe53e7bd9 Mon Sep 17 00:00:00 2001 From: Jian He Date: Mon, 12 May 2014 20:48:23 +0000 Subject: [PATCH] Merge r1594085 from trunk. YARN-2016. Fix a bug in GetApplicationsRequestPBImpl to add the missed fields to proto. Contributed by Junping Du git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1594086 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-yarn-project/CHANGES.txt | 3 + .../impl/pb/GetApplicationsRequestPBImpl.java | 21 +++- .../yarn/api/TestGetApplicationsRequest.java | 107 ++++++++++++++++++ 3 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestGetApplicationsRequest.java diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 39b9942062a..75721329b87 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -90,6 +90,9 @@ Release 2.5.0 - UNRELEASED YARN-1975. Fix yarn application CLI to print the scheme of the tracking url of failed/killed applications. (Junping Du via jianhe) + YARN-2016. Fix a bug in GetApplicationsRequestPBImpl to add the missed fields + to proto. (Junping Du via jianhe) + Release 2.4.1 - UNRELEASED INCOMPATIBLE CHANGES 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 733f19f715d..918b8757004 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 @@ -121,6 +121,25 @@ public void remove() { if (this.scope != null) { builder.setScope(ProtoUtils.convertToProtoFormat(scope)); } + if (this.start != null) { + builder.setStartBegin(start.getMinimumLong()); + builder.setStartEnd(start.getMaximumLong()); + } + + if (this.finish != null) { + builder.setFinishBegin(start.getMinimumLong()); + builder.setFinishEnd(start.getMaximumLong()); + } + + builder.setLimit(limit); + + if (this.users != null && !this.users.isEmpty()) { + builder.addAllUsers(this.users); + } + + if (this.queues != null && !this.queues.isEmpty()) { + builder.addAllQueues(this.queues); + } } private void addLocalApplicationTypesToProto() { @@ -326,7 +345,7 @@ public void setLimit(long limit) { public LongRange getStartRange() { if (this.start == null) { GetApplicationsRequestProtoOrBuilder p = viaProto ? proto: builder; - if (p.hasStartBegin() || p.hasFinishBegin()) { + if (p.hasStartBegin() || p.hasStartEnd()) { long begin = p.hasStartBegin() ? p.getStartBegin() : 0L; long end = p.hasStartEnd() ? p.getStartEnd() : Long.MAX_VALUE; this.start = new LongRange(begin, end); 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 new file mode 100644 index 00000000000..67e885ea23c --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/TestGetApplicationsRequest.java @@ -0,0 +1,107 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.yarn.api; + +import java.util.EnumSet; +import java.util.HashSet; +import java.util.Set; + +import org.apache.commons.lang.math.LongRange; +import org.apache.hadoop.yarn.api.protocolrecords.ApplicationsRequestScope; +import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest; +import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.GetApplicationsRequestPBImpl; +import org.apache.hadoop.yarn.api.records.YarnApplicationState; +import org.junit.Assert; +import org.junit.Test; + +public class TestGetApplicationsRequest { + + @Test + public void testGetApplicationsRequest(){ + GetApplicationsRequest request = GetApplicationsRequest.newInstance(); + + EnumSet appStates = + EnumSet.of(YarnApplicationState.ACCEPTED); + request.setApplicationStates(appStates); + + Set tags = new HashSet(); + tags.add("tag1"); + request.setApplicationTags(tags); + + Set types = new HashSet(); + types.add("type1"); + request.setApplicationTypes(types); + + long begin = System.currentTimeMillis(); + long end = System.currentTimeMillis() + 1; + request.setStartRange(begin, end); + request.setFinishRange(begin, end); + + long limit = 100L; + request.setLimit(limit); + + Set queues = new HashSet(); + queues.add("queue1"); + request.setQueues(queues); + + + Set users = new HashSet(); + users.add("user1"); + request.setUsers(users); + + ApplicationsRequestScope scope = ApplicationsRequestScope.ALL; + request.setScope(scope); + + GetApplicationsRequest requestFromProto = new GetApplicationsRequestPBImpl( + ((GetApplicationsRequestPBImpl)request).getProto()); + + // verify all properties are the same as original request + Assert.assertEquals( + "ApplicationStates from proto is not the same with original request", + requestFromProto.getApplicationStates(), appStates); + + Assert.assertEquals( + "ApplicationTags from proto is not the same with original request", + requestFromProto.getApplicationTags(), tags); + + Assert.assertEquals( + "ApplicationTypes from proto is not the same with original request", + requestFromProto.getApplicationTypes(), types); + + Assert.assertEquals( + "StartRange from proto is not the same with original request", + requestFromProto.getStartRange(), new LongRange(begin, end)); + + Assert.assertEquals( + "FinishRange from proto is not the same with original request", + requestFromProto.getFinishRange(), new LongRange(begin, end)); + + Assert.assertEquals( + "Limit from proto is not the same with original request", + requestFromProto.getLimit(), limit); + + Assert.assertEquals( + "Queues from proto is not the same with original request", + requestFromProto.getQueues(), queues); + + Assert.assertEquals( + "Users from proto is not the same with original request", + requestFromProto.getUsers(), users); + } + +}