From d7f5d76869391df15107a6c89ba09d741f990182 Mon Sep 17 00:00:00 2001 From: Zhijie Shen Date: Fri, 6 Jun 2014 17:47:03 +0000 Subject: [PATCH] YARN-2118. Fixed the type mismatch in Map#containsKey check of TimelineWebServices#injectOwnerInfo. Contributed by Ted Yu. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1600967 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-yarn-project/CHANGES.txt | 3 ++ .../timeline/webapp/TimelineWebServices.java | 2 +- .../webapp/TestTimelineWebServices.java | 30 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 9e2b71420f..1efb87ea98 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -195,6 +195,9 @@ Release 2.5.0 - UNRELEASED YARN-2119. DEFAULT_PROXY_ADDRESS should use DEFAULT_PROXY_PORT. (Anubhav Dhoot via kasha) + YARN-2118. Fixed the type mismatch in Map#containsKey check of + TimelineWebServices#injectOwnerInfo. (Ted Yu via zjshen) + Release 2.4.1 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/timeline/webapp/TimelineWebServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/timeline/webapp/TimelineWebServices.java index 8c7762dad1..a4e8d58c4c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/timeline/webapp/TimelineWebServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/timeline/webapp/TimelineWebServices.java @@ -519,7 +519,7 @@ private static void injectOwnerInfo(TimelineEntity timelineEntity, String owner) throws YarnException { if (timelineEntity.getPrimaryFilters() != null && timelineEntity.getPrimaryFilters().containsKey( - TimelineStore.SystemFilter.ENTITY_OWNER)) { + TimelineStore.SystemFilter.ENTITY_OWNER.toString())) { throw new YarnException( "User should not use the timeline system filter key: " + TimelineStore.SystemFilter.ENTITY_OWNER); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/timeline/webapp/TestTimelineWebServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/timeline/webapp/TestTimelineWebServices.java index 24cc5ca3c6..832a79a927 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/timeline/webapp/TestTimelineWebServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/timeline/webapp/TestTimelineWebServices.java @@ -21,6 +21,11 @@ import static org.junit.Assert.assertEquals; import java.io.IOException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import javax.inject.Singleton; import javax.servlet.Filter; @@ -39,7 +44,9 @@ import org.apache.hadoop.yarn.api.records.timeline.TimelineEvent; import org.apache.hadoop.yarn.api.records.timeline.TimelineEvents; import org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse; +import org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse.TimelinePutError; import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.security.AdminACLsManager; import org.apache.hadoop.yarn.server.timeline.TestMemoryTimelineStore; import org.apache.hadoop.yarn.server.timeline.TimelineStore; @@ -362,6 +369,29 @@ public void testGetEvents() throws Exception { Assert.assertEquals(0, event2.getEventInfo().size()); } + @Test + public void testPostEntitiesWithPrimaryFilter() throws Exception { + TimelineEntities entities = new TimelineEntities(); + TimelineEntity entity = new TimelineEntity(); + Map> filters = new HashMap>(); + filters.put(TimelineStore.SystemFilter.ENTITY_OWNER.toString(), new HashSet()); + entity.setPrimaryFilters(filters); + entity.setEntityId("test id 6"); + entity.setEntityType("test type 6"); + entity.setStartTime(System.currentTimeMillis()); + entities.addEntity(entity); + WebResource r = resource(); + ClientResponse response = r.path("ws").path("v1").path("timeline") + .accept(MediaType.APPLICATION_JSON) + .type(MediaType.APPLICATION_JSON) + .post(ClientResponse.class, entities); + TimelinePutResponse putResposne = response.getEntity(TimelinePutResponse.class); + Assert.assertEquals(1, putResposne.getErrors().size()); + List errors = putResposne.getErrors(); + Assert.assertEquals(TimelinePutResponse.TimelinePutError.SYSTEM_FILTER_CONFLICT, + errors.get(0).getErrorCode()); + } + @Test public void testPostEntities() throws Exception { TimelineEntities entities = new TimelineEntities();