Search in sources :

Example 1 with EventListenerManager

use of io.trino.eventlistener.EventListenerManager in project trino by trinodb.

the class ConnectorManager method createCatalog.

private synchronized void createCatalog(CatalogName catalogName, String connectorName, InternalConnectorFactory factory, Map<String, String> properties) {
    // create all connectors before adding, so a broken connector does not leave the system half updated
    CatalogClassLoaderSupplier duplicatePluginClassLoaderFactory = new CatalogClassLoaderSupplier(catalogName, factory.getDuplicatePluginClassLoaderFactory(), handleResolver);
    MaterializedConnector connector = new MaterializedConnector(catalogName, createConnector(catalogName, factory.getConnectorFactory(), duplicatePluginClassLoaderFactory, properties), duplicatePluginClassLoaderFactory::destroy);
    MaterializedConnector informationSchemaConnector = new MaterializedConnector(createInformationSchemaCatalogName(catalogName), new InformationSchemaConnector(catalogName.getCatalogName(), nodeManager, metadataManager, accessControlManager), () -> {
    });
    CatalogName systemId = createSystemTablesCatalogName(catalogName);
    SystemTablesProvider systemTablesProvider;
    if (nodeManager.getCurrentNode().isCoordinator()) {
        systemTablesProvider = new CoordinatorSystemTablesProvider(transactionManager, metadataManager, catalogName.getCatalogName(), new StaticSystemTablesProvider(connector.getSystemTables()));
    } else {
        systemTablesProvider = new StaticSystemTablesProvider(connector.getSystemTables());
    }
    MaterializedConnector systemConnector = new MaterializedConnector(systemId, new SystemConnector(nodeManager, systemTablesProvider, transactionId -> transactionManager.getConnectorTransaction(transactionId, catalogName)), () -> {
    });
    SecurityManagement securityManagement = connector.getAccessControl().isPresent() ? CONNECTOR : SYSTEM;
    Catalog catalog = new Catalog(catalogName.getCatalogName(), connector.getCatalogName(), connectorName, connector.getConnector(), securityManagement, informationSchemaConnector.getCatalogName(), informationSchemaConnector.getConnector(), systemConnector.getCatalogName(), systemConnector.getConnector());
    try {
        addConnectorInternal(connector);
        addConnectorInternal(informationSchemaConnector);
        addConnectorInternal(systemConnector);
        catalogManager.registerCatalog(catalog);
    } catch (Throwable e) {
        catalogManager.removeCatalog(catalog.getCatalogName());
        removeConnectorInternal(systemConnector.getCatalogName());
        removeConnectorInternal(informationSchemaConnector.getCatalogName());
        removeConnectorInternal(connector.getCatalogName());
        throw e;
    }
    connector.getEventListeners().forEach(eventListenerManager::addEventListener);
}
Also used : CoordinatorSystemTablesProvider(io.trino.connector.system.CoordinatorSystemTablesProvider) SystemConnector(io.trino.connector.system.SystemConnector) StaticSystemTablesProvider(io.trino.connector.system.StaticSystemTablesProvider) AccessControlManager(io.trino.security.AccessControlManager) ConnectorRecordSetProvider(io.trino.spi.connector.ConnectorRecordSetProvider) ConnectorSplitManager(io.trino.spi.connector.ConnectorSplitManager) TableProceduresPropertyManager(io.trino.metadata.TableProceduresPropertyManager) TransactionManager(io.trino.transaction.TransactionManager) SecurityManagement(io.trino.metadata.Catalog.SecurityManagement) CoordinatorSystemTablesProvider(io.trino.connector.system.CoordinatorSystemTablesProvider) CatalogName.createSystemTablesCatalogName(io.trino.connector.CatalogName.createSystemTablesCatalogName) NodeInfo(io.airlift.node.NodeInfo) SplitManager(io.trino.split.SplitManager) ConnectorContext(io.trino.spi.connector.ConnectorContext) PreDestroy(javax.annotation.PreDestroy) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) HandleResolver(io.trino.metadata.HandleResolver) PageSorter(io.trino.spi.PageSorter) Map(java.util.Map) MetadataManager(io.trino.metadata.MetadataManager) ConnectorNodePartitioningProvider(io.trino.spi.connector.ConnectorNodePartitioningProvider) ImmutableSet(com.google.common.collect.ImmutableSet) NodeSchedulerConfig(io.trino.execution.scheduler.NodeSchedulerConfig) PageSinkManager(io.trino.split.PageSinkManager) ConnectorAccessControl(io.trino.spi.connector.ConnectorAccessControl) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) PropertyMetadata(io.trino.spi.session.PropertyMetadata) ThreadSafe(javax.annotation.concurrent.ThreadSafe) GuardedBy(javax.annotation.concurrent.GuardedBy) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader) TableProcedureMetadata(io.trino.spi.connector.TableProcedureMetadata) ConnectorIndexProvider(io.trino.spi.connector.ConnectorIndexProvider) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) SessionPropertyManager(io.trino.metadata.SessionPropertyManager) List(java.util.List) VersionEmbedder(io.trino.spi.VersionEmbedder) CONNECTOR(io.trino.metadata.Catalog.SecurityManagement.CONNECTOR) Optional(java.util.Optional) SystemConnector(io.trino.connector.system.SystemConnector) ColumnPropertyManager(io.trino.metadata.ColumnPropertyManager) SystemTable(io.trino.spi.connector.SystemTable) RecordPageSourceProvider(io.trino.split.RecordPageSourceProvider) InternalNodeManager(io.trino.metadata.InternalNodeManager) Logger(io.airlift.log.Logger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NodePartitioningManager(io.trino.sql.planner.NodePartitioningManager) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) Procedure(io.trino.spi.procedure.Procedure) Verify.verify(com.google.common.base.Verify.verify) CatalogName.createInformationSchemaCatalogName(io.trino.connector.CatalogName.createInformationSchemaCatalogName) PageIndexerFactory(io.trino.spi.PageIndexerFactory) Objects.requireNonNull(java.util.Objects.requireNonNull) TableProceduresRegistry(io.trino.metadata.TableProceduresRegistry) IndexManager(io.trino.index.IndexManager) ConnectorFactory(io.trino.spi.connector.ConnectorFactory) Catalog(io.trino.metadata.Catalog) SchemaPropertyManager(io.trino.metadata.SchemaPropertyManager) SYSTEM(io.trino.metadata.Catalog.SecurityManagement.SYSTEM) InformationSchemaConnector(io.trino.connector.informationschema.InformationSchemaConnector) PluginClassLoader(io.trino.server.PluginClassLoader) SystemTablesProvider(io.trino.connector.system.SystemTablesProvider) ConnectorPageSourceProvider(io.trino.spi.connector.ConnectorPageSourceProvider) PageSourceManager(io.trino.split.PageSourceManager) EventListenerManager(io.trino.eventlistener.EventListenerManager) CatalogManager(io.trino.metadata.CatalogManager) TablePropertyManager(io.trino.metadata.TablePropertyManager) ProcedureRegistry(io.trino.metadata.ProcedureRegistry) MaterializedViewPropertyManager(io.trino.metadata.MaterializedViewPropertyManager) EventListener(io.trino.spi.eventlistener.EventListener) TypeManager(io.trino.spi.type.TypeManager) AnalyzePropertyManager(io.trino.metadata.AnalyzePropertyManager) ConnectorPageSinkProvider(io.trino.spi.connector.ConnectorPageSinkProvider) Connector(io.trino.spi.connector.Connector) SecurityManagement(io.trino.metadata.Catalog.SecurityManagement) Catalog(io.trino.metadata.Catalog) StaticSystemTablesProvider(io.trino.connector.system.StaticSystemTablesProvider) InformationSchemaConnector(io.trino.connector.informationschema.InformationSchemaConnector) CatalogName.createSystemTablesCatalogName(io.trino.connector.CatalogName.createSystemTablesCatalogName) CatalogName.createInformationSchemaCatalogName(io.trino.connector.CatalogName.createInformationSchemaCatalogName) StaticSystemTablesProvider(io.trino.connector.system.StaticSystemTablesProvider) CoordinatorSystemTablesProvider(io.trino.connector.system.CoordinatorSystemTablesProvider) SystemTablesProvider(io.trino.connector.system.SystemTablesProvider)

