Search in sources :

Example 56 with AtlasPerfTracer

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

the class EntityREST method deleteByUniqueAttribute.

/**
 * Delete an entity identified by its type and unique attributes.
 * @param  typeName - entity type to be deleted
 * @param  servletRequest - request containing unique attributes/values
 * @return EntityMutationResponse
 */
@DELETE
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
@Path("/uniqueAttribute/type/{typeName}")
public EntityMutationResponse deleteByUniqueAttribute(@PathParam("typeName") String typeName, @Context HttpServletRequest servletRequest) throws AtlasBaseException {
    AtlasPerfTracer perf = null;
    try {
        Map<String, Object> attributes = getAttributes(servletRequest);
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.deleteByUniqueAttribute(" + typeName + "," + attributes + ")");
        }
        AtlasEntityType entityType = ensureEntityType(typeName);
        return entitiesStore.deleteByUniqueAttributes(entityType, attributes);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 57 with AtlasPerfTracer

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

the class EntityREST method getByUniqueAttributes.

/**
 * Fetch complete definition of an entity given its type and unique attribute.
 * @param typeName
 * @return AtlasEntityWithExtInfo
 * @throws AtlasBaseException
 */
@GET
@Path("/uniqueAttribute/type/{typeName}")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasEntityWithExtInfo getByUniqueAttributes(@PathParam("typeName") String typeName, @Context HttpServletRequest servletRequest) throws AtlasBaseException {
    AtlasPerfTracer perf = null;
    try {
        Map<String, Object> attributes = getAttributes(servletRequest);
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.getByUniqueAttributes(" + typeName + "," + attributes + ")");
        }
        AtlasEntityType entityType = ensureEntityType(typeName);
        validateUniqueAttribute(entityType, attributes);
        return entitiesStore.getByUniqueAttributes(entityType, attributes);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 58 with AtlasPerfTracer

use of org.apache.atlas.utils.AtlasPerfTracer in project 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);
            }
        });
        Map<String, Object> response = new HashMap<>();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put(TRAIT_NAME, traitName);
        return Response.ok(AtlasJson.toV1Json(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) HashMap(java.util.HashMap) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer)

Example 59 with AtlasPerfTracer

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

the class EntityResource method getTraitDefinitionsForEntity.

/**
 * Fetches the trait definitions of all the traits associated to the given entity
 * @param guid globally unique identifier for the entity
 */
@GET
@Path("{guid}/traitDefinitions")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getTraitDefinitionsForEntity(@PathParam("guid") String guid) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> EntityResource.getTraitDefinitionsForEntity({})", guid);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.getTraitDefinitionsForEntity(" + guid + ")");
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Fetching all trait definitions for entity={}", guid);
        }
        final List<AtlasClassification> classifications = entitiesStore.getClassifications(guid);
        List<Struct> traits = new ArrayList<>(classifications.size());
        for (AtlasClassification classification : classifications) {
            Struct trait = restAdapters.getTrait(classification);
            traits.add(trait);
        }
        Map<String, Object> response = new HashMap<>();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put(AtlasClient.RESULTS, traits);
        response.put(AtlasClient.COUNT, traits.size());
        return Response.ok(AtlasJson.toV1Json(response)).build();
    } catch (AtlasBaseException e) {
        LOG.error("Unable to get trait definition for entity {}", guid, e);
        throw toWebApplicationException(e);
    } catch (IllegalArgumentException e) {
        LOG.error("Unable to get trait definition for entity {}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get trait definitions for entity {}", guid, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get trait definitions for entity {}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== EntityResource.getTraitDefinitionsForEntity({})", guid);
        }
    }
}
Also used : HashMap(java.util.HashMap) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) ArrayList(java.util.ArrayList) Struct(org.apache.atlas.v1.model.instance.Struct) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification)

Example 60 with AtlasPerfTracer

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

the class EntityResource method getTraitNames.

// Trait management functions
/**
 * Gets the list of trait names for a given entity represented by a guid.
 *
 * @param guid globally unique identifier for the entity
 * @return a list of trait names for the given entity guid
 */
@GET
@Path("{guid}/traits")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getTraitNames(@PathParam("guid") String guid) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> EntityResource.getTraitNames({})", guid);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.getTraitNames(" + guid + ")");
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Fetching trait names for entity={}", guid);
        }
        final List<AtlasClassification> classifications = entitiesStore.getClassifications(guid);
        List<String> traitNames = new ArrayList<>();
        for (AtlasClassification classification : classifications) {
            traitNames.add(classification.getTypeName());
        }
        Map<String, Object> response = new HashMap<>();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put(AtlasClient.RESULTS, traitNames);
        response.put(AtlasClient.COUNT, traitNames.size());
        return Response.ok(AtlasJson.toV1Json(response)).build();
    } catch (AtlasBaseException e) {
        LOG.error("Unable to get trait definition for entity {}", guid, e);
        throw toWebApplicationException(e);
    } catch (IllegalArgumentException e) {
        LOG.error("Unable to get trait definition for entity {}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get trait names for entity {}", guid, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get trait names for entity {}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== EntityResource.getTraitNames({})", guid);
        }
    }
}
Also used : HashMap(java.util.HashMap) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) ArrayList(java.util.ArrayList) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification)

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