Search in sources :

Example 1 with CatalogException

use of com.thinkbiganalytics.kylo.catalog.CatalogException in project kylo by Teradata.

the class DataSourceController method createDataSource.

@POST
@ApiOperation("Create a new data source")
@ApiResponses({ @ApiResponse(code = 200, message = "Data source created", response = DataSource.class), @ApiResponse(code = 400, message = "Invalid connector", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "Internal server error", response = RestResponseStatus.class) })
@Consumes(MediaType.APPLICATION_JSON)
public Response createDataSource(@Nonnull final CreateDataSourceEntity source) {
    log.entry(source);
    final DataSource dataSource;
    try {
        // TODO: Remove this check for the ID and force updates to use the PUT to updateDataSource() for a more typical REST API
        if (StringUtils.isNotEmpty(source.getId())) {
            return updateDataSource(source);
        } else {
            try {
                dataSource = dataSourceService.createDataSource(source, source.isDetectSimilarNiFiControllerServices());
            } catch (final CatalogException e) {
                if (log.isDebugEnabled()) {
                    log.debug("Cannot create data source from request: " + source, e);
                }
                throw new BadRequestException(getMessage(e));
            }
        }
    } catch (PotentialControllerServiceConflictException e) {
        throw new WebApplicationException(Response.status(Status.CONFLICT).entity(e.getControllerServiceConflictEntity()).build());
    } catch (DataSourceAlreadyExistsException e) {
        throw new BadRequestException(e.getMessage());
    }
    return Response.ok(log.exit(dataSource)).build();
}
Also used : DataSourceAlreadyExistsException(com.thinkbiganalytics.metadata.api.catalog.DataSourceAlreadyExistsException) WebApplicationException(javax.ws.rs.WebApplicationException) PotentialControllerServiceConflictException(com.thinkbiganalytics.kylo.catalog.datasource.PotentialControllerServiceConflictException) CatalogException(com.thinkbiganalytics.kylo.catalog.CatalogException) BadRequestException(javax.ws.rs.BadRequestException) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with CatalogException

use of com.thinkbiganalytics.kylo.catalog.CatalogException in project kylo by Teradata.

the class DataSourceController method doListFiles.

private List<DataSetFile> doListFiles(@QueryParam("path") String path, DataSource dataSource) {
    final List<DataSetFile> files;
    try {
        log.debug("Listing files at path: {}", path);
        files = fileManager.listFiles(path, dataSource);
    } catch (final AccessDeniedException e) {
        log.debug("Access denied accessing path: {}: {}", path, e, e);
        throw new ForbiddenException(getMessage("catalog.datasource.listFiles.forbidden", path));
    } catch (final CatalogException e) {
        log.debug("Catalog exception when accessing path: {}: {}", path, e, e);
        throw new BadRequestException(getMessage(e));
    } catch (final Exception e) {
        if (exceptionTransformer.causesInChain(e)) {
            throw new ThriftConnectionException(e);
        }
        if (log.isErrorEnabled()) {
            log.error("Failed to list data source files at path " + path + ": " + e, e);
        }
        final RestResponseStatus status = new RestResponseStatus.ResponseStatusBuilder().message(getMessage("catalog.datasource.listFiles.error", path)).url(request.getRequestURI()).setDeveloperMessage(e).buildError();
        throw new InternalServerErrorException(Response.serverError().entity(status).build());
    }
    return files;
}
Also used : AccessDeniedException(java.nio.file.AccessDeniedException) ForbiddenException(javax.ws.rs.ForbiddenException) CatalogException(com.thinkbiganalytics.kylo.catalog.CatalogException) BadRequestException(javax.ws.rs.BadRequestException) ThriftConnectionException(com.thinkbiganalytics.hive.exceptions.ThriftConnectionException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) DataSetFile(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetFile) TTransportException(org.apache.thrift.transport.TTransportException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NotFoundException(javax.ws.rs.NotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) AccessDeniedException(java.nio.file.AccessDeniedException) SQLException(java.sql.SQLException) ThriftConnectionException(com.thinkbiganalytics.hive.exceptions.ThriftConnectionException) CatalogException(com.thinkbiganalytics.kylo.catalog.CatalogException) PotentialControllerServiceConflictException(com.thinkbiganalytics.kylo.catalog.datasource.PotentialControllerServiceConflictException) ForbiddenException(javax.ws.rs.ForbiddenException) DataSourceAlreadyExistsException(com.thinkbiganalytics.metadata.api.catalog.DataSourceAlreadyExistsException) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus)

Example 3 with CatalogException

use of com.thinkbiganalytics.kylo.catalog.CatalogException in project kylo by Teradata.

the class DataSetController method updateDataSet.

@PUT
@ApiOperation("Updates an existing data set")
@ApiResponses({ @ApiResponse(code = 200, message = "Data set updated", response = DataSet.class), @ApiResponse(code = 400, message = "Invalid data source", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "Internal server error", response = RestResponseStatus.class) })
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)
public Response updateDataSet(@Nonnull final DataSet source) {
    log.entry(source);
    final boolean encryptCredentials = true;
    final DataSet dataSet;
    try {
        dataSet = dataSetService.updateDataSet(source, encryptCredentials);
    } catch (final CatalogException e) {
        throw new BadRequestException(getMessage(e));
    }
    return Response.ok(log.exit(dataSet)).build();
}
Also used : DataSet(com.thinkbiganalytics.kylo.catalog.rest.model.DataSet) CatalogException(com.thinkbiganalytics.kylo.catalog.CatalogException) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with CatalogException

