Search in sources :

Example 1 with Connector

use of com.thinkbiganalytics.metadata.api.catalog.Connector in project kylo by Teradata.

the class MigrateLegacyDatasourcesUpgradeAction method upgradeTo.

@Override
public void upgradeTo(final KyloVersion targetVersion) {
    log.info("Setting up catalog access control: {}", targetVersion);
    try {
        NodeTypeManager typeMgr = JcrMetadataAccess.getActiveSession().getWorkspace().getNodeTypeManager();
        NodeType dataSourceType = typeMgr.getNodeType("tba:DataSource");
        Connector conn = pluginManager.getPlugin("jdbc").flatMap(plugin -> connectorProvider.findByPlugin(plugin.getId())).orElseThrow(() -> new IllegalStateException("No JDBC connector found"));
        legacyProvider.getDatasources().stream().map(JcrDatasource.class::cast).map(JcrDatasource::getNode).filter(node -> JcrUtil.isNodeType(node, "tba:userDatasource")).filter(node -> JcrUtil.isNodeType(JcrUtil.getNode(node, "tba:details"), "tba:jdbcDatasourceDetails")).forEach(jdbcNode -> {
            try {
                // Move the legacy datasource node to a temporary parent that doesn't have any constraints (the catalog folder).
                Node tmpParent = JcrUtil.getNode(JcrUtil.getRootNode(jdbcNode), "metadata/catalog");
                String dsSystemName = dataSourceProvider.generateSystemName(JcrUtil.getName(jdbcNode));
                Path catDsPath = MetadataPaths.dataSourcePath(conn.getSystemName(), dsSystemName);
                Node catDsNode = JcrUtil.moveNode(jdbcNode, JcrUtil.path(tmpParent.getPath()).resolve(dsSystemName));
                // Wrap the node as a legacy UserDataSource and collect its properties.
                JcrUserDatasource legacyDs = JcrUtil.getJcrObject(catDsNode, JcrUserDatasource.class);
                Set<? extends JcrFeed> referencingFeeds = legacyDs.getFeedSources().stream().map(FeedSource::getFeed).map(JcrFeed.class::cast).collect(Collectors.toSet());
                AtomicReference<String> controllerServiceId = new AtomicReference<>();
                AtomicReference<String> password = new AtomicReference<>();
                legacyDs.getDetails().filter(JcrJdbcDatasourceDetails.class::isInstance).map(JcrJdbcDatasourceDetails.class::cast).ifPresent(details -> {
                    controllerServiceId.set(details.getControllerServiceId().orElse(null));
                    password.set("{cipher}" + details.getPassword());
                });
                if (this.accessController.isEntityAccessControlled()) {
                    legacyDs.disableAccessControl(legacyDs.getOwner());
                }
                // Convert the legacy type into the catalog type.
                JcrDataSource catDs = convertToDataSource(catDsNode, catDsPath, dataSourceType, controllerServiceId.get(), password.get());
                linkDataSets(catDs, referencingFeeds);
                if (this.accessController.isEntityAccessControlled()) {
                    List<SecurityRole> roles = roleProvider.getEntityRoles(SecurityRole.DATASOURCE);
                    actionsProvider.getAvailableActions(AllowedActions.DATASOURCE).ifPresent(actions -> catDs.enableAccessControl((JcrAllowedActions) actions, legacyDs.getOwner(), roles));
                }
            } catch (RepositoryException e) {
                throw new UpgradeException("Failed to migrate legacy datasources", e);
            }
        });
    } catch (IllegalStateException | RepositoryException e) {
        throw new UpgradeException("Failed to migrate legacy datasources", e);
    }
}
Also used : Arrays(java.util.Arrays) MetadataPaths(com.thinkbiganalytics.metadata.modeshape.common.MetadataPaths) LoggerFactory(org.slf4j.LoggerFactory) JcrUserDatasource(com.thinkbiganalytics.metadata.modeshape.datasource.JcrUserDatasource) StringUtils(org.apache.commons.lang3.StringUtils) JcrDataSetProvider(com.thinkbiganalytics.metadata.modeshape.catalog.dataset.JcrDataSetProvider) FeedProvider(com.thinkbiganalytics.metadata.api.feed.FeedProvider) SecurityRole(com.thinkbiganalytics.security.role.SecurityRole) JcrDataSource(com.thinkbiganalytics.metadata.modeshape.catalog.datasource.JcrDataSource) JcrDatasource(com.thinkbiganalytics.metadata.modeshape.datasource.JcrDatasource) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) UpgradeException(com.thinkbiganalytics.server.upgrade.UpgradeException) JcrAllowedEntityActionsProvider(com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedEntityActionsProvider) Path(java.nio.file.Path) JcrPropertyUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrPropertyUtil) JcrJdbcDatasourceDetails(com.thinkbiganalytics.metadata.modeshape.datasource.JcrJdbcDatasourceDetails) NifiControllerServiceProperties(com.thinkbiganalytics.feedmgr.nifi.NifiControllerServiceProperties) Set(java.util.Set) Collectors(java.util.stream.Collectors) SecurityRoleProvider(com.thinkbiganalytics.security.role.SecurityRoleProvider) IconableMixin(com.thinkbiganalytics.metadata.modeshape.common.mixin.IconableMixin) JcrDerivedDatasource(com.thinkbiganalytics.metadata.modeshape.datasource.JcrDerivedDatasource) List(java.util.List) NodeType(javax.jcr.nodetype.NodeType) JcrAllowedActions(com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions) JcrFeedSource(com.thinkbiganalytics.metadata.modeshape.feed.JcrFeedSource) JcrMetadataAccess(com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess) KyloUpgrader(com.thinkbiganalytics.server.upgrade.KyloUpgrader) JcrDataSourceProvider(com.thinkbiganalytics.metadata.modeshape.catalog.datasource.JcrDataSourceProvider) ConnectorPluginManager(com.thinkbiganalytics.kylo.catalog.ConnectorPluginManager) PropertiedMixin(com.thinkbiganalytics.metadata.modeshape.common.mixin.PropertiedMixin) AtomicReference(java.util.concurrent.atomic.AtomicReference) AllowedActions(com.thinkbiganalytics.security.action.AllowedActions) Inject(javax.inject.Inject) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) JcrDataSet(com.thinkbiganalytics.metadata.modeshape.catalog.dataset.JcrDataSet) UpgradeAction(com.thinkbiganalytics.server.upgrade.UpgradeAction) RepositoryException(javax.jcr.RepositoryException) JcrFeed(com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed) Node(javax.jcr.Node) FeedSource(com.thinkbiganalytics.metadata.api.feed.FeedSource) JcrDataSetSparkParameters(com.thinkbiganalytics.metadata.modeshape.catalog.JcrDataSetSparkParameters) ConnectorProvider(com.thinkbiganalytics.metadata.api.catalog.ConnectorProvider) SystemEntityMixin(com.thinkbiganalytics.metadata.modeshape.common.mixin.SystemEntityMixin) Logger(org.slf4j.Logger) DataSetSparkParameters(com.thinkbiganalytics.metadata.api.catalog.DataSetSparkParameters) Profile(org.springframework.context.annotation.Profile) Component(org.springframework.stereotype.Component) Connector(com.thinkbiganalytics.metadata.api.catalog.Connector) Workspace(org.modeshape.jcr.api.Workspace) JcrUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrUtil) KyloVersion(com.thinkbiganalytics.KyloVersion) DatasourceProvider(com.thinkbiganalytics.metadata.api.datasource.DatasourceProvider) Path(java.nio.file.Path) Connector(com.thinkbiganalytics.metadata.api.catalog.Connector) SecurityRole(com.thinkbiganalytics.security.role.SecurityRole) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) JcrUserDatasource(com.thinkbiganalytics.metadata.modeshape.datasource.JcrUserDatasource) Node(javax.jcr.Node) AtomicReference(java.util.concurrent.atomic.AtomicReference) JcrDataSource(com.thinkbiganalytics.metadata.modeshape.catalog.datasource.JcrDataSource) RepositoryException(javax.jcr.RepositoryException) UpgradeException(com.thinkbiganalytics.server.upgrade.UpgradeException) JcrDatasource(com.thinkbiganalytics.metadata.modeshape.datasource.JcrDatasource) JcrAllowedActions(com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions) JcrFeedSource(com.thinkbiganalytics.metadata.modeshape.feed.JcrFeedSource) FeedSource(com.thinkbiganalytics.metadata.api.feed.FeedSource) NodeType(javax.jcr.nodetype.NodeType) JcrJdbcDatasourceDetails(com.thinkbiganalytics.metadata.modeshape.datasource.JcrJdbcDatasourceDetails)

