use of com.thinkbiganalytics.kylo.catalog.spi.ConnectorPlugin in project kylo by Teradata.
the class DefaultDataSourcesUpgradeAction method upgradeTo.
@Override
public void upgradeTo(final KyloVersion targetVersion) {
log.info("Creating default catalog data sources: {}", targetVersion);
Optional<ConnectorPlugin> plugin = pluginManager.getPlugin("hive");
if (plugin.isPresent()) {
Optional<Connector> connector = connectorProvider.findByPlugin(plugin.get().getId());
if (connector.isPresent()) {
List<DataSource> hiveSources = dataSourceProvider.findByConnector(connector.get().getId());
// If at least one Hive data source exists then do nothing.
if (hiveSources.size() == 0) {
log.info("Creating default Hive data source");
DataSource ds = dataSourceProvider.create(connector.get().getId(), "Hive");
ds.setDescription("The default Hive data source");
DataSetSparkParameters params = ds.getSparkParameters();
params.setFormat("hive");
params.addOption("driver", this.driver);
params.addOption("url", this.url);
params.addOption("user", this.user);
params.addOption("password", this.password);
} else {
log.info("One or more Hive data sources already found: {}", hiveSources.stream().map(DataSource::toString).collect(Collectors.toList()));
}
} else {
log.warn("No Hive connector found - cannot create a default Hive data source");
}
} else {
log.warn("No Hive connector plugin found - cannot create a default Hive data source");
}
}
use of com.thinkbiganalytics.kylo.catalog.spi.ConnectorPlugin in project kylo by Teradata.
the class TestSpringConfiguration method connectorPluginManager.
@Bean
public ConnectorPluginManager connectorPluginManager() {
ConnectorPluginDescriptor descr = new ConnectorPluginDescriptor("dummy", "Dummy Connector", "jdbc");
ConnectorPlugin plugin = Mockito.mock(ConnectorPlugin.class);
Mockito.when(plugin.getDescriptor()).thenReturn(descr);
ConnectorPluginManager mgr = Mockito.mock(ConnectorPluginManager.class);
Mockito.when(mgr.getPlugin(anyString())).thenReturn(Optional.of(plugin));
return mgr;
}
use of com.thinkbiganalytics.kylo.catalog.spi.ConnectorPlugin in project kylo by Teradata.
the class CatalogMetadataConfig method doPluginSyncAction.
private void doPluginSyncAction(ConnectorPluginManager pluginMgr, MetadataAccess metadata) {
metadata.commit(() -> {
List<ConnectorPlugin> plugins = pluginMgr.getPlugins();
Map<String, Connector> connectorMap = connectorProvider().findAll(true).stream().collect(Collectors.toMap(Connector::getPluginId, c -> c));
for (ConnectorPlugin plugin : plugins) {
Connector connector = connectorMap.get(plugin.getId());
ConnectorPluginDescriptor descr = plugin.getDescriptor();
if (connector != null) {
connectorMap.get(plugin.getId()).setActive(true);
connectorMap.remove(plugin.getId());
} else {
String title = descr.getTitle();
connector = connectorProvider().create(plugin.getId(), title);
}
connector.setIconColor(descr.getColor());
connector.setIcon(descr.getIcon());
if (StringUtils.isNotBlank(descr.getFormat())) {
connector.getSparkParameters().setFormat(descr.getFormat());
}
}
// least one data source, or removed if they don't.
for (Connector connector : connectorMap.values()) {
if (connector.getDataSources().isEmpty()) {
connectorProvider().deleteById(connector.getId());
} else {
connector.setActive(false);
}
}
}, MetadataAccess.SERVICE);
}
use of com.thinkbiganalytics.kylo.catalog.spi.ConnectorPlugin in project kylo by Teradata.
the class TemporaryConnectorPluginConfig method connectorPluginManager.
@Bean
public ConnectorPluginManager connectorPluginManager(Optional<List<ConnectorPlugin>> plugins) {
List<ConnectorPlugin> list = plugins.orElse(Collections.emptyList());
ConnectorPluginManager mgr = new DefaultConnectorPluginManager();
list.forEach(plugin -> mgr.register(plugin));
return mgr;
}
use of com.thinkbiganalytics.kylo.catalog.spi.ConnectorPlugin 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