Search in sources :

Example 1 with ConnectorTab

use of com.thinkbiganalytics.kylo.catalog.rest.model.ConnectorTab in project kylo by Teradata.

the class DataSourceController method testDataSource.

@POST
@ApiOperation("Tests datasource")
@ApiResponses({ @ApiResponse(code = 204, message = "Data source test successful", response = DataSource.class), @ApiResponse(code = 400, message = "Invalid datasource", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "Internal server error", response = RestResponseStatus.class) })
@Consumes(MediaType.APPLICATION_JSON)
@Path("/test")
public Response testDataSource(@Nonnull final DataSource dataSource) {
    log.entry(dataSource);
    String pluginId = dataSource.getConnector().getPluginId();
    Optional<ConnectorPlugin> plugin = this.pluginManager.getPlugin(pluginId);
    if (!plugin.isPresent()) {
        throw new BadRequestException(getMessage("catalog.datasource.testDataSource.connectorPluginNotFound", pluginId));
    }
    List<ConnectorTab> tabs = plugin.get().getDescriptor().getTabs();
    if (tabs == null) {
        throw new BadRequestException(getMessage("catalog.datasource.testDataSource.testNotAvailableForPlugin", pluginId));
    }
    ConnectorTab connectorTab = tabs.get(0);
    String sref = connectorTab.getSref();
    DataSource decrypted = modelTransform.decryptOptions(dataSource);
    if (".browse".equals(sref)) {
        doListFiles(DataSourceUtil.getPaths(decrypted).orElseThrow(IllegalStateException::new).get(0), decrypted);
    } else if (".connection".equals(sref)) {
        doListTables(null, null, decrypted);
    } else {
        throw new BadRequestException(getMessage("catalog.datasource.testDataSource.testNotAvailableForTab", sref));
    }
    log.exit();
    return Response.noContent().build();
}
Also used : ConnectorPlugin(com.thinkbiganalytics.kylo.catalog.spi.ConnectorPlugin) BadRequestException(javax.ws.rs.BadRequestException) ConnectorTab(com.thinkbiganalytics.kylo.catalog.rest.model.ConnectorTab) DataSource(com.thinkbiganalytics.kylo.catalog.rest.model.DataSource) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ConnectorTab (com.thinkbiganalytics.kylo.catalog.rest.model.ConnectorTab)1 DataSource (com.thinkbiganalytics.kylo.catalog.rest.model.DataSource)1 ConnectorPlugin (com.thinkbiganalytics.kylo.catalog.spi.ConnectorPlugin)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 Path (javax.ws.rs.Path)1