falcon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From venkat...@apache.org
Subject [5/5] incubator-falcon git commit: FALCON-875 Enitiy Summary endpoint filterBy does not filter entities without pipelines. Contributed by Balu Vellanki
Date Sat, 08 Nov 2014 05:32:39 GMT
FALCON-875 Enitiy Summary endpoint filterBy does not filter entities without pipelines. Contributed
by Balu Vellanki


Project: http://git-wip-us.apache.org/repos/asf/incubator-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-falcon/commit/394055a5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-falcon/tree/394055a5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-falcon/diff/394055a5

Branch: refs/heads/master
Commit: 394055a544dc3dddf20469f3f9b2c1ee53a208bb
Parents: 2186a36
Author: Venkatesh Seetharam <venkatesh@apache.org>
Authored: Fri Nov 7 21:32:33 2014 -0800
Committer: Venkatesh Seetharam <venkatesh@apache.org>
Committed: Fri Nov 7 21:33:26 2014 -0800

----------------------------------------------------------------------
 CHANGES.txt                                     |  3 +
 .../falcon/resource/AbstractEntityManager.java  | 68 ++++++++++++--------
 .../falcon/resource/EntityManagerTest.java      | 27 +++++---
 3 files changed, 61 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/394055a5/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index d2ca59f..5de597e 100755
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -129,6 +129,9 @@ Trunk (Unreleased)
   OPTIMIZATIONS
 
   BUG FIXES