use of com.thinkbiganalytics.kylo.catalog.CatalogException in project kylo by Teradata.

the class DataSetProvider method createDataSet.

/**
 * Creates a new data set using the specified template.
 * @param encryptedCredentials
 *
 * @throws CatalogException if the data set is not valid
 */
@Nonnull
public DataSet createDataSet(@Nonnull final DataSet source, boolean encryptedCredentials) {
    // Find data source
    final DataSource dataSource = Optional.of(source).map(DataSet::getDataSource).map(DataSource::getId).flatMap(dataSourceProvider::findDataSource).orElseThrow(() -> new CatalogException("catalog.dataset.datasource.invalid"));
    // Validate data set
    final DataSet dataSet = new DataSet(source);
    dataSet.setDataSource(dataSource);
    validateDataSet(dataSet);
    return metadataService.commit(() -> {
        // Require admin permission if the results should include unencrypted credentials.
        accessController.checkPermission(AccessController.SERVICES, encryptedCredentials ? FeedServicesAccessControl.ACCESS_DATASOURCES : FeedServicesAccessControl.ADMIN_DATASOURCES);
        // Resolve the real data set if possible, otherwise create
        com.thinkbiganalytics.metadata.api.catalog.DataSource.ID dataSourceId = dataSourceMetadataProvider.resolveId(dataSource.getId());
        com.thinkbiganalytics.metadata.api.catalog.DataSet ds = modelTransform.buildDataSet(source, metadataProvider.build(dataSourceId));
        return modelTransform.dataSetToRestModel(encryptedCredentials).apply(ds);
    });
}
Also used : DataSet(com.thinkbiganalytics.kylo.catalog.rest.model.DataSet) CatalogException(com.thinkbiganalytics.kylo.catalog.CatalogException) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Nonnull(javax.annotation.Nonnull)

Example 5 with CatalogException

use of com.thinkbiganalytics.kylo.catalog.CatalogException in project kylo by Teradata.

the class DataSourceProvider method updateDataSource.

/**
 * Updates a data source using the specified template.
 *
 * @throws CatalogException if the data source is not valid
 */
@Nonnull
public DataSource updateDataSource(@Nonnull final DataSource source) {
    return metadataService.commit(() -> {
        // Find data source
        final Optional<com.thinkbiganalytics.metadata.api.catalog.DataSource.ID> domainId = Optional.ofNullable(source.getId()).map(metadataProvider::resolveId);
        final com.thinkbiganalytics.metadata.api.catalog.DataSource domain = domainId.flatMap(metadataProvider::find).orElseThrow(() -> new CatalogException("catalog.datasource.notFound.id", source.getId()));
        // Create or update controller service
        final ConnectorPluginDescriptor plugin = pluginManager.getPlugin(domain.getConnector().getPluginId()).map(ConnectorPlugin::getDescriptor).orElse(null);
        if (plugin != null && plugin.getNifiControllerService() != null) {
            createOrUpdateNiFiControllerService(source, plugin, false);
        }
        // Update catalog
        final DataSource updatedDataSource = this.credentialManager.applyPlaceholders(source, SecurityContextUtil.getCurrentPrincipals());
        modelTransform.updateDataSource(updatedDataSource, domain);
        // Return a copy with the connector
        return modelTransform.dataSourceToRestModel().apply(domain);
    });
}
Also used : CatalogException(com.thinkbiganalytics.kylo.catalog.CatalogException) ConnectorPluginDescriptor(com.thinkbiganalytics.kylo.catalog.rest.model.ConnectorPluginDescriptor) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Nonnull(javax.annotation.Nonnull)

Aggregations

CatalogException (com.thinkbiganalytics.kylo.catalog.CatalogException)11 DataSource (com.thinkbiganalytics.kylo.catalog.rest.model.DataSource)5 Nonnull (javax.annotation.Nonnull)5 BadRequestException (javax.ws.rs.BadRequestException)5 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 Consumes (javax.ws.rs.Consumes)4 DataSet (com.thinkbiganalytics.kylo.catalog.rest.model.DataSet)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 PotentialControllerServiceConflictException (com.thinkbiganalytics.kylo.catalog.datasource.PotentialControllerServiceConflictException)2 ConnectorPluginDescriptor (com.thinkbiganalytics.kylo.catalog.rest.model.ConnectorPluginDescriptor)2 DataSetFile (com.thinkbiganalytics.kylo.catalog.rest.model.DataSetFile)2 DataSourceAlreadyExistsException (com.thinkbiganalytics.metadata.api.catalog.DataSourceAlreadyExistsException)2 POST (javax.ws.rs.POST)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 BasicAWSCredentialsProvider (org.apache.hadoop.fs.s3a.BasicAWSCredentialsProvider)2 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 AWSCredentialsProviderChain (com.amazonaws.auth.AWSCredentialsProviderChain)1