Search in sources :

Example 1 with DataSetTable

use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTable in project kylo by Teradata.

the class DataSourceController method listTables.

@GET
@Path("{id}/tables")
@ApiOperation("List tables in a data source")
@ApiResponses({ @ApiResponse(code = 200, message = "List of tables", response = DataSetTable.class, responseContainer = "List"), @ApiResponse(code = 404, message = "Data source does not exist", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "Failed to list tables", response = RestResponseStatus.class) })
public Response listTables(@PathParam("id") final String dataSourceId, @QueryParam("catalog") final String catalogName, @QueryParam("schema") final String schemaName) {
    log.entry(dataSourceId, catalogName, schemaName);
    // read as the user to see if they can access the datasource
    boolean hasAccess = metadataService.read(() -> {
        return findDataSource(dataSourceId, true) != null;
    });
    if (hasAccess) {
        return metadataService.read(() -> {
            // List tables
            final DataSource dataSource = findDataSource(dataSourceId, false);
            final List<DataSetTable> tables = doListTables(catalogName, schemaName, dataSource);
            return Response.ok(log.exit(tables)).build();
        }, MetadataAccess.SERVICE);
    } else {
        log.debug("Access denied accessing datasource : {}", dataSourceId);
        throw new ForbiddenException(getMessage("catalog.datasource.forbidden"));
    }
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) DataSetTable(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTable) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with DataSetTable

use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTable in project kylo by Teradata.

the class DefaultCatalogTableManager method createTable.

/**
 * Converts a JDBC table to a data set model.
 */
@Nonnull
private DataSetTable createTable(@Nonnull final JdbcTable table) {
    final DataSetTable entry = new DataSetTable();
    entry.setCatalog(table.getCatalog());
    entry.setName(table.getName());
    entry.setQualifiedIdentifier(table.getQualifiedIdentifier());
    entry.setRemarks(table.getRemarks());
    entry.setSchema(table.getSchema());
    entry.setType(table.getType());
    return entry;
}
Also used : DataSetTable(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTable) Nonnull(javax.annotation.Nonnull)

Example 3 with DataSetTable

use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTable in project kylo by Teradata.

the class DefaultCatalogTableManager method createCatalog.

/**
 * Converts a JDBC catalog to a data set model.
 */
@Nonnull
private DataSetTable createCatalog(@Nonnull final JdbcCatalog catalog) {
    final DataSetTable entry = new DataSetTable();
    entry.setName(catalog.getCatalog());
    entry.setType("CATALOG");
    return entry;
}
Also used : DataSetTable(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTable) Nonnull(javax.annotation.Nonnull)

Example 4 with DataSetTable

use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTable in project kylo by Teradata.

the class DataSourceController method doListTables.

private List<DataSetTable> doListTables(@QueryParam("catalog") String catalogName, @QueryParam("schema") String schemaName, DataSource dataSource) {
    final List<DataSetTable> tables;
    try {
        log.debug("List tables for catalog:{} schema:{}", catalogName, schemaName);
        tables = tableManager.listCatalogsOrTables(dataSource, catalogName, schemaName);
    } catch (final Exception e) {
        if (exceptionTransformer.causesInChain(e)) {
            throw new ThriftConnectionException(e);
        }
        if (log.isErrorEnabled()) {
            log.error("Failed to list tables for catalog [" + catalogName + "] schema [" + schemaName + "]: " + e, e);
        }
        final RestResponseStatus status = new RestResponseStatus.ResponseStatusBuilder().message(getMessage("catalog.datasource.listTables.error", catalogName, schemaName)).url(request.getRequestURI()).setDeveloperMessage(e).buildError();
        throw new InternalServerErrorException(Response.serverError().entity(status).build());
    }
    return tables;
}
Also used : DataSetTable(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTable) ThriftConnectionException(com.thinkbiganalytics.hive.exceptions.ThriftConnectionException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) TTransportException(org.apache.thrift.transport.TTransportException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NotFoundException(javax.ws.rs.NotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) AccessDeniedException(java.nio.file.AccessDeniedException) SQLException(java.sql.SQLException) ThriftConnectionException(com.thinkbiganalytics.hive.exceptions.ThriftConnectionException) CatalogException(com.thinkbiganalytics.kylo.catalog.CatalogException) PotentialControllerServiceConflictException(com.thinkbiganalytics.kylo.catalog.datasource.PotentialControllerServiceConflictException) ForbiddenException(javax.ws.rs.ForbiddenException) DataSourceAlreadyExistsException(com.thinkbiganalytics.metadata.api.catalog.DataSourceAlreadyExistsException) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus)

Example 5 with DataSetTable

use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTable in project kylo by Teradata.

the class DefaultCatalogTableManager method createSchema.

/**
 * Converts a JDBC schema to a data set model.
 */
@Nonnull
private DataSetTable createSchema(@Nonnull final JdbcSchema schema) {
    final DataSetTable entry = new DataSetTable();
    entry.setCatalog(schema.getCatalog());
    entry.setName(schema.getSchema());
    entry.setType("SCHEMA");
    return entry;
}
Also used : DataSetTable(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTable) Nonnull(javax.annotation.Nonnull)

Aggregations

DataSetTable (com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTable)5 Nonnull (javax.annotation.Nonnull)3 ForbiddenException (javax.ws.rs.ForbiddenException)2 ThriftConnectionException (com.thinkbiganalytics.hive.exceptions.ThriftConnectionException)1 CatalogException (com.thinkbiganalytics.kylo.catalog.CatalogException)1 PotentialControllerServiceConflictException (com.thinkbiganalytics.kylo.catalog.datasource.PotentialControllerServiceConflictException)1 DataSource (com.thinkbiganalytics.kylo.catalog.rest.model.DataSource)1 DataSourceAlreadyExistsException (com.thinkbiganalytics.metadata.api.catalog.DataSourceAlreadyExistsException)1 RestResponseStatus (com.thinkbiganalytics.rest.model.RestResponseStatus)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 AccessDeniedException (java.nio.file.AccessDeniedException)1 SQLException (java.sql.SQLException)1 BadRequestException (javax.ws.rs.BadRequestException)1 GET (javax.ws.rs.GET)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 NotFoundException (javax.ws.rs.NotFoundException)1 Path (javax.ws.rs.Path)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 TTransportException (org.apache.thrift.transport.TTransportException)1