Search in sources :

Example 81 with AtlasPerfTracer

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

the class DataSetLineageResource method outputsGraph.

/**
 * Returns the outputs graph for a given entity.
 *
 * @param tableName table name
 */
@GET
@Path("table/{tableName}/outputs/graph")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public DataSetLineageResponse outputsGraph(@Context HttpServletRequest request, @PathParam("tableName") String tableName) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> DataSetLineageResource.outputsGraph({})", tableName);
    }
    DataSetLineageResponse ret = new DataSetLineageResponse();
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataSetLineageResource.outputsGraph(tableName=" + tableName + ")");
        }
        String guid = getGuid(tableName);
        AtlasLineageInfo lineageInfo = atlasLineageService.getAtlasLineageInfo(guid, LineageDirection.OUTPUT, -1);
        ret.setTableName(tableName);
        ret.setRequestId(Servlets.getRequestId());
        ret.setResults(LineageUtils.toLineageStruct(lineageInfo, typeRegistry));
        return ret;
    } catch (IllegalArgumentException e) {
        LOG.error("Unable to get lineage outputs graph for table {}", tableName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get lineage outputs graph for table {}", tableName, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get lineage outputs graph for table {}", tableName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) DataSetLineageResponse(org.apache.atlas.v1.model.lineage.DataSetLineageResponse) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 82 with AtlasPerfTracer

use of org.apache.atlas.utils.AtlasPerfTracer in project 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 LineageResponse outputsGraph(@PathParam("guid") String guid) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> LineageResource.outputsGraph({})", guid);
    }
    LineageResponse ret = new LineageResponse();
    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);
        ret.setRequestId(Servlets.getRequestId());
        ret.setResults(LineageUtils.toLineageStruct(lineageInfo, typeRegistry));
        return ret;
    } 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;
    } 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) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) LineageResponse(org.apache.atlas.v1.model.lineage.LineageResponse) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 83 with AtlasPerfTracer

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

the class TypesResource method getDefinition.

/**
 * Fetch the complete definition of a given type name which is unique.
 *
 * @param typeName name of a type which is unique.
 */
@GET
@Path("{typeName}")
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response getDefinition(@Context HttpServletRequest request, @PathParam("typeName") String typeName) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> TypesResource.getDefinition({})", typeName);
    }
    AtlasPerfTracer perf = null;
    if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
        perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getDefinition(" + typeName + ")");
    }
    Map<String, Object> response = new HashMap<>();
    try {
        TypesDef typesDef = TypeConverterUtil.toTypesDef(typeRegistry.getType(typeName), typeRegistry);
        ;
        response.put(AtlasClient.TYPENAME, typeName);
        response.put(AtlasClient.DEFINITION, typesDef);
        response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
        return Response.ok(AtlasJson.toV1Json(response)).build();
    } catch (AtlasBaseException e) {
        LOG.error("Unable to get type definition for type {}", typeName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e));
    } catch (IllegalArgumentException e) {
        LOG.error("Unable to get type definition for type {}", typeName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get type definition for type {}", typeName, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get type definition for type {}", typeName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== TypesResource.getDefinition({})", typeName);
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) TypesDef(org.apache.atlas.v1.model.typedef.TypesDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 84 with AtlasPerfTracer

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

the class ClassificationSearchProcessor method execute.

@Override
public List<AtlasVertex> execute() {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ClassificationSearchProcessor.execute({})", context);
    }
    List<AtlasVertex> ret = new ArrayList<>();
    AtlasPerfTracer perf = null;
    if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
        perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "ClassificationSearchProcessor.execute(" + context + ")");
    }
    try {
        final int startIdx = context.getSearchParameters().getOffset();
        final int limit = context.getSearchParameters().getLimit();
        final boolean activeOnly = context.getSearchParameters().getExcludeDeletedEntities();
        // query to start at 0, even though startIdx can be higher - because few results in earlier retrieval could
        // have been dropped: like non-active-entities or duplicate-entities (same entity pointed to by multiple
        // classifications in the result)
        // 
        // first 'startIdx' number of entries will be ignored
        int qryOffset = 0;
        int resultIdx = qryOffset;
        final Set<String> processedGuids = new HashSet<>();
        final List<AtlasVertex> entityVertices = new ArrayList<>();
        final List<AtlasVertex> classificationVertices = new ArrayList<>();
        for (; ret.size() < limit; qryOffset += limit) {
            entityVertices.clear();
            classificationVertices.clear();
            if (context.terminateSearch()) {
                LOG.warn("query terminated: {}", context.getSearchParameters());
                break;
            }
            if (indexQuery != null) {
                Iterator<AtlasIndexQuery.Result> queryResult = indexQuery.vertices(qryOffset, limit);
                if (!queryResult.hasNext()) {
                    // no more results from index query - end of search
                    break;
                }
                getVerticesFromIndexQueryResult(queryResult, classificationVertices);
                // Do in-memory filtering before the graph query
                CollectionUtils.filter(classificationVertices, inMemoryPredicate);
            } else {
                if (context.getSearchParameters().getTagFilters() == null) {
                    // We can use single graph query to determine in this case
                    Iterator<AtlasVertex> queryResult = entityGraphQueryTraitNames.vertices(qryOffset, limit).iterator();
                    if (!queryResult.hasNext()) {
                        // no more results - end of search
                        break;
                    }
                    getVertices(queryResult, entityVertices);
                } else {
                    Iterator<AtlasVertex> queryResult = tagGraphQueryWithAttributes.vertices(qryOffset, limit).iterator();
                    if (!queryResult.hasNext()) {
                        // no more results - end of search
                        break;
                    }
                    getVertices(queryResult, classificationVertices);
                    // Do in-memory filtering before the graph query
                    CollectionUtils.filter(classificationVertices, inMemoryPredicate);
                }
            }
            // vertex results (as these might be lower in number)
            if (CollectionUtils.isNotEmpty(classificationVertices)) {
                for (AtlasVertex classificationVertex : classificationVertices) {
                    Iterable<AtlasEdge> edges = classificationVertex.getEdges(AtlasEdgeDirection.IN);
                    for (AtlasEdge edge : edges) {
                        AtlasVertex entityVertex = edge.getOutVertex();
                        if (activeOnly && AtlasGraphUtilsV1.getState(entityVertex) != AtlasEntity.Status.ACTIVE) {
                            continue;
                        }
                        String guid = AtlasGraphUtilsV1.getIdFromVertex(entityVertex);
                        if (processedGuids.contains(guid)) {
                            continue;
                        }
                        entityVertices.add(entityVertex);
                        processedGuids.add(guid);
                    }
                }
            }
            super.filter(entityVertices);
            resultIdx = collectResultVertices(ret, startIdx, limit, resultIdx, entityVertices);
        }
    } finally {
        AtlasPerfTracer.log(perf);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== ClassificationSearchProcessor.execute({}): ret.size()={}", context, ret.size());
    }
    return ret;
}
Also used : AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) ArrayList(java.util.ArrayList) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) HashSet(java.util.HashSet)

