Search in sources :

Example 46 with AtlasPerfTracer

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

the class TaxonomyService method getTaxonomyTerms.

@GET
@Path("{taxonomyName}/terms")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getTaxonomyTerms(@Context HttpHeaders headers, @Context UriInfo ui, @PathParam("taxonomyName") String taxonomyName) throws CatalogException {
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.getTaxonomyTerms(" + taxonomyName + ")");
        }
        String queryString = decode(getQueryString(ui));
        TermPath termPath = new TermPath(taxonomyName, null);
        Request request = new CollectionRequest(Collections.<String, Object>singletonMap("termPath", termPath), queryString);
        Result result = getResources(termResourceProvider, request);
        return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build();
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 47 with AtlasPerfTracer

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

the class EntityREST method partialUpdateEntityByUniqueAttrs.

/*******
     * Entity Partial Update - Allows a subset of attributes to be updated on
     * an entity which is identified by its type and unique attribute  eg: Referenceable.qualifiedName.
     * Null updates are not possible
     *******/
@PUT
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
@Path("/uniqueAttribute/type/{typeName}")
public EntityMutationResponse partialUpdateEntityByUniqueAttrs(@PathParam("typeName") String typeName, @Context HttpServletRequest servletRequest, AtlasEntityWithExtInfo entityInfo) throws Exception {
    AtlasPerfTracer perf = null;
    try {
        Map<String, Object> uniqueAttributes = getAttributes(servletRequest);
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.partialUpdateEntityByUniqueAttrs(" + typeName + "," + uniqueAttributes + ")");
        }
        AtlasEntityType entityType = ensureEntityType(typeName);
        validateUniqueAttribute(entityType, uniqueAttributes);
        return entitiesStore.updateByUniqueAttributes(entityType, uniqueAttributes, entityInfo);
    } 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) PUT(javax.ws.rs.PUT)

Example 48 with AtlasPerfTracer

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

the class EntityREST method deleteClassification.

/**
     * Deletes a given classification from an existing entity represented by a guid.
     * @param guid      globally unique identifier for the entity
     * @param classificationName name of the classifcation
     */
@DELETE
@Path("/guid/{guid}/classification/{classificationName}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public void deleteClassification(@PathParam("guid") String guid, @PathParam("classificationName") final String classificationName) throws AtlasBaseException {
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.deleteClassification(" + guid + "," + classificationName + ")");
        }
        if (StringUtils.isEmpty(guid)) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        }
        ensureClassificationType(classificationName);
        entitiesStore.deleteClassifications(guid, new ArrayList<String>() {

            {
                add(classificationName);
            }
        });
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 49 with AtlasPerfTracer

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

the class TypesResource method update.

/**
     * Update of existing types - if the given type doesn't exist, creates new type
     * Allowed updates are:
     * 1. Add optional attribute
     * 2. Change required to optional attribute
     * 3. Add super types - super types shouldn't contain any required attributes
     * @param request
     * @return
     */
@PUT
@Consumes({ Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON })
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response update(@Context HttpServletRequest request) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> TypesResource.update()");
    }
    AtlasPerfTracer perf = null;
    if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
        perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.update()");
    }
    JSONArray typesResponse = new JSONArray();
    try {
        final String typeDefinition = Servlets.getRequestPayload(request);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Updating type with definition {} ", typeDefinition);
        }
        AtlasTypesDef updateTypesDef = TypeConverterUtil.toAtlasTypesDef(typeDefinition, typeRegistry);
        AtlasTypesDef updatedTypesDef = typesREST.updateAtlasTypeDefs(updateTypesDef);
        List<String> typeNames = TypeConverterUtil.getTypeNames(updatedTypesDef);
        for (int i = 0; i < typeNames.size(); i++) {
            final String name = typeNames.get(i);
            typesResponse.put(new JSONObject() {

                {
                    put(AtlasClient.NAME, name);
                }
            });
        }
        JSONObject response = new JSONObject();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put(AtlasClient.TYPES, typesResponse);
        return Response.ok().entity(response).build();
    } catch (AtlasBaseException e) {
        LOG.error("Unable to persist types", e);
        throw new WebApplicationException(Servlets.getErrorResponse(e));
    } catch (IllegalArgumentException e) {
        LOG.error("Unable to persist types", e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to persist types", e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to persist types", e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== TypesResource.update()");
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) JSONObject(org.codehaus.jettison.json.JSONObject) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) JSONArray(org.codehaus.jettison.json.JSONArray) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 50 with AtlasPerfTracer

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

the class TypesResource method getTypesByFilter.

/**
     * Return the list of type names in the type system which match the specified filter.
     *
     * @return list of type names
     * @param typeCategory returns types whose category is the given typeCategory
     * @param supertype returns types which contain the given supertype
     * @param notsupertype returns types which do not contain the given supertype
     *
     * Its possible to specify combination of these filters in one request and the conditions are combined with AND
     * For example, typeCategory = TRAIT && supertype contains 'X' && supertype !contains 'Y'
     * If there is no filter, all the types are returned
     */
@GET
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getTypesByFilter(@Context HttpServletRequest request, @QueryParam("type") String typeCategory, @QueryParam("supertype") String supertype, @QueryParam("notsupertype") String notsupertype) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> TypesResource.getTypesByFilter({}, {}, {})", typeCategory, supertype, notsupertype);
    }
    AtlasPerfTracer perf = null;
    if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
        perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getTypesByFilter(" + typeCategory + ", " + supertype + ", " + notsupertype + ")");
    }
    JSONObject response = new JSONObject();
    try {
        List<String> result = TypeConverterUtil.getTypeNames(typesREST.getTypeDefHeaders(request));
        response.put(AtlasClient.RESULTS, new JSONArray(result));
        response.put(AtlasClient.COUNT, result.size());
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        return Response.ok(response).build();
    } catch (AtlasBaseException e) {
        LOG.warn("TypesREST exception: {} {}", e.getClass().getSimpleName(), e.getMessage());
        throw new WebApplicationException(Servlets.getErrorResponse(e));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get types list", e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get types list", e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== TypesResource.getTypesByFilter({}, {}, {})", typeCategory, supertype, notsupertype);
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) JSONObject(org.codehaus.jettison.json.JSONObject) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) JSONArray(org.codehaus.jettison.json.JSONArray) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)50 Produces (javax.ws.rs.Produces)36 Path (javax.ws.rs.Path)30 JSONObject (org.codehaus.jettison.json.JSONObject)24 GET (javax.ws.rs.GET)18 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)17 HashMap (java.util.HashMap)14 Consumes (javax.ws.rs.Consumes)12 WebApplicationException (javax.ws.rs.WebApplicationException)10 JSONArray (org.codehaus.jettison.json.JSONArray)9 POST (javax.ws.rs.POST)7 DiscoveryException (org.apache.atlas.discovery.DiscoveryException)7 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)7 DELETE (javax.ws.rs.DELETE)6 AtlasException (org.apache.atlas.AtlasException)6 PUT (javax.ws.rs.PUT)5 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)5 InstanceRequest (org.apache.atlas.catalog.InstanceRequest)4 Result (org.apache.atlas.catalog.Result)4 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)4