Example 2 with EventListenerManager

use of io.trino.eventlistener.EventListenerManager in project trino by trinodb.

the class TestCreateTableTask method testCreateLikeDenyPermission.

@Test
public void testCreateLikeDenyPermission() {
    CreateTable statement = getCreatleLikeStatement(false);
    TestingAccessControlManager accessControl = new TestingAccessControlManager(transactionManager, new EventListenerManager(new EventListenerConfig()));
    accessControl.deny(privilege("parent_table", SELECT_COLUMN));
    CreateTableTask createTableTask = new CreateTableTask(plannerContext, accessControl, columnPropertyManager, tablePropertyManager);
    assertThatThrownBy(() -> getFutureValue(createTableTask.internalExecute(statement, testSession, List.of(), output -> {
    }))).isInstanceOf(AccessDeniedException.class).hasMessageContaining("Cannot reference columns of table");
}
Also used : AccessDeniedException(io.trino.spi.security.AccessDeniedException) CreateTable(io.trino.sql.tree.CreateTable) EventListenerManager(io.trino.eventlistener.EventListenerManager) TestingAccessControlManager(io.trino.testing.TestingAccessControlManager) EventListenerConfig(io.trino.eventlistener.EventListenerConfig) Test(org.testng.annotations.Test)

Example 3 with EventListenerManager