Example 85 with AtlasPerfTracer

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

the class FullTextSearchProcessor method execute.

@Override
public List<AtlasVertex> execute() {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> FullTextSearchProcessor.execute({})", context);
    }
    List<AtlasVertex> ret = new ArrayList<>();
    AtlasPerfTracer perf = null;
    if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
        perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "FullTextSearchProcessor.execute(" + context + ")");
    }
    try {
        final int startIdx = context.getSearchParameters().getOffset();
        final int limit = context.getSearchParameters().getLimit();
        final boolean activeOnly = context.getSearchParameters().getExcludeDeletedEntities();
        // query to start at 0, even though startIdx can be higher - because few results in earlier retrieval could
        // have been dropped: like vertices of non-entity or non-active-entity
        // 
        // first 'startIdx' number of entries will be ignored
        int qryOffset = 0;
        int resultIdx = qryOffset;
        final List<AtlasVertex> entityVertices = new ArrayList<>();
        for (; ret.size() < limit; qryOffset += limit) {
            entityVertices.clear();
            if (context.terminateSearch()) {
                LOG.warn("query terminated: {}", context.getSearchParameters());
                break;
            }
            Iterator<AtlasIndexQuery.Result> idxQueryResult = indexQuery.vertices(qryOffset, limit);
            if (!idxQueryResult.hasNext()) {
                // no more results from solr - end of search
                break;
            }
            while (idxQueryResult.hasNext()) {
                AtlasVertex vertex = idxQueryResult.next().getVertex();
                // skip non-entity vertices
                if (!AtlasGraphUtilsV1.isEntityVertex(vertex)) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("FullTextSearchProcessor.execute(): ignoring non-entity vertex (id={})", vertex.getId());
                    }
                    continue;
                }
                if (activeOnly && AtlasGraphUtilsV1.getState(vertex) != AtlasEntity.Status.ACTIVE) {
                    continue;
                }
                entityVertices.add(vertex);
            }
            super.filter(entityVertices);
            resultIdx = collectResultVertices(ret, startIdx, limit, resultIdx, entityVertices);
        }
    } finally {
        AtlasPerfTracer.log(perf);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== FullTextSearchProcessor.execute({}): ret.size()={}", context, ret.size());
    }
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) ArrayList(java.util.ArrayList)

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