Search in sources :

Example 1 with AtlasLineageInfo

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;
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 2 with AtlasLineageInfo

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;
}
Also used : AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo)

Example 3 with AtlasLineageInfo

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

Example 4 with AtlasLineageInfo

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);
    }
}
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 5 with AtlasLineageInfo

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

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