Search in sources :

Example 11 with Bootstrap

use of io.airlift.bootstrap.Bootstrap in project presto by prestodb.

the class PrestoVerifier method run.

public int run(String[] args) throws Exception {
    if (args.length > 0) {
        System.setProperty("config", args[0]);
    }
    ImmutableList.Builder<Module> builder = ImmutableList.<Module>builder().add(new PrestoVerifierModule()).addAll(getAdditionalModules());
    Bootstrap app = new Bootstrap(builder.build());
    Injector injector = app.strictConfig().initialize();
    try {
        VerifierConfig config = injector.getInstance(VerifierConfig.class);
        injector.injectMembers(this);
        Set<String> supportedEventClients = injector.getInstance(Key.get(new TypeLiteral<Set<String>>() {
        }, Names.named(SUPPORTED_EVENT_CLIENTS)));
        for (String clientType : config.getEventClients()) {
            checkArgument(supportedEventClients.contains(clientType), "Unsupported event client: %s", clientType);
        }
        Set<EventClient> eventClients = injector.getInstance(Key.get(new TypeLiteral<Set<EventClient>>() {
        }));
        VerifierDao dao = new DBI(config.getQueryDatabase()).onDemand(VerifierDao.class);
        ImmutableList.Builder<QueryPair> queriesBuilder = ImmutableList.builder();
        for (String suite : config.getSuites()) {
            queriesBuilder.addAll(dao.getQueriesBySuite(suite, config.getMaxQueries()));
        }
        List<QueryPair> queries = queriesBuilder.build();
        queries = applyOverrides(config, queries);
        queries = filterQueryTypes(new SqlParser(getParserOptions()), config, queries);
        queries = filterQueries(queries);
        if (config.getShadowWrites()) {
            Sets.SetView<QueryType> allowedTypes = Sets.union(config.getTestQueryTypes(), config.getControlQueryTypes());
            checkArgument(!Sets.intersection(allowedTypes, ImmutableSet.of(CREATE, MODIFY)).isEmpty(), "CREATE or MODIFY queries must be allowed in test or control to use write shadowing");
            queries = rewriteQueries(new SqlParser(getParserOptions()), config, queries);
        }
        // Load jdbc drivers if needed
        if (config.getAdditionalJdbcDriverPath() != null) {
            List<URL> urlList = getUrls(config.getAdditionalJdbcDriverPath());
            URL[] urls = new URL[urlList.size()];
            urlList.toArray(urls);
            if (config.getTestJdbcDriverName() != null) {
                loadJdbcDriver(urls, config.getTestJdbcDriverName());
            }
            if (config.getControlJdbcDriverName() != null) {
                loadJdbcDriver(urls, config.getControlJdbcDriverName());
            }
        }
        // TODO: construct this with Guice
        Verifier verifier = new Verifier(System.out, config, eventClients);
        return verifier.run(queries);
    } finally {
        injector.getInstance(LifeCycleManager.class).stop();
    }
}
Also used : ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) DBI(org.skife.jdbi.v2.DBI) URL(java.net.URL) TypeLiteral(com.google.inject.TypeLiteral) Injector(com.google.inject.Injector) Sets(com.google.common.collect.Sets) Bootstrap(io.airlift.bootstrap.Bootstrap) SqlParser(com.facebook.presto.sql.parser.SqlParser) EventClient(io.airlift.event.client.EventClient) LifeCycleManager(io.airlift.bootstrap.LifeCycleManager) Module(com.google.inject.Module)

Example 12 with Bootstrap

use of io.airlift.bootstrap.Bootstrap in project presto by prestodb.

the class KafkaConnectorFactory method create.

