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();
}
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;
}
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();
}
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);
});
}
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);
});
}
Aggregations