Search in sources :

Example 6 with Bootstrap

use of com.facebook.airlift.bootstrap.Bootstrap in project presto by prestodb.

the class RaptorConnectorFactory method create.

@Override
public Connector create(String catalogName, 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 FileSystemModule(fileSystemProviders), new BackupModule(backupProviders), new StorageModule(catalogName), new RaptorModule(catalogName), new RaptorSecurityModule(), new RaptorProcedureModule());
        Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        return injector.getInstance(RaptorConnector.class);
    } catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
Also used : MBeanModule(org.weakref.jmx.guice.MBeanModule) StorageModule(com.facebook.presto.raptor.storage.StorageModule) BackupModule(com.facebook.presto.raptor.backup.BackupModule) RaptorSecurityModule(com.facebook.presto.raptor.security.RaptorSecurityModule) JsonModule(com.facebook.airlift.json.JsonModule) NodeManager(com.facebook.presto.spi.NodeManager) FileSystemModule(com.facebook.presto.raptor.filesystem.FileSystemModule) RebindSafeMBeanServer(com.facebook.presto.raptor.util.RebindSafeMBeanServer) Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) PageSorter(com.facebook.presto.spi.PageSorter) TypeManager(com.facebook.presto.common.type.TypeManager) ManagementFactory.getPlatformMBeanServer(java.lang.management.ManagementFactory.getPlatformMBeanServer) MBeanServer(javax.management.MBeanServer) RebindSafeMBeanServer(com.facebook.presto.raptor.util.RebindSafeMBeanServer)

Example 7 with Bootstrap

use of com.facebook.airlift.bootstrap.Bootstrap in project presto by prestodb.

the class PrestoSparkInjectorFactory method create.

