Search in sources :

Example 11 with Bootstrap

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

the class TestStatisticsWriterNode method getJsonCodec.

private JsonCodec<StatisticsWriterNode> getJsonCodec() throws Exception {
    Module module = binder -> {
        SqlParser sqlParser = new SqlParser();
        FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
        binder.install(new JsonModule());
        binder.install(new HandleJsonModule());
        binder.bind(SqlParser.class).toInstance(sqlParser);
        binder.bind(TypeManager.class).toInstance(functionAndTypeManager);
        newSetBinder(binder, Type.class);
        jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class);
        jsonCodecBinder(binder).bindJsonCodec(StatisticsWriterNode.class);
    };
    Bootstrap app = new Bootstrap(ImmutableList.of(module));
    Injector injector = app.doNotInitializeLogging().quiet().initialize();
    HandleResolver handleResolver = injector.getInstance(HandleResolver.class);
    handleResolver.addConnectorName("test", new TestingHandleResolver());
    return injector.getInstance(new Key<JsonCodec<StatisticsWriterNode>>() {
    });
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) Module(com.google.inject.Module) JsonCodec(com.facebook.airlift.json.JsonCodec) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) ColumnStatisticMetadata(com.facebook.presto.spi.statistics.ColumnStatisticMetadata) Key(com.google.inject.Key) Assert.assertEquals(org.testng.Assert.assertEquals) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) JsonCodecBinder.jsonCodecBinder(com.facebook.airlift.json.JsonCodecBinder.jsonCodecBinder) ValuesNode(com.facebook.presto.spi.plan.ValuesNode) ImmutableList(com.google.common.collect.ImmutableList) TypeManager(com.facebook.presto.common.type.TypeManager) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) Multibinder.newSetBinder(com.google.inject.multibindings.Multibinder.newSetBinder) TableHandle(com.facebook.presto.spi.TableHandle) Type(com.facebook.presto.common.type.Type) JsonModule(com.facebook.airlift.json.JsonModule) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) ROW_COUNT(com.facebook.presto.spi.statistics.TableStatisticType.ROW_COUNT) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) JsonBinder.jsonBinder(com.facebook.airlift.json.JsonBinder.jsonBinder) TestingTransactionHandle(com.facebook.presto.testing.TestingTransactionHandle) UUID(java.util.UUID) SqlParser(com.facebook.presto.sql.parser.SqlParser) Injector(com.google.inject.Injector) TestingHandleResolver(com.facebook.presto.testing.TestingHandleResolver) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) ColumnStatisticType(com.facebook.presto.spi.statistics.ColumnStatisticType) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) TestingTableHandle(com.facebook.presto.testing.TestingMetadata.TestingTableHandle) Optional(java.util.Optional) ConnectorId(com.facebook.presto.spi.ConnectorId) HandleResolver(com.facebook.presto.metadata.HandleResolver) TestingHandleResolver(com.facebook.presto.testing.TestingHandleResolver) HandleResolver(com.facebook.presto.metadata.HandleResolver) TestingHandleResolver(com.facebook.presto.testing.TestingHandleResolver) SqlParser(com.facebook.presto.sql.parser.SqlParser) HandleJsonModule(com.facebook.presto.metadata.HandleJsonModule) JsonModule(com.facebook.airlift.json.JsonModule) Type(com.facebook.presto.common.type.Type) ColumnStatisticType(com.facebook.presto.spi.statistics.ColumnStatisticType) 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) 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)

Example 12 with Bootstrap

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

the class FileAuthenticatorFactory method create.

@Override
public PasswordAuthenticator create(Map<String, String> config) {
    try {
        Bootstrap app = new Bootstrap(binder -> {
            configBinder(binder).bindConfig(FileConfig.class);
            binder.bind(FileAuthenticator.class).in(Scopes.SINGLETON);
        });
        Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        return injector.getInstance(FileAuthenticator.class);
    } catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
Also used : Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap)

Example 13 with Bootstrap

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

the class PrometheusConnectorFactory method create.

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

Example 14 with Bootstrap

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

the class FileSessionPropertyManagerFactory method create.

@Override
public SessionPropertyConfigurationManager create(Map<String, String> config, SessionPropertyConfigurationManagerContext context) {
    try {
        Bootstrap app = new Bootstrap(new JsonModule(), new FileSessionPropertyManagerModule());
        Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        return injector.getInstance(FileSessionPropertyManager.class);
    } catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
Also used : Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) JsonModule(com.facebook.airlift.json.JsonModule)

Example 15 with Bootstrap

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

the class FileResourceGroupConfigurationManagerFactory method create.

@Override
public ResourceGroupConfigurationManager<VariableMap> create(Map<String, String> config, ResourceGroupConfigurationManagerContext context) {
    try {
        Bootstrap app = new Bootstrap(new JsonModule(), new FileResourceGroupsModule(), binder -> binder.bind(ClusterMemoryPoolManager.class).toInstance(context.getMemoryPoolManager()));
        Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        return injector.getInstance(FileResourceGroupConfigurationManager.class);
    } catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
Also used : Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) 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