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