public Injector create() {
    // TODO: migrate docker containers to a newer JVM, then re-enable it
    // verifyJvmRequirements();
    verifySystemTimeIsReasonable();
    ImmutableList.Builder<Module> modules = ImmutableList.builder();
    modules.add(new JsonModule(), new SmileModule(), new EventListenerModule(), new PrestoSparkModule(sparkProcessType, sqlParserOptions), new WarningCollectorModule());
    if (isForTesting) {
        modules.add(binder -> {
            binder.bind(TestingAccessControlManager.class).in(Scopes.SINGLETON);
            binder.bind(AccessControlManager.class).to(TestingAccessControlManager.class).in(Scopes.SINGLETON);
            binder.bind(AccessControl.class).to(AccessControlManager.class).in(Scopes.SINGLETON);
            binder.bind(TestingTempStorageManager.class).in(Scopes.SINGLETON);
            binder.bind(TempStorageManager.class).to(TestingTempStorageManager.class).in(Scopes.SINGLETON);
            newSetBinder(binder, PrestoSparkServiceWaitTimeMetrics.class).addBinding().to(PrestoSparkTestingServiceWaitTimeMetrics.class).in(Scopes.SINGLETON);
        });
    } else {
        modules.add(new AccessControlModule());
        modules.add(new TempStorageModule());
    }
    modules.addAll(additionalModules);
    Bootstrap app = new Bootstrap(modules.build());
    // Stream redirect doesn't work well with spark logging
    app.doNotInitializeLogging();
    Map<String, String> requiredProperties = new HashMap<>();
    requiredProperties.put("node.environment", "spark");
    requiredProperties.putAll(configProperties);
    app.setRequiredConfigurationProperties(ImmutableMap.copyOf(requiredProperties));
    Injector injector = app.initialize();
    try {
        injector.getInstance(PluginManager.class).loadPlugins();
        injector.getInstance(StaticCatalogStore.class).loadCatalogs(catalogProperties);
        injector.getInstance(ResourceGroupManager.class).loadConfigurationManager();
        injector.getInstance(PasswordAuthenticatorManager.class).loadPasswordAuthenticator();
        eventListenerProperties.ifPresent(properties -> injector.getInstance(EventListenerManager.class).loadConfiguredEventListener(properties));
        if (!isForTesting) {
            if (accessControlProperties.isPresent()) {
                injector.getInstance(AccessControlManager.class).loadSystemAccessControl(accessControlProperties.get());
            } else {
                injector.getInstance(AccessControlManager.class).loadSystemAccessControl();
            }
            if (tempStorageProperties.isPresent()) {
                injector.getInstance(TempStorageManager.class).loadTempStorages(tempStorageProperties.get());
            } else {
                injector.getInstance(TempStorageManager.class).loadTempStorages();
            }
        }
        if ((sparkProcessType.equals(DRIVER))) {
            if (sessionPropertyConfigurationProperties.isPresent()) {
                injector.getInstance(SessionPropertyDefaults.class).loadConfigurationManager(sessionPropertyConfigurationProperties.get());
            } else {
                injector.getInstance(SessionPropertyDefaults.class).loadConfigurationManager();
            }
        }
        if (sparkProcessType.equals(DRIVER) || !injector.getInstance(FeaturesConfig.class).isInlineSqlFunctions()) {
            if (functionNamespaceProperties.isPresent()) {
                injector.getInstance(StaticFunctionNamespaceStore.class).loadFunctionNamespaceManagers(functionNamespaceProperties.get());
            } else {
                injector.getInstance(StaticFunctionNamespaceStore.class).loadFunctionNamespaceManagers();
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return injector;
}
Also used : AccessControlManager(com.facebook.presto.security.AccessControlManager) TestingAccessControlManager(com.facebook.presto.testing.TestingAccessControlManager) WarningCollectorModule(com.facebook.presto.execution.warnings.WarningCollectorModule) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) PasswordAuthenticatorManager(com.facebook.presto.server.security.PasswordAuthenticatorManager) PluginManager(com.facebook.presto.server.PluginManager) TempStorageModule(com.facebook.presto.storage.TempStorageModule) TempStorageManager(com.facebook.presto.storage.TempStorageManager) TestingTempStorageManager(com.facebook.presto.testing.TestingTempStorageManager) Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) EventListenerModule(com.facebook.presto.eventlistener.EventListenerModule) AccessControlModule(com.facebook.presto.security.AccessControlModule) StaticCatalogStore(com.facebook.presto.metadata.StaticCatalogStore) SessionPropertyDefaults(com.facebook.presto.server.SessionPropertyDefaults) StaticFunctionNamespaceStore(com.facebook.presto.metadata.StaticFunctionNamespaceStore) ResourceGroupManager(com.facebook.presto.execution.resourceGroups.ResourceGroupManager) JsonModule(com.facebook.airlift.json.JsonModule) TestingAccessControlManager(com.facebook.presto.testing.TestingAccessControlManager) TestingTempStorageManager(com.facebook.presto.testing.TestingTempStorageManager) SmileModule(com.facebook.airlift.json.smile.SmileModule) Module(com.google.inject.Module) WarningCollectorModule(com.facebook.presto.execution.warnings.WarningCollectorModule) AccessControlModule(com.facebook.presto.security.AccessControlModule) JsonModule(com.facebook.airlift.json.JsonModule) EventListenerModule(com.facebook.presto.eventlistener.EventListenerModule) SmileModule(com.facebook.airlift.json.smile.SmileModule) TempStorageModule(com.facebook.presto.storage.TempStorageModule)

Example 8 with Bootstrap

use of com.facebook.airlift.bootstrap.Bootstrap in project presto by prestodb.

the class JdbcConnectorFactory method create.

@Override
public Connector create(String catalogName, Map<String, String> requiredConfig, ConnectorContext context) {
    requireNonNull(requiredConfig, "requiredConfig is null");
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        Bootstrap app = new Bootstrap(binder -> {
            binder.bind(FunctionMetadataManager.class).toInstance(context.getFunctionMetadataManager());
            binder.bind(StandardFunctionResolution.class).toInstance(context.getStandardFunctionResolution());
            binder.bind(RowExpressionService.class).toInstance(context.getRowExpressionService());
        }, new JdbcModule(catalogName), module);
        Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperties(requiredConfig).initialize();
        return injector.getInstance(JdbcConnector.class);
    } catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
Also used : RowExpressionService(com.facebook.presto.spi.relation.RowExpressionService) Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) StandardFunctionResolution(com.facebook.presto.spi.function.StandardFunctionResolution) ThreadContextClassLoader(com.facebook.presto.spi.classloader.ThreadContextClassLoader) FunctionMetadataManager(com.facebook.presto.spi.function.FunctionMetadataManager)

