use of com.thinkbiganalytics.metadata.rest.model.data.Datasource in project kylo by Teradata.
the class FeedLineageBuilder method buildDatasource.
private Datasource buildDatasource(com.thinkbiganalytics.metadata.api.datasource.Datasource domainDatasource) {
Datasource ds = restDatasources.get(domainDatasource.getId().toString());
if (ds == null) {
// build the data source
ds = datasourceTransform.toDatasource(domainDatasource, DatasourceModelTransform.Level.BASIC);
restDatasources.put(ds.getId(), ds);
// populate the Feed relationships
if (domainDatasource.getFeedSources() != null) {
List<com.thinkbiganalytics.metadata.rest.model.feed.Feed> feedList = new ArrayList<>();
for (com.thinkbiganalytics.metadata.api.feed.FeedSource domainSrc : domainDatasource.getFeedSources()) {
com.thinkbiganalytics.metadata.rest.model.feed.Feed feed = build(domainSrc.getFeed());
feedList.add(feed);
}
ds.getSourceForFeeds().addAll(feedList);
}
if (domainDatasource.getFeedDestinations() != null) {
List<com.thinkbiganalytics.metadata.rest.model.feed.Feed> feedList = new ArrayList<>();
for (com.thinkbiganalytics.metadata.api.feed.FeedDestination domainDest : domainDatasource.getFeedDestinations()) {
com.thinkbiganalytics.metadata.rest.model.feed.Feed feed = build(domainDest.getFeed());
feedList.add(feed);
}
ds.getDestinationForFeeds().addAll(feedList);
}
}
return ds;
}
use of com.thinkbiganalytics.metadata.rest.model.data.Datasource in project kylo by Teradata.
the class DatasourceController method query.
/**
* Executes a query on the specified datasource.
*
* @param idStr the datasource id
* @param query the SQL query
* @return the SQL result
*/
@GET
@Path("{id}/query")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Executes a query and returns the result.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the result.", response = QueryResult.class), @ApiResponse(code = 403, message = "Access denied.", response = RestResponseStatus.class), @ApiResponse(code = 400, 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 query(@PathParam("id") final String idStr, @QueryParam("query") final String query) {
// 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 = datasetProvider.getDatasource(datasetProvider.resolve(idStr));
return Optional.ofNullable(datasource).map(com.thinkbiganalytics.metadata.api.datasource.Datasource::getId);
});
// Execute query
return metadata.read(() -> {
final QueryResult result = id.map(datasetProvider::getDatasource).map(ds -> datasourceTransform.toDatasource(ds, DatasourceModelTransform.Level.ADMIN)).filter(JdbcDatasource.class::isInstance).map(JdbcDatasource.class::cast).map(datasource -> dbcpConnectionPoolTableInfo.executeQueryForDatasource(datasource, query)).orElseThrow(() -> new NotFoundException("No JDBC datasource exists with the given ID: " + idStr));
return Response.ok(result).build();
}, MetadataAccess.SERVICE);
}
use of com.thinkbiganalytics.metadata.rest.model.data.Datasource in project kylo by Teradata.
the class DatasourceController method getTableNames.
/**
* Gets the table names from the specified data source.
*
* @param idStr the data source id
* @param schema the schema name, or {@code null} for all schemas
* @return the list of table names
*/
@GET
@Path("{id}/tables")
@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 table 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 getTableNames(@PathParam("id") final String idStr, @QueryParam("schema") final String schema, @QueryParam("tableName") final String tableName) {
// 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 = datasetProvider.getDatasource(datasetProvider.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(datasetProvider::getDatasource).map(ds -> datasourceTransform.toDatasource(ds, DatasourceModelTransform.Level.ADMIN)).filter(JdbcDatasource.class::isInstance).map(JdbcDatasource.class::cast).map(datasource -> dbcpConnectionPoolTableInfo.getTableNamesForDatasource(datasource, schema, tableName)).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 DatasourceController method generatePreviewQuery.
/**
* Executes a query on the specified datasource.
*
* @param idStr the datasource id
* @param query the SQL query
* @return the SQL result
*/
@GET
@Path("{id}/preview/{schema}/{table}")
@Produces(MediaType.TEXT_PLAIN)
@ApiOperation("Generates a preview query appropriate for the type of datasource and returns the result.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the result.", response = QueryResult.class), @ApiResponse(code = 403, message = "Access denied.", response = RestResponseStatus.class), @ApiResponse(code = 400, 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 generatePreviewQuery(@PathParam("id") final String idStr, @PathParam("schema") final String schema, @PathParam("table") final String tableName, @QueryParam("limit") @DefaultValue("10") final int limit) {
// 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 = datasetProvider.getDatasource(datasetProvider.resolve(idStr));
return Optional.ofNullable(datasource).map(com.thinkbiganalytics.metadata.api.datasource.Datasource::getId);
});
// Execute query
return metadata.read(() -> {
final String result = id.map(datasetProvider::getDatasource).map(ds -> datasourceTransform.toDatasource(ds, DatasourceModelTransform.Level.ADMIN)).filter(JdbcDatasource.class::isInstance).map(JdbcDatasource.class::cast).map(datasource -> dbcpConnectionPoolTableInfo.generatePreviewQueryForDatasource(datasource, schema, tableName, limit)).orElseThrow(() -> new NotFoundException("No JDBC datasource exists with the given ID: " + idStr));
return Response.ok(result).build();
}, MetadataAccess.SERVICE);
}
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 = datasetProvider.getDatasource(datasetProvider.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(datasetProvider::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);
}
Aggregations