Search in sources :

Example 1 with SchemaResponse

use of org.apache.atlas.v1.model.lineage.SchemaResponse 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 2 with SchemaResponse

use of org.apache.atlas.v1.model.lineage.SchemaResponse 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 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)2 SchemaResponse (org.apache.atlas.v1.model.lineage.SchemaResponse)2 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)1 SchemaDetails (org.apache.atlas.v1.model.lineage.SchemaResponse.SchemaDetails)1