Search in sources :

Example 76 with AtlasPerfTracer

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

the class EntityREST method addClassification.

/**
 * Bulk API to associate a tag to multiple entities
 */
@POST
@Path("/bulk/classification")
@Consumes({ Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON })
@Produces(Servlets.JSON_MEDIA_TYPE)
public void addClassification(ClassificationAssociateRequest request) throws AtlasBaseException {
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.addClassification(" + request + ")");
        }
        AtlasClassification classification = request == null ? null : request.getClassification();
        List<String> entityGuids = request == null ? null : request.getEntityGuids();
        if (classification == null || StringUtils.isEmpty(classification.getTypeName())) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "no classification");
        }
        if (CollectionUtils.isEmpty(entityGuids)) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "empty guid list");
        }
        entitiesStore.addClassification(entityGuids, classification);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 77 with AtlasPerfTracer

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

the class EntityREST method getByUniqueAttributes.

/**
 * Fetch complete definition of an entity given its type and unique attribute.
 *
 * In addition to the typeName path parameter, attribute key-value pair(s) can be provided in the following format
 *
 * attr:<attrName>=<attrValue>
 *
 * NOTE: The attrName and attrValue should be unique across entities, eg. qualifiedName
 *
 * The REST request would look something like this
 *
 * GET /v2/entity/uniqueAttribute/type/aType?attr:aTypeAttribute=someValue
 *
 * @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 {
    Servlets.validateQueryParamLength("typeName", typeName);
    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 78 with AtlasPerfTracer

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

the class EntityREST method deleteByUniqueAttribute.

/**
 * Delete an entity identified by its type and unique attributes.
 *
 * In addition to the typeName path parameter, attribute key-value pair(s) can be provided in the following format
 *
 * attr:<attrName>=<attrValue>
 *
 * NOTE: The attrName and attrValue should be unique across entities, eg. qualifiedName
 *
 * The REST request would look something like this
 *
 * DELETE /v2/entity/uniqueAttribute/type/aType?attr:aTypeAttribute=someValue
 *
 * @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 {
    Servlets.validateQueryParamLength("typeName", typeName);
    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 79 with AtlasPerfTracer

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

the class EntityREST method updateClassifications.

/**
 * Updates classifications to an existing entity represented by a guid.
 * @param  guid globally unique identifier for the entity
 * @return classification for the given entity guid
 */
@PUT
@Path("/guid/{guid}/classifications")
@Produces(Servlets.JSON_MEDIA_TYPE)
public void updateClassifications(@PathParam("guid") final String guid, List<AtlasClassification> classifications) throws AtlasBaseException {
    Servlets.validateQueryParamLength("guid", guid);
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.updateClassifications(" + guid + ")");
        }
        if (StringUtils.isEmpty(guid)) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        }
        entitiesStore.updateClassifications(guid, classifications);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 80 with AtlasPerfTracer

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

the class EntityREST method setPropagatedClassificationState.

/**
 * Disable/Enable propagated classification for an existing entity represented by its guid.
 * @param guid               globally unique identifier for the entity
 * @param classificationName name of the propagated classification
 * @param sourceEntityGuid   source entity guid of the propagated classification
 * @param disablePropagation disable/enable propagation
 */
@PUT
@Path("/guid/{guid}/propagatedClassifications/{classificationName}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public void setPropagatedClassificationState(@PathParam("guid") String guid, @PathParam("classificationName") final String classificationName, @QueryParam("sourceEntityGuid") String sourceEntityGuid, @QueryParam("disablePropagation") boolean disablePropagation) throws AtlasBaseException {
    Servlets.validateQueryParamLength("guid", guid);
    Servlets.validateQueryParamLength("classificationName", classificationName);
    Servlets.validateQueryParamLength("sourceEntityGuid", sourceEntityGuid);
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.setPropagatedClassificationState(" + guid + "," + classificationName + "," + sourceEntityGuid + "," + disablePropagation + ")");
        }
        if (StringUtils.isEmpty(guid)) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        }
        if (StringUtils.isEmpty(classificationName)) {
            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "propagated classification not specified");
        }
        if (StringUtils.isEmpty(sourceEntityGuid)) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, sourceEntityGuid);
        }
        ensureClassificationType(classificationName);
        entitiesStore.setPropagatedClassificationState(guid, classificationName, sourceEntityGuid, disablePropagation);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

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