falcon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From venkat...@apache.org
Subject [3/3] git commit: FALCON-859 EntitySummary RestAPI : Change pathParam "cluster" to queryParam. Contributed by Balu Vellanki
Date Tue, 04 Nov 2014 00:57:09 GMT
FALCON-859 EntitySummary RestAPI : Change pathParam "cluster" to queryParam. 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/aace8f48
Tree: http://git-wip-us.apache.org/repos/asf/incubator-falcon/tree/aace8f48
Diff: http://git-wip-us.apache.org/repos/asf/incubator-falcon/diff/aace8f48

Branch: refs/heads/master
Commit: aace8f4844efffe395dc1c27dd7e9c827b43d718
Parents: 0fbcd72
Author: Venkatesh Seetharam <venkatesh@apache.org>
Authored: Mon Nov 3 16:17:19 2014 -0800
Committer: Venkatesh Seetharam <venkatesh@apache.org>
Committed: Mon Nov 3 16:17:19 2014 -0800

----------------------------------------------------------------------
 CHANGES.txt                                     |  3 ++
 .../java/org/apache/falcon/cli/FalconCLI.java   | 16 +++++++++--
 .../org/apache/falcon/client/FalconClient.java  |  8 ++----
 .../security/DefaultAuthorizationProvider.java  |  3 --
 docs/src/site/twiki/FalconCLI.twiki             |  2 +-
 docs/src/site/twiki/restapi/EntitySummary.twiki |  8 +++---
 .../AbstractSchedulableEntityManager.java       | 10 +++++++
 .../proxy/SchedulableEntityManagerProxy.java    |  4 +--
 .../security/FalconAuthorizationFilter.java     | 29 +++++++++++++-------
 .../resource/SchedulableEntityManager.java      |  4 +--
 .../EntityManagerPaginationJerseyIT.java        |  3 +-
 11 files changed, 59 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/aace8f48/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 610fd49..6cc4a35 100755
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -125,6 +125,9 @@ Trunk (Unreleased)
   OPTIMIZATIONS
 
   BUG FIXES
+   FALCON-859 EntitySummary RestAPI : Change pathParam "cluster" to queryParam
+   (Balu Vellanki via Venkatesh Seetharam)
+
    FALCON-858 entity/instance Rest API - make keys for filterBy param case
    insensitive (Balu Vellanki via Venkatesh Seetharam)
 

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/aace8f48/client/src/main/java/org/apache/falcon/cli/FalconCLI.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/falcon/cli/FalconCLI.java b/client/src/main/java/org/apache/falcon/cli/FalconCLI.java
index 01f3480..f85f53c 100644
--- a/client/src/main/java/org/apache/falcon/cli/FalconCLI.java
+++ b/client/src/main/java/org/apache/falcon/cli/FalconCLI.java
@@ -29,6 +29,7 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.falcon.LifeCycle;
 import org.apache.falcon.client.FalconCLIException;
 import org.apache.falcon.client.FalconClient;
+import org.apache.falcon.entity.v0.EntityType;
 import org.apache.falcon.entity.v0.SchemaHelper;
 import org.apache.falcon.resource.EntityList;
 import org.apache.falcon.resource.InstancesResult;
