Search in sources :

Example 1 with ThreadContextClassLoader

use of com.facebook.presto.spi.classloader.ThreadContextClassLoader in project presto by prestodb.

the class AtopConnectorFactory method create.

@Override
public Connector create(String connectorId, Map<String, String> requiredConfig, ConnectorContext context) {
    requireNonNull(requiredConfig, "requiredConfig is null");
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        Bootstrap app = new Bootstrap(new AtopModule(atopFactoryClass, context.getTypeManager(), context.getNodeManager(), context.getNodeManager().getEnvironment(), connectorId), installModuleIf(AtopConnectorConfig.class, config -> config.getSecurity().equalsIgnoreCase(SECURITY_NONE), new AllowAllAccessControlModule()), installModuleIf(AtopConnectorConfig.class, config -> config.getSecurity().equalsIgnoreCase(SECURITY_FILE), binder -> {
            binder.install(new FileBasedAccessControlModule());
            binder.install(new JsonModule());
        }));
        Injector injector = app.strictConfig().doNotInitializeLogging().setRequiredConfigurationProperties(requiredConfig).initialize();
        return injector.getInstance(AtopConnector.class);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : Connector(com.facebook.presto.spi.connector.Connector) SECURITY_FILE(com.facebook.presto.atop.AtopConnectorConfig.SECURITY_FILE) ConditionalModule.installModuleIf(io.airlift.configuration.ConditionalModule.installModuleIf) ConnectorHandleResolver(com.facebook.presto.spi.ConnectorHandleResolver) Throwables(com.google.common.base.Throwables) SECURITY_NONE(com.facebook.presto.atop.AtopConnectorConfig.SECURITY_NONE) AllowAllAccessControlModule(com.facebook.presto.plugin.base.security.AllowAllAccessControlModule) ConnectorFactory(com.facebook.presto.spi.connector.ConnectorFactory) Injector(com.google.inject.Injector) FileBasedAccessControlModule(com.facebook.presto.plugin.base.security.FileBasedAccessControlModule) Bootstrap(io.airlift.bootstrap.Bootstrap) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ThreadContextClassLoader(com.facebook.presto.spi.classloader.ThreadContextClassLoader) ConnectorContext(com.facebook.presto.spi.connector.ConnectorContext) JsonModule(io.airlift.json.JsonModule) Injector(com.google.inject.Injector) AllowAllAccessControlModule(com.facebook.presto.plugin.base.security.AllowAllAccessControlModule) Bootstrap(io.airlift.bootstrap.Bootstrap) FileBasedAccessControlModule(com.facebook.presto.plugin.base.security.FileBasedAccessControlModule) ThreadContextClassLoader(com.facebook.presto.spi.classloader.ThreadContextClassLoader) JsonModule(io.airlift.json.JsonModule)

Example 2 with ThreadContextClassLoader

use of com.facebook.presto.spi.classloader.ThreadContextClassLoader in project presto by prestodb.

the class HiveConnector method beginTransaction.

@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly) {
    checkConnectorSupports(READ_UNCOMMITTED, isolationLevel);
    ConnectorTransactionHandle transaction = new HiveTransactionHandle();
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        transactionManager.put(transaction, metadataFactory.create());
    }
    return transaction;
}
Also used : ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) ThreadContextClassLoader(com.facebook.presto.spi.classloader.ThreadContextClassLoader)

Example 3 with ThreadContextClassLoader

use of com.facebook.presto.spi.classloader.ThreadContextClassLoader in project presto by prestodb.

the class HiveConnector method rollback.

@Override
public void rollback(ConnectorTransactionHandle transaction) {
    HiveMetadata metadata = (HiveMetadata) transactionManager.remove(transaction);
    checkArgument(metadata != null, "no such transaction: %s", transaction);
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        metadata.rollback();
    }
}
Also used : ThreadContextClassLoader(com.facebook.presto.spi.classloader.ThreadContextClassLoader)

Example 4 with ThreadContextClassLoader

use of com.facebook.presto.spi.classloader.ThreadContextClassLoader in project presto by prestodb.

the class HiveConnectorFactory method create.

