Search in sources :

Example 1 with DataSourceAlreadyExistsException

use of com.thinkbiganalytics.metadata.api.catalog.DataSourceAlreadyExistsException 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)

Aggregations

CatalogException (com.thinkbiganalytics.kylo.catalog.CatalogException)1 PotentialControllerServiceConflictException (com.thinkbiganalytics.kylo.catalog.datasource.PotentialControllerServiceConflictException)1 DataSource (com.thinkbiganalytics.kylo.catalog.rest.model.DataSource)1 DataSourceAlreadyExistsException (com.thinkbiganalytics.metadata.api.catalog.DataSourceAlreadyExistsException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 BadRequestException (javax.ws.rs.BadRequestException)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 WebApplicationException (javax.ws.rs.WebApplicationException)1