Search in sources :

Example 96 with AtlasPerfTracer

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

the class LineageResource method inputsGraph.

/**
 * Returns input lineage graph for the given entity id.
 * @param guid dataset entity id
 * @return
 */
@GET
@Path("{guid}/inputs/graph")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response inputsGraph(@PathParam("guid") String guid) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> LineageResource.inputsGraph({})", guid);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "LineageResource.inputsGraph(" + guid + ")");
        }
        AtlasLineageInfo lineageInfo = atlasLineageService.getAtlasLineageInfo(guid, LineageDirection.INPUT, -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 inputs graph for entity guid={}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get lineage inputs graph for entity guid={}", guid, e);
        throw e;
    } catch (JSONException e) {
        LOG.error("Unable to get lineage inputs 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.inputsGraph({})", 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 97 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 98 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 99 with AtlasPerfTracer

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

the class MetadataDiscoveryResource method searchUsingQueryDSL.

/**
 * Search using query DSL format.
 *
 * @param dslQuery search query in DSL format.
 * @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
 * Limit and offset in API are used in conjunction with limit and offset in DSL query
 * Final limit = min(API limit, max(query limit - API offset, 0))
 * Final offset = API offset + query offset
 *
 * @return JSON representing the type and results.
 */
@GET
@Path("search/dsl")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response searchUsingQueryDSL(@QueryParam("query") String dslQuery, @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("limit") int limit, @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("offset") int offset) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> MetadataDiscoveryResource.searchUsingQueryDSL({}, {}, {})", dslQuery, limit, offset);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.searchUsingQueryDSL(" + dslQuery + ", " + limit + ", " + offset + ")");
        }
        dslQuery = ParamChecker.notEmpty(dslQuery, "dslQuery cannot be null");
        QueryParams queryParams = validateQueryParams(limit, offset);
        final String jsonResultStr = discoveryService.searchByDSL(dslQuery, queryParams);
        JSONObject response = new DSLJSONResponseBuilder().results(jsonResultStr).query(dslQuery).build();
        return Response.ok(response).build();
    } catch (DiscoveryException | IllegalArgumentException e) {
        LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== MetadataDiscoveryResource.searchUsingQueryDSL({}, {}, {})", dslQuery, limit, offset);
        }
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) 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 100 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)

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