falcon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From venkat...@apache.org
Subject git commit: FALCON-171 Provide status in /api/entities/list. Contributed by Haohui Mai
Date Wed, 13 Nov 2013 01:07:24 GMT
Updated Branches:
  refs/heads/master 17f901a66 -> cd78c3aa5


FALCON-171 Provide status in /api/entities/list. 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/cd78c3aa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-falcon/tree/cd78c3aa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-falcon/diff/cd78c3aa

Branch: refs/heads/master
Commit: cd78c3aa5f60afcaad7eddd0bf5f2279ed53e35d
Parents: 17f901a
Author: Venkatesh Seetharam <venkatesh@apache.org>
Authored: Tue Nov 12 17:07:03 2013 -0800
Committer: Venkatesh Seetharam <venkatesh@apache.org>
Committed: Tue Nov 12 17:07:03 2013 -0800

----------------------------------------------------------------------
 CHANGES.txt                                     |  3 +
 .../org/apache/falcon/resource/EntityList.java  | 33 ++++++-----
 .../falcon/resource/AbstractEntityManager.java  | 61 +++++++++++++-------
 3 files changed, 62 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/cd78c3aa/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 8d69374..d86b98a 100755
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -78,6 +78,9 @@ Trunk (Unreleased)
 
   IMPROVEMENTS
 
+    FALCON-171 Provide status in /api/entities/list.
+    (Haohui Mai via Venkatesh Seetharam)
+
     FALCON-187 Update Falcon start script to also redirect
     stdout to the log file. (Arpit Gupta via Venkatesh Seetharam)
 

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/cd78c3aa/client/src/main/java/org/apache/falcon/resource/EntityList.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/falcon/resource/EntityList.java b/client/src/main/java/org/apache/falcon/resource/EntityList.java
index 64dbae0..91ac00b 100644
--- a/client/src/main/java/org/apache/falcon/resource/EntityList.java
+++ b/client/src/main/java/org/apache/falcon/resource/EntityList.java
@@ -34,7 +34,7 @@ import javax.xml.bind.annotation.XmlRootElement;
 public class EntityList {
 
     @XmlElement(name = "entity")
-    private EntityElement[] elements;
+    private final EntityElement[] elements;
 
     /**
      * Element within an entity.
@@ -45,32 +45,35 @@ public class EntityList {
         public String type;
         @XmlElement
         public String name;
+        @XmlElement
+        public String status;
         //RESUME CHECKSTYLE CHECK VisibilityModifierCheck
 
-        public EntityElement() {
-
-        }
-
-        public EntityElement(String type, String name) {
-            this.type = type;
-            this.name = name;
-        }
-
         @Override
         public String toString() {
-            return "(" + type + ") " + name + "\n";
+            return "(" + type + ") " + name + "(" + status + ")\n";
         }
     }
 
     //For JAXB
     public EntityList() {
+        this.elements = null;
+    }
+
+    public EntityList(EntityElement[] elements) {
+        this.elements = elements;
     }
 
     public EntityList(Entity[] elements) {
-        EntityElement[] items = new EntityElement[elements.length];
-        for (int index = 0; index < elements.length; index++) {
-            items[index] = new EntityElement(elements[index].
-                    getEntityType().name().toLowerCase(), elements[index].getName());
+        int len = elements.length;
+        EntityElement[] items = new EntityElement[len];
+        for (int i = 0; i < len; i++) {
+            Entity e = elements[i];
+            EntityElement o = new EntityElement();
+            o.type = e.getEntityType().name().toLowerCase();
+            o.name = e.getName();
+            o.status = "";
+            items[i] = o;
         }
         this.elements = items;
     }

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/cd78c3aa/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 d5605df..c899407 100644
--- a/prism/src/main/java/org/apache/falcon/resource/AbstractEntityManager.java
+++ b/prism/src/main/java/org/apache/falcon/resource/AbstractEntityManager.java
@@ -382,22 +382,8 @@ public abstract class AbstractEntityManager {
         try {
             entityObj = EntityUtil.getEntity(type, entity);
             EntityType entityType = EntityType.valueOf(type.toUpperCase());
-            String status;
-
-            if (entityType.isSchedulable()) {
-                if (workflowEngine.isActive(entityObj)) {
-                    if (workflowEngine.isSuspended(entityObj)) {
-                        status = EntityStatus.SUSPENDED.name();
-                    } else {
-                        status = EntityStatus.RUNNING.name();
-                    }
-                } else {
-                    status = EntityStatus.SUBMITTED.name();
-                }
-            } else {
-                status = EntityStatus.SUBMITTED.name();
-            }
-            return new APIResult(Status.SUCCEEDED, status);
+            EntityStatus status = getStatus(entityObj, entityType);
+            return new APIResult(Status.SUCCEEDED, status.name());
         } catch (FalconWebException e) {
             throw e;
         } catch (Exception e) {
@@ -407,6 +393,25 @@ public abstract class AbstractEntityManager {
         }
     }
 
+    protected EntityStatus getStatus(Entity entity, EntityType type) throws FalconException
{
+        EntityStatus status;
+
+        if (type.isSchedulable()) {
+            if (workflowEngine.isActive(entity)) {
+                if (workflowEngine.isSuspended(entity)) {
+                    status = EntityStatus.SUSPENDED;
+                } else {
+                    status = EntityStatus.RUNNING;
+                }
+            } else {
+                status = EntityStatus.SUBMITTED;
+            }
+        } else {
+            status = EntityStatus.SUBMITTED;
+        }
+        return status;
+    }
+
     /**
      * Returns dependencies.
      *
@@ -436,16 +441,32 @@ public abstract class AbstractEntityManager {
     public EntityList getDependencies(String type) {
         try {
             EntityType entityType = EntityType.valueOf(type.toUpperCase());
+            final String entityTypeString = type.toLowerCase();
             Collection<String> entityNames = configStore.getEntities(entityType);
             if (entityNames == null || entityNames.isEmpty()) {
                 return new EntityList(new Entity[]{});
             }
-            Entity[] entities = new Entity[entityNames.size()];
-            int index = 0;
+
+            int len = entityNames.size();
+            EntityList.EntityElement[] elements = new EntityList.EntityElement[len];
+
+            int i = 0;
             for (String entityName : entityNames) {
-                entities[index++] = configStore.get(entityType, entityName);
+                Entity e = configStore.get(entityType, entityName);
+                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";
+                }
+                elem.status = statusString;
+                elements[i++] = elem;
             }
-            return new EntityList(entities);
+            return new EntityList(elements);
         } catch (Exception e) {
             LOG.error("Unable to get list for entities for (" + type + ")", e);
             throw FalconWebException.newException(e, Response.Status.BAD_REQUEST);


Mime
View raw message