Search in sources :

Example 36 with AtlasPerfTracer

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

the class MetadataDiscoveryResource method searchUsingFullText.

/**
     * Search using full text search.
     *
     * @param query search query.
     * @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value
     * @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0
     * @return JSON representing the type and results.
     */
@GET
@Path("search/fulltext")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response searchUsingFullText(@QueryParam("query") String query, @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("limit") int limit, @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("offset") int offset) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> MetadataDiscoveryResource.searchUsingFullText({}, {}, {})", query, limit, offset);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.searchUsingFullText(" + query + ", " + limit + ", " + offset + ")");
        }
        query = ParamChecker.notEmpty(query, "query cannot be null or empty");
        QueryParams queryParams = validateQueryParams(limit, offset);
        final String jsonResultStr = discoveryService.searchByFullText(query, queryParams);
        JSONArray rowsJsonArr = new JSONArray(jsonResultStr);
        JSONObject response = new FullTextJSonResponseBuilder().results(rowsJsonArr).query(query).build();
        return Response.ok(response).build();
    } catch (DiscoveryException | IllegalArgumentException e) {
        LOG.error("Unable to get entity list for query {}", query, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get entity list for query {}", query, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get entity list for query {}", query, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== MetadataDiscoveryResource.searchUsingFullText({}, {}, {})", query, limit, offset);
        }
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) JSONArray(org.codehaus.jettison.json.JSONArray) QueryParams(org.apache.atlas.query.QueryParams) 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)

Example 37 with AtlasPerfTracer

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

the class TaxonomyService method createSubTerm.

@POST
@Path("{taxonomyName}/terms/{termName}/{remainder:.*}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response createSubTerm(String body, @Context HttpHeaders headers, @Context UriInfo ui, @PathParam("taxonomyName") String taxonomyName, @PathParam("termName") String termName, @PathParam("remainder") String remainder) throws CatalogException {
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.createSubTerm(" + taxonomyName + ", " + termName + ", " + remainder + ")");
        }
        Map<String, Object> properties = parsePayload(body);
        String[] pathTokens = remainder.split("/");
        validateName(pathTokens[pathTokens.length - 1]);
        properties.put("termPath", new TermPath(taxonomyName, String.format("%s%s", termName, remainder.replaceAll("/?terms/?([.]*)", "$1."))));
        createResource(termResourceProvider, new InstanceRequest(properties));
        return Response.status(Response.Status.CREATED).entity(new Results(ui.getRequestUri().toString(), 201)).build();
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 38 with AtlasPerfTracer

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

the class DataSetLineageResource method schema.

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

Example 39 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 40 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)

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