falcon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From venkat...@apache.org
Subject [1/5] git commit: FALCON-788 Lineage: Minor bug fixes. Contributed by Sowmya Ramesh
Date Wed, 08 Oct 2014 23:44:40 GMT
Repository: incubator-falcon
Updated Branches:
  refs/heads/master 5c305434c -> 396db7825


FALCON-788 Lineage: Minor bug fixes. Contributed by Sowmya Ramesh


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

Branch: refs/heads/master
Commit: b0929b4432870d1ffda79604b2ed29596934cc7a
Parents: 152afb1
Author: Venkatesh Seetharam <venkatesh@apache.org>
Authored: Wed Oct 8 14:56:36 2014 -0700
Committer: Venkatesh Seetharam <venkatesh@apache.org>
Committed: Wed Oct 8 16:20:38 2014 -0700

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 +
 .../metadata/AbstractMetadataResource.java      | 20 ++++++++-
 .../metadata/LineageMetadataResource.java       | 43 ++++----------------
 .../metadata/MetadataDiscoveryResource.java     |  7 ++--
 .../metadata/LineageMetadataResourceTest.java   |  4 +-
 5 files changed, 33 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/b0929b44/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index b17afa3..dca9fa9 100755
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -112,6 +112,8 @@ Trunk (Unreleased)
   OPTIMIZATIONS
 
   BUG FIXES
+   FALCON-788 Lineage: Minor bug fixes (Sowmya Ramesh via Venkatesh Seetharam)
+
    FALCON-777 UT intermittent failures in Messaging tests depending on Thread.sleep
    (Sowmya Ramesh via Venkatesh Seetharam)
 

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/b0929b44/prism/src/main/java/org/apache/falcon/resource/metadata/AbstractMetadataResource.java
----------------------------------------------------------------------
diff --git a/prism/src/main/java/org/apache/falcon/resource/metadata/AbstractMetadataResource.java
b/prism/src/main/java/org/apache/falcon/resource/metadata/AbstractMetadataResource.java
index a6c9b78..e9c90fc 100644
--- a/prism/src/main/java/org/apache/falcon/resource/metadata/AbstractMetadataResource.java
+++ b/prism/src/main/java/org/apache/falcon/resource/metadata/AbstractMetadataResource.java
@@ -25,6 +25,9 @@ import org.apache.falcon.service.Services;
 
 import java.util.Set;
 
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
 /**
  * A base class for managing Metadata operations.
 ]*/
