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()));
}
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()));
}
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);
}
}
}
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;
}
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));
}
Aggregations