Search in sources :

Example 1 with ConnectorPlugin

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");
    }
}
Also used : ConnectorPlugin(com.thinkbiganalytics.kylo.catalog.spi.ConnectorPlugin) Connector(com.thinkbiganalytics.metadata.api.catalog.Connector) DataSetSparkParameters(com.thinkbiganalytics.metadata.api.catalog.DataSetSparkParameters) DataSource(com.thinkbiganalytics.metadata.api.catalog.DataSource)

Example 2 with ConnectorPlugin

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;
}
Also used : ConnectorPlugin(com.thinkbiganalytics.kylo.catalog.spi.ConnectorPlugin) ConnectorPluginManager(com.thinkbiganalytics.kylo.catalog.ConnectorPluginManager) ConnectorPluginDescriptor(com.thinkbiganalytics.kylo.catalog.rest.model.ConnectorPluginDescriptor) Bean(org.springframework.context.annotation.Bean)

Example 3 with ConnectorPlugin

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);
}
Also used : ConnectorProvider(com.thinkbiganalytics.metadata.api.catalog.ConnectorProvider) JcrDataSourceProvider(com.thinkbiganalytics.metadata.modeshape.catalog.datasource.JcrDataSourceProvider) Logger(org.slf4j.Logger) Session(javax.jcr.Session) ConnectorPlugin(com.thinkbiganalytics.kylo.catalog.spi.ConnectorPlugin) ConnectorAlreadyExistsException(com.thinkbiganalytics.metadata.api.catalog.ConnectorAlreadyExistsException) DataSourceProvider(com.thinkbiganalytics.metadata.api.catalog.DataSourceProvider) ConnectorPluginManager(com.thinkbiganalytics.kylo.catalog.ConnectorPluginManager) PostMetadataConfigAction(com.thinkbiganalytics.metadata.api.PostMetadataConfigAction) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) JcrDataSetProvider(com.thinkbiganalytics.metadata.modeshape.catalog.dataset.JcrDataSetProvider) List(java.util.List) DataSetProvider(com.thinkbiganalytics.metadata.api.catalog.DataSetProvider) ConnectorPluginDescriptor(com.thinkbiganalytics.kylo.catalog.rest.model.ConnectorPluginDescriptor) Connector(com.thinkbiganalytics.metadata.api.catalog.Connector) Workspace(org.modeshape.jcr.api.Workspace) Map(java.util.Map) JcrConnectorProvider(com.thinkbiganalytics.metadata.modeshape.catalog.connector.JcrConnectorProvider) Bean(org.springframework.context.annotation.Bean) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) JcrMetadataAccess(com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess) ConnectorPlugin(com.thinkbiganalytics.kylo.catalog.spi.ConnectorPlugin) Connector(com.thinkbiganalytics.metadata.api.catalog.Connector) ConnectorPluginDescriptor(com.thinkbiganalytics.kylo.catalog.rest.model.ConnectorPluginDescriptor)

Example 4 with ConnectorPlugin

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;
}
Also used : ConnectorPlugin(com.thinkbiganalytics.kylo.catalog.spi.ConnectorPlugin) ConnectorPluginManager(com.thinkbiganalytics.kylo.catalog.ConnectorPluginManager) Bean(org.springframework.context.annotation.Bean)

Example 5 with ConnectorPlugin

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

ConnectorPlugin (com.thinkbiganalytics.kylo.catalog.spi.ConnectorPlugin)5 ConnectorPluginManager (com.thinkbiganalytics.kylo.catalog.ConnectorPluginManager)3 Bean (org.springframework.context.annotation.Bean)3 ConnectorPluginDescriptor (com.thinkbiganalytics.kylo.catalog.rest.model.ConnectorPluginDescriptor)2 Connector (com.thinkbiganalytics.metadata.api.catalog.Connector)2 ConnectorTab (com.thinkbiganalytics.kylo.catalog.rest.model.ConnectorTab)1 DataSource (com.thinkbiganalytics.kylo.catalog.rest.model.DataSource)1 MetadataAccess (com.thinkbiganalytics.metadata.api.MetadataAccess)1 PostMetadataConfigAction (com.thinkbiganalytics.metadata.api.PostMetadataConfigAction)1 ConnectorAlreadyExistsException (com.thinkbiganalytics.metadata.api.catalog.ConnectorAlreadyExistsException)1 ConnectorProvider (com.thinkbiganalytics.metadata.api.catalog.ConnectorProvider)1 DataSetProvider (com.thinkbiganalytics.metadata.api.catalog.DataSetProvider)1 DataSetSparkParameters (com.thinkbiganalytics.metadata.api.catalog.DataSetSparkParameters)1 DataSource (com.thinkbiganalytics.metadata.api.catalog.DataSource)1 DataSourceProvider (com.thinkbiganalytics.metadata.api.catalog.DataSourceProvider)1 JcrMetadataAccess (com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess)1 JcrConnectorProvider (com.thinkbiganalytics.metadata.modeshape.catalog.connector.JcrConnectorProvider)1 JcrDataSetProvider (com.thinkbiganalytics.metadata.modeshape.catalog.dataset.JcrDataSetProvider)1 JcrDataSourceProvider (com.thinkbiganalytics.metadata.modeshape.catalog.datasource.JcrDataSourceProvider)1 ApiOperation (io.swagger.annotations.ApiOperation)1