@Override
public Connector create(String connectorId, Map<String, String> config, ConnectorContext context) {
    requireNonNull(config, "config is null");
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        Bootstrap app = new Bootstrap(new MBeanModule(), new JsonModule(), new HiveClientModule(connectorId, context.getTypeManager(), context.getPageIndexerFactory(), context.getNodeManager()), new HiveMetastoreModule(connectorId, Optional.ofNullable(metastore)), new HiveSecurityModule(), new HiveAuthenticationModule(), binder -> {
            MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
            binder.bind(MBeanServer.class).toInstance(new RebindSafeMBeanServer(platformMBeanServer));
            binder.bind(NodeVersion.class).toInstance(new NodeVersion(context.getNodeManager().getCurrentNode().getVersion()));
        });
        Injector injector = app.strictConfig().doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        LifeCycleManager lifeCycleManager = injector.getInstance(LifeCycleManager.class);
        HiveMetadataFactory metadataFactory = injector.getInstance(HiveMetadataFactory.class);
        HiveTransactionManager transactionManager = injector.getInstance(HiveTransactionManager.class);
        ConnectorSplitManager splitManager = injector.getInstance(ConnectorSplitManager.class);
        ConnectorPageSourceProvider connectorPageSource = injector.getInstance(ConnectorPageSourceProvider.class);
        ConnectorPageSinkProvider pageSinkProvider = injector.getInstance(ConnectorPageSinkProvider.class);
        ConnectorNodePartitioningProvider connectorDistributionProvider = injector.getInstance(ConnectorNodePartitioningProvider.class);
        HiveSessionProperties hiveSessionProperties = injector.getInstance(HiveSessionProperties.class);
        HiveTableProperties hiveTableProperties = injector.getInstance(HiveTableProperties.class);
        ConnectorAccessControl accessControl = injector.getInstance(ConnectorAccessControl.class);
        return new HiveConnector(lifeCycleManager, metadataFactory, transactionManager, new ClassLoaderSafeConnectorSplitManager(splitManager, classLoader), new ClassLoaderSafeConnectorPageSourceProvider(connectorPageSource, classLoader), new ClassLoaderSafeConnectorPageSinkProvider(pageSinkProvider, classLoader), new ClassLoaderSafeNodePartitioningProvider(connectorDistributionProvider, classLoader), ImmutableSet.of(), hiveSessionProperties.getSessionProperties(), HiveSchemaProperties.SCHEMA_PROPERTIES, hiveTableProperties.getTableProperties(), accessControl, classLoader);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : MBeanModule(org.weakref.jmx.guice.MBeanModule) ClassLoaderSafeConnectorPageSourceProvider(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorPageSourceProvider) Injector(com.google.inject.Injector) HiveSecurityModule(com.facebook.presto.hive.security.HiveSecurityModule) Bootstrap(io.airlift.bootstrap.Bootstrap) HiveMetastoreModule(com.facebook.presto.hive.metastore.HiveMetastoreModule) ThreadContextClassLoader(com.facebook.presto.spi.classloader.ThreadContextClassLoader) ClassLoaderSafeNodePartitioningProvider(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeNodePartitioningProvider) MBeanServer(javax.management.MBeanServer) ConnectorAccessControl(com.facebook.presto.spi.connector.ConnectorAccessControl) HiveAuthenticationModule(com.facebook.presto.hive.authentication.HiveAuthenticationModule) ClassLoaderSafeConnectorPageSinkProvider(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorPageSinkProvider) JsonModule(io.airlift.json.JsonModule) LifeCycleManager(io.airlift.bootstrap.LifeCycleManager) ConnectorPageSinkProvider(com.facebook.presto.spi.connector.ConnectorPageSinkProvider) ClassLoaderSafeConnectorPageSinkProvider(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorPageSinkProvider) ClassLoaderSafeConnectorSplitManager(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorSplitManager) ConnectorSplitManager(com.facebook.presto.spi.connector.ConnectorSplitManager) ConnectorPageSourceProvider(com.facebook.presto.spi.connector.ConnectorPageSourceProvider) ClassLoaderSafeConnectorPageSourceProvider(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorPageSourceProvider) ConnectorNodePartitioningProvider(com.facebook.presto.spi.connector.ConnectorNodePartitioningProvider) ClassLoaderSafeConnectorSplitManager(com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorSplitManager)

Example 5 with ThreadContextClassLoader

use of com.facebook.presto.spi.classloader.ThreadContextClassLoader in project presto by prestodb.

the class JdbcConnectorFactory method create.

@Override
public Connector create(String connectorId, Map<String, String> requiredConfig, ConnectorContext context) {
    requireNonNull(requiredConfig, "requiredConfig is null");
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        Bootstrap app = new Bootstrap(new JdbcModule(connectorId), module);
        Injector injector = app.strictConfig().doNotInitializeLogging().setRequiredConfigurationProperties(requiredConfig).initialize();
        return injector.getInstance(JdbcConnector.class);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : Injector(com.google.inject.Injector) Bootstrap(io.airlift.bootstrap.Bootstrap) ThreadContextClassLoader(com.facebook.presto.spi.classloader.ThreadContextClassLoader)

Aggregations

ThreadContextClassLoader (com.facebook.presto.spi.classloader.ThreadContextClassLoader)15 Injector (com.google.inject.Injector)7 Bootstrap (io.airlift.bootstrap.Bootstrap)7 JsonModule (io.airlift.json.JsonModule)6 Connector (com.facebook.presto.spi.connector.Connector)2 ClassLoaderSafeConnectorPageSourceProvider (com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorPageSourceProvider)2 ClassLoaderSafeConnectorSplitManager (com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorSplitManager)2 LifeCycleManager (io.airlift.bootstrap.LifeCycleManager)2 IOException (java.io.IOException)2 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)1 SECURITY_FILE (com.facebook.presto.atop.AtopConnectorConfig.SECURITY_FILE)1 SECURITY_NONE (com.facebook.presto.atop.AtopConnectorConfig.SECURITY_NONE)1 InformationSchemaConnector (com.facebook.presto.connector.informationSchema.InformationSchemaConnector)1 SystemConnector (com.facebook.presto.connector.system.SystemConnector)1 HiveAuthenticationModule (com.facebook.presto.hive.authentication.HiveAuthenticationModule)1 HiveMetastoreModule (com.facebook.presto.hive.metastore.HiveMetastoreModule)1 HiveSecurityModule (com.facebook.presto.hive.security.HiveSecurityModule)1 OrcDataSource (com.facebook.presto.orc.OrcDataSource)1 OrcRecordReader (com.facebook.presto.orc.OrcRecordReader)1 AllowAllAccessControlModule (com.facebook.presto.plugin.base.security.AllowAllAccessControlModule)1