@Override
public Connector create(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 KafkaConnectorModule(), binder -> {
            binder.bind(KafkaConnectorId.class).toInstance(new KafkaConnectorId(connectorId));
            binder.bind(TypeManager.class).toInstance(context.getTypeManager());
            binder.bind(NodeManager.class).toInstance(context.getNodeManager());
            if (tableDescriptionSupplier.isPresent()) {
                binder.bind(new TypeLiteral<Supplier<Map<SchemaTableName, KafkaTopicDescription>>>() {
                }).toInstance(tableDescriptionSupplier.get());
            } else {
                binder.bind(new TypeLiteral<Supplier<Map<SchemaTableName, KafkaTopicDescription>>>() {
                }).to(KafkaTableDescriptionSupplier.class).in(Scopes.SINGLETON);
            }
        });
        Injector injector = app.strictConfig().doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        return injector.getInstance(KafkaConnector.class);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : JsonModule(io.airlift.json.JsonModule) SchemaTableName(com.facebook.presto.spi.SchemaTableName) NodeManager(com.facebook.presto.spi.NodeManager) TypeLiteral(com.google.inject.TypeLiteral) Injector(com.google.inject.Injector) Bootstrap(io.airlift.bootstrap.Bootstrap) TypeManager(com.facebook.presto.spi.type.TypeManager) Supplier(java.util.function.Supplier) Map(java.util.Map)

Example 13 with Bootstrap

use of io.airlift.bootstrap.Bootstrap in project presto by prestodb.

the class PrestoServer method run.

@Override
public void run() {
    verifyJvmRequirements();
    verifySystemTimeIsReasonable();
    Logger log = Logger.get(PrestoServer.class);
    ImmutableList.Builder<Module> modules = ImmutableList.builder();
    modules.add(new NodeModule(), new DiscoveryModule(), new HttpServerModule(), new JsonModule(), new JaxrsModule(true), new MBeanModule(), new JmxModule(), new JmxHttpModule(), new LogJmxModule(), new TraceTokenModule(), new JsonEventModule(), new HttpEventModule(), new EmbeddedDiscoveryModule(), new ServerSecurityModule(), new AccessControlModule(), new EventListenerModule(), new ServerMainModule(sqlParserOptions), new GracefulShutdownModule());
    modules.addAll(getAdditionalModules());
    Bootstrap app = new Bootstrap(modules.build());
    try {
        Injector injector = app.strictConfig().initialize();
        injector.getInstance(PluginManager.class).loadPlugins();
        injector.getInstance(StaticCatalogStore.class).loadCatalogs();
        // TODO: remove this huge hack
        updateConnectorIds(injector.getInstance(Announcer.class), injector.getInstance(CatalogManager.class), injector.getInstance(ServerConfig.class), injector.getInstance(NodeSchedulerConfig.class));
        injector.getInstance(ResourceGroupManager.class).loadConfigurationManager();
        injector.getInstance(AccessControlManager.class).loadSystemAccessControl();
        injector.getInstance(EventListenerManager.class).loadConfiguredEventListener();
        injector.getInstance(Announcer.class).start();
        log.info("======== SERVER STARTED ========");
    } catch (Throwable e) {
        log.error(e);
        System.exit(1);
    }
}
Also used : AccessControlManager(com.facebook.presto.security.AccessControlManager) MBeanModule(org.weakref.jmx.guice.MBeanModule) JmxModule(io.airlift.jmx.JmxModule) LogJmxModule(io.airlift.log.LogJmxModule) ImmutableList(com.google.common.collect.ImmutableList) EmbeddedDiscoveryModule(com.facebook.presto.discovery.EmbeddedDiscoveryModule) DiscoveryModule(io.airlift.discovery.client.DiscoveryModule) NodeSchedulerConfig(com.facebook.presto.execution.scheduler.NodeSchedulerConfig) JsonEventModule(io.airlift.event.client.JsonEventModule) Logger(io.airlift.log.Logger) HttpEventModule(io.airlift.event.client.HttpEventModule) Announcer(io.airlift.discovery.client.Announcer) ServerSecurityModule(com.facebook.presto.server.security.ServerSecurityModule) Injector(com.google.inject.Injector) Bootstrap(io.airlift.bootstrap.Bootstrap) EventListenerModule(com.facebook.presto.eventlistener.EventListenerModule) AccessControlModule(com.facebook.presto.security.AccessControlModule) StaticCatalogStore(com.facebook.presto.metadata.StaticCatalogStore) NodeModule(io.airlift.node.NodeModule) JaxrsModule(io.airlift.jaxrs.JaxrsModule) EmbeddedDiscoveryModule(com.facebook.presto.discovery.EmbeddedDiscoveryModule) ResourceGroupManager(com.facebook.presto.execution.resourceGroups.ResourceGroupManager) LogJmxModule(io.airlift.log.LogJmxModule) JsonModule(io.airlift.json.JsonModule) EventListenerManager(com.facebook.presto.eventlistener.EventListenerManager) CatalogManager(com.facebook.presto.metadata.CatalogManager) TraceTokenModule(io.airlift.tracetoken.TraceTokenModule) HttpServerModule(io.airlift.http.server.HttpServerModule) Module(com.google.inject.Module) MBeanModule(org.weakref.jmx.guice.MBeanModule) JmxModule(io.airlift.jmx.JmxModule) JaxrsModule(io.airlift.jaxrs.JaxrsModule) JmxHttpModule(io.airlift.jmx.JmxHttpModule) JsonEventModule(io.airlift.event.client.JsonEventModule) NodeModule(io.airlift.node.NodeModule) HttpServerModule(io.airlift.http.server.HttpServerModule) AccessControlModule(com.facebook.presto.security.AccessControlModule) EmbeddedDiscoveryModule(com.facebook.presto.discovery.EmbeddedDiscoveryModule) EventListenerModule(com.facebook.presto.eventlistener.EventListenerModule) ServerSecurityModule(com.facebook.presto.server.security.ServerSecurityModule) HttpEventModule(io.airlift.event.client.HttpEventModule) DiscoveryModule(io.airlift.discovery.client.DiscoveryModule) TraceTokenModule(io.airlift.tracetoken.TraceTokenModule) LogJmxModule(io.airlift.log.LogJmxModule) JsonModule(io.airlift.json.JsonModule) JmxHttpModule(io.airlift.jmx.JmxHttpModule)

