falcon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From venkat...@apache.org
Subject [1/2] git commit: FALCON-190 Entity list REST API should allow the client to query different fields. Contributed by Haohui Mai
Date Wed, 13 Nov 2013 23:58:14 GMT
Updated Branches:
  refs/heads/master bf63dbf19 -> 9e376c20e


FALCON-190 Entity list REST API should allow the client to query different fields. Contributed
by Haohui Mai


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

Branch: refs/heads/master
Commit: 7de95ad78a0a8b3b2a7e856ba488d2b57a749aed
Parents: bf63dbf
Author: Venkatesh Seetharam <venkatesh@apache.org>
Authored: Wed Nov 13 15:52:23 2013 -0800
Committer: Venkatesh Seetharam <venkatesh@apache.org>
Committed: Wed Nov 13 15:52:23 2013 -0800

----------------------------------------------------------------------
 CHANGES.txt                                     |  3 ++
 .../falcon/resource/AbstractEntityManager.java  | 26 +++++++---
 .../proxy/SchedulableEntityManagerProxy.java    |  5 +-
 .../resource/SchedulableEntityManager.java      |  5 +-
 .../falcon/resource/EntityManagerJerseyIT.java  | 53 ++++++++++++++------
 5 files changed, 64 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/7de95ad7/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 8dfb5b9..226e0f0 100755
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -78,6 +78,9 @@ Trunk (Unreleased)
 
   IMPROVEMENTS
 
