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