Search in sources :

Example 11 with AtlasPerfTracer

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

the class LineageResource method outputsGraph.

/**
     * Returns the outputs graph for a given entity id.
     *
     * @param guid dataset entity id
     */
@GET
@Path("{guid}/outputs/graph")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response outputsGraph(@PathParam("guid") String guid) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> LineageResource.outputsGraph({})", guid);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "LineageResource.outputsGraph(" + guid + ")");
        }
        AtlasLineageInfo lineageInfo = atlasLineageService.getAtlasLineageInfo(guid, LineageDirection.OUTPUT, -1);
        final String result = LineageUtils.toLineageStruct(lineageInfo, typeRegistry);
        JSONObject response = new JSONObject();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put(AtlasClient.RESULTS, new JSONObject(result));
        return Response.ok(response).build();
    } catch (AtlasBaseException e) {
        LOG.error("Unable to get lineage outputs graph for entity guid={}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get lineage outputs graph for entity guid={}", guid, e);
        throw e;
    } catch (JSONException e) {
        LOG.error("Unable to get lineage outputs graph for entity guid={}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== LineageResource.outputsGraph({})", guid);
        }
    }
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) JSONObject(org.codehaus.jettison.json.JSONObject) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) JSONException(org.codehaus.jettison.json.JSONException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with AtlasPerfTracer

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

the class MetadataDiscoveryResource method searchUsingGremlinQuery.

/**
     * Search using raw gremlin query format.
     *
     * @param gremlinQuery search query in raw gremlin format.
     * @return JSON representing the type and results.
     */
@GET
@Path("search/gremlin")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
@InterfaceAudience.Private
public Response searchUsingGremlinQuery(@QueryParam("query") String gremlinQuery) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> MetadataDiscoveryResource.searchUsingGremlinQuery({})", gremlinQuery);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.searchUsingGremlinQuery(" + gremlinQuery + ")");
        }
        gremlinQuery = ParamChecker.notEmpty(gremlinQuery, "gremlinQuery cannot be null or empty");
        final List<Map<String, String>> results = discoveryService.searchByGremlin(gremlinQuery);
        JSONObject response = new JSONObject();
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        response.put(AtlasClient.QUERY, gremlinQuery);
        response.put(AtlasClient.QUERY_TYPE, QUERY_TYPE_GREMLIN);
        JSONArray list = new JSONArray();
        for (Map<String, String> result : results) {
            list.put(new JSONObject(result));
        }
        response.put(AtlasClient.RESULTS, list);
        response.put(AtlasClient.COUNT, list.length());
        return Response.ok(response).build();
    } catch (DiscoveryException | IllegalArgumentException e) {
        LOG.error("Unable to get entity list for gremlinQuery {}", gremlinQuery, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get entity list for gremlinQuery {}", gremlinQuery, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get entity list for gremlinQuery {}", gremlinQuery, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== MetadataDiscoveryResource.searchUsingGremlinQuery({})", gremlinQuery);
        }
    }
}
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) Map(java.util.Map) 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 13 with AtlasPerfTracer

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

the class EntityService method tagEntities.

@POST
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response tagEntities(String body, @Context HttpHeaders headers, @Context UriInfo ui) throws CatalogException {
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.tagEntities()");
        }
        Map<String, Object> properties = parsePayload(body);
        if (properties.get("tags") == null || properties.size() != 1) {
            throw new CatalogException("Invalid Request, no 'tags' property specified. Creation of entity resource not supported.", 400);
        }
        String queryString = decode(getQueryString(ui));
        Collection<String> createResults = createResources(entityTagResourceProvider, new CollectionRequest(properties, queryString));
        Collection<Results> result = new ArrayList<>();
        for (String relativeUrl : createResults) {
            result.add(new Results(ui.getBaseUri().toString() + relativeUrl, 201));
        }
        return Response.status(Response.Status.CREATED).entity(new GenericEntity<Collection<Results>>(result) {
        }).build();
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : CollectionRequest(org.apache.atlas.catalog.CollectionRequest) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) GenericEntity(javax.ws.rs.core.GenericEntity) CatalogException(org.apache.atlas.catalog.exception.CatalogException) ArrayList(java.util.ArrayList) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 14 with AtlasPerfTracer

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

the class EntityService method deleteEntityTag.

@DELETE
@Path("{entityId}/tags/{tag}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response deleteEntityTag(@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.deleteEntityTag()");
        }
        Map<String, Object> properties = new HashMap<>();
        properties.put("id", entityId);
        properties.put("name", tagName);
        deleteResource(entityTagResourceProvider, new InstanceRequest(properties));
        return Response.status(Response.Status.OK).entity(new Results(ui.getRequestUri().toString(), 200)).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) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 15 with AtlasPerfTracer

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

the class TaxonomyService method updateTerm.

@PUT
@Path("{taxonomyName}/terms/{termName}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response updateTerm(String body, @Context HttpHeaders headers, @Context UriInfo ui, @PathParam("taxonomyName") String taxonomyName, @PathParam("termName") String termName) throws CatalogException {
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.updateTerm(" + taxonomyName + ", " + termName + ")");
        }
        Map<String, Object> queryProperties = new HashMap<>();
        queryProperties.put("termPath", new TermPath(taxonomyName, termName));
        Map<String, Object> updateProperties = parsePayload(body);
        updateResource(termResourceProvider, new InstanceRequest(queryProperties, updateProperties));
        return Response.status(Response.Status.OK).entity(new Results(ui.getRequestUri().toString(), 200)).build();
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : HashMap(java.util.HashMap) 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)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