Search in sources :

Example 11 with AtlasLineageInfo

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

the class EntityLineageServiceTest method testGetLineageInfo.

@Test
public void testGetLineageInfo() throws Exception {
    TestUtils.skipForGremlin3EnabledGraphDb();
    String entityGuid = getEntityId(HIVE_TABLE_TYPE, "name", "sales_fact_monthly_mv");
    AtlasLineageInfo bothLineage = getBothLineageInfo(entityGuid, 5);
    assertNotNull(bothLineage);
    System.out.println("both lineage = " + bothLineage);
    Map<String, AtlasEntityHeader> entities = bothLineage.getGuidEntityMap();
    assertNotNull(entities);
    Set<LineageRelation> relations = bothLineage.getRelations();
    assertNotNull(relations);
    Assert.assertEquals(entities.size(), 6);
    Assert.assertEquals(relations.size(), 5);
    Assert.assertEquals(bothLineage.getLineageDepth(), 5);
    Assert.assertEquals(bothLineage.getLineageDirection(), AtlasLineageInfo.LineageDirection.BOTH);
    assertTrue(entities.containsKey(bothLineage.getBaseEntityGuid()));
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test) BaseRepositoryTest(org.apache.atlas.BaseRepositoryTest)

Example 12 with AtlasLineageInfo

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

the class EntityLineageServiceTest method testCircularLineage.

/**
 * Circular Lineage Test.
 */
@Test
public void testCircularLineage() throws Exception {
    TestUtils.skipForGremlin3EnabledGraphDb();
    String entityGuid = getEntityId(HIVE_TABLE_TYPE, "name", "table2");
    AtlasLineageInfo circularLineage = getInputLineageInfo(entityGuid, 5);
    assertNotNull(circularLineage);
    System.out.println("circular lineage = " + circularLineage);
    Map<String, AtlasEntityHeader> entities = circularLineage.getGuidEntityMap();
    assertNotNull(entities);
    Set<LineageRelation> relations = circularLineage.getRelations();
    assertNotNull(relations);
    Assert.assertEquals(entities.size(), 4);
    Assert.assertEquals(relations.size(), 4);
    Assert.assertEquals(circularLineage.getLineageDepth(), 5);
    Assert.assertEquals(circularLineage.getLineageDirection(), LineageDirection.INPUT);
    assertTrue(entities.containsKey(circularLineage.getBaseEntityGuid()));
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test) BaseRepositoryTest(org.apache.atlas.BaseRepositoryTest)

Example 13 with AtlasLineageInfo

use of org.apache.atlas.model.lineage.AtlasLineageInfo 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 14 with AtlasLineageInfo

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

the class LineageUtils method toLineageStruct.

public static String toLineageStruct(AtlasLineageInfo lineageInfo, AtlasTypeRegistry registry) throws AtlasBaseException {
    String ret = null;
    if (lineageInfo != null) {
        Map<String, AtlasEntityHeader> entities = lineageInfo.getGuidEntityMap();
        Set<AtlasLineageInfo.LineageRelation> relations = lineageInfo.getRelations();
        AtlasLineageInfo.LineageDirection direction = lineageInfo.getLineageDirection();
        Map<String, Struct> verticesMap = new HashMap<>();
        // Lineage Entities mapping -> verticesMap (vertices)
        for (String guid : entities.keySet()) {
            AtlasEntityHeader entityHeader = entities.get(guid);
            if (isDataSet(entityHeader.getTypeName(), registry)) {
                Map<String, Object> vertexIdMap = new HashMap<>();
                TypeSystem.IdType idType = TypeSystem.getInstance().getIdType();
                vertexIdMap.put(idType.idAttrName(), guid);
                vertexIdMap.put(idType.stateAttrName(), (entityHeader.getStatus() == AtlasEntity.Status.ACTIVE) ? "ACTIVE" : "DELETED");
                vertexIdMap.put(idType.typeNameAttrName(), entityHeader.getTypeName());
                Object qualifiedName = entityHeader.getAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME);
                if (qualifiedName == null) {
                    qualifiedName = entityHeader.getDisplayText();
                }
                Map<String, Object> values = new HashMap<>();
                values.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, qualifiedName);
                values.put(VERTEX_ID_ATTR_NAME, constructResultStruct(vertexIdMap, true));
                values.put(AtlasClient.NAME, entityHeader.getDisplayText());
                verticesMap.put(guid, constructResultStruct(values, false));
            }
        }
        // Lineage Relations mapping -> edgesMap (edges)
        Map<String, List<String>> edgesMap = new HashMap<>();
        for (AtlasLineageInfo.LineageRelation relation : relations) {
            String fromEntityId = relation.getFromEntityId();
            String toEntityId = relation.getToEntityId();
            if (direction == AtlasLineageInfo.LineageDirection.INPUT) {
                if (!edgesMap.containsKey(toEntityId)) {
                    edgesMap.put(toEntityId, new ArrayList<String>());
                }
                edgesMap.get(toEntityId).add(fromEntityId);
            } else if (direction == AtlasLineageInfo.LineageDirection.OUTPUT) {
                if (!edgesMap.containsKey(fromEntityId)) {
                    edgesMap.put(fromEntityId, new ArrayList<String>());
                }
                edgesMap.get(fromEntityId).add(toEntityId);
            }
        }
        Map<String, Object> map = new HashMap<>();
        map.put(VERTICES_ATTR_NAME, verticesMap);
        map.put(EDGES_ATTR_NAME, edgesMap);
        ret = InstanceSerialization.toJson(constructResultStruct(map, false), false);
    }
    return ret;
}
Also used : TypeSystem(org.apache.atlas.typesystem.types.TypeSystem) AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Struct(org.apache.atlas.typesystem.Struct) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) ArrayList(java.util.ArrayList) List(java.util.List)

Example 15 with AtlasLineageInfo

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

the class QuickStartV2IT method testLineageIsMaintained.

@Test
public void testLineageIsMaintained() throws AtlasServiceException, JSONException {
    String salesFactTableId = getTableId(QuickStartV2.SALES_FACT_TABLE);
    String timeDimTableId = getTableId(QuickStartV2.TIME_DIM_TABLE);
    String salesFactDailyMVId = getTableId(QuickStartV2.SALES_FACT_DAILY_MV_TABLE);
    String salesFactMonthlyMvId = getTableId(QuickStartV2.SALES_FACT_MONTHLY_MV_TABLE);
    String salesDailyProcessId = getProcessId(QuickStartV2.LOAD_SALES_DAILY_PROCESS);
    String salesMonthlyProcessId = getProcessId(QuickStartV2.LOAD_SALES_MONTHLY_PROCESS);
    AtlasLineageInfo inputLineage = atlasClientV2.getLineageInfo(salesFactDailyMVId, LineageDirection.BOTH, 0);
    List<LineageRelation> relations = new ArrayList<>(inputLineage.getRelations());
    Map<String, AtlasEntityHeader> entityMap = inputLineage.getGuidEntityMap();
    assertEquals(relations.size(), 5);
    assertEquals(entityMap.size(), 6);
    assertTrue(entityMap.containsKey(salesFactTableId));
    assertTrue(entityMap.containsKey(timeDimTableId));
    assertTrue(entityMap.containsKey(salesFactDailyMVId));
    assertTrue(entityMap.containsKey(salesDailyProcessId));
    assertTrue(entityMap.containsKey(salesFactMonthlyMvId));
    assertTrue(entityMap.containsKey(salesMonthlyProcessId));
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) ArrayList(java.util.ArrayList) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test)

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