Search in sources :

Example 31 with Bootstrap

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

the class HiveFunctionNamespaceManagerFactory method create.

@Override
public FunctionNamespaceManager<?> create(String catalogName, Map<String, String> config, FunctionNamespaceManagerContext context) {
    requireNonNull(config, "config is null");
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        Bootstrap app = new Bootstrap(new HiveFunctionModule(catalogName, classLoader, context.getTypeManager()));
        Injector injector = app.noStrictConfig().doNotInitializeLogging().setRequiredConfigurationProperties(config).quiet().initialize();
        return injector.getInstance(FunctionNamespaceManager.class);
    }
}
Also used : Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) ThreadContextClassLoader(com.facebook.presto.spi.classloader.ThreadContextClassLoader)

Example 32 with Bootstrap

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

the class TestHiveSplit method getJsonCodec.

private JsonCodec<HiveSplit> getJsonCodec() throws Exception {
    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(HiveSplit.class);
    };
    Bootstrap app = new Bootstrap(ImmutableList.of(module));
    Injector injector = app.doNotInitializeLogging().quiet().initialize();
    HandleResolver handleResolver = injector.getInstance(HandleResolver.class);
    handleResolver.addConnectorName("hive", new HiveHandleResolver());
    return injector.getInstance(new Key<JsonCodec<HiveSplit>>() {
    });
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) Module(com.google.inject.Module) JsonCodec(com.facebook.airlift.json.JsonCodec) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) NO_PREFERENCE(com.facebook.presto.spi.schedule.NodeSelectionStrategy.NO_PREFERENCE) Column(com.facebook.presto.hive.metastore.Column) REGULAR(com.facebook.presto.hive.HiveColumnHandle.ColumnType.REGULAR) Key(com.google.inject.Key) BlockEncoding(com.facebook.presto.common.block.BlockEncoding) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) NO_CACHE_REQUIREMENT(com.facebook.presto.hive.CacheQuotaRequirement.NO_CACHE_REQUIREMENT) OptionalInt(java.util.OptionalInt) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) JsonCodecBinder.jsonCodecBinder(com.facebook.airlift.json.JsonCodecBinder.jsonCodecBinder) BlockJsonSerde(com.facebook.presto.block.BlockJsonSerde) BlockEncodingSerde(com.facebook.presto.common.block.BlockEncodingSerde) ImmutableList(com.google.common.collect.ImmutableList) BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) TypeManager(com.facebook.presto.common.type.TypeManager) Map(java.util.Map) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) Multibinder.newSetBinder(com.google.inject.multibindings.Multibinder.newSetBinder) HIVE_LONG(com.facebook.presto.hive.HiveType.HIVE_LONG) Type(com.facebook.presto.common.type.Type) JsonModule(com.facebook.airlift.json.JsonModule) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) Storage(com.facebook.presto.hive.metastore.Storage) ImmutableSet(com.google.common.collect.ImmutableSet) StorageFormat(com.facebook.presto.hive.metastore.StorageFormat) ImmutableMap(com.google.common.collect.ImmutableMap) HostAddress(com.facebook.presto.spi.HostAddress) Set(java.util.Set) JsonBinder.jsonBinder(com.facebook.airlift.json.JsonBinder.jsonBinder) Instant(java.time.Instant) Scopes(com.google.inject.Scopes) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) Injector(com.google.inject.Injector) HIVE_STRING(com.facebook.presto.hive.HiveType.HIVE_STRING) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) ColumnHandle(com.facebook.presto.spi.ColumnHandle) Optional(java.util.Optional) ConfigBinder.configBinder(com.facebook.airlift.configuration.ConfigBinder.configBinder) Block(com.facebook.presto.common.block.Block) SplitWeight(com.facebook.presto.spi.SplitWeight) HandleResolver(com.facebook.presto.metadata.HandleResolver) 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)

Example 33 with Bootstrap

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

the class TestBenchmarkSuiteModule method testDbBenchmarkSuiteSupplier.

@Test
public void testDbBenchmarkSuiteSupplier() {
    Bootstrap app = new Bootstrap(ImmutableList.<Module>builder().add(new BenchmarkSuiteModule(ImmutableSet.of())).build());
    Injector injector = null;
    try {
        injector = app.setRequiredConfigurationProperties(ImmutableMap.<String, String>builder().putAll(DEFAULT_CONFIGURATION_PROPERTIES).put("benchmark-suite.database-url", "jdbc://localhost:1080").put("benchmark-suite.suite", "test").build()).initialize();
        assertTrue(injector.getInstance(BenchmarkSuiteSupplier.class) instanceof MySqlBenchmarkSuiteSupplier);
    } finally {
        if (injector != null) {
            injector.getInstance(LifeCycleManager.class).stop();
        }
    }
}
Also used : LifeCycleManager(com.facebook.airlift.bootstrap.LifeCycleManager) Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) Test(org.testng.annotations.Test)

Example 34 with Bootstrap

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

the class TestBenchmarkSuiteModule method testInvalidBenchmarkSuiteSupplier.

@Test(expectedExceptions = CreationException.class, expectedExceptionsMessageRegExp = "Unable to create injector.*")
public void testInvalidBenchmarkSuiteSupplier() {
    Bootstrap app = new Bootstrap(ImmutableList.<Module>builder().add(new BenchmarkSuiteModule(ImmutableSet.of("test-supplier"))).build());
    Injector injector = null;
    try {
        injector = app.setRequiredConfigurationProperties(ImmutableMap.<String, String>builder().putAll(DEFAULT_CONFIGURATION_PROPERTIES).put("benchmark-query-supplier", "unknown-supplier").build()).initialize();
    } finally {
        if (injector != null) {
            injector.getInstance(LifeCycleManager.class).stop();
        }
    }
}
Also used : LifeCycleManager(com.facebook.airlift.bootstrap.LifeCycleManager) Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) Test(org.testng.annotations.Test)

Example 35 with Bootstrap

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

the class TestingElasticsearchConnectorFactory method create.

@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context) {
    requireNonNull(catalogName, "catalogName is null");
    requireNonNull(config, "config is null");
    try {
        Bootstrap app = new Bootstrap(new JsonModule(), new ElasticsearchConnectorModule(), binder -> {
            binder.bind(TypeManager.class).toInstance(context.getTypeManager());
            binder.bind(NodeManager.class).toInstance(context.getNodeManager());
        });
        Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        return injector.getInstance(ElasticsearchConnector.class);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : NodeManager(com.facebook.presto.spi.NodeManager) Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) TypeManager(com.facebook.presto.common.type.TypeManager) JsonModule(com.facebook.airlift.json.JsonModule)

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