Search in sources :

Example 1 with InvalidControllerServiceLookupException

use of com.thinkbiganalytics.feedmgr.nifi.controllerservice.InvalidControllerServiceLookupException in project kylo by Teradata.

the class NifiIntegrationRestController method getTableNames.

@GET
@Path("/controller-services/{serviceId}/tables")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets a list of table names from the specified database.", notes = "Connects to the database specified by the controller service using the password defined in Kylo's application.properties file.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the table names.", response = String.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Nifi or the database are unavailable.", response = RestResponseStatus.class) })
public Response getTableNames(@PathParam("serviceId") String serviceId, @QueryParam("serviceName") @DefaultValue("") String serviceName, @QueryParam("schema") String schema, @QueryParam("tableName") String tableName) {
    final Optional<DataSource> dataSource = findDataSourceForControllerServiceId(serviceId);
    final List<String> tables;
    if (dataSource.isPresent()) {
        log.info("Query for Table Names against data source: {}", dataSource.get().getId());
        try {
            tables = catalogTableManager.getTableNames(dataSource.get(), schema, tableName);
        } catch (final SQLException | InvalidControllerServiceLookupException e) {
            log.error("Unable to list table names for data source: {}", dataSource.get().getId(), e);
            throw new InternalServerErrorException("Unable to connect to the data source", e);
        }
    } else {
        log.info("Query for Table Names against service: {}({})", serviceName, serviceId);
        try {
            tables = dbcpConnectionPoolTableInfo.getTableNamesForControllerService(serviceId, serviceName, schema, tableName);
        } catch (final InvalidControllerServiceLookupException e) {
            log.error("Unable to list table names for controller service: {}", serviceName, e);
            throw new InternalServerErrorException("Unable to connect to the data source", e);
        }
    }
    return Response.ok(tables).build();
}
Also used : InvalidControllerServiceLookupException(com.thinkbiganalytics.feedmgr.nifi.controllerservice.InvalidControllerServiceLookupException) SQLException(java.sql.SQLException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

InvalidControllerServiceLookupException (com.thinkbiganalytics.feedmgr.nifi.controllerservice.InvalidControllerServiceLookupException)1 DataSource (com.thinkbiganalytics.kylo.catalog.rest.model.DataSource)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 SQLException (java.sql.SQLException)1 GET (javax.ws.rs.GET)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1