Search in sources :

Example 1 with SchemaDetails

use of org.apache.atlas.v1.model.lineage.SchemaResponse.SchemaDetails in project atlas by apache.

the class EntityLineageService method getSchemaForHiveTableByGuid.

@Override
@GraphTransaction
public SchemaDetails getSchemaForHiveTableByGuid(final String guid) throws AtlasBaseException {
    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST);
    }
    SchemaDetails ret = new SchemaDetails();
    AtlasEntityType hive_column = atlasTypeRegistry.getEntityTypeByName("hive_column");
    ret.setDataType(AtlasTypeUtil.toClassTypeDefinition(hive_column));
    AtlasEntityWithExtInfo entityWithExtInfo = entityRetriever.toAtlasEntityWithExtInfo(guid);
    AtlasEntity entity = entityWithExtInfo.getEntity();
    AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(atlasTypeRegistry, AtlasPrivilege.ENTITY_READ, new AtlasEntityHeader(entity)), "read entity schema: guid=", guid);
    Map<String, AtlasEntity> referredEntities = entityWithExtInfo.getReferredEntities();
    List<String> columnIds = getColumnIds(entity);
    if (MapUtils.isNotEmpty(referredEntities)) {
        List<Map<String, Object>> rows = referredEntities.entrySet().stream().filter(e -> isColumn(columnIds, e)).map(e -> AtlasTypeUtil.toMap(e.getValue())).collect(Collectors.toList());
        ret.setRows(rows);
    }
    return ret;
}
Also used : AtlasPrivilege(org.apache.atlas.authorize.AtlasPrivilege) StringUtils(org.apache.commons.lang.StringUtils) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasTypeUtil(org.apache.atlas.type.AtlasTypeUtil) LoggerFactory(org.slf4j.LoggerFactory) LineageRelation(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) HashMap(java.util.HashMap) Constants(org.apache.atlas.repository.Constants) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) AtlasErrorCode(org.apache.atlas.AtlasErrorCode) GraphTransaction(org.apache.atlas.annotation.GraphTransaction) CollectionUtils(org.apache.commons.collections.CollectionUtils) Service(org.springframework.stereotype.Service) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Map(java.util.Map) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) LineageDirection(org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityGraphRetriever(org.apache.atlas.repository.store.graph.v1.EntityGraphRetriever) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) Logger(org.slf4j.Logger) SchemaDetails(org.apache.atlas.v1.model.lineage.SchemaResponse.SchemaDetails) MapUtils(org.apache.commons.collections.MapUtils) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Set(java.util.Set) AtlasGremlinQuery(org.apache.atlas.util.AtlasGremlinQueryProvider.AtlasGremlinQuery) AtlasAuthorizationUtils(org.apache.atlas.authorize.AtlasAuthorizationUtils) Collectors(java.util.stream.Collectors) AtlasLineageInfo(org.apache.atlas.model.lineage.AtlasLineageInfo) AtlasGraphUtilsV1(org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1) List(java.util.List) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasClient(org.apache.atlas.AtlasClient) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasGremlinQueryProvider(org.apache.atlas.util.AtlasGremlinQueryProvider) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityAccessRequest(org.apache.atlas.authorize.AtlasEntityAccessRequest) SchemaDetails(org.apache.atlas.v1.model.lineage.SchemaResponse.SchemaDetails) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) HashMap(java.util.HashMap) Map(java.util.Map) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 2 with SchemaDetails

use of org.apache.atlas.v1.model.lineage.SchemaResponse.SchemaDetails in project atlas by apache.

the class DataSetLineageResource method schema.

/**
 * Return the schema for the given tableName.
 *
 * @param tableName table name
 */
@GET
@Path("table/{tableName}/schema")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public SchemaResponse schema(@Context HttpServletRequest request, @PathParam("tableName") String tableName) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> DataSetLineageResource.schema({})", tableName);
    }
    AtlasPerfTracer perf = null;
    SchemaResponse ret = new SchemaResponse();
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "DataSetLineageResource.schema(tableName=" + tableName + ")");
        }
        SchemaDetails schemaDetails = atlasLineageService.getSchemaForHiveTableByName(tableName);
        ret.setRequestId(Servlets.getRequestId());
        ret.setTableName(tableName);
        ret.setResults(schemaDetails);
        return ret;
    } catch (IllegalArgumentException e) {
        LOG.error("Unable to get schema for table {}", tableName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get schema for table {}", tableName, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get schema for table {}", tableName, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) SchemaDetails(org.apache.atlas.v1.model.lineage.SchemaResponse.SchemaDetails) SchemaResponse(org.apache.atlas.v1.model.lineage.SchemaResponse) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with SchemaDetails

use of org.apache.atlas.v1.model.lineage.SchemaResponse.SchemaDetails in project atlas by apache.

the class LineageResource method schema.

/**
 * Returns the schema for the given dataset id.
 *
 * @param guid dataset entity id
 */
@GET
@Path("{guid}/schema")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public SchemaResponse schema(@PathParam("guid") String guid) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> LineageResource.schema({})", guid);
    }
    AtlasPerfTracer perf = null;
    SchemaResponse ret = new SchemaResponse();
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "LineageResource.schema(" + guid + ")");
        }
        SchemaResponse.SchemaDetails schemaDetails = atlasLineageService.getSchemaForHiveTableByGuid(guid);
        ret.setRequestId(Servlets.getRequestId());
        ret.setResults(schemaDetails);
        return ret;
    } catch (IllegalArgumentException e) {
        LOG.error("Unable to get schema for entity guid={}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get schema for entity guid={}", guid, e);
        throw e;
    } catch (AtlasBaseException e) {
        LOG.error("Unable to get schema for entity={}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, e.getAtlasErrorCode().getHttpCode()));
    } catch (Throwable e) {
        LOG.error("Unable to get schema for entity={}", guid, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== LineageResource.schema({})", guid);
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) SchemaResponse(org.apache.atlas.v1.model.lineage.SchemaResponse) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)2 SchemaResponse (org.apache.atlas.v1.model.lineage.SchemaResponse)2 SchemaDetails (org.apache.atlas.v1.model.lineage.SchemaResponse.SchemaDetails)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 AtlasClient (org.apache.atlas.AtlasClient)1 AtlasErrorCode (org.apache.atlas.AtlasErrorCode)1 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)1