Commit 84c8636d by Shwetha G S

Merge pull request #113 from sumashivaprasad/BUG_37105

BUG-36503 - Standardizing response on internal errors, client side errors
parents d0ce7d60 d2fba3b4
...@@ -90,11 +90,11 @@ public class EntityResource { ...@@ -90,11 +90,11 @@ public class EntityResource {
response.put(MetadataServiceClient.DEFINITION, entity); response.put(MetadataServiceClient.DEFINITION, entity);
return Response.created(locationURI).entity(response).build(); return Response.created(locationURI).entity(response).build();
} catch (MetadataException | IOException | IllegalArgumentException e) { } catch (MetadataException | IllegalArgumentException e) {
LOG.error("Unable to persist entity instance", e); LOG.error("Unable to persist entity instance", e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) { } catch (Throwable e) {
LOG.error("Unable to persist entity instance", e); LOG.error("Unable to persist entity instance", e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
...@@ -132,7 +132,7 @@ public class EntityResource { ...@@ -132,7 +132,7 @@ public class EntityResource {
LOG.error("An entity with GUID={} does not exist", guid, e); LOG.error("An entity with GUID={} does not exist", guid, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.NOT_FOUND)); Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
} catch (JSONException e) { } catch (Throwable e) {
LOG.error("Unable to get instance definition for GUID {}", guid, e); LOG.error("Unable to get instance definition for GUID {}", guid, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
...@@ -168,7 +168,7 @@ public class EntityResource { ...@@ -168,7 +168,7 @@ public class EntityResource {
LOG.error("Unable to get entity list for type {}", entityType, e); LOG.error("Unable to get entity list for type {}", entityType, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) { } catch (Throwable e) {
LOG.error("Unable to get entity list for type {}", entityType, e); LOG.error("Unable to get entity list for type {}", entityType, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
...@@ -198,7 +198,7 @@ public class EntityResource { ...@@ -198,7 +198,7 @@ public class EntityResource {
LOG.error("Unable to add property {} to entity id {}", property, guid, e); LOG.error("Unable to add property {} to entity id {}", property, guid, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) { } catch (Throwable e) {
LOG.error("Unable to add property {} to entity id {}", property, guid, e); LOG.error("Unable to add property {} to entity id {}", property, guid, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
...@@ -231,7 +231,7 @@ public class EntityResource { ...@@ -231,7 +231,7 @@ public class EntityResource {
LOG.error("Unable to get trait names for entity {}", guid, e); LOG.error("Unable to get trait names for entity {}", guid, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) { } catch (Throwable e) {
LOG.error("Unable to get trait names for entity {}", guid, e); LOG.error("Unable to get trait names for entity {}", guid, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
...@@ -267,7 +267,7 @@ public class EntityResource { ...@@ -267,7 +267,7 @@ public class EntityResource {
LOG.error("Unable to add trait for entity={}", guid, e); LOG.error("Unable to add trait for entity={}", guid, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) { } catch (Throwable e) {
LOG.error("Unable to add trait for entity={}", guid, e); LOG.error("Unable to add trait for entity={}", guid, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
...@@ -301,7 +301,7 @@ public class EntityResource { ...@@ -301,7 +301,7 @@ public class EntityResource {
LOG.error("Unable to delete trait name={} for entity={}", traitName, guid, e); LOG.error("Unable to delete trait name={} for entity={}", traitName, guid, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) { } catch (Throwable e) {
LOG.error("Unable to delete trait name={} for entity={}", traitName, guid, e); LOG.error("Unable to delete trait name={} for entity={}", traitName, guid, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
......
...@@ -18,12 +18,11 @@ ...@@ -18,12 +18,11 @@
package org.apache.hadoop.metadata.web.resources; package org.apache.hadoop.metadata.web.resources;
import com.google.common.base.Preconditions;
import org.apache.hadoop.metadata.MetadataServiceClient; import org.apache.hadoop.metadata.MetadataServiceClient;
import org.apache.hadoop.metadata.ParamChecker;
import org.apache.hadoop.metadata.discovery.DiscoveryException; import org.apache.hadoop.metadata.discovery.DiscoveryException;
import org.apache.hadoop.metadata.discovery.LineageService; import org.apache.hadoop.metadata.discovery.LineageService;
import org.apache.hadoop.metadata.web.util.Servlets; import org.apache.hadoop.metadata.web.util.Servlets;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -69,10 +68,11 @@ public class HiveLineageResource { ...@@ -69,10 +68,11 @@ public class HiveLineageResource {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response inputs(@Context HttpServletRequest request, public Response inputs(@Context HttpServletRequest request,
@PathParam("tableName") String tableName) { @PathParam("tableName") String tableName) {
Preconditions.checkNotNull(tableName, "table name cannot be null");
LOG.info("Fetching lineage inputs for tableName={}", tableName); LOG.info("Fetching lineage inputs for tableName={}", tableName);
try { try {
ParamChecker.notEmpty(tableName, "table name cannot be null");
final String jsonResult = lineageService.getInputs(tableName); final String jsonResult = lineageService.getInputs(tableName);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
...@@ -81,11 +81,11 @@ public class HiveLineageResource { ...@@ -81,11 +81,11 @@ public class HiveLineageResource {
response.put(MetadataServiceClient.RESULTS, new JSONObject(jsonResult)); response.put(MetadataServiceClient.RESULTS, new JSONObject(jsonResult));
return Response.ok(response).build(); return Response.ok(response).build();
} catch (DiscoveryException e) { } catch (DiscoveryException | IllegalArgumentException e) {
LOG.error("Unable to get lineage inputs for table {}", tableName, e); LOG.error("Unable to get lineage inputs for table {}", tableName, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) { } catch (Throwable e) {
LOG.error("Unable to get lineage inputs for table {}", tableName, e); LOG.error("Unable to get lineage inputs for table {}", tableName, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
...@@ -103,10 +103,10 @@ public class HiveLineageResource { ...@@ -103,10 +103,10 @@ public class HiveLineageResource {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response inputsGraph(@Context HttpServletRequest request, public Response inputsGraph(@Context HttpServletRequest request,
@PathParam("tableName") String tableName) { @PathParam("tableName") String tableName) {
Preconditions.checkNotNull(tableName, "table name cannot be null");
LOG.info("Fetching lineage inputs graph for tableName={}", tableName); LOG.info("Fetching lineage inputs graph for tableName={}", tableName);
try { try {
ParamChecker.notEmpty(tableName, "table name cannot be null");
final String jsonResult = lineageService.getInputsGraph(tableName); final String jsonResult = lineageService.getInputsGraph(tableName);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
...@@ -115,11 +115,11 @@ public class HiveLineageResource { ...@@ -115,11 +115,11 @@ public class HiveLineageResource {
response.put(MetadataServiceClient.RESULTS, new JSONObject(jsonResult)); response.put(MetadataServiceClient.RESULTS, new JSONObject(jsonResult));
return Response.ok(response).build(); return Response.ok(response).build();
} catch (DiscoveryException e) { } catch (DiscoveryException | IllegalArgumentException e) {
LOG.error("Unable to get lineage inputs graph for table {}", tableName, e); LOG.error("Unable to get lineage inputs graph for table {}", tableName, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) { } catch (Throwable e) {
LOG.error("Unable to get lineage inputs graph for table {}", tableName, e); LOG.error("Unable to get lineage inputs graph for table {}", tableName, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
...@@ -138,10 +138,10 @@ public class HiveLineageResource { ...@@ -138,10 +138,10 @@ public class HiveLineageResource {
public Response outputs(@Context HttpServletRequest request, public Response outputs(@Context HttpServletRequest request,
@PathParam("tableName") String tableName) { @PathParam("tableName") String tableName) {
Preconditions.checkNotNull(tableName, "table name cannot be null");
LOG.info("Fetching lineage outputs for tableName={}", tableName); LOG.info("Fetching lineage outputs for tableName={}", tableName);
try { try {
ParamChecker.notEmpty(tableName, "table name cannot be null");
final String jsonResult = lineageService.getOutputs(tableName); final String jsonResult = lineageService.getOutputs(tableName);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
...@@ -150,11 +150,11 @@ public class HiveLineageResource { ...@@ -150,11 +150,11 @@ public class HiveLineageResource {
response.put(MetadataServiceClient.RESULTS, new JSONObject(jsonResult)); response.put(MetadataServiceClient.RESULTS, new JSONObject(jsonResult));
return Response.ok(response).build(); return Response.ok(response).build();
} catch (DiscoveryException e) { } catch (DiscoveryException | IllegalArgumentException e) {
LOG.error("Unable to get lineage outputs for table {}", tableName, e); LOG.error("Unable to get lineage outputs for table {}", tableName, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) { } catch (Throwable e) {
LOG.error("Unable to get lineage outputs for table {}", tableName, e); LOG.error("Unable to get lineage outputs for table {}", tableName, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
...@@ -172,10 +172,11 @@ public class HiveLineageResource { ...@@ -172,10 +172,11 @@ public class HiveLineageResource {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response outputsGraph(@Context HttpServletRequest request, public Response outputsGraph(@Context HttpServletRequest request,
@PathParam("tableName") String tableName) { @PathParam("tableName") String tableName) {
Preconditions.checkNotNull(tableName, "table name cannot be null");
LOG.info("Fetching lineage outputs graph for tableName={}", tableName); LOG.info("Fetching lineage outputs graph for tableName={}", tableName);
try { try {
ParamChecker.notEmpty(tableName, "table name cannot be null");
final String jsonResult = lineageService.getOutputsGraph(tableName); final String jsonResult = lineageService.getOutputsGraph(tableName);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
...@@ -184,11 +185,11 @@ public class HiveLineageResource { ...@@ -184,11 +185,11 @@ public class HiveLineageResource {
response.put(MetadataServiceClient.RESULTS, new JSONObject(jsonResult)); response.put(MetadataServiceClient.RESULTS, new JSONObject(jsonResult));
return Response.ok(response).build(); return Response.ok(response).build();
} catch (DiscoveryException e) { } catch (DiscoveryException | IllegalArgumentException e) {
LOG.error("Unable to get lineage outputs graph for table {}", tableName, e); LOG.error("Unable to get lineage outputs graph for table {}", tableName, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) { } catch (Throwable e) {
LOG.error("Unable to get lineage outputs graph for table {}", tableName, e); LOG.error("Unable to get lineage outputs graph for table {}", tableName, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
...@@ -207,10 +208,11 @@ public class HiveLineageResource { ...@@ -207,10 +208,11 @@ public class HiveLineageResource {
public Response schema(@Context HttpServletRequest request, public Response schema(@Context HttpServletRequest request,
@PathParam("tableName") String tableName) { @PathParam("tableName") String tableName) {
Preconditions.checkNotNull(tableName, "table name cannot be null");
LOG.info("Fetching schema for tableName={}", tableName); LOG.info("Fetching schema for tableName={}", tableName);
try { try {
ParamChecker.notEmpty(tableName, "table name cannot be null");
final String jsonResult = lineageService.getSchema(tableName); final String jsonResult = lineageService.getSchema(tableName);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
...@@ -219,11 +221,11 @@ public class HiveLineageResource { ...@@ -219,11 +221,11 @@ public class HiveLineageResource {
response.put(MetadataServiceClient.RESULTS, new JSONObject(jsonResult)); response.put(MetadataServiceClient.RESULTS, new JSONObject(jsonResult));
return Response.ok(response).build(); return Response.ok(response).build();
} catch (DiscoveryException e) { } catch (DiscoveryException | IllegalArgumentException e) {
LOG.error("Unable to get schema for table {}", tableName, e); LOG.error("Unable to get schema for table {}", tableName, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) { } catch (Throwable e) {
LOG.error("Unable to get schema for table {}", tableName, e); LOG.error("Unable to get schema for table {}", tableName, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
......
...@@ -20,6 +20,7 @@ package org.apache.hadoop.metadata.web.resources; ...@@ -20,6 +20,7 @@ package org.apache.hadoop.metadata.web.resources;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import org.apache.hadoop.metadata.MetadataServiceClient; import org.apache.hadoop.metadata.MetadataServiceClient;
import org.apache.hadoop.metadata.ParamChecker;
import org.apache.hadoop.metadata.discovery.DiscoveryException; import org.apache.hadoop.metadata.discovery.DiscoveryException;
import org.apache.hadoop.metadata.discovery.DiscoveryService; import org.apache.hadoop.metadata.discovery.DiscoveryService;
import org.apache.hadoop.metadata.web.util.Servlets; import org.apache.hadoop.metadata.web.util.Servlets;
...@@ -76,20 +77,22 @@ public class MetadataDiscoveryResource { ...@@ -76,20 +77,22 @@ public class MetadataDiscoveryResource {
@Path("search") @Path("search")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response search(@QueryParam("query") String query) { public Response search(@QueryParam("query") String query) {
Preconditions.checkNotNull(query, "query cannot be null");
if (query.startsWith("g.")) { // raw gremlin query
return searchUsingGremlinQuery(query);
}
JSONObject response; JSONObject response;
try { // fall back to dsl try { // fall back to dsl
ParamChecker.notEmpty(query, "query cannot be null");
if (query.startsWith("g.")) { // raw gremlin query
return searchUsingGremlinQuery(query);
}
final String jsonResultStr = discoveryService.searchByDSL(query); final String jsonResultStr = discoveryService.searchByDSL(query);
response = new DSLJSONResponseBuilder().results(jsonResultStr) response = new DSLJSONResponseBuilder().results(jsonResultStr)
.query(query) .query(query)
.build(); .build();
} catch (IllegalArgumentException e) {
LOG.error("Unable to get entity list for empty query", e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (Throwable throwable) { } catch (Throwable throwable) {
LOG.error("Unable to get entity list for query {} using dsl", query, throwable); LOG.error("Unable to get entity list for query {} using dsl", query, throwable);
...@@ -99,10 +102,10 @@ public class MetadataDiscoveryResource { ...@@ -99,10 +102,10 @@ public class MetadataDiscoveryResource {
.query(query) .query(query)
.build(); .build();
} catch (DiscoveryException e) { } catch (DiscoveryException | IllegalArgumentException e) {
LOG.error("Unable to get entity list for query {}", query, e); LOG.error("Unable to get entity list for query {}", query, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) { } catch(Throwable e) {
LOG.error("Unable to get entity list for query {}", query, e); LOG.error("Unable to get entity list for query {}", query, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
...@@ -124,9 +127,8 @@ public class MetadataDiscoveryResource { ...@@ -124,9 +127,8 @@ public class MetadataDiscoveryResource {
@Path("search/dsl") @Path("search/dsl")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response searchUsingQueryDSL(@QueryParam("query") String dslQuery) { public Response searchUsingQueryDSL(@QueryParam("query") String dslQuery) {
Preconditions.checkNotNull(dslQuery, "dslQuery cannot be null");
try { try {
ParamChecker.notEmpty(dslQuery, "dslQuery cannot be null");
final String jsonResultStr = discoveryService.searchByDSL(dslQuery); final String jsonResultStr = discoveryService.searchByDSL(dslQuery);
JSONObject response = new DSLJSONResponseBuilder().results(jsonResultStr) JSONObject response = new DSLJSONResponseBuilder().results(jsonResultStr)
...@@ -135,11 +137,11 @@ public class MetadataDiscoveryResource { ...@@ -135,11 +137,11 @@ public class MetadataDiscoveryResource {
return Response.ok(response) return Response.ok(response)
.build(); .build();
} catch (DiscoveryException e) { } catch (DiscoveryException | IllegalArgumentException e) {
LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e); LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) { } catch(Throwable e) {
LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e); LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
...@@ -156,9 +158,8 @@ public class MetadataDiscoveryResource { ...@@ -156,9 +158,8 @@ public class MetadataDiscoveryResource {
@Path("search/gremlin") @Path("search/gremlin")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response searchUsingGremlinQuery(@QueryParam("query") String gremlinQuery) { public Response searchUsingGremlinQuery(@QueryParam("query") String gremlinQuery) {
Preconditions.checkNotNull(gremlinQuery, "gremlinQuery cannot be null");
try { try {
ParamChecker.notEmpty(gremlinQuery, "gremlinQuery cannot be null or empty");
final List<Map<String, String>> results = discoveryService final List<Map<String, String>> results = discoveryService
.searchByGremlin(gremlinQuery); .searchByGremlin(gremlinQuery);
...@@ -176,11 +177,11 @@ public class MetadataDiscoveryResource { ...@@ -176,11 +177,11 @@ public class MetadataDiscoveryResource {
return Response.ok(response) return Response.ok(response)
.build(); .build();
} catch (DiscoveryException e) { } catch (DiscoveryException | IllegalArgumentException e) {
LOG.error("Unable to get entity list for gremlinQuery {}", gremlinQuery, e); LOG.error("Unable to get entity list for gremlinQuery {}", gremlinQuery, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) { } catch(Throwable e) {
LOG.error("Unable to get entity list for gremlinQuery {}", gremlinQuery, e); LOG.error("Unable to get entity list for gremlinQuery {}", gremlinQuery, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
...@@ -197,9 +198,8 @@ public class MetadataDiscoveryResource { ...@@ -197,9 +198,8 @@ public class MetadataDiscoveryResource {
@Path("search/fulltext") @Path("search/fulltext")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response searchUsingFullText(@QueryParam("query") String query) { public Response searchUsingFullText(@QueryParam("query") String query) {
Preconditions.checkNotNull(query, "query cannot be null");
try { try {
ParamChecker.notEmpty(query, "query cannot be null or empty");
final String jsonResultStr = discoveryService.searchByFullText(query); final String jsonResultStr = discoveryService.searchByFullText(query);
JSONArray rowsJsonArr = new JSONArray(jsonResultStr); JSONArray rowsJsonArr = new JSONArray(jsonResultStr);
...@@ -208,10 +208,10 @@ public class MetadataDiscoveryResource { ...@@ -208,10 +208,10 @@ public class MetadataDiscoveryResource {
.build(); .build();
return Response.ok(response) return Response.ok(response)
.build(); .build();
} catch (DiscoveryException e) { } catch (DiscoveryException | IllegalArgumentException e) {
LOG.error("Unable to get entity list for query {}", query, e); LOG.error("Unable to get entity list for query {}", query, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) { } catch(Throwable e) {
LOG.error("Unable to get entity list for query {}", query, e); LOG.error("Unable to get entity list for query {}", query, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR)); throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} }
......
...@@ -101,10 +101,14 @@ public class TypesResource { ...@@ -101,10 +101,14 @@ public class TypesResource {
response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
response.put(MetadataServiceClient.TYPES, typesAddedList); response.put(MetadataServiceClient.TYPES, typesAddedList);
return Response.status(ClientResponse.Status.CREATED).entity(response).build(); return Response.status(ClientResponse.Status.CREATED).entity(response).build();
} catch (Exception e) { } catch (MetadataException | IllegalArgumentException e) {
LOG.error("Unable to persist types", e); LOG.error("Unable to persist types", e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (Throwable e) {
LOG.error("Unable to persist types", e);
throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} }
} }
...@@ -122,7 +126,7 @@ public class TypesResource { ...@@ -122,7 +126,7 @@ public class TypesResource {
final String typeDefinition = metadataService.getTypeDefinition(typeName); final String typeDefinition = metadataService.getTypeDefinition(typeName);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put("typeName", typeName); response.put(MetadataServiceClient.TYPENAME, typeName);
response.put(MetadataServiceClient.DEFINITION, typeDefinition); response.put(MetadataServiceClient.DEFINITION, typeDefinition);
response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
...@@ -131,10 +135,14 @@ public class TypesResource { ...@@ -131,10 +135,14 @@ public class TypesResource {
LOG.error("Unable to get type definition for type {}", typeName, e); LOG.error("Unable to get type definition for type {}", typeName, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.NOT_FOUND)); Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
} catch (JSONException e) { } catch (JSONException | IllegalArgumentException e) {
LOG.error("Unable to get type definition for type {}", typeName, e); LOG.error("Unable to get type definition for type {}", typeName, e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (Throwable e) {
LOG.error("Unable to get type definition for type {}", typeName, e);
throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} }
} }
...@@ -165,14 +173,14 @@ public class TypesResource { ...@@ -165,14 +173,14 @@ public class TypesResource {
response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
return Response.ok(response).build(); return Response.ok(response).build();
} catch (IllegalArgumentException ie) { } catch (IllegalArgumentException | MetadataException ie) {
LOG.error("Unsupported typeName while retrieving type list {}", type); LOG.error("Unsupported typeName while retrieving type list {}", type);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse("Unsupported type " + type, Response.Status.BAD_REQUEST)); Servlets.getErrorResponse("Unsupported type " + type, Response.Status.BAD_REQUEST));
} catch (Exception e) { } catch (Throwable e) {
LOG.error("Unable to get types list", e); LOG.error("Unable to get types list", e);
throw new WebApplicationException( throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST)); Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} }
} }
} }
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