Search in sources :

Example 21 with EntityNotFoundException

use of org.apache.atlas.typesystem.exception.EntityNotFoundException in project incubator-atlas by apache.

the class LineageResource method schema.

/**
 * Returns the schema for the given dataset id.
 *
 * @param guid dataset entity id
 */
@GET
@Path("{guid}/schema")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response schema(@PathParam("guid") String guid) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> LineageResource.schema({})", guid);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "LineageResource.schema(" + guid + ")");
        }
        final String jsonResult = lineageService.getSchemaForEntity(guid);
        JSONObject response = new JSONObject();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put(AtlasClient.RESULTS, new JSONObject(jsonResult));
        return Response.ok(response).build();
    } catch (SchemaNotFoundException e) {
        LOG.error("schema not found for {}", guid);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
    } catch (EntityNotFoundException e) {
        LOG.error("table entity not found for {}", guid);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
    } catch (DiscoveryException | IllegalArgumentException e) {
        LOG.error("Unable to get schema for entity guid={}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get schema for entity guid={}", guid, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get schema for entity={}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== LineageResource.schema({})", guid);
        }
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) SchemaNotFoundException(org.apache.atlas.typesystem.exception.SchemaNotFoundException) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) DiscoveryException(org.apache.atlas.discovery.DiscoveryException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)21 JSONObject (org.codehaus.jettison.json.JSONObject)10 AtlasException (org.apache.atlas.AtlasException)8 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)7 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)6 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)5 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)5 HashMap (java.util.HashMap)4 DiscoveryException (org.apache.atlas.discovery.DiscoveryException)4 Referenceable (org.apache.atlas.typesystem.Referenceable)4 Test (org.testng.annotations.Test)4 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)3 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)3 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)3 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)3 Id (org.apache.atlas.typesystem.persistence.Id)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)2 EntityResult (org.apache.atlas.model.legacy.EntityResult)2