use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSource in project kylo by Teradata.
the class DataSourceController method getDataSources.
@GET
@ApiOperation("Lists all data sources")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the data sources", response = SearchResult.class), @ApiResponse(code = 400, message = "", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "Internal server error", response = RestResponseStatus.class) })
public Response getDataSources(@QueryParam("connector") final String connectorId, @QueryParam("filter") final String filter, @QueryParam("limit") final Integer limit, @QueryParam("start") final Integer start) {
log.entry(connectorId, filter, limit, start);
final boolean encryptCredentials = true;
// Validate parameters
if (start != null && start < 0) {
throw new BadRequestException(getMessage("catalog.datasource.getDataSources.invalidStart"));
}
if (limit != null && limit < 1) {
throw new BadRequestException(getMessage("catalog.datasource.getDataSources.invalidLimit"));
}
// Fetch page
final PageRequest pageRequest = new PageRequest((start != null) ? start : 0, (limit != null) ? limit : Integer.MAX_VALUE);
return metadataService.read(() -> {
// Require admin permission if the results should include unencrypted credentials.
accessController.checkPermission(AccessController.SERVICES, encryptCredentials ? FeedServicesAccessControl.ACCESS_DATASOURCES : FeedServicesAccessControl.ADMIN_DATASOURCES);
Page<com.thinkbiganalytics.metadata.api.catalog.DataSource> domainPage = dataSourceProvider.findPage(pageRequest, filter);
final Page<DataSource> page = domainPage.map(modelTransform.convertDataSourceToRestModel(true, encryptCredentials));
// Return results
final SearchResult<DataSource> searchResult = new SearchResultImpl<>();
searchResult.setData(page.getContent());
searchResult.setRecordsTotal(page.getTotalElements());
return Response.ok(searchResult).build();
});
}
use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSource in project kylo by Teradata.
the class DataSourceController method getDataSource.
@GET
@ApiOperation("Gets the specified data source")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the data source", response = DataSource.class), @ApiResponse(code = 404, message = "Data source was not found", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "Internal server error", response = RestResponseStatus.class) })
@Path("{id}")
public Response getDataSource(@PathParam("id") final String dataSourceId, @QueryParam("credentials") @DefaultValue("embed") final String credentialMode) {
// TODO Change default to be "none"
log.entry(dataSourceId);
CredentialMode mode;
final boolean encryptCredentials = true;
try {
mode = CredentialMode.valueOf(credentialMode.toUpperCase());
} catch (IllegalArgumentException e) {
return Response.status(log.exit(Status.BAD_REQUEST)).entity(getMessage("catalog.datasource.credential.arg.invalid", credentialMode)).build();
}
final Set<Principal> principals = SecurityContextUtil.getCurrentPrincipals();
// TODO remove encrypt flag when real credential manager is in place
DataSource dataSource = findDataSource(dataSourceId, encryptCredentials);
switch(mode) {
case NONE:
dataSource = this.credentialManager.applyPlaceholders(dataSource, principals);
break;
case EMBED:
dataSource = this.credentialManager.applyCredentials(dataSource, principals);
break;
case ATTACH:
Map<String, String> credProps = this.credentialManager.getCredentials(dataSource, encryptCredentials, principals);
DataSourceCredentials creds = new DataSourceCredentials(credProps, encryptCredentials);
dataSource = this.credentialManager.applyPlaceholders(dataSource, principals);
dataSource.setCredentials(creds);
}
return Response.ok(log.exit(dataSource)).build();
}
use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSource in project kylo by Teradata.
the class DataSetUtil method getPaths.
/**
* Gets the paths for the specified data set.
*/
@Nonnull
public static Optional<List<String>> getPaths(@Nonnull final DataSet dataSet) {
final DataSetTemplate connectorTemplate = Optional.of(dataSet).map(DataSet::getDataSource).map(DataSource::getConnector).map(Connector::getTemplate).orElse(null);
final DataSetTemplate dataSetTemplate = Optional.of(dataSet).map(DataSet::getDataSource).map(DataSource::getTemplate).orElse(null);
List<String> paths = new ArrayList<>();
// Add "path" option
if (dataSet.getOptions() != null && dataSet.getOptions().get("path") != null) {
paths.add(dataSet.getOptions().get("path"));
} else if (dataSetTemplate != null && dataSetTemplate.getOptions() != null && dataSetTemplate.getOptions().get("path") != null) {
paths.add(dataSetTemplate.getOptions().get("path"));
} else if (connectorTemplate != null && connectorTemplate.getOptions() != null && connectorTemplate.getOptions().get("path") != null) {
paths.add(connectorTemplate.getOptions().get("path"));
}
// Add paths list
if (dataSet.getPaths() != null) {
paths.addAll(dataSet.getPaths());
} else if (dataSetTemplate != null && dataSetTemplate.getPaths() != null) {
paths.addAll(dataSetTemplate.getPaths());
} else if (connectorTemplate != null && connectorTemplate.getPaths() != null) {
paths.addAll(connectorTemplate.getPaths());
} else if (paths.isEmpty()) {
paths = null;
}
return Optional.ofNullable(paths);
}
use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSource in project kylo by Teradata.
the class CatalogMetadataController method getDataSource.
@GET
@ApiOperation("Gets the specified data source")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the data source", response = DataSource.class), @ApiResponse(code = 404, message = "Data source was not found", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "Internal server error", response = RestResponseStatus.class) })
@Path("datasource/{id}")
public Response getDataSource(@PathParam("id") final String dataSourceId, @QueryParam("credentials") @DefaultValue("embed") final String credentialMode) {
// TODO Change default to be "none"
log.entry(dataSourceId);
final boolean encryptCredentials = true;
CredentialMode mode;
try {
mode = CredentialMode.valueOf(credentialMode.toUpperCase());
} catch (IllegalArgumentException e) {
return Response.status(log.exit(Response.Status.BAD_REQUEST)).entity(getMessage("catalog.datasource.credential.arg.invalid", credentialMode)).build();
}
final Set<Principal> principals = SecurityContextUtil.getCurrentPrincipals();
// TODO remove encrypt flag when real credential manager is in place
DataSource dataSource = findDataSource(dataSourceId, encryptCredentials);
switch(mode) {
case NONE:
dataSource = this.credentialManager.applyPlaceholders(dataSource, principals);
break;
case EMBED:
dataSource = this.credentialManager.applyCredentials(dataSource, principals);
break;
case ATTACH:
Map<String, String> credProps = this.credentialManager.getCredentials(dataSource, encryptCredentials, principals);
DataSourceCredentials creds = new DataSourceCredentials(credProps, encryptCredentials);
dataSource = this.credentialManager.applyPlaceholders(dataSource, principals);
dataSource.setCredentials(creds);
}
return Response.ok(log.exit(dataSource)).build();
}
use of com.thinkbiganalytics.kylo.catalog.rest.model.DataSource in project kylo by Teradata.
the class SparkShellProxyController method resolveDatasources.
/**
* Retrieves all details of the specified data sources.
*/
@Nonnull
private List<Datasource> resolveDatasources(@Nonnull final List<Datasource> sources) {
// Verify access to data sources
accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_DATASOURCES);
final List<com.thinkbiganalytics.metadata.api.datasource.Datasource.ID> datasourceIds = metadata.read(() -> sources.stream().map(com.thinkbiganalytics.metadata.datasource.Datasource::getId).map(datasourceProvider::resolve).map(id -> {
final com.thinkbiganalytics.metadata.api.datasource.Datasource datasource = datasourceProvider.getDatasource(id);
if (datasource != null) {
return datasource.getId();
} else {
throw new BadRequestException("No datasource exists with the given ID: " + id);
}
}).collect(Collectors.toList()));
// Retrieve admin-level details
return metadata.read(() -> datasourceIds.stream().map(datasourceProvider::getDatasource).map(datasource -> {
if (datasource instanceof com.thinkbiganalytics.metadata.api.datasource.UserDatasource) {
return (com.thinkbiganalytics.metadata.datasource.Datasource) datasourceTransform.toDatasource(datasource, DatasourceModelTransform.Level.ADMIN);
} else {
throw new BadRequestException("Not a supported datasource: " + datasource.getClass().getSimpleName() + " " + datasource.getId());
}
}).map(datasource -> {
if (datasource instanceof com.thinkbiganalytics.metadata.datasource.JdbcDatasource) {
return new JdbcDatasource((com.thinkbiganalytics.metadata.datasource.JdbcDatasource) datasource);
} else {
throw new BadRequestException("Not a supported datasource: " + datasource.getClass().getSimpleName());
}
}).collect(Collectors.toList()), MetadataAccess.SERVICE);
}
Aggregations