use of io.trino.eventlistener.EventListenerManager in project trino by trinodb.

the class TestCreateTableTask method testCreateLikeWithPropertiesDenyPermission.

@Test
public void testCreateLikeWithPropertiesDenyPermission() {
    CreateTable statement = getCreatleLikeStatement(true);
    TestingAccessControlManager accessControl = new TestingAccessControlManager(transactionManager, new EventListenerManager(new EventListenerConfig()));
    accessControl.deny(privilege("parent_table", SHOW_CREATE_TABLE));
    CreateTableTask createTableTask = new CreateTableTask(plannerContext, accessControl, columnPropertyManager, tablePropertyManager);
    assertThatThrownBy(() -> getFutureValue(createTableTask.internalExecute(statement, testSession, List.of(), output -> {
    }))).isInstanceOf(AccessDeniedException.class).hasMessageContaining("Cannot reference properties of table");
}
Also used : AccessDeniedException(io.trino.spi.security.AccessDeniedException) CreateTable(io.trino.sql.tree.CreateTable) EventListenerManager(io.trino.eventlistener.EventListenerManager) TestingAccessControlManager(io.trino.testing.TestingAccessControlManager) EventListenerConfig(io.trino.eventlistener.EventListenerConfig) Test(org.testng.annotations.Test)

Aggregations

EventListenerManager (io.trino.eventlistener.EventListenerManager)3 EventListenerConfig (io.trino.eventlistener.EventListenerConfig)2 AccessDeniedException (io.trino.spi.security.AccessDeniedException)2 CreateTable (io.trino.sql.tree.CreateTable)2 TestingAccessControlManager (io.trino.testing.TestingAccessControlManager)2 Test (org.testng.annotations.Test)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Verify.verify (com.google.common.base.Verify.verify)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Logger (io.airlift.log.Logger)1 NodeInfo (io.airlift.node.NodeInfo)1 CatalogName.createInformationSchemaCatalogName (io.trino.connector.CatalogName.createInformationSchemaCatalogName)1 CatalogName.createSystemTablesCatalogName (io.trino.connector.CatalogName.createSystemTablesCatalogName)1 InformationSchemaConnector (io.trino.connector.informationschema.InformationSchemaConnector)1 CoordinatorSystemTablesProvider (io.trino.connector.system.CoordinatorSystemTablesProvider)1 StaticSystemTablesProvider (io.trino.connector.system.StaticSystemTablesProvider)1 SystemConnector (io.trino.connector.system.SystemConnector)1 SystemTablesProvider (io.trino.connector.system.SystemTablesProvider)1