Search in sources :

Example 1 with SessionPropertyConfigurationManager

use of io.trino.spi.session.SessionPropertyConfigurationManager in project trino by trinodb.

the class SessionPropertyDefaults method newSessionWithDefaultProperties.

public Session newSessionWithDefaultProperties(Session session, Optional<String> queryType, ResourceGroupId resourceGroupId) {
    SessionPropertyConfigurationManager configurationManager = delegate.get();
    if (configurationManager == null) {
        return session;
    }
    SessionConfigurationContext context = new SessionConfigurationContext(session.getIdentity().getUser(), session.getSource(), session.getClientTags(), queryType, resourceGroupId);
    Map<String, String> systemPropertyOverrides = configurationManager.getSystemSessionProperties(context);
    Map<String, Map<String, String>> catalogPropertyOverrides = configurationManager.getCatalogSessionProperties(context);
    return session.withDefaultProperties(systemPropertyOverrides, catalogPropertyOverrides, accessControl);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) SessionPropertyConfigurationManager(io.trino.spi.session.SessionPropertyConfigurationManager) SessionConfigurationContext(io.trino.spi.session.SessionConfigurationContext)

Example 2 with SessionPropertyConfigurationManager

use of io.trino.spi.session.SessionPropertyConfigurationManager 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)

Example 3 with SessionPropertyConfigurationManager

use of io.trino.spi.session.SessionPropertyConfigurationManager in project trino by trinodb.

the class TestFileSessionPropertyManager method assertProperties.

@Override
protected void assertProperties(Map<String, String> systemProperties, Map<String, Map<String, String>> catalogProperties, SessionMatchSpec... specs) throws IOException {
    try (TempFile tempFile = new TempFile()) {
        Path configurationFile = tempFile.path();
        Files.write(configurationFile, CODEC.toJsonBytes(Arrays.asList(specs)));
        SessionPropertyConfigurationManager manager = new FileSessionPropertyManager(new FileSessionPropertyManagerConfig().setConfigFile(configurationFile.toFile()));
        assertEquals(manager.getSystemSessionProperties(CONTEXT), systemProperties);
        assertEquals(manager.getCatalogSessionProperties(CONTEXT), catalogProperties);
    }
}
Also used : Path(java.nio.file.Path) TempFile(io.airlift.testing.TempFile) SessionPropertyConfigurationManager(io.trino.spi.session.SessionPropertyConfigurationManager)

Aggregations

SessionPropertyConfigurationManager (io.trino.spi.session.SessionPropertyConfigurationManager)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 TempFile (io.airlift.testing.TempFile)1 ThreadContextClassLoader (io.trino.spi.classloader.ThreadContextClassLoader)1 SessionConfigurationContext (io.trino.spi.session.SessionConfigurationContext)1 SessionPropertyConfigurationManagerFactory (io.trino.spi.session.SessionPropertyConfigurationManagerFactory)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1