Example 9 with Bootstrap

use of com.facebook.airlift.bootstrap.Bootstrap in project presto by prestodb.

the class DeltaConnectorFactory method create.

@Override
public Connector create(String catalogName, Map<String, String> requiredConfig, ConnectorContext context) {
    requireNonNull(requiredConfig, "requiredConfig is null");
    try {
        Bootstrap app = new Bootstrap(new JsonModule(), new DeltaModule(catalogName, context.getTypeManager()), new HiveS3Module(catalogName), new HiveGcsModule(), new HiveAuthenticationModule(), new HiveMetastoreModule(catalogName, Optional.empty()), binder -> {
            binder.bind(RowExpressionService.class).toInstance(context.getRowExpressionService());
        });
        Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperties(requiredConfig).initialize();
        return injector.getInstance(DeltaConnector.class);
    } catch (Exception exception) {
        throwIfUnchecked(exception);
        throw new RuntimeException(exception);
    }
}
Also used : HiveS3Module(com.facebook.presto.hive.s3.HiveS3Module) HiveGcsModule(com.facebook.presto.hive.gcs.HiveGcsModule) RowExpressionService(com.facebook.presto.spi.relation.RowExpressionService) Injector(com.google.inject.Injector) HiveAuthenticationModule(com.facebook.presto.hive.authentication.HiveAuthenticationModule) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) HiveMetastoreModule(com.facebook.presto.hive.metastore.HiveMetastoreModule) JsonModule(com.facebook.airlift.json.JsonModule)

Example 10 with Bootstrap

use of com.facebook.airlift.bootstrap.Bootstrap in project presto by prestodb.

the class TestDeltaTableHandle method getJsonCodec.