Example 2 with Connector

use of com.thinkbiganalytics.metadata.api.catalog.Connector 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 3 with Connector

use of com.thinkbiganalytics.metadata.api.catalog.Connector in project kylo by Teradata.

the class AccessControlConfigurator method ensureCatalogAccessControl.

/**
 * Ensures that the entity-level access control is setup up for the entities introduced by the connector architecture.
 */
public void ensureCatalogAccessControl() {
    List<Connector> connectors = connectorProvider.findAll(true);
    List<SecurityRole> conntorRoles = this.roleProvider.getEntityRoles(SecurityRole.CONNECTOR);
    Optional<AllowedActions> connectorActions = this.actionsProvider.getAvailableActions(AllowedActions.CONNECTOR);
    connectors.stream().forEach(conn -> {
        Principal owner = conn.getOwner() != null ? conn.getOwner() : JcrMetadataAccess.getActiveUser();
        connectorActions.ifPresent(actions -> ((JcrConnector) conn).enableAccessControl((JcrAllowedActions) actions, owner, conntorRoles));
    });
    List<DataSource> dataSources = dataSourceProvider.findAll();
    List<SecurityRole> dataSourceRoles = this.roleProvider.getEntityRoles(SecurityRole.DATASOURCE);
    Optional<AllowedActions> dataSourceActions = this.actionsProvider.getAvailableActions(AllowedActions.DATASOURCE);
    dataSources.stream().map(JcrDataSource.class::cast).forEach(dataSource -> {
        Principal owner = dataSource.getOwner() != null ? dataSource.getOwner() : JcrMetadataAccess.getActiveUser();
        dataSourceActions.ifPresent(actions -> dataSource.enableAccessControl((JcrAllowedActions) actions, owner, dataSourceRoles));
    });
}
Also used : JcrConnector(com.thinkbiganalytics.metadata.modeshape.catalog.connector.JcrConnector) Connector(com.thinkbiganalytics.metadata.api.catalog.Connector) SecurityRole(com.thinkbiganalytics.security.role.SecurityRole) JcrAllowedActions(com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions) AllowedActions(com.thinkbiganalytics.security.action.AllowedActions) JcrAllowedActions(com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions) Principal(java.security.Principal) JcrDataSource(com.thinkbiganalytics.metadata.modeshape.catalog.datasource.JcrDataSource) DataSource(com.thinkbiganalytics.metadata.api.catalog.DataSource)

