falcon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shweth...@apache.org
Subject falcon git commit: FALCON-749 Improve error printed in falcon CLI. Contributed by Suresh Srinivas
Date Fri, 09 Jan 2015 10:24:27 GMT
Repository: falcon
Updated Branches:
  refs/heads/master b17baec7d -> 4a9151efc


FALCON-749 Improve error printed in falcon CLI. Contributed by Suresh Srinivas


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

Branch: refs/heads/master
Commit: 4a9151efc0a17248d93ba6c588bef7e2b05c7f19
Parents: b17baec
Author: shwethags <shwetha.gs@inmobi.com>
Authored: Fri Jan 9 15:53:46 2015 +0530
Committer: shwethags <shwetha.gs@inmobi.com>
Committed: Fri Jan 9 15:53:46 2015 +0530

----------------------------------------------------------------------
 CHANGES.txt                                       |  2 ++
 .../java/org/apache/falcon/cli/FalconCLI.java     |  4 ++--
 .../org/apache/falcon/client/FalconClient.java    |  7 +++----
 .../org/apache/falcon/entity/v0/EntityType.java   | 10 ++++++++++
 .../java/org/apache/falcon/entity/EntityUtil.java |  2 +-
 .../security/DefaultAuthorizationProvider.java    |  2 +-
 .../org/apache/falcon/entity/EntityTypeTest.java  | 15 +++++++++++++++
 .../falcon/resource/AbstractEntityManager.java    | 18 +++++++++---------
 .../falcon/resource/AbstractInstanceManager.java  |  4 ++--
 .../AbstractSchedulableEntityManager.java         |  4 ++--
 .../proxy/SchedulableEntityManagerProxy.java      |  2 +-
 .../security/FalconAuthorizationFilter.java       |  2 +-
 12 files changed, 49 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/falcon/blob/4a9151ef/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 2752376..8781a8e 100755
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -7,6 +7,8 @@ Trunk (Unreleased)
   NEW FEATURES
 
   IMPROVEMENTS
+   FALCON-749 Improve error printed in falcon CLI. (Suresh Srinivas via Shwetha GS)
+
    FALCON-977 Drop incubator/incubating from falcon codebase. (Shwetha GS
    via Srikanth Sundarrajan)
 

http://git-wip-us.apache.org/repos/asf/falcon/blob/4a9151ef/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 ca514c1..3620c3b 100644
--- a/client/src/main/java/org/apache/falcon/cli/FalconCLI.java
+++ b/client/src/main/java/org/apache/falcon/cli/FalconCLI.java
@@ -382,7 +382,7 @@ public class FalconCLI {
                 FalconClient.DEFAULT_NUM_RESULTS, "numResults");
         Integer numInstances = parseIntegerInput(commandLine.getOptionValue(NUM_INSTANCES_OPT),
7, "numInstances");
         validateNotEmpty(entityType, ENTITY_TYPE_OPT);
-        EntityType entityTypeEnum = EntityType.valueOf(entityType.toUpperCase());
+        EntityType entityTypeEnum = EntityType.getEnum(entityType);
         validateSortOrder(sortOrder);
         String entityAction = "entity";
 