@@ -35,23 +38,36 @@ public abstract class AbstractMetadataResource {
     protected MetadataMappingService service;
 
     public AbstractMetadataResource() {
-        service = (MetadataMappingService)getService(MetadataMappingService.SERVICE_NAME);
+        FalconService falconService = getService(MetadataMappingService.SERVICE_NAME);
+        service = (falconService != null) ? (MetadataMappingService)falconService : null;
     }
 
-    public static FalconService getService(String serviceName) {
+    private static FalconService getService(String serviceName) {
         return (Services.get().isRegistered(serviceName))
                 ? Services.get().getService(serviceName) : null;
     }
 
     protected Graph getGraph() {
+        checkIfMetadataMappingServiceIsEnabled();
         return service.getGraph();
     }
 
     protected Set<String> getVertexIndexedKeys() {
+        checkIfMetadataMappingServiceIsEnabled();
         return service.getVertexIndexedKeys();
     }
 
     protected Set<String> getEdgeIndexedKeys() {
+        checkIfMetadataMappingServiceIsEnabled();
         return service.getEdgeIndexedKeys();
     }
+
+    private void checkIfMetadataMappingServiceIsEnabled() {
+        if (service == null) {
+            throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
+                    .entity("Lineage " + MetadataMappingService.SERVICE_NAME + " is not enabled.")
+                    .type("text/plain")
+                    .build());
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/b0929b44/prism/src/main/java/org/apache/falcon/resource/metadata/LineageMetadataResource.java
----------------------------------------------------------------------
diff --git a/prism/src/main/java/org/apache/falcon/resource/metadata/LineageMetadataResource.java
b/prism/src/main/java/org/apache/falcon/resource/metadata/LineageMetadataResource.java
index 2181bea..ed50ce0 100644
--- a/prism/src/main/java/org/apache/falcon/resource/metadata/LineageMetadataResource.java
+++ b/prism/src/main/java/org/apache/falcon/resource/metadata/LineageMetadataResource.java
@@ -26,6 +26,7 @@ import com.tinkerpop.blueprints.VertexQuery;
 import com.tinkerpop.blueprints.util.io.graphson.GraphSONMode;
 import com.tinkerpop.blueprints.util.io.graphson.GraphSONUtility;
 import org.apache.commons.lang.StringUtils;
+import org.apache.falcon.FalconWebException;
 import org.apache.falcon.metadata.GraphUtils;
 import org.apache.falcon.metadata.RelationshipLabel;
 import org.apache.falcon.metadata.RelationshipProperty;
@@ -69,7 +70,6 @@ public class LineageMetadataResource extends AbstractMetadataResource {
     @Path("/serialize")
     @Produces({MediaType.APPLICATION_JSON})
     public Response serializeGraph() {
-        checkIfMetadataMappingServiceIsEnabled();
         String file = StartupProperties.get().getProperty("falcon.graph.serialize.path")
                 + "/lineage-graph-" + System.currentTimeMillis() + ".json";
         LOG.info("Serialize Graph to: {}", file);
@@ -77,8 +77,7 @@ public class LineageMetadataResource extends AbstractMetadataResource {
             GraphUtils.dump(getGraph(), file);
             return Response.ok().build();
         } catch (Exception e) {
-            throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
-                    .entity(JSONObject.quote("An error occurred: " + e.getMessage())).build());
+            throw FalconWebException.newException(e, Response.Status.INTERNAL_SERVER_ERROR);
         }
     }
 
@@ -92,14 +91,12 @@ public class LineageMetadataResource extends AbstractMetadataResource
{
     @Path("/vertices/all")
     @Produces({MediaType.APPLICATION_JSON})
     public Response getVertices() {
-        checkIfMetadataMappingServiceIsEnabled();
         LOG.info("Get All Vertices");
         try {
             JSONObject response = buildJSONResponse(getGraph().getVertices());
             return Response.ok(response).build();
         } catch (JSONException e) {
-            throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
-                    .entity(JSONObject.quote("An error occurred: " + e.getMessage())).build());
+            throw FalconWebException.newException(e, Response.Status.INTERNAL_SERVER_ERROR);
         }
     }
 
@@ -113,7 +110,6 @@ public class LineageMetadataResource extends AbstractMetadataResource
{
     @Path("/vertices/{id}")
     @Produces({MediaType.APPLICATION_JSON})
     public Response getVertex(@PathParam("id") final String vertexId) {
-        checkIfMetadataMappingServiceIsEnabled();
         LOG.info("Get vertex for vertexId= {}", vertexId);
         validateInputs("Invalid argument: vertex id passed is null or empty.", vertexId);
         try {
@@ -124,8 +120,7 @@ public class LineageMetadataResource extends AbstractMetadataResource
{
                     vertex, getVertexIndexedKeys(), GraphSONMode.NORMAL));
             return Response.ok(response).build();
         } catch (JSONException e) {
-            throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
-                    .entity(JSONObject.quote("An error occurred: " + e.getMessage())).build());
+            throw FalconWebException.newException(e, Response.Status.INTERNAL_SERVER_ERROR);
         }
     }
 
@@ -153,7 +148,6 @@ public class LineageMetadataResource extends AbstractMetadataResource
{
     public Response getVertexProperties(@PathParam("id") final String vertexId,
                                         @DefaultValue("false") @QueryParam("relationships")
                                         final String relationships) {
-        checkIfMetadataMappingServiceIsEnabled();
         LOG.info("Get vertex for vertexId= {}", vertexId);
         validateInputs("Invalid argument: vertex id passed is null or empty.", vertexId);
         try {
@@ -166,8 +160,7 @@ public class LineageMetadataResource extends AbstractMetadataResource
{
             response.put(TOTAL_SIZE, vertexProperties.size());
             return Response.ok(response).build();
         } catch (JSONException e) {
-            throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
-                    .entity(JSONObject.quote("An error occurred: " + e.getMessage())).build());
+            throw FalconWebException.newException(e, Response.Status.INTERNAL_SERVER_ERROR);
         }
     }
 
@@ -253,7 +246,6 @@ public class LineageMetadataResource extends AbstractMetadataResource
{
     @Produces({MediaType.APPLICATION_JSON})
     public Response getVertices(@QueryParam("key") final String key,
                                 @QueryParam("value") final String value) {
-        checkIfMetadataMappingServiceIsEnabled();
         LOG.info("Get vertices for property key= {}, value= {}", key, value);
         validateInputs("Invalid argument: key or value passed is null or empty.", key, value);
         try {
@@ -261,8 +253,7 @@ public class LineageMetadataResource extends AbstractMetadataResource
{
             return Response.ok(response).build();
 
         } catch (JSONException e) {
-            throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
-                    .entity(JSONObject.quote("An error occurred: " + e.getMessage())).build());
+            throw FalconWebException.newException(e, Response.Status.INTERNAL_SERVER_ERROR);
         }
     }
 
@@ -278,7 +269,6 @@ public class LineageMetadataResource extends AbstractMetadataResource
{
     @Produces({MediaType.APPLICATION_JSON})
     public Response getVertexEdges(@PathParam("id") String vertexId,
                                    @PathParam("direction") String direction) {
-        checkIfMetadataMappingServiceIsEnabled();
         LOG.info("Get vertex edges for vertexId= {}, direction= {}", vertexId, direction);
         // Validate vertex id. Direction is validated in VertexQueryArguments.
         validateInputs("Invalid argument: vertex id or direction passed is null or empty.",
vertexId, direction);
@@ -288,8 +278,7 @@ public class LineageMetadataResource extends AbstractMetadataResource
{
             return getVertexEdges(vertex, direction);
 
         } catch (JSONException e) {
-            throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
-                    .entity(JSONObject.quote("An error occurred: " + e.getMessage())).build());
+            throw FalconWebException.newException(e, Response.Status.INTERNAL_SERVER_ERROR);
         }
     }
 
@@ -347,15 +336,13 @@ public class LineageMetadataResource extends AbstractMetadataResource
{
     @Path("/edges/all")
     @Produces({MediaType.APPLICATION_JSON})
     public Response getEdges() {
-        checkIfMetadataMappingServiceIsEnabled();
         LOG.info("Get All Edges.");
         try {
             JSONObject response = buildJSONResponse(getGraph().getEdges());
             return Response.ok(response).build();
 
         } catch (JSONException e) {
-            throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
-                    .entity(JSONObject.quote("An error occurred: " + e.getMessage())).build());
+            throw FalconWebException.newException(e, Response.Status.INTERNAL_SERVER_ERROR);
         }
     }
 
@@ -369,7 +356,6 @@ public class LineageMetadataResource extends AbstractMetadataResource
{
     @Path("/edges/{id}")
     @Produces({MediaType.APPLICATION_JSON})
     public Response getEdge(@PathParam("id") final String edgeId) {
-        checkIfMetadataMappingServiceIsEnabled();
         LOG.info("Get vertex for edgeId= {}", edgeId);
         validateInputs("Invalid argument: edge id passed is null or empty.", edgeId);
         try {
@@ -386,8 +372,7 @@ public class LineageMetadataResource extends AbstractMetadataResource
{
                     edge, getEdgeIndexedKeys(), GraphSONMode.NORMAL));
             return Response.ok(response).build();
         } catch (JSONException e) {
-            throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
-                    .entity(JSONObject.quote("An error occurred: " + e.getMessage())).build());
+            throw FalconWebException.newException(e, Response.Status.INTERNAL_SERVER_ERROR);
         }
     }
 
@@ -407,16 +392,6 @@ public class LineageMetadataResource extends AbstractMetadataResource
{
         return response;
     }
 
-    private void checkIfMetadataMappingServiceIsEnabled() {
-        if (service == null) {
-            throw new WebApplicationException(
-                    Response.status(Response.Status.NOT_FOUND)
-                            .entity("Lineage Metadata Service is not enabled.")
-                            .type("text/plain")
-                            .build());
-        }
-    }
-
     private static void validateInputs(String errorMsg, String... inputs) {
         for (String input : inputs) {
             if (StringUtils.isEmpty(input)) {

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/b0929b44/prism/src/main/java/org/apache/falcon/resource/metadata/MetadataDiscoveryResource.java
----------------------------------------------------------------------
diff --git a/prism/src/main/java/org/apache/falcon/resource/metadata/MetadataDiscoveryResource.java
b/prism/src/main/java/org/apache/falcon/resource/metadata/MetadataDiscoveryResource.java
index 63ed3b6..1983371 100644
--- a/prism/src/main/java/org/apache/falcon/resource/metadata/MetadataDiscoveryResource.java
+++ b/prism/src/main/java/org/apache/falcon/resource/metadata/MetadataDiscoveryResource.java
@@ -25,6 +25,7 @@ import com.tinkerpop.blueprints.Vertex;
 import com.tinkerpop.blueprints.util.io.graphson.GraphSONMode;
 import com.tinkerpop.blueprints.util.io.graphson.GraphSONUtility;
 import org.apache.commons.lang.StringUtils;
+import org.apache.falcon.FalconWebException;
 import org.apache.falcon.metadata.RelationshipLabel;
 import org.apache.falcon.metadata.RelationshipProperty;
 import org.apache.falcon.metadata.RelationshipType;
@@ -81,8 +82,7 @@ public class MetadataDiscoveryResource extends AbstractMetadataResource
{
             response.put(TOTAL_SIZE, dimensionValues.length());
             return Response.ok(response).build();
         } catch (JSONException e) {
-            throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
-                    .entity(JSONObject.quote("An error occurred: " + e.getMessage())).build());
+            throw FalconWebException.newException(e, Response.Status.INTERNAL_SERVER_ERROR);
         }
     }
 
@@ -117,8 +117,7 @@ public class MetadataDiscoveryResource extends AbstractMetadataResource
{
             vertexProperties.put("outVertices", getAdjacentVerticesJson(outEdges, Direction.IN));
 
         } catch (JSONException e) {
-            throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
-                    .entity(JSONObject.quote("An error occurred: " + e.getMessage())).build());
+            throw FalconWebException.newException(e, Response.Status.INTERNAL_SERVER_ERROR);
         }
 
         return Response.ok(vertexProperties).build();

http://git-wip-us.apache.org/repos/asf/incubator-falcon/blob/b0929b44/prism/src/test/java/org/apache/falcon/resource/metadata/LineageMetadataResourceTest.java
----------------------------------------------------------------------
diff --git a/prism/src/test/java/org/apache/falcon/resource/metadata/LineageMetadataResourceTest.java
b/prism/src/test/java/org/apache/falcon/resource/metadata/LineageMetadataResourceTest.java
index 0a8efc9..cabb44c 100644
--- a/prism/src/test/java/org/apache/falcon/resource/metadata/LineageMetadataResourceTest.java
+++ b/prism/src/test/java/org/apache/falcon/resource/metadata/LineageMetadataResourceTest.java
@@ -344,9 +344,7 @@ public class LineageMetadataResourceTest {
         Services.get().reset();
         try {
             LineageMetadataResource resource = new LineageMetadataResource();
-            Response response = resource.getVertices();
-            Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
-            Assert.assertEquals(response.getEntity().toString(), "Lineage Metadata Service
is not enabled.");
+            resource.getVertices();
         } finally {
             Services.get().register(new WorkflowJobEndNotificationService());
             Services.get().register(testContext.getService());


Mime
View raw message