Example 14 with Bootstrap

use of io.airlift.bootstrap.Bootstrap in project presto by prestodb.

the class TestHeartbeatFailureDetector method testExcludesCurrentNode.

@Test
public void testExcludesCurrentNode() throws Exception {
    Bootstrap app = new Bootstrap(new TestingNodeModule(), new TestingJmxModule(), new TestingDiscoveryModule(), new TestingHttpServerModule(), new TraceTokenModule(), new JsonModule(), new JaxrsModule(true), new FailureDetectorModule(), new Module() {

        @Override
        public void configure(Binder binder) {
            configBinder(binder).bindConfig(QueryManagerConfig.class);
            discoveryBinder(binder).bindSelector("presto");
            discoveryBinder(binder).bindHttpAnnouncement("presto");
            // Jersey with jetty 9 requires at least one resource
            // todo add a dummy resource to airlift jaxrs in this case
            jaxrsBinder(binder).bind(FooResource.class);
        }
    });
    Injector injector = app.strictConfig().doNotInitializeLogging().initialize();
    ServiceSelector selector = injector.getInstance(Key.get(ServiceSelector.class, serviceType("presto")));
    assertEquals(selector.selectAllServices().size(), 1);
    HeartbeatFailureDetector detector = injector.getInstance(HeartbeatFailureDetector.class);
    detector.updateMonitoredServices();
    assertEquals(detector.getTotalCount(), 0);
    assertEquals(detector.getActiveCount(), 0);
    assertEquals(detector.getFailedCount(), 0);
    assertTrue(detector.getFailed().isEmpty());
}
Also used : TestingHttpServerModule(io.airlift.http.server.testing.TestingHttpServerModule) TestingNodeModule(io.airlift.node.testing.TestingNodeModule) ServiceSelector(io.airlift.discovery.client.ServiceSelector) JaxrsModule(io.airlift.jaxrs.JaxrsModule) JsonModule(io.airlift.json.JsonModule) TraceTokenModule(io.airlift.tracetoken.TraceTokenModule) TestingJmxModule(io.airlift.jmx.testing.TestingJmxModule) Binder(com.google.inject.Binder) DiscoveryBinder.discoveryBinder(io.airlift.discovery.client.DiscoveryBinder.discoveryBinder) JaxrsBinder.jaxrsBinder(io.airlift.jaxrs.JaxrsBinder.jaxrsBinder) ConfigBinder.configBinder(io.airlift.configuration.ConfigBinder.configBinder) TestingDiscoveryModule(io.airlift.discovery.client.testing.TestingDiscoveryModule) Injector(com.google.inject.Injector) Bootstrap(io.airlift.bootstrap.Bootstrap) QueryManagerConfig(com.facebook.presto.execution.QueryManagerConfig) Module(com.google.inject.Module) TestingHttpServerModule(io.airlift.http.server.testing.TestingHttpServerModule) JaxrsModule(io.airlift.jaxrs.JaxrsModule) TraceTokenModule(io.airlift.tracetoken.TraceTokenModule) TestingJmxModule(io.airlift.jmx.testing.TestingJmxModule) TestingDiscoveryModule(io.airlift.discovery.client.testing.TestingDiscoveryModule) JsonModule(io.airlift.json.JsonModule) TestingNodeModule(io.airlift.node.testing.TestingNodeModule) Test(org.testng.annotations.Test)