@@ -36,13 +37,13 @@ import org.apache.falcon.resource.InstancesResult;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Properties;
 import java.util.Set;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.concurrent.atomic.AtomicReference;
 
 /**
@@ -412,6 +413,7 @@ public class FalconCLI {
                     filterTags, orderBy, sortOrder, offset, numResults);
             result = entityList != null ? entityList.toString() : "No entity of type (" +
entityType + ") found.";
         }  else if (optionsList.contains(SUMMARY_OPT)) {
+            validateEntityTypeForSummary(entityType);
             validateNotEmpty(cluster, CLUSTER_OPT);
             validateEntityFields(fields);
             validateFilterBy(filterBy, entityAction);
@@ -426,6 +428,14 @@ public class FalconCLI {
         OUT.get().println(result);
     }
 
+    private void validateEntityTypeForSummary(String type) throws FalconCLIException {
+        EntityType entityType = EntityType.valueOf(type.toUpperCase());
+        if (!entityType.isSchedulable()) {
+            throw new FalconCLIException("Invalid entity type " + entityType
+                    + " for EntitySummary API. Valid options are feed or process");
+        }
+    }
+
     private void validateNotEmpty(String paramVal, String paramName) throws FalconCLIException
{
         if (StringUtils.isEmpty(paramVal)) {
             throw new FalconCLIException("Missing argument : " + paramName);

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/aace8f48/client/src/main/java/org/apache/falcon/client/FalconClient.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/falcon/client/FalconClient.java b/client/src/main/java/org/apache/falcon/client/FalconClient.java
index 4872140..6aeb59b 100644
--- a/client/src/main/java/org/apache/falcon/client/FalconClient.java
+++ b/client/src/main/java/org/apache/falcon/client/FalconClient.java
@@ -632,11 +632,9 @@ public class FalconClient {
                                             String fields, String filterBy, String filterTags,
                                             String orderBy, String sortOrder, Integer offset,
Integer numResults,
                                             Integer numInstances) throws FalconCLIException
{
-        WebResource resource;
-        if (StringUtils.isEmpty(cluster)) {
-            resource = service.path(entities.path).path(entityType);
-        } else {
-            resource = service.path(entities.path).path(entityType).path(cluster);
+        WebResource resource = service.path(entities.path).path(entityType);
+        if (!StringUtils.isEmpty(cluster)) {
+            resource = resource.queryParam("cluster", cluster);
         }
 
         resource = addParamsToResource(resource, start, end, null, null,

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/aace8f48/common/src/main/java/org/apache/falcon/security/DefaultAuthorizationProvider.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/falcon/security/DefaultAuthorizationProvider.java
b/common/src/main/java/org/apache/falcon/security/DefaultAuthorizationProvider.java
index 50e4e78..e7895f8 100644
--- a/common/src/main/java/org/apache/falcon/security/DefaultAuthorizationProvider.java
+++ b/common/src/main/java/org/apache/falcon/security/DefaultAuthorizationProvider.java
@@ -122,9 +122,6 @@ public class DefaultAuthorizationProvider implements AuthorizationProvider
{
         Validate.isTrue(RESOURCES.contains(resource), "Illegal resource: " + resource);
         Validate.notEmpty(action, "Action cannot be empty or null");
 
-        LOG.info("Authorizing authenticatedUser={}, against resource={}, action={}, entity
name={}, "
-                + "entity type={}", proxyUgi.getShortUserName(), resource, action, entityName,
entityType);
-
         if (isSuperUser(proxyUgi)) {
             return;
         }

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/aace8f48/docs/src/site/twiki/FalconCLI.twiki
----------------------------------------------------------------------
diff --git a/docs/src/site/twiki/FalconCLI.twiki b/docs/src/site/twiki/FalconCLI.twiki
index e5b2585..6470c0a 100644
--- a/docs/src/site/twiki/FalconCLI.twiki
+++ b/docs/src/site/twiki/FalconCLI.twiki
@@ -61,7 +61,7 @@ Optional Args : -fields <<field1,field2>> -filterBy <<field1:value1,field2:value
 Summary of entities of a particular type and a cluster will be listed. Entity summary has
N most recent instances of entity.
 
 Usage:
-$FALCON_HOME/bin/falcon entity -type [cluster|feed|process] -summary
+$FALCON_HOME/bin/falcon entity -type [feed|process] -summary
 
 Optional Args : -start "yyyy-MM-dd'T'HH:mm'Z'" -end "yyyy-MM-dd'T'HH:mm'Z'" -fields <<field1,field2>>
 -filterBy <<field1:value1,field2:value2>> -tags <<tagkey=tagvalue,tagkey=tagvalue>>

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/aace8f48/docs/src/site/twiki/restapi/EntitySummary.twiki
----------------------------------------------------------------------
diff --git a/docs/src/site/twiki/restapi/EntitySummary.twiki b/docs/src/site/twiki/restapi/EntitySummary.twiki
index f002d81..8e05a12 100644
--- a/docs/src/site/twiki/restapi/EntitySummary.twiki
+++ b/docs/src/site/twiki/restapi/EntitySummary.twiki
@@ -1,4 +1,4 @@
----++  GET /api/entities/summary/:entity-type/:cluster
+---++  GET /api/entities/summary/:entity-type
    * <a href="#Description">Description</a>
    * <a href="#Parameters">Parameters</a>
    * <a href="#Results">Results</a>
@@ -8,8 +8,8 @@
 Given an EntityType and cluster, get list of entities along with summary of N recent instances
of each entity
 
 ---++ Parameters
-   * :entity-type Valid options are cluster, feed or process.
-   * :cluster Show entities that belong to this cluster.
+   * :entity-type Valid options are feed or process.
+   * cluster Show entities that belong to this cluster.
    * start <optional param> Show entity summaries from this date. Date format is yyyy-MM-dd'T'HH:mm'Z'.
       * By default, it is set to (end - 2 days).
    * end <optional param> Show entity summary up to this date. Date format is yyyy-MM-dd'T'HH:mm'Z'.
@@ -34,7 +34,7 @@ Show entities along with summary of N instances for each entity.
 ---++ Examples
 ---+++ Rest Call
 <verbatim>
-GET http://localhost:15000/api/entities/summary/feed/primary-cluster?filterBy=STATUS:RUNNING&fields=status&tags=consumer=consumer@xyz.com&orderBy=name&offset=0&numResults=1&numInstances=2
+GET http://localhost:15000/api/entities/summary/feed?cluster=primary-cluster&filterBy=STATUS:RUNNING&fields=status&tags=consumer=consumer@xyz.com&orderBy=name&offset=0&numResults=1&numInstances=2
 </verbatim>
 ---+++ Result
 <verbatim>

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/aace8f48/prism/src/main/java/org/apache/falcon/resource/AbstractSchedulableEntityManager.java
----------------------------------------------------------------------
diff --git a/prism/src/main/java/org/apache/falcon/resource/AbstractSchedulableEntityManager.java
b/prism/src/main/java/org/apache/falcon/resource/AbstractSchedulableEntityManager.java
index 687fde9..d994e25 100644
--- a/prism/src/main/java/org/apache/falcon/resource/AbstractSchedulableEntityManager.java
+++ b/prism/src/main/java/org/apache/falcon/resource/AbstractSchedulableEntityManager.java
@@ -177,6 +177,7 @@ public abstract class AbstractSchedulableEntityManager extends AbstractInstanceM
         HashSet<String> fieldSet = new HashSet<String>(Arrays.asList(fields.toLowerCase().split(",")));
         Pair<Date, Date> startAndEndDates = getStartEndDatesForSummary(startDate, endDate);
         validateEntityFilterByClause(filterBy);
+        validateTypeForEntitySummary(type);
 
         List<Entity> entities;
         String colo;
@@ -222,6 +223,15 @@ public abstract class AbstractSchedulableEntityManager extends AbstractInstanceM
         return new EntitySummaryResult("Entity Summary Result",
                 entitySummaries.toArray(new EntitySummaryResult.EntitySummary[entitySummaries.size()]));
     }
+
+    private void validateTypeForEntitySummary(String type) {
+        EntityType entityType = EntityType.valueOf(type.toUpperCase());
+        if (!entityType.isSchedulable()) {
+            throw FalconWebException.newException("Invalid entity type " + type
+                + " for EntitySummary API. Valid options are feed or process",
+                Response.Status.BAD_REQUEST);
+        }
+    }
     //RESUME CHECKSTYLE CHECK ParameterNumberCheck
 
     private Pair<Date, Date> getStartEndDatesForSummary(String startDate, String endDate)
{

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/aace8f48/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 a4122a5..fb9d9f3 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
@@ -406,13 +406,13 @@ public class SchedulableEntityManagerProxy extends AbstractSchedulableEntityMana
     }
 
     @GET
-    @Path("summary/{type}/{cluster}")
+    @Path("summary/{type}")
     @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
     @Monitored(event = "summary")
     @Override
     public EntitySummaryResult getEntitySummary(
             @Dimension("type") @PathParam("type") final String type,
-            @Dimension("cluster") @PathParam("cluster") final String cluster,
+            @Dimension("cluster") @QueryParam("cluster") final String cluster,
             @DefaultValue("") @QueryParam("start") String startStr,
             @DefaultValue("") @QueryParam("end") String endStr,
             @DefaultValue("") @QueryParam("fields") final String entityFields,

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/aace8f48/prism/src/main/java/org/apache/falcon/security/FalconAuthorizationFilter.java
----------------------------------------------------------------------
diff --git a/prism/src/main/java/org/apache/falcon/security/FalconAuthorizationFilter.java
b/prism/src/main/java/org/apache/falcon/security/FalconAuthorizationFilter.java
index c82e0bf..3cdb749 100644
--- a/prism/src/main/java/org/apache/falcon/security/FalconAuthorizationFilter.java
+++ b/prism/src/main/java/org/apache/falcon/security/FalconAuthorizationFilter.java
@@ -108,10 +108,13 @@ public class FalconAuthorizationFilter implements Filter {
 
         final String resource = pathSplits[0];
         final String action = pathSplits[1];
-        final String entityType = pathSplits.length > 2 ? pathSplits[2] : null;
-        final String entityName = pathSplits.length > 3 ? pathSplits[3] : null;
-
-        return new RequestParts(resource, action, entityName, entityType);
+        if (resource.equalsIgnoreCase("entities") || resource.equalsIgnoreCase("instance"))
{
+            final String entityType = pathSplits.length > 2 ? pathSplits[2] : null;
+            final String entityName = pathSplits.length > 3 ? pathSplits[3] : null;
+            return new RequestParts(resource, action, entityName, entityType);
+        } else {
+            return new RequestParts(resource, action, null, null);
+        }
     }
 
     private static class RequestParts {
@@ -146,12 +149,18 @@ public class FalconAuthorizationFilter implements Filter {
 
         @Override
         public String toString() {
-            return "RequestParts{"
-                    + "resource='" + resource + '\''
-                    + ", action='" + action + '\''
-                    + ", entityName='" + entityName + '\''
-                    + ", entityType='" + entityType + '\''
-                    + '}';
+            StringBuilder sb = new StringBuilder();
+            sb.append("RequestParts{")
+                    .append("resource='").append(resource).append("'")
+                    .append(", action='").append(action).append("'");
+            if (entityName != null) {
+                sb.append(", entityName='").append(entityName).append("'");
+            }
+            if (entityType != null) {
+                sb.append(", entityType='").append(entityType).append("'");
+            }
+            sb.append("}");
+            return sb.toString();
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/aace8f48/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 c318bfb..5f4f495 100644
--- a/webapp/src/main/java/org/apache/falcon/resource/SchedulableEntityManager.java
+++ b/webapp/src/main/java/org/apache/falcon/resource/SchedulableEntityManager.java
@@ -72,13 +72,13 @@ public class SchedulableEntityManager extends AbstractSchedulableEntityManager
{
     }
 
     @GET
-    @Path("summary/{type}/{cluster}")
+    @Path("summary/{type}")
     @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
     @Monitored(event = "summary")
     @Override
     public EntitySummaryResult getEntitySummary(
             @Dimension("type") @PathParam("type") String type,
-            @Dimension("cluster") @PathParam("cluster") String cluster,
+            @Dimension("cluster") @QueryParam("cluster") String cluster,
             @DefaultValue("") @QueryParam("start") String startStr,
             @DefaultValue("") @QueryParam("end") String endStr,
             @DefaultValue("") @QueryParam("fields") String fields,

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/aace8f48/webapp/src/test/java/org/apache/falcon/resource/EntityManagerPaginationJerseyIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/falcon/resource/EntityManagerPaginationJerseyIT.java
b/webapp/src/test/java/org/apache/falcon/resource/EntityManagerPaginationJerseyIT.java
index 7021ea9..faf7b86 100644
--- a/webapp/src/test/java/org/apache/falcon/resource/EntityManagerPaginationJerseyIT.java
+++ b/webapp/src/test/java/org/apache/falcon/resource/EntityManagerPaginationJerseyIT.java
@@ -105,7 +105,8 @@ public class EntityManagerPaginationJerseyIT {
         OozieTestUtils.waitForProcessWFtoStart(context);
 
         ClientResponse response = context.service
-                .path("api/entities/summary/process/" + overlay.get("cluster"))
+                .path("api/entities/summary/process")
+                .queryParam("cluster", overlay.get("cluster"))
                 .queryParam("fields", "status,pipelines")
                 .queryParam("numInstances", "1")
                 .queryParam("orderBy", "name")


Mime
View raw message