Search in sources :

Example 56 with Bootstrap

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

the class PinotConnectorFactory method create.

@Override
public Connector create(final String connectorId, Map<String, String> config, ConnectorContext context) {
    requireNonNull(connectorId, "connectorId is null");
    requireNonNull(config, "config is null");
    try {
        Bootstrap app = new Bootstrap(new JsonModule(), new MBeanModule(), new PinotModule(connectorId), binder -> {
            binder.bind(MBeanServer.class).toInstance(new RebindSafeMBeanServer(getPlatformMBeanServer()));
            binder.bind(ConnectorId.class).toInstance(new ConnectorId(connectorId));
            binder.bind(TypeManager.class).toInstance(context.getTypeManager());
            binder.bind(FunctionMetadataManager.class).toInstance(context.getFunctionMetadataManager());
            binder.bind(NodeManager.class).toInstance(context.getNodeManager());
            binder.bind(RowExpressionService.class).toInstance(context.getRowExpressionService());
            binder.bind(LogicalRowExpressions.class).toInstance(new LogicalRowExpressions(context.getRowExpressionService().getDeterminismEvaluator(), context.getStandardFunctionResolution(), context.getFunctionMetadataManager()));
            binder.bind(StandardFunctionResolution.class).toInstance(context.getStandardFunctionResolution());
            binder.bind(PinotMetrics.class).in(Scopes.SINGLETON);
            newExporter(binder).export(PinotMetrics.class).as(generatedNameOf(PinotMetrics.class, connectorId));
            binder.bind(ConnectorNodePartitioningProvider.class).to(PinotNodePartitioningProvider.class).in(Scopes.SINGLETON);
        });
        Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        return injector.getInstance(PinotConnector.class);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : MBeanModule(org.weakref.jmx.guice.MBeanModule) LogicalRowExpressions(com.facebook.presto.expressions.LogicalRowExpressions) JsonModule(com.facebook.airlift.json.JsonModule) FunctionMetadataManager(com.facebook.presto.spi.function.FunctionMetadataManager) NodeManager(com.facebook.presto.spi.NodeManager) RowExpressionService(com.facebook.presto.spi.relation.RowExpressionService) Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) TypeManager(com.facebook.presto.common.type.TypeManager) StandardFunctionResolution(com.facebook.presto.spi.function.StandardFunctionResolution) ManagementFactory.getPlatformMBeanServer(java.lang.management.ManagementFactory.getPlatformMBeanServer) MBeanServer(javax.management.MBeanServer) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 57 with Bootstrap

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

the class H2FunctionNamespaceManagerFactory method create.

@Override
public FunctionNamespaceManager<?> create(String catalogName, Map<String, String> config, FunctionNamespaceManagerContext context) {
    try {
        Bootstrap app = new Bootstrap(new DriftNettyClientModule(), new MySqlFunctionNamespaceManagerModule(catalogName), new H2ConnectionModule(), new SimpleAddressSqlFunctionExecutorsModule());
        Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        return injector.getInstance(MySqlFunctionNamespaceManager.class);
    } catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
Also used : MySqlFunctionNamespaceManagerModule(com.facebook.presto.functionNamespace.mysql.MySqlFunctionNamespaceManagerModule) SimpleAddressSqlFunctionExecutorsModule(com.facebook.presto.functionNamespace.execution.SimpleAddressSqlFunctionExecutorsModule) DriftNettyClientModule(com.facebook.drift.transport.netty.client.DriftNettyClientModule) Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap)

Example 58 with Bootstrap

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

the class AbstractVerifyCommand method run.

@Override
public void run() {
    if (configFilename != null) {
        System.setProperty("config", configFilename);
    }
    Bootstrap app = new Bootstrap(ImmutableList.<Module>builder().add(new VerifierModule(getSqlParserOptions(), getCustomQueryFilterClasses())).add(new SourceQueryModule(getCustomSourceQuerySupplierTypes())).add(new EventClientModule(getCustomEventClientTypes())).add(new QueryActionsModule(getSqlExceptionClassifier(), getCustomQueryActionTypes())).addAll(getAdditionalModules()).build());
    Injector injector = null;
    try {
        injector = app.initialize();
    } catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    } finally {
        if (injector != null) {
            try {
                injector.getInstance(LifeCycleManager.class).stop();
            } catch (Exception e) {
                log.error(e);
            }
        }
    }
}
Also used : QueryActionsModule(com.facebook.presto.verifier.prestoaction.QueryActionsModule) LifeCycleManager(com.facebook.airlift.bootstrap.LifeCycleManager) Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) SourceQueryModule(com.facebook.presto.verifier.source.SourceQueryModule) EventClientModule(com.facebook.presto.verifier.event.EventClientModule)

Example 59 with Bootstrap

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

the class TestPrestoQuerySourceQuerySupplier method setup.

@BeforeClass
public void setup() throws Exception {
    queryRunner = setupPresto();
    String host = queryRunner.getServer().getAddress().getHost();
    int port = queryRunner.getServer().getAddress().getPort();
    Bootstrap app = new Bootstrap(ImmutableList.<Module>builder().add(new SourceQueryModule(ImmutableSet.of())).add(new QueryActionsModule(PrestoExceptionClassifier.defaultBuilder().build(), ImmutableSet.of())).add(binder -> {
        configBinder(binder).bindConfig(VerifierConfig.class);
        binder.bind(SqlParserOptions.class).toInstance(new SqlParserOptions());
        binder.bind(SqlParser.class).in(SINGLETON);
    }).build());
    injector = app.setRequiredConfigurationProperties(ImmutableMap.<String, String>builder().put("test-id", "10000").put("control.hosts", format("%s,%s", host, host)).put("control.jdbc-port", String.valueOf(port)).put("source-query.supplier", "presto-query").put("source-query.query", SOURCE_FETCHING_QUERY).put("source-query.catalog", CATALOG).put("source-query.schema", SCHEMA).put("source-query.username", "test_user").build()).initialize();
}
Also used : SqlParserOptions(com.facebook.presto.sql.parser.SqlParserOptions) QueryActionsModule(com.facebook.presto.verifier.prestoaction.QueryActionsModule) SqlParser(com.facebook.presto.sql.parser.SqlParser) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) BeforeClass(org.testng.annotations.BeforeClass)

Example 60 with Bootstrap

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

the class TestSourceQueryModule method testMySqlSourceQuerySupplier.

@Test
public void testMySqlSourceQuerySupplier() throws Exception {
    Bootstrap app = new Bootstrap(ImmutableList.<Module>builder().add(new SourceQueryModule(ImmutableSet.of())).build());
    Injector injector = app.setRequiredConfigurationProperties(ImmutableMap.<String, String>builder().putAll(DEFAULT_CONFIGURATION_PROPERTIES).put("source-query.database", "jdbc://localhost:1080").put("source-query.suites", "test").put("source-query.max-queries-per-suite", "1000").build()).initialize();
    assertTrue(injector.getInstance(SourceQuerySupplier.class) instanceof MySqlSourceQuerySupplier);
}
Also used : Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) Test(org.testng.annotations.Test)

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