use of org.apache.atlas.model.lineage.AtlasLineageInfo in project atlas by apache.
the class EntityLineageService method getAtlasLineageInfo.
@Override
@GraphTransaction
public AtlasLineageInfo getAtlasLineageInfo(String guid, LineageDirection direction, int depth) throws AtlasBaseException {
AtlasLineageInfo lineageInfo;
AtlasEntityHeader entity = entityRetriever.toAtlasEntityHeaderWithClassifications(guid);
AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(atlasTypeRegistry, AtlasPrivilege.ENTITY_READ, entity), "read entity lineage: guid=", guid);
AtlasEntityType entityType = atlasTypeRegistry.getEntityTypeByName(entity.getTypeName());
if (entityType == null || !entityType.getTypeAndAllSuperTypes().contains(AtlasClient.DATA_SET_SUPER_TYPE)) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_DATASET, guid);
}
if (direction != null) {
if (direction.equals(LineageDirection.INPUT)) {
lineageInfo = getLineageInfo(guid, LineageDirection.INPUT, depth);
} else if (direction.equals(LineageDirection.OUTPUT)) {
lineageInfo = getLineageInfo(guid, LineageDirection.OUTPUT, depth);
} else if (direction.equals(LineageDirection.BOTH)) {
lineageInfo = getBothLineageInfo(guid, depth);
} else {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_LINEAGE_INVALID_PARAMS, "direction", direction.toString());
}
} else {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_LINEAGE_INVALID_PARAMS, "direction", null);
}
return lineageInfo;
}
use of org.apache.atlas.model.lineage.AtlasLineageInfo in project atlas by apache.
the class EntityLineageService method getBothLineageInfo.
private AtlasLineageInfo getBothLineageInfo(String guid, int depth) throws AtlasBaseException {
AtlasLineageInfo inputLineage = getLineageInfo(guid, LineageDirection.INPUT, depth);
AtlasLineageInfo outputLineage = getLineageInfo(guid, LineageDirection.OUTPUT, depth);
AtlasLineageInfo ret = inputLineage;
ret.getRelations().addAll(outputLineage.getRelations());
ret.getGuidEntityMap().putAll(outputLineage.getGuidEntityMap());
ret.setLineageDirection(LineageDirection.BOTH);
return ret;
}
use of org.apache.atlas.model.lineage.AtlasLineageInfo in project atlas by apache.
the class QuickStartV2IT method testLineageIsMaintained.
@Test
public void testLineageIsMaintained() throws AtlasServiceException {
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));
}
use of org.apache.atlas.model.lineage.AtlasLineageInfo in project atlas by apache.
the class DataSetLineageResource method inputsGraph.
/**
* Returns the inputs graph for a given entity.
*
* @param tableName table name
*/
@GET
@Path("table/{tableName}/inputs/graph")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public DataSetLineageResponse inputsGraph(@Context HttpServletRequest request, @PathParam("tableName") String tableName) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> DataSetLineageResource.inputsGraph({})", tableName);
}
DataSetLineageResponse ret = new DataSetLineageResponse();
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataSetLineageResource.inputsGraph(tableName=" + tableName + ")");
}
String guid = getGuid(tableName);
AtlasLineageInfo lineageInfo = atlasLineageService.getAtlasLineageInfo(guid, LineageDirection.INPUT, -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 inputs graph for table {}", tableName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (WebApplicationException e) {
LOG.error("Unable to get lineage inputs graph for table {}", tableName, e);
throw e;
} catch (Throwable e) {
LOG.error("Unable to get lineage inputs graph for table {}", tableName, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
}
}
use of org.apache.atlas.model.lineage.AtlasLineageInfo in project 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 LineageResponse inputsGraph(@PathParam("guid") String guid) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> LineageResource.inputsGraph({})", guid);
}
LineageResponse ret = new LineageResponse();
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);
ret.setRequestId(Servlets.getRequestId());
ret.setResults(LineageUtils.toLineageStruct(lineageInfo, typeRegistry));
return ret;
} 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;
} finally {
AtlasPerfTracer.log(perf);
if (LOG.isDebugEnabled()) {
LOG.debug("<== LineageResource.inputsGraph({})", guid);
}
}
}
Aggregations