+    FALCON-190 Entity list REST API should allow the client to
+    query different fields (Haohui Mai via Venkatesh Seetharam)
+
     FALCON-188 hadoop-2 profile is not carried through to
     oozie package (Haohui Mai via Venkatesh Seetharam)
 

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/7de95ad7/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 c899407..7ec6cd1 100644
--- a/prism/src/main/java/org/apache/falcon/resource/AbstractEntityManager.java
+++ b/prism/src/main/java/org/apache/falcon/resource/AbstractEntityManager.java
@@ -436,9 +436,17 @@ public abstract class AbstractEntityManager {
      * Returns the list of entities registered of a given type.
      *
      * @param type entity type
+     * @param fieldStr fields that the query is interested in, separated by comma
+     *
+     * @param type entity type
      * @return String
      */
-    public EntityList getDependencies(String type) {
+    public EntityList getEntityList(String type, String fieldStr) {
+        HashSet<String> fields = new HashSet<String>(Arrays.asList(fieldStr.split(",")));
+
+        // Currently only the status of the entity is supported
+        boolean requireStatus = fields.contains("status");
+
         try {
             EntityType entityType = EntityType.valueOf(type.toUpperCase());
             final String entityTypeString = type.toLowerCase();
@@ -456,14 +464,16 @@ public abstract class AbstractEntityManager {
                 EntityList.EntityElement elem = new EntityList.EntityElement();
                 elem.name = e.getName();
                 elem.type = entityTypeString;
-                String statusString;
-                try {
-                    EntityStatus status = getStatus(e, entityType);
-                    statusString = status.name();
-                } catch (FalconException e1) {
-                    statusString = "UNKNOWN";
+                if (requireStatus) {
+                    String statusString;
+                    try {
+                        EntityStatus status = getStatus(e, entityType);
+                        statusString = status.name();
+                    } catch (FalconException e1) {
+                        statusString = "UNKNOWN";
+                    }
+                    elem.status = statusString;
                 }
-                elem.status = statusString;
                 elements[i++] = elem;
             }
             return new EntityList(elements);

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/7de95ad7/prism/src/main/java/org/apache/falcon/resource/proxy/SchedulableEntityManagerProxy.java
----------------------------------------------------------------------
diff --git a/prism/src/main/java/org/apache/falcon/resource/proxy/SchedulableEntityManagerProxy.java
b/prism/src/main/java/org/apache/falcon/resource/proxy/SchedulableEntityManagerProxy.java
index 0b6b34a..8ba2a97 100644
--- a/prism/src/main/java/org/apache/falcon/resource/proxy/SchedulableEntityManagerProxy.java
+++ b/prism/src/main/java/org/apache/falcon/resource/proxy/SchedulableEntityManagerProxy.java
@@ -283,8 +283,9 @@ public class SchedulableEntityManagerProxy extends AbstractSchedulableEntityMana
     @Path("list/{type}")
     @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
     @Override
-    public EntityList getDependencies(@PathParam("type") String type) {
-        return super.getDependencies(type);
+    public EntityList getEntityList(@PathParam("type") String type,
+                                    @DefaultValue("") @QueryParam("fields") String fields)
{
+        return super.getEntityList(type, fields);
     }
 
     @GET

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/7de95ad7/webapp/src/main/java/org/apache/falcon/resource/SchedulableEntityManager.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/falcon/resource/SchedulableEntityManager.java
b/webapp/src/main/java/org/apache/falcon/resource/SchedulableEntityManager.java
index b17dcc8..3c9078d 100644
--- a/webapp/src/main/java/org/apache/falcon/resource/SchedulableEntityManager.java
+++ b/webapp/src/main/java/org/apache/falcon/resource/SchedulableEntityManager.java
@@ -58,8 +58,9 @@ public class SchedulableEntityManager extends AbstractSchedulableEntityManager
{
     @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
     @Monitored(event = "dependencies")
     @Override
-    public EntityList getDependencies(@Dimension("type") @PathParam("type") String type)
{
-        return super.getDependencies(type);
+    public EntityList getEntityList(@Dimension("type") @PathParam("type") String type,
+                                    @DefaultValue("") @QueryParam("fields") String fields)
{
+        return super.getEntityList(type, fields);
     }
 
     @GET

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/7de95ad7/webapp/src/test/java/org/apache/falcon/resource/EntityManagerJerseyIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/falcon/resource/EntityManagerJerseyIT.java b/webapp/src/test/java/org/apache/falcon/resource/EntityManagerJerseyIT.java
index 767ff4b..cb2fcbb 100644
--- a/webapp/src/test/java/org/apache/falcon/resource/EntityManagerJerseyIT.java
+++ b/webapp/src/test/java/org/apache/falcon/resource/EntityManagerJerseyIT.java
@@ -79,7 +79,7 @@ public class EntityManagerJerseyIT {
     public void testLibExtensions() throws Exception {
         TestContext context = newContext();
         Map<String, String> overlay = context.getUniqueOverlay();
-        ClientResponse response = context.submitToFalcon(context.CLUSTER_TEMPLATE, overlay,
EntityType.CLUSTER);
+        ClientResponse response = context.submitToFalcon(TestContext.CLUSTER_TEMPLATE, overlay,
EntityType.CLUSTER);
         context.assertSuccessful(response);
         FileSystem fs = context.getCluster().getFileSystem();
         assertLibs(fs, new Path("/project/falcon/working/libext/FEED/retention"));
@@ -296,7 +296,7 @@ public class EntityManagerJerseyIT {
         ClientResponse response;
         Map<String, String> overlay = context.getUniqueOverlay();
 
-        response = context.submitToFalcon(context.CLUSTER_TEMPLATE, overlay, EntityType.CLUSTER);
+        response = context.submitToFalcon(TestContext.CLUSTER_TEMPLATE, overlay, EntityType.CLUSTER);
         context.assertSuccessful(response);
 
         response = context.submitToFalcon(TestContext.FEED_TEMPLATE1, overlay, EntityType.FEED);
@@ -319,10 +319,10 @@ public class EntityManagerJerseyIT {
         ClientResponse response;
         Map<String, String> overlay = context.getUniqueOverlay();
 
-        response = context.submitToFalcon(context.CLUSTER_TEMPLATE, overlay, EntityType.CLUSTER);
+        response = context.submitToFalcon(TestContext.CLUSTER_TEMPLATE, overlay, EntityType.CLUSTER);
         context.assertSuccessful(response);
 
-        response = context.submitToFalcon(context.CLUSTER_TEMPLATE, overlay, EntityType.CLUSTER);
+        response = context.submitToFalcon(TestContext.CLUSTER_TEMPLATE, overlay, EntityType.CLUSTER);
         context.assertSuccessful(response);
     }
 
@@ -382,7 +382,7 @@ public class EntityManagerJerseyIT {
         Map<String, String> overlay = context.getUniqueOverlay();
 
         InputStream stream = context.getServletInputStream(
-                context.overlayParametersOverTemplate(context.CLUSTER_TEMPLATE, overlay));
+                context.overlayParametersOverTemplate(TestContext.CLUSTER_TEMPLATE, overlay));
 
         clientRepsonse = context.service.path("api/entities/validate/cluster")
                 .accept(MediaType.TEXT_XML).type(MediaType.TEXT_XML)
@@ -397,7 +397,7 @@ public class EntityManagerJerseyIT {
         ClientResponse clientRepsonse;
         Map<String, String> overlay = context.getUniqueOverlay();
 
-        clientRepsonse = context.submitToFalcon(context.CLUSTER_TEMPLATE, overlay,
+        clientRepsonse = context.submitToFalcon(TestContext.CLUSTER_TEMPLATE, overlay,
                 EntityType.CLUSTER);
         context.assertSuccessful(clientRepsonse);
 
@@ -435,7 +435,7 @@ public class EntityManagerJerseyIT {
         ClientResponse response;
         Map<String, String> overlay = context.getUniqueOverlay();
 
-        response = context.submitToFalcon(context.CLUSTER_TEMPLATE, overlay, EntityType.CLUSTER);
+        response = context.submitToFalcon(TestContext.CLUSTER_TEMPLATE, overlay, EntityType.CLUSTER);
         context.assertSuccessful(response);
 
         response = context.submitToFalcon(TestContext.FEED_TEMPLATE1, overlay, EntityType.FEED);
@@ -454,7 +454,7 @@ public class EntityManagerJerseyIT {
         ClientResponse response;
         Map<String, String> overlay = context.getUniqueOverlay();
 
-        response = context.submitToFalcon(context.CLUSTER_TEMPLATE, overlay, EntityType.CLUSTER);
+        response = context.submitToFalcon(TestContext.CLUSTER_TEMPLATE, overlay, EntityType.CLUSTER);
         context.assertSuccessful(response);
 
         response = context.submitToFalcon(TestContext.FEED_TEMPLATE1, overlay, EntityType.FEED);
@@ -509,7 +509,7 @@ public class EntityManagerJerseyIT {
         ClientResponse response;
         Map<String, String> overlay = context.getUniqueOverlay();
 
-        response = context.submitToFalcon(context.CLUSTER_TEMPLATE, overlay, EntityType.CLUSTER);
+        response = context.submitToFalcon(TestContext.CLUSTER_TEMPLATE, overlay, EntityType.CLUSTER);
         context.assertSuccessful(response);
 
         response = context.submitToFalcon(TestContext.FEED_TEMPLATE1, overlay, EntityType.FEED);
@@ -580,7 +580,7 @@ public class EntityManagerJerseyIT {
         ClientResponse response;
         Map<String, String> overlay = context.getUniqueOverlay();
 
-        response = context.submitToFalcon(context.CLUSTER_TEMPLATE, overlay, EntityType.CLUSTER);
+        response = context.submitToFalcon(TestContext.CLUSTER_TEMPLATE, overlay, EntityType.CLUSTER);
         context.assertSuccessful(response);
 
         response = context.submitToFalcon(TestContext.FEED_TEMPLATE1, overlay, EntityType.FEED);
@@ -599,7 +599,7 @@ public class EntityManagerJerseyIT {
         ClientResponse response;
         Map<String, String> overlay = context.getUniqueOverlay();
 
-        response = context.submitToFalcon(context.CLUSTER_TEMPLATE, overlay, EntityType.CLUSTER);
+        response = context.submitToFalcon(TestContext.CLUSTER_TEMPLATE, overlay, EntityType.CLUSTER);
         context.assertSuccessful(response);
 
         response = context.submitToFalcon(TestContext.FEED_TEMPLATE1, overlay, EntityType.FEED);
@@ -650,7 +650,7 @@ public class EntityManagerJerseyIT {
     }
 
     @Test
-    public void testGetDependencies() throws Exception {
+    public void testGetEntityList() throws Exception {
         TestContext context = newContext();
         ClientResponse response;
         response = context.service
@@ -660,14 +660,35 @@ public class EntityManagerJerseyIT {
         Assert.assertEquals(response.getStatus(), 200);
 
         Map<String, String> overlay = context.getUniqueOverlay();
-
-        response = context.submitToFalcon(context.CLUSTER_TEMPLATE, overlay, EntityType.CLUSTER);
+        overlay.put("cluster", "WTF-" + overlay.get("cluster"));
+        response = context.submitToFalcon(TestContext.CLUSTER_TEMPLATE, overlay, EntityType.CLUSTER);
         context.assertSuccessful(response);
 
         response = context.service
                 .path("api/entities/list/cluster/")
-                .header("Remote-User", TestContext.REMOTE_USER).type(MediaType.TEXT_XML)
-                .accept(MediaType.TEXT_XML).get(ClientResponse.class);
+                .header("Remote-User", TestContext.REMOTE_USER)
+                .type(MediaType.TEXT_XML)
+                .accept(MediaType.TEXT_XML)
+                .get(ClientResponse.class);
         Assert.assertEquals(response.getStatus(), 200);
+        EntityList result = response.getEntity(EntityList.class);
+        Assert.assertNotNull(result);
+        for (EntityList.EntityElement entityElement : result.getElements()) {
+            Assert.assertNull(entityElement.status); // status is null
+        }
+
+        response = context.service
+                .path("api/entities/list/cluster/")
+                .queryParam("fields", "status")
+                .header("Remote-User", TestContext.REMOTE_USER)
+                .type(MediaType.APPLICATION_JSON)
+                .accept(MediaType.APPLICATION_JSON)
+                .get(ClientResponse.class);
+        Assert.assertEquals(response.getStatus(), 200);
+        result = response.getEntity(EntityList.class);
+        Assert.assertNotNull(result);
+        for (EntityList.EntityElement entityElement : result.getElements()) {
+            Assert.assertNotNull(entityElement.status); // status is null
+        }
     }
 }


Mime
View raw message