use of com.thinkbiganalytics.metadata.rest.model.data.Datasource in project kylo by Teradata.
the class DatasourceController method getSchemaNames.
/**
* Gets the table names from the specified data source.
*
* @param idStr the data source id
* @return the list of schema names
*/
@GET
@Path("{id}/schemas")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets the table names from the data source.", notes = "Connects to the database specified by the data source.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the schema names.", response = String.class, responseContainer = "List"), @ApiResponse(code = 403, message = "Access denied.", response = RestResponseStatus.class), @ApiResponse(code = 404, message = "A JDBC data source with that id does not exist.", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "NiFi or the database are unavailable.", response = RestResponseStatus.class) })
public Response getSchemaNames(@PathParam("id") final String idStr) {
// Verify user has access to data source
final Optional<com.thinkbiganalytics.metadata.api.datasource.Datasource.ID> id = metadata.read(() -> {
accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_DATASOURCES);
final com.thinkbiganalytics.metadata.api.datasource.Datasource datasource = datasourceProvider.getDatasource(datasourceProvider.resolve(idStr));
return Optional.ofNullable(datasource).map(com.thinkbiganalytics.metadata.api.datasource.Datasource::getId);
});
// Retrieve table names using system user
return metadata.read(() -> {
final List<String> tables = id.map(datasourceProvider::getDatasource).map(ds -> datasourceTransform.toDatasource(ds, DatasourceModelTransform.Level.ADMIN)).filter(JdbcDatasource.class::isInstance).map(JdbcDatasource.class::cast).map(datasource -> dbcpConnectionPoolTableInfo.getSchemaNamesForDatasource(datasource)).orElseThrow(() -> new NotFoundException("No JDBC datasource exists with the given ID: " + idStr));
return Response.ok(tables).build();
}, MetadataAccess.SERVICE);
}
use of com.thinkbiganalytics.metadata.rest.model.data.Datasource in project kylo by Teradata.
the class IntegrationTestBase method deleteExistingDatasources.
protected void deleteExistingDatasources() {
LOG.info("Deleting existing Datasources");
Datasource[] datasources = getDatasources();
for (Datasource datasource : datasources) {
deleteDatasource(datasource.getId());
}
datasources = getDatasources();
Assert.assertTrue(datasources.length == 0);
DataSource[] jdbcDataSources = getJdbcDataSources();
if (jdbcDataSources != null) {
for (DataSource dataSource : jdbcDataSources) {
deleteDataSource(dataSource.getId());
}
}
jdbcDataSources = getJdbcDataSources();
Assert.assertTrue(jdbcDataSources.length == 0);
}
Aggregations