Search in sources :

Example 1 with JsonModule

use of io.airlift.json.JsonModule 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 JsonModule

use of io.airlift.json.JsonModule 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 3 with JsonModule

use of io.airlift.json.JsonModule in project presto by prestodb.

the class ExampleConnectorFactory method create.

@Override
public Connector create(final String connectorId, Map<String, String> requiredConfig, ConnectorContext context) {
    requireNonNull(requiredConfig, "requiredConfig is null");
    try {
        // A plugin is not required to use Guice; it is just very convenient
        Bootstrap app = new Bootstrap(new JsonModule(), new ExampleModule(connectorId, context.getTypeManager()));
        Injector injector = app.strictConfig().doNotInitializeLogging().setRequiredConfigurationProperties(requiredConfig).initialize();
        return injector.getInstance(ExampleConnector.class);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : Injector(com.google.inject.Injector) Bootstrap(io.airlift.bootstrap.Bootstrap) JsonModule(io.airlift.json.JsonModule)

Example 4 with JsonModule

use of io.airlift.json.JsonModule in project presto by prestodb.

the class MemoryConnectorFactory method create.

@Override
public Connector create(String connectorId, Map<String, String> requiredConfig, ConnectorContext context) {
    requireNonNull(requiredConfig, "requiredConfig is null");
    try {
        // A plugin is not required to use Guice; it is just very convenient
        Bootstrap app = new Bootstrap(new JsonModule(), new MemoryModule(connectorId, context.getTypeManager(), context.getNodeManager()));
        Injector injector = app.strictConfig().doNotInitializeLogging().setRequiredConfigurationProperties(requiredConfig).initialize();
        return injector.getInstance(MemoryConnector.class);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : Injector(com.google.inject.Injector) Bootstrap(io.airlift.bootstrap.Bootstrap) JsonModule(io.airlift.json.JsonModule)

Example 5 with JsonModule

use of io.airlift.json.JsonModule in project presto by prestodb.

the class RaptorConnectorFactory method create.

@Override
public Connector create(String connectorId, Map<String, String> config, ConnectorContext context) {
    NodeManager nodeManager = context.getNodeManager();
    try {
        Bootstrap app = new Bootstrap(new JsonModule(), new MBeanModule(), binder -> {
            MBeanServer mbeanServer = new RebindSafeMBeanServer(getPlatformMBeanServer());
            binder.bind(MBeanServer.class).toInstance(mbeanServer);
            binder.bind(NodeManager.class).toInstance(nodeManager);
            binder.bind(PageSorter.class).toInstance(context.getPageSorter());
            binder.bind(TypeManager.class).toInstance(context.getTypeManager());
        }, metadataModule, new BackupModule(backupProviders), new StorageModule(connectorId), new RaptorModule(connectorId));
        Injector injector = app.strictConfig().doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        return injector.getInstance(RaptorConnector.class);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : MBeanModule(org.weakref.jmx.guice.MBeanModule) StorageModule(com.facebook.presto.raptor.storage.StorageModule) BackupModule(com.facebook.presto.raptor.backup.BackupModule) JsonModule(io.airlift.json.JsonModule) NodeManager(com.facebook.presto.spi.NodeManager) RebindSafeMBeanServer(com.facebook.presto.raptor.util.RebindSafeMBeanServer) Injector(com.google.inject.Injector) Bootstrap(io.airlift.bootstrap.Bootstrap) PageSorter(com.facebook.presto.spi.PageSorter) TypeManager(com.facebook.presto.spi.type.TypeManager) ManagementFactory.getPlatformMBeanServer(java.lang.management.ManagementFactory.getPlatformMBeanServer) RebindSafeMBeanServer(com.facebook.presto.raptor.util.RebindSafeMBeanServer) MBeanServer(javax.management.MBeanServer)

Aggregations

Injector (com.google.inject.Injector)19 JsonModule (io.airlift.json.JsonModule)19 Bootstrap (io.airlift.bootstrap.Bootstrap)17 ThreadContextClassLoader (com.facebook.presto.spi.classloader.ThreadContextClassLoader)6 MBeanModule (org.weakref.jmx.guice.MBeanModule)4 NodeManager (com.facebook.presto.spi.NodeManager)3 TypeManager (com.facebook.presto.spi.type.TypeManager)3 Module (com.google.inject.Module)3 LifeCycleManager (io.airlift.bootstrap.LifeCycleManager)3 JaxrsModule (io.airlift.jaxrs.JaxrsModule)3 Map (java.util.Map)3 MBeanServer (javax.management.MBeanServer)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 SchemaTableName (com.facebook.presto.spi.SchemaTableName)2 ClassLoaderSafeConnectorPageSourceProvider (com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorPageSourceProvider)2 ClassLoaderSafeConnectorSplitManager (com.facebook.presto.spi.connector.classloader.ClassLoaderSafeConnectorSplitManager)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Binder (com.google.inject.Binder)2 TypeLiteral (com.google.inject.TypeLiteral)2 TraceTokenModule (io.airlift.tracetoken.TraceTokenModule)2