+   FALCON-875 Enitiy Summary endpoint filterBy does not filter entities
+   without pipelines (Balu Vellanki via Venkatesh Seetharam)
+
    FALCON-874 Rest API - Instance and Entity orderBy param values should be
    case insensitive (Balu Vellanki via Venkatesh Seetharam)
 

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/394055a5/prism/src/main/java/org/apache/falcon/resource/AbstractEntityManager.java
----------------------------------------------------------------------
diff --git a/prism/src/main/java/org/apache/falcon/resource/AbstractEntityManager.java b/prism/src/main/java/org/apache/falcon/resource/AbstractEntityManager.java
index ceacb4e..7fce88c 100644
--- a/prism/src/main/java/org/apache/falcon/resource/AbstractEntityManager.java
+++ b/prism/src/main/java/org/apache/falcon/resource/AbstractEntityManager.java
@@ -672,10 +672,8 @@ public abstract class AbstractEntityManager {
     private boolean filterEntity(Entity entity, String entityStatus,
                                  Map<String, String> filterByFieldsValues, List<String>
filterByTags,
                                  List<String> tags, List<String> pipelines) {
-        return !((filterByTags.isEmpty() || !filterEntityByTags(filterByTags, tags))
-                && (filterByFieldsValues.isEmpty()
-                || !filterEntityByFields(entity, filterByFieldsValues, entityStatus, pipelines)));
-
+        return filterEntityByTags(filterByTags, tags)
+                || filterEntityByFields(entity, filterByFieldsValues, entityStatus, pipelines);
     }
 
     protected boolean isEntityAuthorized(Entity entity) {
@@ -693,51 +691,65 @@ public abstract class AbstractEntityManager {
     }
 
     private boolean filterEntityByTags(List<String> filterTagsList, List<String>
tags) {
-        boolean filterEntity = false;
-        if (!filterTagsList.isEmpty() && tags.isEmpty()) {
+        if (filterTagsList.isEmpty()) {
+            return false;
+        } else if (tags.isEmpty()) {
             return true;
         }
+
         for (String tag : filterTagsList) {
             if (!tags.contains(tag)) {
-                filterEntity = true;
-                break;
+                return true;
             }
         }
 
-        return filterEntity;
+        return false;
     }
 
     private boolean filterEntityByFields(Entity entity, Map<String, String> filterKeyVals,
                                          String status, List<String> pipelines) {
+        if (filterKeyVals.isEmpty()) {
+            return false;
+        }
+
         for (Map.Entry<String, String> pair : filterKeyVals.entrySet()) {
-            String filterValue = pair.getValue();
-            if (StringUtils.isEmpty(filterValue)) {
-                continue; // nothing to filter
-            }
             EntityList.EntityFilterByFields filter =
                     EntityList.EntityFilterByFields.valueOf(pair.getKey().toUpperCase());
-            switch (filter) {
-
-            case TYPE:
-                return !entity.getEntityType().toString().equalsIgnoreCase(filterValue);
+            if (isEntityFiltered(entity, filter, pair, status, pipelines)) {
+                return true;
+            }
+        }
 
-            case NAME:
-                return !entity.getName().equalsIgnoreCase(filterValue);
+        return false;
+    }
 
-            case STATUS:
-                return  !status.equalsIgnoreCase(filterValue);
+    private boolean isEntityFiltered(Entity entity, EntityList.EntityFilterByFields filter,
+                                     Map.Entry<String, String> pair,
+                                     String status, List<String> pipelines) {
+        switch (filter) {
+        case TYPE:
+            return !entity.getEntityType().toString().equalsIgnoreCase(pair.getValue());
 
-            case PIPELINES:
-                return  entity.getEntityType().equals(EntityType.PROCESS) && !pipelines.contains(filterValue);
+        case NAME:
+            return !entity.getName().equalsIgnoreCase(pair.getValue());
 
-            case CLUSTER:
-                return  !EntityUtil.getClustersDefined(entity).contains(filterValue);
+        case STATUS:
+            return !status.equalsIgnoreCase(pair.getValue());
 
-            default:
-                break;
+        case PIPELINES:
+            if (!entity.getEntityType().equals(EntityType.PROCESS)) {
+                throw FalconWebException.newException(
+                        "Invalid filterBy key for non process entities " + pair.getKey(),
+                        Response.Status.BAD_REQUEST);
             }
+            return !pipelines.contains(pair.getValue());
+
+        case CLUSTER:
+            return !EntityUtil.getClustersDefined(entity).contains(pair.getValue());
+
+        default:
+            return false;
         }
-        return false;
     }
 
     private List<Entity> sortEntities(List<Entity> entities, String orderBy,
String sortOrder) {

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/394055a5/prism/src/test/java/org/apache/falcon/resource/EntityManagerTest.java
----------------------------------------------------------------------
diff --git a/prism/src/test/java/org/apache/falcon/resource/EntityManagerTest.java b/prism/src/test/java/org/apache/falcon/resource/EntityManagerTest.java
index 2244e5f..e39947a 100644
--- a/prism/src/test/java/org/apache/falcon/resource/EntityManagerTest.java
+++ b/prism/src/test/java/org/apache/falcon/resource/EntityManagerTest.java
@@ -17,6 +17,7 @@
  */
 package org.apache.falcon.resource;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.falcon.FalconWebException;
 import org.apache.falcon.entity.v0.Entity;
 import org.apache.falcon.entity.v0.EntityType;
@@ -173,19 +174,19 @@ public class EntityManagerTest extends AbstractEntityManager {
                 "testPipeline,dataReplicationPipeline");
         configStore.publish(EntityType.PROCESS, process2);
 
-        Entity process3 = buildProcess("process3", user, "consumer=consumer@xyz.com", "testPipeline");
+        Entity process3 = buildProcess("process3", user, "", "testPipeline");
         configStore.publish(EntityType.PROCESS, process3);
 
-        Entity process4 = buildProcess("process4", user, "owner=producer@xyz.com", "dataReplicationPipeline");
+        Entity process4 = buildProcess("process4", user, "owner=producer@xyz.com", "");
         configStore.publish(EntityType.PROCESS, process4);
 
         EntityList entityList = this.getEntityList("process", "tags", "PIPELINES:dataReplicationPipeline",
-                "", "name", "desc", 1, 2);
+                "", "name", "desc", 1, 1);
         Assert.assertNotNull(entityList.getElements());
-        Assert.assertEquals(entityList.getElements().length, 2);
-        Assert.assertEquals(entityList.getElements()[1].name, "process1");
-        Assert.assertEquals(entityList.getElements()[1].tag.size(), 2);
-        Assert.assertEquals(entityList.getElements()[1].tag.get(0), "consumer=consumer@xyz.com");
+        Assert.assertEquals(entityList.getElements().length, 1);
+        Assert.assertEquals(entityList.getElements()[0].name, "process1");
+        Assert.assertEquals(entityList.getElements()[0].tag.size(), 2);
+        Assert.assertEquals(entityList.getElements()[0].tag.get(0), "consumer=consumer@xyz.com");
         Assert.assertEquals(entityList.getElements()[0].status, null);
 
 
@@ -202,6 +203,10 @@ public class EntityManagerTest extends AbstractEntityManager {
                 "consumer=consumer@xyz.com, owner=producer@xyz.com", "name", "", 10, 2);
         Assert.assertEquals(entityList.getElements().length, 0);
 
+        entityList = this.getEntityList("process", "pipelines", "",
+                "owner=producer@xyz.com", "name", "", 1, 2);
+        Assert.assertEquals(entityList.getElements().length, 2);
+
         // Test negative value for numResults, should throw an exception.
         try {
             this.getEntityList("process", "pipelines", "",
@@ -230,8 +235,12 @@ public class EntityManagerTest extends AbstractEntityManager {
         Process process = new Process();
         process.setName(name);
         process.setACL(acl);
-        process.setPipelines(pipelines);
-        process.setTags(tags);
+        if (!StringUtils.isEmpty(pipelines)) {
+            process.setPipelines(pipelines);
+        }
+        if (!StringUtils.isEmpty(tags)) {
+            process.setTags(tags);
+        }
         process.setClusters(buildClusters("cluster" + name));
         return process;
     }


Mime
View raw message