private JsonCodec<DeltaTableHandle> getJsonCodec() {
    Module module = binder -> {
        binder.install(new JsonModule());
        binder.install(new HandleJsonModule());
        configBinder(binder).bindConfig(FeaturesConfig.class);
        FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
        binder.bind(TypeManager.class).toInstance(functionAndTypeManager);
        jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class);
        newSetBinder(binder, Type.class);
        binder.bind(BlockEncodingSerde.class).to(BlockEncodingManager.class).in(Scopes.SINGLETON);
        newSetBinder(binder, BlockEncoding.class);
        jsonBinder(binder).addSerializerBinding(Block.class).to(BlockJsonSerde.Serializer.class);
        jsonBinder(binder).addDeserializerBinding(Block.class).to(BlockJsonSerde.Deserializer.class);
        jsonCodecBinder(binder).bindJsonCodec(DeltaTableHandle.class);
        jsonCodecBinder(binder).bindJsonCodec(DeltaTable.class);
        jsonCodecBinder(binder).bindJsonCodec(DeltaColumnHandle.class);
    };
    Bootstrap app = new Bootstrap(ImmutableList.of(module));
    Injector injector = app.doNotInitializeLogging().quiet().initialize();
    HandleResolver handleResolver = injector.getInstance(HandleResolver.class);
    handleResolver.addConnectorName("delta", new DeltaConnectionHandleResolver());
    return injector.getInstance(new Key<JsonCodec<DeltaTableHandle>>() {
    });
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) Module(com.google.inject.Module) JsonCodec(com.facebook.airlift.json.JsonCodec) PARTITION(com.facebook.presto.delta.DeltaColumnHandle.ColumnType.PARTITION) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) StandardTypes(com.facebook.presto.common.type.StandardTypes) Key(com.google.inject.Key) BlockEncoding(com.facebook.presto.common.block.BlockEncoding) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) SortedRangeSet(com.facebook.presto.common.predicate.SortedRangeSet) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) JsonCodecBinder.jsonCodecBinder(com.facebook.airlift.json.JsonCodecBinder.jsonCodecBinder) REAL(com.facebook.presto.common.type.RealType.REAL) BlockJsonSerde(com.facebook.presto.block.BlockJsonSerde) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) Float.floatToRawIntBits(java.lang.Float.floatToRawIntBits) ImmutableList(com.google.common.collect.ImmutableList) BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) TypeManager(com.facebook.presto.common.type.TypeManager) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) Multibinder.newSetBinder(com.google.inject.multibindings.Multibinder.newSetBinder) Type(com.facebook.presto.common.type.Type) JsonModule(com.facebook.airlift.json.JsonModule) ImmutableMap(com.google.common.collect.ImmutableMap) JsonBinder.jsonBinder(com.facebook.airlift.json.JsonBinder.jsonBinder) DATE(com.facebook.presto.common.type.StandardTypes.DATE) Scopes(com.google.inject.Scopes) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) INTEGER(com.facebook.presto.common.type.StandardTypes.INTEGER) Range(com.facebook.presto.common.predicate.Range) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) Injector(com.google.inject.Injector) DOUBLE(com.facebook.presto.common.type.StandardTypes.DOUBLE) List(java.util.List) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) TypeSignature.parseTypeSignature(com.facebook.presto.common.type.TypeSignature.parseTypeSignature) Optional(java.util.Optional) ConfigBinder.configBinder(com.facebook.airlift.configuration.ConfigBinder.configBinder) Block(com.facebook.presto.common.block.Block) HandleResolver(com.facebook.presto.metadata.HandleResolver) REGULAR(com.facebook.presto.delta.DeltaColumnHandle.ColumnType.REGULAR) HandleResolver(com.facebook.presto.metadata.HandleResolver) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) JsonModule(com.facebook.airlift.json.JsonModule) Type(com.facebook.presto.common.type.Type) JsonCodec(com.facebook.airlift.json.JsonCodec) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) Module(com.google.inject.Module) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) JsonModule(com.facebook.airlift.json.JsonModule) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) BlockEncoding(com.facebook.presto.common.block.BlockEncoding)

Aggregations

Bootstrap (com.facebook.airlift.bootstrap.Bootstrap)61 Injector (com.google.inject.Injector)54 JsonModule (com.facebook.airlift.json.JsonModule)36 TypeManager (com.facebook.presto.common.type.TypeManager)16 Module (com.google.inject.Module)12 Test (org.testng.annotations.Test)12 LifeCycleManager (com.facebook.airlift.bootstrap.LifeCycleManager)11 NodeManager (com.facebook.presto.spi.NodeManager)10 JsonBinder.jsonBinder (com.facebook.airlift.json.JsonBinder.jsonBinder)7 FeaturesConfig (com.facebook.presto.sql.analyzer.FeaturesConfig)7 ImmutableList (com.google.common.collect.ImmutableList)7 MBeanModule (org.weakref.jmx.guice.MBeanModule)7 ConfigBinder.configBinder (com.facebook.airlift.configuration.ConfigBinder.configBinder)6 JsonCodecBinder.jsonCodecBinder (com.facebook.airlift.json.JsonCodecBinder.jsonCodecBinder)6 Type (com.facebook.presto.common.type.Type)6 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)6 FunctionAndTypeManager.createTestFunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager)6 HandleJsonModule (com.facebook.presto.metadata.HandleJsonModule)6 ThreadContextClassLoader (com.facebook.presto.spi.classloader.ThreadContextClassLoader)6 RowExpressionService (com.facebook.presto.spi.relation.RowExpressionService)6