@@ -462,7 +462,7 @@ public class FalconCLI {
     }
 
     private void validateEntityTypeForSummary(String type) throws FalconCLIException {
-        EntityType entityType = EntityType.valueOf(type.toUpperCase());
+        EntityType entityType = EntityType.getEnum(type);
         if (!entityType.isSchedulable()) {
             throw new FalconCLIException("Invalid entity type " + entityType
                     + " for EntitySummary API. Valid options are feed or process");

http://git-wip-us.apache.org/repos/asf/falcon/blob/4a9151ef/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 7f1bc27..5064e46 100644
--- a/client/src/main/java/org/apache/falcon/client/FalconClient.java
+++ b/client/src/main/java/org/apache/falcon/client/FalconClient.java
@@ -673,8 +673,7 @@ public class FalconClient {
         checkIfSuccessful(clientResponse);
         String entity = clientResponse.getEntity(String.class);
 
-        return Entity.fromString(EntityType.valueOf(entityType.toUpperCase()),
-            entity);
+        return Entity.fromString(EntityType.getEnum(entityType), entity);
 
     }
 
@@ -758,7 +757,7 @@ public class FalconClient {
 
     private void checkLifeCycleOption(List<LifeCycle> lifeCycles, String type) throws
FalconCLIException {
         if (lifeCycles != null && !lifeCycles.isEmpty()) {
-            EntityType entityType = EntityType.valueOf(type.toUpperCase().trim());
+            EntityType entityType = EntityType.getEnum(type);
             for (LifeCycle lifeCycle : lifeCycles) {
                 if (entityType != lifeCycle.getTag().getType()) {
                     throw new FalconCLIException("Incorrect lifecycle: " + lifeCycle + "for
given type: " + type);
@@ -771,7 +770,7 @@ public class FalconClient {
         if (type == null || type.isEmpty()) {
             throw new FalconCLIException("entity type is empty");
         } else {
-            EntityType entityType = EntityType.valueOf(type.toUpperCase().trim());
+            EntityType entityType = EntityType.getEnum(type);
             if (entityType == EntityType.CLUSTER) {
                 throw new FalconCLIException(
                         "Instance management functions don't apply to Cluster entities");

http://git-wip-us.apache.org/repos/asf/falcon/blob/4a9151ef/client/src/main/java/org/apache/falcon/entity/v0/EntityType.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/falcon/entity/v0/EntityType.java b/client/src/main/java/org/apache/falcon/entity/v0/EntityType.java
index bc7b1f2..13c85a4 100644
--- a/client/src/main/java/org/apache/falcon/entity/v0/EntityType.java
+++ b/client/src/main/java/org/apache/falcon/entity/v0/EntityType.java
@@ -25,6 +25,7 @@ import org.apache.falcon.entity.v0.process.Process;
 import javax.xml.bind.*;
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
+import java.util.Arrays;
 
 /**
  * Enum for types of entities in Falcon Process, Feed and Cluster.
@@ -95,4 +96,13 @@ public enum EntityType {
     public String[] getImmutableProperties() {
         return immutableProperties;
     }
+
+    public static EntityType getEnum(String type) {
+        try {
+            return EntityType.valueOf(type.toUpperCase().trim());
+        } catch (IllegalArgumentException iae) {
+            throw new IllegalArgumentException("Invalid entity type: " + type + ". Expected
"
+                    + Arrays.toString(values()).toLowerCase() + ".");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/falcon/blob/4a9151ef/common/src/main/java/org/apache/falcon/entity/EntityUtil.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/falcon/entity/EntityUtil.java b/common/src/main/java/org/apache/falcon/entity/EntityUtil.java
index 1a5d30c..febbe50 100644
--- a/common/src/main/java/org/apache/falcon/entity/EntityUtil.java
+++ b/common/src/main/java/org/apache/falcon/entity/EntityUtil.java
@@ -81,7 +81,7 @@ public final class EntityUtil {
     public static <T extends Entity> T getEntity(String type, String entityName) throws
FalconException {
         EntityType entityType;
         try {
-            entityType = EntityType.valueOf(type.toUpperCase());
+            entityType = EntityType.getEnum(type);
         } catch (IllegalArgumentException e) {
             throw new FalconException("Invalid entity type: " + type, e);
         }

http://git-wip-us.apache.org/repos/asf/falcon/blob/4a9151ef/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 d2d48c7..f6da2cf 100644
--- a/common/src/main/java/org/apache/falcon/security/DefaultAuthorizationProvider.java
+++ b/common/src/main/java/org/apache/falcon/security/DefaultAuthorizationProvider.java
@@ -316,7 +316,7 @@ public class DefaultAuthorizationProvider implements AuthorizationProvider
{
         throws EntityNotRegisteredException, AuthorizationException {
 
         try {
-            EntityType type = EntityType.valueOf(entityType.toUpperCase());
+            EntityType type = EntityType.getEnum(entityType);
             return EntityUtil.getEntity(type, entityName);
         } catch (FalconException e) {
             if (e instanceof EntityNotRegisteredException) {

http://git-wip-us.apache.org/repos/asf/falcon/blob/4a9151ef/common/src/test/java/org/apache/falcon/entity/EntityTypeTest.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/falcon/entity/EntityTypeTest.java b/common/src/test/java/org/apache/falcon/entity/EntityTypeTest.java
index e947f69..640e87d 100644
--- a/common/src/test/java/org/apache/falcon/entity/EntityTypeTest.java
+++ b/common/src/test/java/org/apache/falcon/entity/EntityTypeTest.java
@@ -39,4 +39,19 @@ public class EntityTypeTest {
         Assert.assertTrue(EntityType.FEED.isSchedulable());
         Assert.assertFalse(EntityType.CLUSTER.isSchedulable());
     }
+
+    @Test
+    public void testValidEntityTypes() {
+        Assert.assertEquals(EntityType.FEED, EntityType.getEnum("feed"));
+        Assert.assertEquals(EntityType.FEED, EntityType.getEnum("FeEd"));
+        Assert.assertEquals(EntityType.CLUSTER, EntityType.getEnum("cluster"));
+        Assert.assertEquals(EntityType.CLUSTER, EntityType.getEnum("cluSTER"));
+        Assert.assertEquals(EntityType.PROCESS, EntityType.getEnum("process"));
+        Assert.assertEquals(EntityType.PROCESS, EntityType.getEnum("pRocess"));
+    }
+
+    @Test(expectedExceptions = IllegalArgumentException.class)
+    public void testInvalidEntityTypes() throws Exception {
+        EntityType.getEnum("invalid");
+    }
 }

http://git-wip-us.apache.org/repos/asf/falcon/blob/4a9151ef/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 4a686e7..0d34ef3 100644
--- a/prism/src/main/java/org/apache/falcon/resource/AbstractEntityManager.java
+++ b/prism/src/main/java/org/apache/falcon/resource/AbstractEntityManager.java
@@ -135,7 +135,7 @@ public abstract class AbstractEntityManager {
                 return DeploymentUtil.getDefaultColos();
             }
 
-            if (EntityType.valueOf(type.toUpperCase()) == EntityType.CLUSTER) {
+            if (EntityType.getEnum(type) == EntityType.CLUSTER) {
                 return getAllColos();
             }
 
@@ -151,7 +151,7 @@ public abstract class AbstractEntityManager {
                 return DeploymentUtil.getDefaultColos();
             }
 
-            if (EntityType.valueOf(type.toUpperCase()) == EntityType.CLUSTER) {
+            if (EntityType.getEnum(type) == EntityType.CLUSTER) {
                 return getAllColos();
             }
 
@@ -201,7 +201,7 @@ public abstract class AbstractEntityManager {
      */
     public APIResult validate(HttpServletRequest request, String type) {
         try {
-            EntityType entityType = EntityType.valueOf(type.toUpperCase());
+            EntityType entityType = EntityType.getEnum(type);
             Entity entity = deserializeEntity(request, entityType);
             validate(entity);
 
@@ -235,7 +235,7 @@ public abstract class AbstractEntityManager {
     public APIResult delete(HttpServletRequest request, String type, String entity, String
colo) {
         checkColo(colo);
         try {
-            EntityType entityType = EntityType.valueOf(type.toUpperCase());
+            EntityType entityType = EntityType.getEnum(type);
             String removedFromEngine = "";
             try {
                 Entity entityObj = EntityUtil.getEntity(type, entity);
@@ -265,7 +265,7 @@ public abstract class AbstractEntityManager {
     public synchronized APIResult update(HttpServletRequest request, String type, String
entityName, String colo) {
         checkColo(colo);
         try {
-            EntityType entityType = EntityType.valueOf(type.toUpperCase());
+            EntityType entityType = EntityType.getEnum(type);
             Entity oldEntity = EntityUtil.getEntity(type, entityName);
             Entity newEntity = deserializeEntity(request, entityType);
             // KLUDGE - Until ACL is mandated entity passed should be decorated for equals
check to pass
@@ -343,7 +343,7 @@ public abstract class AbstractEntityManager {
     protected synchronized Entity submitInternal(HttpServletRequest request, String type)
         throws IOException, FalconException {
 
-        EntityType entityType = EntityType.valueOf(type.toUpperCase());
+        EntityType entityType = EntityType.getEnum(type);
         Entity entity = deserializeEntity(request, entityType);
         // KLUDGE - Until ACL is mandated entity passed should be decorated for equals check
to pass
         decorateEntityWithACL(entity);
@@ -473,7 +473,7 @@ public abstract class AbstractEntityManager {
         Entity entityObj;
         try {
             entityObj = EntityUtil.getEntity(type, entity);
-            EntityType entityType = EntityType.valueOf(type.toUpperCase());
+            EntityType entityType = EntityType.getEnum(type);
             EntityStatus status = getStatus(entityObj, entityType);
             return new APIResult(Status.SUCCEEDED, status.name());
         } catch (FalconWebException e) {
@@ -575,7 +575,7 @@ public abstract class AbstractEntityManager {
         final Map<String, String> filterByFieldsValues = getFilterByFieldsValues(filterBy);
         final List<String> filterByTags = getFilterByTags(filterTags);
 
-        EntityType entityType = EntityType.valueOf(type.toUpperCase());
+        EntityType entityType = EntityType.getEnum(type);
         Collection<String> entityNames = configStore.getEntities(entityType);
         if (entityNames.isEmpty()) {
             return Collections.emptyList();
@@ -894,7 +894,7 @@ public abstract class AbstractEntityManager {
      */
     public String getEntityDefinition(String type, String entityName) {
         try {
-            EntityType entityType = EntityType.valueOf(type.toUpperCase());
+            EntityType entityType = EntityType.getEnum(type);
             Entity entity = configStore.get(entityType, entityName);
             if (entity == null) {
                 throw new NoSuchElementException(entityName + " (" + type + ") not found");

http://git-wip-us.apache.org/repos/asf/falcon/blob/4a9151ef/prism/src/main/java/org/apache/falcon/resource/AbstractInstanceManager.java
----------------------------------------------------------------------
diff --git a/prism/src/main/java/org/apache/falcon/resource/AbstractInstanceManager.java b/prism/src/main/java/org/apache/falcon/resource/AbstractInstanceManager.java
index 26a4289..ed30869 100644
--- a/prism/src/main/java/org/apache/falcon/resource/AbstractInstanceManager.java
+++ b/prism/src/main/java/org/apache/falcon/resource/AbstractInstanceManager.java
@@ -55,7 +55,7 @@ public abstract class AbstractInstanceManager extends AbstractEntityManager
{
             throw FalconWebException.newInstanceException("entity type is empty",
                     Response.Status.BAD_REQUEST);
         } else {
-            EntityType entityType = EntityType.valueOf(type.toUpperCase());
+            EntityType entityType = EntityType.getEnum(type);
             if (entityType == EntityType.CLUSTER) {
                 throw FalconWebException.newInstanceException(
                         "Instance management functions don't apply to Cluster entities",
@@ -68,7 +68,7 @@ public abstract class AbstractInstanceManager extends AbstractEntityManager
{
 
     protected List<LifeCycle> checkAndUpdateLifeCycle(List<LifeCycle> lifeCycleValues,
                                                       String type) throws FalconException
{
-        EntityType entityType = EntityType.valueOf(type.toUpperCase().trim());
+        EntityType entityType = EntityType.getEnum(type);
         if (lifeCycleValues == null || lifeCycleValues.isEmpty()) {
             List<LifeCycle> lifeCycles = new ArrayList<LifeCycle>();
             if (entityType == EntityType.PROCESS) {

http://git-wip-us.apache.org/repos/asf/falcon/blob/4a9151ef/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 a4d1f8b..b8d12ee 100644
--- a/prism/src/main/java/org/apache/falcon/resource/AbstractSchedulableEntityManager.java
+++ b/prism/src/main/java/org/apache/falcon/resource/AbstractSchedulableEntityManager.java
@@ -225,7 +225,7 @@ public abstract class AbstractSchedulableEntityManager extends AbstractInstanceM
     }
 
     private void validateTypeForEntitySummary(String type) {
-        EntityType entityType = EntityType.valueOf(type.toUpperCase());
+        EntityType entityType = EntityType.getEnum(type);
         if (!entityType.isSchedulable()) {
             throw FalconWebException.newException("Invalid entity type " + type
                 + " for EntitySummary API. Valid options are feed or process",
@@ -265,7 +265,7 @@ public abstract class AbstractSchedulableEntityManager extends AbstractInstanceM
     }
 
     private void checkSchedulableEntity(String type) throws UnschedulableEntityException
{
-        EntityType entityType = EntityType.valueOf(type.toUpperCase());
+        EntityType entityType = EntityType.getEnum(type);
         if (!entityType.isSchedulable()) {
             throw new UnschedulableEntityException(
                     "Entity type (" + type + ") " + " cannot be Scheduled/Suspended/Resumed");

http://git-wip-us.apache.org/repos/asf/falcon/blob/4a9151ef/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 cfa70a0..85e846f 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
@@ -134,7 +134,7 @@ public class SchedulableEntityManagerProxy extends AbstractSchedulableEntityMana
     private Entity getEntity(HttpServletRequest request, String type) {
         try {
             request.getInputStream().reset();
-            Entity entity = deserializeEntity(request, EntityType.valueOf(type.toUpperCase()));
+            Entity entity = deserializeEntity(request, EntityType.getEnum(type));
             request.getInputStream().reset();
             return entity;
         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/falcon/blob/4a9151ef/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 071187a..6b022c9 100644
--- a/prism/src/main/java/org/apache/falcon/security/FalconAuthorizationFilter.java
+++ b/prism/src/main/java/org/apache/falcon/security/FalconAuthorizationFilter.java
@@ -139,7 +139,7 @@ public class FalconAuthorizationFilter implements Filter {
         }
 
         try {
-            EntityType type = EntityType.valueOf(entityType.toUpperCase());
+            EntityType type = EntityType.getEnum(entityType);
             Entity entity = EntityUtil.getEntity(type, entityName);
             if (entity != null && entity.getACL() != null) {
                 final String aclOwner = entity.getACL().getOwner();


Mime
View raw message