Example 15 with Bootstrap

use of io.airlift.bootstrap.Bootstrap in project presto by prestodb.

the class CassandraConnectorFactory method create.

@Override
public Connector create(String connectorId, Map<String, String> config, ConnectorContext context) {
    requireNonNull(config, "config is null");
    try {
        Bootstrap app = new Bootstrap(new MBeanModule(), new JsonModule(), new CassandraClientModule(connectorId), new Module() {

            @Override
            public void configure(Binder binder) {
                MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
                binder.bind(MBeanServer.class).toInstance(new RebindSafeMBeanServer(platformMBeanServer));
            }
        });
        Injector injector = app.strictConfig().doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        return injector.getInstance(CassandraConnector.class);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : MBeanModule(org.weakref.jmx.guice.MBeanModule) Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) Bootstrap(io.airlift.bootstrap.Bootstrap) Module(com.google.inject.Module) MBeanModule(org.weakref.jmx.guice.MBeanModule) JsonModule(io.airlift.json.JsonModule) JsonModule(io.airlift.json.JsonModule) MBeanServer(javax.management.MBeanServer)

Aggregations

Injector (com.google.inject.Injector)21 Bootstrap (io.airlift.bootstrap.Bootstrap)21 JsonModule (io.airlift.json.JsonModule)17 ThreadContextClassLoader (com.facebook.presto.spi.classloader.ThreadContextClassLoader)7 NodeManager (com.facebook.presto.spi.NodeManager)4 Module (com.google.inject.Module)4 LifeCycleManager (io.airlift.bootstrap.LifeCycleManager)4 MBeanServer (javax.management.MBeanServer)4 MBeanModule (org.weakref.jmx.guice.MBeanModule)4 TypeManager (com.facebook.presto.spi.type.TypeManager)3 TypeLiteral (com.google.inject.TypeLiteral)3 JaxrsModule (io.airlift.jaxrs.JaxrsModule)3 Map (java.util.Map)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 ImmutableList (com.google.common.collect.ImmutableList)2 Binder (com.google.inject.Binder)2 TraceTokenModule (io.airlift.tracetoken.TraceTokenModule)2 Supplier (java.util.function.Supplier)2