Example 4 with Connector

use of com.thinkbiganalytics.metadata.api.catalog.Connector 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 5 with Connector

use of com.thinkbiganalytics.metadata.api.catalog.Connector in project kylo by Teradata.

the class JcrDataSetProviderTest method setup.

@BeforeClass
public void setup() {
    metadata.commit(() -> {
        Connector conn = this.connProvider.create("plugin1", "test1" + "_conn");
        this.dSrcIds.add(this.dataSourceProvider.create(conn.getId(), "dataset0").getId());
        this.dSrcIds.add(this.dataSourceProvider.create(conn.getId(), "dataset1").getId());
    }, MetadataAccess.SERVICE);
}
Also used : Connector(com.thinkbiganalytics.metadata.api.catalog.Connector) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

Connector (com.thinkbiganalytics.metadata.api.catalog.Connector)7 ConnectorPluginManager (com.thinkbiganalytics.kylo.catalog.ConnectorPluginManager)2 ConnectorPlugin (com.thinkbiganalytics.kylo.catalog.spi.ConnectorPlugin)2 ConnectorProvider (com.thinkbiganalytics.metadata.api.catalog.ConnectorProvider)2 DataSetSparkParameters (com.thinkbiganalytics.metadata.api.catalog.DataSetSparkParameters)2 DataSource (com.thinkbiganalytics.metadata.api.catalog.DataSource)2 JcrMetadataAccess (com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess)2 JcrDataSetProvider (com.thinkbiganalytics.metadata.modeshape.catalog.dataset.JcrDataSetProvider)2 JcrDataSource (com.thinkbiganalytics.metadata.modeshape.catalog.datasource.JcrDataSource)2 JcrDataSourceProvider (com.thinkbiganalytics.metadata.modeshape.catalog.datasource.JcrDataSourceProvider)2 JcrAllowedActions (com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions)2 AllowedActions (com.thinkbiganalytics.security.action.AllowedActions)2 SecurityRole (com.thinkbiganalytics.security.role.SecurityRole)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Workspace (org.modeshape.jcr.api.Workspace)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2