Search in sources :

Example 16 with ThreadContextClassLoader

use of io.trino.spi.classloader.ThreadContextClassLoader in project trino by trinodb.

the class EventListenerManager method createEventListener.

private EventListener createEventListener(File configFile) {
    log.info("-- Loading event listener %s --", configFile);
    configFile = configFile.getAbsoluteFile();
    Map<String, String> properties = loadEventListenerProperties(configFile);
    String name = properties.remove(EVENT_LISTENER_NAME_PROPERTY);
    checkArgument(!isNullOrEmpty(name), "EventListener plugin configuration for %s does not contain %s", configFile, EVENT_LISTENER_NAME_PROPERTY);
    EventListenerFactory factory = eventListenerFactories.get(name);
    checkArgument(factory != null, "Event listener factory '%s' is not registered. Available factories: %s", name, eventListenerFactories.keySet());
    EventListener eventListener;
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(factory.getClass().getClassLoader())) {
        eventListener = factory.create(properties);
    }
    log.info("-- Loaded event listener %s --", configFile);
    return eventListener;
}
Also used : EventListenerFactory(io.trino.spi.eventlistener.EventListenerFactory) EventListener(io.trino.spi.eventlistener.EventListener) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader)

Example 17 with ThreadContextClassLoader

use of io.trino.spi.classloader.ThreadContextClassLoader in project trino by trinodb.

the class GroupProviderManager method setConfiguredGroupProvider.

private void setConfiguredGroupProvider(String name, Map<String, String> properties) {
    requireNonNull(name, "name is null");
    requireNonNull(properties, "properties is null");
    log.info("-- Loading group provider %s --", name);
    GroupProviderFactory factory = groupProviderFactories.get(name);
    checkState(factory != null, "Group provider %s is not registered", name);
    GroupProvider groupProvider;
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(factory.getClass().getClassLoader())) {
        groupProvider = factory.create(ImmutableMap.copyOf(properties));
    }
    checkState(configuredGroupProvider.compareAndSet(Optional.empty(), Optional.of(groupProvider)), "groupProvider is already set");
    log.info("-- Loaded group provider %s --", name);
}
Also used : GroupProvider(io.trino.spi.security.GroupProvider) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader) GroupProviderFactory(io.trino.spi.security.GroupProviderFactory)

Example 18 with ThreadContextClassLoader

use of io.trino.spi.classloader.ThreadContextClassLoader in project trino by trinodb.

the class IcebergTransactionManager method rollback.

public void rollback(ConnectorTransactionHandle transaction) {
    MemoizedMetadata transactionalMetadata = transactions.remove(transaction);
    checkArgument(transactionalMetadata != null, "no such transaction: %s", transaction);
    transactionalMetadata.optionalGet().ifPresent(metadata -> {
        try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
            metadata.rollback();
        }
    });
}
Also used : ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader)

Example 19 with ThreadContextClassLoader

use of io.trino.spi.classloader.ThreadContextClassLoader in project trino by trinodb.

the class HeaderAuthenticatorManager method loadAuthenticator.

private HeaderAuthenticator loadAuthenticator(File configFile) {
    Map<String, String> properties;
    try {
        properties = new HashMap<>(loadPropertiesFrom(configFile.getPath()));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    String name = properties.remove(NAME_PROPERTY);
    checkState(!isNullOrEmpty(name), "Header authenticator configuration %s does not contain '%s'", configFile, NAME_PROPERTY);
    log.info("-- Loading header authenticator --");
    HeaderAuthenticatorFactory factory = factories.get(name);
    checkState(factory != null, "Header authenticator '%s' is not registered", name);
    HeaderAuthenticator authenticator;
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(factory.getClass().getClassLoader())) {
        authenticator = factory.create(ImmutableMap.copyOf(properties));
    }
    log.info("-- Loaded header authenticator %s --", name);
    return authenticator;
}
Also used : HeaderAuthenticator(io.trino.spi.security.HeaderAuthenticator) HeaderAuthenticatorFactory(io.trino.spi.security.HeaderAuthenticatorFactory) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader)

Example 20 with ThreadContextClassLoader

use of io.trino.spi.classloader.ThreadContextClassLoader in project trino by trinodb.

the class SessionPropertyDefaults method setConfigurationManager.

@VisibleForTesting
public void setConfigurationManager(String name, Map<String, String> properties) {
    log.info("-- Loading session property configuration manager --");
    SessionPropertyConfigurationManagerFactory factory = factories.get(name);
    checkState(factory != null, "Session property configuration manager '%s' is not registered", name);
    SessionPropertyConfigurationManager manager;
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(factory.getClass().getClassLoader())) {
        manager = factory.create(properties, configurationManagerContext);
    }
    checkState(delegate.compareAndSet(null, manager), "sessionPropertyConfigurationManager is already set");
    log.info("-- Loaded session property configuration manager %s --", name);
}
Also used : SessionPropertyConfigurationManagerFactory(io.trino.spi.session.SessionPropertyConfigurationManagerFactory) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader) SessionPropertyConfigurationManager(io.trino.spi.session.SessionPropertyConfigurationManager) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ThreadContextClassLoader (io.trino.spi.classloader.ThreadContextClassLoader)23 Injector (com.google.inject.Injector)7 Bootstrap (io.airlift.bootstrap.Bootstrap)7 JsonModule (io.airlift.json.JsonModule)7 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 CatalogName (io.trino.plugin.base.CatalogName)4 Connector (io.trino.spi.connector.Connector)4 ConnectorContext (io.trino.spi.connector.ConnectorContext)4 TypeManager (io.trino.spi.type.TypeManager)4 Map (java.util.Map)4 Key (com.google.inject.Key)3 Module (com.google.inject.Module)3 TypeLiteral (com.google.inject.TypeLiteral)3 LifeCycleManager (io.airlift.bootstrap.LifeCycleManager)3 EventModule (io.airlift.event.client.EventModule)3 CatalogNameModule (io.trino.plugin.base.CatalogNameModule)3 ClassLoaderSafeConnectorPageSinkProvider (io.trino.plugin.base.classloader.ClassLoaderSafeConnectorPageSinkProvider)3 ClassLoaderSafeConnectorPageSourceProvider (io.trino.plugin.base.classloader.ClassLoaderSafeConnectorPageSourceProvider)3 ClassLoaderSafeConnectorSplitManager (io.trino.plugin.base.classloader.ClassLoaderSafeConnectorSplitManager)3 ClassLoaderSafeNodePartitioningProvider (io.trino.plugin.base.classloader.ClassLoaderSafeNodePartitioningProvider)3