Commit d97a7236 by Dan Markwat
parents c7218046 7828bdf5
...@@ -26,9 +26,9 @@ import com.tinkerpop.blueprints.Edge; ...@@ -26,9 +26,9 @@ import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Graph; import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.Vertex;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.metadata.MetadataException; import org.apache.hadoop.metadata.MetadataException;
import org.apache.hadoop.metadata.discovery.DiscoveryService; import org.apache.hadoop.metadata.discovery.DiscoveryService;
import org.apache.hadoop.metadata.repository.graph.GraphHelper;
import org.apache.hadoop.metadata.repository.graph.GraphService; import org.apache.hadoop.metadata.repository.graph.GraphService;
import org.apache.hadoop.metadata.types.TypeSystem; import org.apache.hadoop.metadata.types.TypeSystem;
import org.apache.hadoop.metadata.web.util.Servlets; import org.apache.hadoop.metadata.web.util.Servlets;
...@@ -160,19 +160,24 @@ public class MetadataDiscoveryResource { ...@@ -160,19 +160,24 @@ public class MetadataDiscoveryResource {
HashMap<String,Map<String,String>> edges = new HashMap<String,Map<String,String>>(); HashMap<String,Map<String,String>> edges = new HashMap<String,Map<String,String>>();
// Get the Vertex with the specified GUID. // Get the Vertex with the specified GUID.
for (Vertex v: getGraph().query().has("guid", guid).vertices()) { Vertex v = GraphHelper.findVertexByGUID(getGraph(), guid);
if (v != null) {
searchWalker(v, depth, 0, edges, vertices, edgesToFollow); searchWalker(v, depth, 0, edges, vertices, edgesToFollow);
LOG.debug("Vertex {} found for guid {}", v, guid);
} else {
LOG.debug("Vertex not found for guid {}", guid);
} }
try { try {
response.put("requestId", Thread.currentThread().getName());
response.put("vertices",vertices); response.put("vertices",vertices);
response.put("edges",edges); response.put("edges",edges);
} catch (JSONException e) { } catch (JSONException e) {
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse("Search: Error building JSON result set.", Response.Status.INTERNAL_SERVER_ERROR)); Servlets.getErrorResponse("Search: Error building JSON result set.", Response.Status.INTERNAL_SERVER_ERROR));
} }
LOG.debug("JSON result:" + response.toString());
return Response.ok(response).build(); return Response.ok(response).build();
} }
...@@ -215,13 +220,18 @@ public class MetadataDiscoveryResource { ...@@ -215,13 +220,18 @@ public class MetadataDiscoveryResource {
HashMap<String,Map<String,String>> vertices = new HashMap<String,Map<String,String>>(); HashMap<String,Map<String,String>> vertices = new HashMap<String,Map<String,String>>();
HashMap<String,Map<String,String>> edges = new HashMap<String,Map<String,String>>(); HashMap<String,Map<String,String>> edges = new HashMap<String,Map<String,String>>();
int resultCount = 0;
for (Vertex v: getGraph().query().has(prop,searchText).vertices()) { for (Vertex v: getGraph().query().has(prop,searchText).vertices()) {
searchWalker(v, depth, 0, edges, vertices, null); searchWalker(v, depth, 0, edges, vertices, null);
resultCount++;
} }
LOG.debug("Search for {} returned {} results.", searchText ,resultCount);
try { try {
response.put("requestId", Thread.currentThread().getName());
response.put("vertices",vertices); response.put("vertices",vertices);
response.put("edges",edges); response.put("edges",edges);
} catch (JSONException e) { } catch (JSONException e) {
...@@ -229,6 +239,7 @@ public class MetadataDiscoveryResource { ...@@ -229,6 +239,7 @@ public class MetadataDiscoveryResource {
Servlets.getErrorResponse("Search: Error building JSON result set.", Response.Status.INTERNAL_SERVER_ERROR)); Servlets.getErrorResponse("Search: Error building JSON result set.", Response.Status.INTERNAL_SERVER_ERROR));
} }
LOG.debug("JSON result:" + response.toString());
return Response.ok(response).build(); return Response.ok(response).build();
} }
...@@ -305,15 +316,5 @@ public class MetadataDiscoveryResource { ...@@ -305,15 +316,5 @@ public class MetadataDiscoveryResource {
} }
private static void validateInputs(String errorMsg, String... inputs) {
for (String input : inputs) {
if (StringUtils.isEmpty(input)) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST)
.entity(errorMsg)
.type("text/plain")
.build());
}
}
}
} }
...@@ -59,18 +59,19 @@ public class MetadataDiscoveryResourceIT extends BaseResourceIT { ...@@ -59,18 +59,19 @@ public class MetadataDiscoveryResourceIT extends BaseResourceIT {
} }
@Test (dependsOnMethods = "testUriExists", enabled = false) @Test (dependsOnMethods = "testFullTextUriExists")
public void testSearchForNonExistentText() throws Exception { public void testSearchForText() throws Exception {
WebResource resource = service WebResource resource = service
.path("api/metadata/discovery/search/fulltext") .path("api/metadata/discovery/search/fulltext")
.queryParam("depth", "0").queryParam("text","foo").queryParam("property","Name"); .queryParam("depth", "3").queryParam("text","bar").queryParam("property","hive_table.name");
ClientResponse clientResponse = resource ClientResponse clientResponse = resource
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON)
.method(HttpMethod.GET, ClientResponse.class); .method(HttpMethod.GET, ClientResponse.class);
//TODO - Assure zero vertices and edges. //TODO - Assure zero vertices and edges.
Assert.assertEquals(true,true); Assert.assertNotEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment