Search in sources :

Example 31 with AtlasLineageInfo

use of org.apache.atlas.model.lineage.AtlasLineageInfo in project incubator-atlas by apache.

the class QuickStartV2 method lineage.

private void lineage() throws AtlasServiceException {
    System.out.println("\nSample Lineage Info: ");
    AtlasLineageInfo lineageInfo = atlasClientV2.getLineageInfo(getTableId(SALES_FACT_DAILY_MV_TABLE), LineageDirection.BOTH, 0);
    Set<LineageRelation> relations = lineageInfo.getRelations();
    Map<String, AtlasEntityHeader> guidEntityMap = lineageInfo.getGuidEntityMap();
    for (LineageRelation relation : relations) {
        AtlasEntityHeader fromEntity = guidEntityMap.get(relation.getFromEntityId());
        AtlasEntityHeader toEntity = guidEntityMap.get(relation.getToEntityId());
        System.out.println(fromEntity.getDisplayText() + "(" + fromEntity.getTypeName() + ") -> " + toEntity.getDisplayText() + "(" + toEntity.getTypeName() + ")");
    }
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader)

Example 32 with AtlasLineageInfo

use of org.apache.atlas.model.lineage.AtlasLineageInfo in project incubator-atlas by apache.

the class EntityLineageService method getLineageInfo.

private AtlasLineageInfo getLineageInfo(String guid, LineageDirection direction, int depth) throws AtlasBaseException {
    Map<String, AtlasEntityHeader> entities = new HashMap<>();
    Set<LineageRelation> relations = new HashSet<>();
    String lineageQuery = getLineageQuery(guid, direction, depth);
    List paths = (List) graph.executeGremlinScript(lineageQuery, true);
    if (CollectionUtils.isNotEmpty(paths)) {
        for (Object path : paths) {
            if (path instanceof List) {
                List vertices = (List) path;
                if (CollectionUtils.isNotEmpty(vertices)) {
                    AtlasEntityHeader prev = null;
                    for (Object vertex : vertices) {
                        if (!(vertex instanceof AtlasVertex)) {
                            continue;
                        }
                        AtlasEntityHeader entity = entityRetriever.toAtlasEntityHeader((AtlasVertex) vertex);
                        if (!entities.containsKey(entity.getGuid())) {
                            entities.put(entity.getGuid(), entity);
                        }
                        if (prev != null) {
                            if (direction.equals(LineageDirection.INPUT)) {
                                relations.add(new LineageRelation(entity.getGuid(), prev.getGuid()));
                            } else if (direction.equals(LineageDirection.OUTPUT)) {
                                relations.add(new LineageRelation(prev.getGuid(), entity.getGuid()));
                            }
                        }
                        prev = entity;
                    }
                }
            }
        }
    }
    return new AtlasLineageInfo(guid, entities, relations, direction, depth);
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) HashMap(java.util.HashMap) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) List(java.util.List) HashSet(java.util.HashSet)

Aggregations

AtlasLineageInfo (org.apache.atlas.model.lineage.AtlasLineageInfo)32 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)24 Test (org.testng.annotations.Test)17 LineageRelation (org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation)11 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)6 Consumes (javax.ws.rs.Consumes)6 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 WebApplicationException (javax.ws.rs.WebApplicationException)6 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)6 ArrayList (java.util.ArrayList)5 BaseRepositoryTest (org.apache.atlas.BaseRepositoryTest)5 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)5 JSONObject (org.codehaus.jettison.json.JSONObject)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 HashMap (java.util.HashMap)4 List (java.util.List)4 HashSet (java.util.HashSet)2 DataSetLineageResponse (org.apache.atlas.v1.model.lineage.DataSetLineageResponse)2