Search in sources :

Example 31 with DataSource

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();
    });
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) SearchResultImpl(com.thinkbiganalytics.rest.model.search.SearchResultImpl) BadRequestException(javax.ws.rs.BadRequestException) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 32 with DataSource

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();
}
Also used : DataSourceCredentials(com.thinkbiganalytics.kylo.catalog.rest.model.DataSourceCredentials) Principal(java.security.Principal) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 33 with DataSource

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);
}
Also used : DefaultDataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DefaultDataSetTemplate) DataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate) DataSet(com.thinkbiganalytics.kylo.catalog.rest.model.DataSet) ArrayList(java.util.ArrayList) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Nonnull(javax.annotation.Nonnull)

Example 34 with DataSource

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();
}
Also used : DataSourceCredentials(com.thinkbiganalytics.kylo.catalog.rest.model.DataSourceCredentials) Principal(java.security.Principal) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 35 with DataSource

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);
}
Also used : Datasource(com.thinkbiganalytics.spark.rest.model.Datasource) JdbcDatasource(com.thinkbiganalytics.spark.rest.model.JdbcDatasource) Produces(javax.ws.rs.Produces) DataSourceProvider(com.thinkbiganalytics.metadata.api.catalog.DataSourceProvider) DatasourceModelTransform(com.thinkbiganalytics.feedmgr.service.datasource.DatasourceModelTransform) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiParam(io.swagger.annotations.ApiParam) AsyncResponseSubscriber(com.thinkbiganalytics.kylo.reactive.AsyncResponseSubscriber) StringUtils(org.apache.commons.lang3.StringUtils) PreviewDataSetTransformResponse(com.thinkbiganalytics.spark.rest.model.PreviewDataSetTransformResponse) MediaType(javax.ws.rs.core.MediaType) SaveRequest(com.thinkbiganalytics.spark.rest.model.SaveRequest) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) AccessController(com.thinkbiganalytics.security.AccessController) PageSpec(com.thinkbiganalytics.spark.rest.model.PageSpec) FeedServicesAccessControl(com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) SchemaParserAnnotationTransformer(com.thinkbiganalytics.discovery.rest.controller.SchemaParserAnnotationTransformer) DataSet(com.thinkbiganalytics.kylo.catalog.rest.model.DataSet) AsyncResponse(javax.ws.rs.container.AsyncResponse) Set(java.util.Set) FileParserFactory(com.thinkbiganalytics.discovery.FileParserFactory) SparkJobContext(com.thinkbiganalytics.kylo.spark.job.SparkJobContext) Suspended(javax.ws.rs.container.Suspended) SparkException(com.thinkbiganalytics.kylo.spark.SparkException) Stream(java.util.stream.Stream) ServerStatusResponse(com.thinkbiganalytics.spark.rest.model.ServerStatusResponse) KyloCatalogReadRequest(com.thinkbiganalytics.spark.rest.model.KyloCatalogReadRequest) WebApplicationException(javax.ws.rs.WebApplicationException) GET(javax.ws.rs.GET) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) DataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate) SparkJobResponse(com.thinkbiganalytics.kylo.spark.rest.model.job.SparkJobResponse) FileSchemaParser(com.thinkbiganalytics.discovery.parser.FileSchemaParser) HttpServletRequest(javax.servlet.http.HttpServletRequest) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus) Datasource(com.thinkbiganalytics.spark.rest.model.Datasource) Api(io.swagger.annotations.Api) Nullable(javax.annotation.Nullable) SparkJobService(com.thinkbiganalytics.kylo.spark.job.SparkJobService) MessageSource(org.springframework.context.MessageSource) SchemaParserDescriptorUtil(com.thinkbiganalytics.discovery.rest.controller.SchemaParserDescriptorUtil) FileMetadataCompletionTask(com.thinkbiganalytics.spark.rest.filemetadata.tasks.FileMetadataCompletionTask) SparkShellProcess(com.thinkbiganalytics.spark.shell.SparkShellProcess) JdbcDatasource(com.thinkbiganalytics.spark.rest.model.JdbcDatasource) SparkJobRequest(com.thinkbiganalytics.kylo.spark.rest.model.job.SparkJobRequest) FileMetadataScalaScriptGenerator(com.thinkbiganalytics.kylo.spark.file.metadata.FileMetadataScalaScriptGenerator) SparkJobStatus(com.thinkbiganalytics.kylo.spark.job.SparkJobStatus) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition) ApiResponse(io.swagger.annotations.ApiResponse) RegistrationRequest(com.thinkbiganalytics.spark.rest.model.RegistrationRequest) DatasourceProvider(com.thinkbiganalytics.metadata.api.datasource.DatasourceProvider) TransformRequest(com.thinkbiganalytics.spark.rest.model.TransformRequest) NoSuchMessageException(org.springframework.context.NoSuchMessageException) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) User(org.springframework.security.core.userdetails.User) TimeoutException(java.util.concurrent.TimeoutException) DefaultDataSetTemplate(com.thinkbiganalytics.kylo.catalog.rest.model.DefaultDataSetTemplate) RequestContextUtils(org.springframework.web.servlet.support.RequestContextUtils) ApiOperation(io.swagger.annotations.ApiOperation) DataSetProvider(com.thinkbiganalytics.metadata.api.catalog.DataSetProvider) Consumes(javax.ws.rs.Consumes) Locale(java.util.Locale) TransformResultModifier(com.thinkbiganalytics.spark.rest.model.TransformResultModifier) BadRequestException(javax.ws.rs.BadRequestException) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) CatalogModelTransform(com.thinkbiganalytics.kylo.catalog.rest.model.CatalogModelTransform) SparkShellRestClient(com.thinkbiganalytics.spark.shell.SparkShellRestClient) FileMetadataTransformResponseModifier(com.thinkbiganalytics.spark.rest.filemetadata.FileMetadataTransformResponseModifier) SchemaParserDescriptor(com.thinkbiganalytics.discovery.model.SchemaParserDescriptor) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) DataSources(com.thinkbiganalytics.spark.rest.model.DataSources) Objects(java.util.Objects) List(java.util.List) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) SaveResponse(com.thinkbiganalytics.spark.rest.model.SaveResponse) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Authentication(org.springframework.security.core.Authentication) PathParam(javax.ws.rs.PathParam) DataSourceUtil(com.thinkbiganalytics.kylo.catalog.datasource.DataSourceUtil) ApiResponses(io.swagger.annotations.ApiResponses) DataSetUtil(com.thinkbiganalytics.kylo.catalog.dataset.DataSetUtil) HashSet(java.util.HashSet) Inject(javax.inject.Inject) TransformResponse(com.thinkbiganalytics.spark.rest.model.TransformResponse) Qualifier(org.springframework.beans.factory.annotation.Qualifier) SubscriberFactory(com.thinkbiganalytics.kylo.reactive.SubscriberFactory) Tag(io.swagger.annotations.Tag) Subscriber(org.reactivestreams.Subscriber) Nonnull(javax.annotation.Nonnull) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) SparkShellSaveException(com.thinkbiganalytics.spark.shell.SparkShellSaveException) PreviewDataSetRequest(com.thinkbiganalytics.spark.rest.model.PreviewDataSetRequest) FileMetadataTaskService(com.thinkbiganalytics.spark.rest.filemetadata.tasks.FileMetadataTaskService) ModifiedTransformResponse(com.thinkbiganalytics.spark.rest.model.ModifiedTransformResponse) SparkShellProcessManager(com.thinkbiganalytics.spark.shell.SparkShellProcessManager) TimeUnit(java.util.concurrent.TimeUnit) Component(org.springframework.stereotype.Component) SparkShellTransformException(com.thinkbiganalytics.spark.shell.SparkShellTransformException) Collections(java.util.Collections) JdbcDatasource(com.thinkbiganalytics.spark.rest.model.JdbcDatasource) BadRequestException(javax.ws.rs.BadRequestException) Nonnull(javax.annotation.Nonnull)

Aggregations

DataSource (com.thinkbiganalytics.kylo.catalog.rest.model.DataSource)41 ApiOperation (io.swagger.annotations.ApiOperation)15 DefaultDataSetTemplate (com.thinkbiganalytics.kylo.catalog.rest.model.DefaultDataSetTemplate)14 ApiResponses (io.swagger.annotations.ApiResponses)14 Nonnull (javax.annotation.Nonnull)14 Path (javax.ws.rs.Path)13 Connector (com.thinkbiganalytics.kylo.catalog.rest.model.Connector)11 CatalogException (com.thinkbiganalytics.kylo.catalog.CatalogException)10 GET (javax.ws.rs.GET)9 BadRequestException (javax.ws.rs.BadRequestException)8 DataSet (com.thinkbiganalytics.kylo.catalog.rest.model.DataSet)7 DataSetTemplate (com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate)7 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 Nullable (javax.annotation.Nullable)7 StringUtils (org.apache.commons.lang3.StringUtils)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 CatalogModelTransform (com.thinkbiganalytics.kylo.catalog.rest.model.CatalogModelTransform)5 ConnectorPluginDescriptor (com.thinkbiganalytics.kylo.catalog.rest.model.ConnectorPluginDescriptor)5