Search in sources :

Example 91 with AtlasPerfTracer

use of org.apache.atlas.utils.AtlasPerfTracer in project incubator-atlas by apache.

the class EntityResource method getEntityDefinition.

/**
 * Fetch the complete definition of an entity given its GUID.
 *
 * @param guid GUID for the entity
 */
@GET
@Path("{guid}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getEntityDefinition(@PathParam("guid") String guid) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> EntityResource.getEntityDefinition({})", guid);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.getEntityDefinition(" + guid + ")");
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Fetching entity definition for guid={} ", guid);
        }
        guid = ParamChecker.notEmpty(guid, "guid cannot be null");
        final String entityDefinition = metadataService.getEntityDefinitionJson(guid);
        JSONObject response = new JSONObject();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        Response.Status status = Response.Status.NOT_FOUND;
        if (entityDefinition != null) {
            response.put(AtlasClient.DEFINITION, new JSONObject(entityDefinition));
            status = Response.Status.OK;
        } else {
            response.put(AtlasClient.ERROR, Servlets.escapeJsonString(String.format("An entity with GUID={%s} does not exist", guid)));
        }
        return Response.status(status).entity(response).build();
    } catch (EntityNotFoundException e) {
        LOG.error("An entity with GUID={} does not exist ", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.NOT_FOUND));
    } catch (AtlasException | IllegalArgumentException e) {
        LOG.error("Bad GUID={} ", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get instance definition for GUID {}", guid, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get instance definition for GUID {}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== EntityResource.getEntityDefinition({})", guid);
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) JSONObject(org.codehaus.jettison.json.JSONObject) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) AtlasException(org.apache.atlas.AtlasException)

Example 92 with AtlasPerfTracer

use of org.apache.atlas.utils.AtlasPerfTracer in project incubator-atlas by apache.

the class EntityResource method deleteTrait.

/**
 * Deletes a given trait from an existing entity represented by a guid.
 *
 * @param guid      globally unique identifier for the entity
 * @param traitName name of the trait
 */
@DELETE
@Path("{guid}/traits/{traitName}")
@Consumes({ Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON })
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response deleteTrait(@Context HttpServletRequest request, @PathParam("guid") String guid, @PathParam(TRAIT_NAME) final String traitName) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> EntityResource.deleteTrait({}, {})", guid, traitName);
    }
    AtlasPerfTracer perf = null;
    if (LOG.isDebugEnabled()) {
        LOG.debug("Deleting trait={} from entity={} ", traitName, guid);
    }
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.deleteTrait(" + guid + ", " + traitName + ")");
        }
        entitiesStore.deleteClassifications(guid, new ArrayList<String>() {

            {
                add(traitName);
            }
        });
        JSONObject response = new JSONObject();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put(TRAIT_NAME, traitName);
        return Response.ok(response).build();
    } catch (AtlasBaseException e) {
        LOG.error("Unable to delete trait name={} for entity={}", traitName, guid, e);
        throw toWebApplicationException(e);
    } catch (IllegalArgumentException e) {
        LOG.error("Unable to delete trait name={} for entity={}", traitName, guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to delete trait name={} for entity={}", traitName, guid, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to delete trait name={} for entity={}", traitName, guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== EntityResource.deleteTrait({}, {})", guid, traitName);
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) JSONObject(org.codehaus.jettison.json.JSONObject) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer)

Example 93 with AtlasPerfTracer

use of org.apache.atlas.utils.AtlasPerfTracer in project incubator-atlas by apache.

the class EntityService method tagEntity.

@POST
@Path("{entityId}/tags/{tag}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response tagEntity(String body, @Context HttpHeaders headers, @Context UriInfo ui, @PathParam("entityId") String entityId, @PathParam("tag") String tagName) throws CatalogException {
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.tagEntity(" + entityId + ", " + tagName + ")");
        }
        Map<String, Object> properties = new HashMap<>();
        properties.put("id", entityId);
        properties.put("name", tagName);
        createResource(entityTagResourceProvider, new InstanceRequest(properties));
        return Response.status(Response.Status.CREATED).entity(new Results(ui.getRequestUri().toString(), 201)).build();
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : HashMap(java.util.HashMap) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) InstanceRequest(org.apache.atlas.catalog.InstanceRequest) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 94 with AtlasPerfTracer

use of org.apache.atlas.utils.AtlasPerfTracer in project incubator-atlas by apache.

the class EntityService method getEntityTags.

@GET
@Path("{entityId}/tags")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getEntityTags(@Context HttpHeaders headers, @Context UriInfo ui, @PathParam("entityId") String entityGuid) throws CatalogException {
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.getEntityTags(" + entityGuid + ")");
        }
        BaseRequest request = new CollectionRequest(Collections.<String, Object>singletonMap("id", entityGuid), decode(getQueryString(ui)));
        Result result = getResources(entityTagResourceProvider, request);
        return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build();
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : CollectionRequest(org.apache.atlas.catalog.CollectionRequest) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) BaseRequest(org.apache.atlas.catalog.BaseRequest) Result(org.apache.atlas.catalog.Result) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 95 with AtlasPerfTracer

use of org.apache.atlas.utils.AtlasPerfTracer 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

AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)108 Produces (javax.ws.rs.Produces)76 Path (javax.ws.rs.Path)67 Consumes (javax.ws.rs.Consumes)45 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)45 GET (javax.ws.rs.GET)43 HashMap (java.util.HashMap)27 JSONObject (org.codehaus.jettison.json.JSONObject)24 WebApplicationException (javax.ws.rs.WebApplicationException)22 ArrayList (java.util.ArrayList)14 DELETE (javax.ws.rs.DELETE)11 POST (javax.ws.rs.POST)11 PUT (javax.ws.rs.PUT)11 AtlasException (org.apache.atlas.AtlasException)10 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)10 JSONArray (org.codehaus.jettison.json.JSONArray)9 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)8 DiscoveryException (org.apache.atlas.discovery.DiscoveryException)7 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)7 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)7