Search in sources :

Example 1 with JaxrsModule

use of com.facebook.airlift.jaxrs.JaxrsModule in project presto by prestodb.

the class TestProxyServer method setupServer.

@BeforeClass
public void setupServer() throws Exception {
    byte[] sharedSecret = Base64.getMimeEncoder().encode("test secret".getBytes(US_ASCII));
    sharedSecretFile = Files.createTempFile("secret", "txt");
    Files.write(sharedSecretFile, sharedSecret);
    Logging.initialize();
    server = new TestingPrestoServer();
    server.installPlugin(new TpchPlugin());
    server.createCatalog("tpch", "tpch");
    server.installPlugin(new BlackHolePlugin());
    server.createCatalog("blackhole", "blackhole");
    server.refreshNodes();
    Bootstrap app = new Bootstrap(new TestingNodeModule("test"), new TestingHttpServerModule(), new JsonModule(), new JaxrsModule(true), new TestingJmxModule(), new ProxyModule());
    Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperty("proxy.uri", server.getBaseUrl().toString()).setRequiredConfigurationProperty("proxy.shared-secret-file", sharedSecretFile.toString()).quiet().initialize();
    lifeCycleManager = injector.getInstance(LifeCycleManager.class);
    httpServerInfo = injector.getInstance(HttpServerInfo.class);
    executorService = newCachedThreadPool(daemonThreadsNamed("test-%s"));
    setupTestTable();
}
Also used : TestingHttpServerModule(com.facebook.airlift.http.server.testing.TestingHttpServerModule) TpchPlugin(com.facebook.presto.tpch.TpchPlugin) TestingNodeModule(com.facebook.airlift.node.testing.TestingNodeModule) TestingPrestoServer(com.facebook.presto.server.testing.TestingPrestoServer) JaxrsModule(com.facebook.airlift.jaxrs.JaxrsModule) JsonModule(com.facebook.airlift.json.JsonModule) TestingJmxModule(com.facebook.airlift.jmx.testing.TestingJmxModule) LifeCycleManager(com.facebook.airlift.bootstrap.LifeCycleManager) BlackHolePlugin(com.facebook.presto.plugin.blackhole.BlackHolePlugin) Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) HttpServerInfo(com.facebook.airlift.http.server.HttpServerInfo) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with JaxrsModule

use of com.facebook.airlift.jaxrs.JaxrsModule in project presto by prestodb.

the class PrestoProxy method start.

public static void start(Module... extraModules) {
    Bootstrap app = new Bootstrap(ImmutableList.<Module>builder().add(new NodeModule()).add(new HttpServerModule()).add(new JsonModule()).add(new JaxrsModule(true)).add(new MBeanModule()).add(new JmxModule()).add(new LogJmxModule()).add(new TraceTokenModule()).add(new EventModule()).add(new ProxyModule()).add(extraModules).build());
    Logger log = Logger.get(PrestoProxy.class);
    try {
        app.initialize();
        log.info("======== SERVER STARTED ========");
    } catch (Throwable t) {
        log.error(t);
        System.exit(1);
    }
}
Also used : MBeanModule(org.weakref.jmx.guice.MBeanModule) EventModule(com.facebook.airlift.event.client.EventModule) JmxModule(com.facebook.airlift.jmx.JmxModule) LogJmxModule(com.facebook.airlift.log.LogJmxModule) NodeModule(com.facebook.airlift.node.NodeModule) JaxrsModule(com.facebook.airlift.jaxrs.JaxrsModule) LogJmxModule(com.facebook.airlift.log.LogJmxModule) Logger(com.facebook.airlift.log.Logger) JsonModule(com.facebook.airlift.json.JsonModule) TraceTokenModule(com.facebook.airlift.tracetoken.TraceTokenModule) HttpServerModule(com.facebook.airlift.http.server.HttpServerModule) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap)

Example 3 with JaxrsModule

use of com.facebook.airlift.jaxrs.JaxrsModule 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(InternalCommunicationConfig.class);
            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.doNotInitializeLogging().quiet().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(com.facebook.airlift.http.server.testing.TestingHttpServerModule) TestingNodeModule(com.facebook.airlift.node.testing.TestingNodeModule) ServiceSelector(com.facebook.airlift.discovery.client.ServiceSelector) JaxrsModule(com.facebook.airlift.jaxrs.JaxrsModule) JsonModule(com.facebook.airlift.json.JsonModule) TraceTokenModule(com.facebook.airlift.tracetoken.TraceTokenModule) TestingJmxModule(com.facebook.airlift.jmx.testing.TestingJmxModule) JaxrsBinder.jaxrsBinder(com.facebook.airlift.jaxrs.JaxrsBinder.jaxrsBinder) Binder(com.google.inject.Binder) ConfigBinder.configBinder(com.facebook.airlift.configuration.ConfigBinder.configBinder) DiscoveryBinder.discoveryBinder(com.facebook.airlift.discovery.client.DiscoveryBinder.discoveryBinder) TestingDiscoveryModule(com.facebook.airlift.discovery.client.testing.TestingDiscoveryModule) InternalCommunicationConfig(com.facebook.presto.server.InternalCommunicationConfig) Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) QueryManagerConfig(com.facebook.presto.execution.QueryManagerConfig) TestingHttpServerModule(com.facebook.airlift.http.server.testing.TestingHttpServerModule) Module(com.google.inject.Module) JaxrsModule(com.facebook.airlift.jaxrs.JaxrsModule) TraceTokenModule(com.facebook.airlift.tracetoken.TraceTokenModule) JsonModule(com.facebook.airlift.json.JsonModule) TestingDiscoveryModule(com.facebook.airlift.discovery.client.testing.TestingDiscoveryModule) TestingJmxModule(com.facebook.airlift.jmx.testing.TestingJmxModule) TestingNodeModule(com.facebook.airlift.node.testing.TestingNodeModule) Test(org.testng.annotations.Test)

Example 4 with JaxrsModule

use of com.facebook.airlift.jaxrs.JaxrsModule 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(), installModuleIf(FeaturesConfig.class, FeaturesConfig::isJsonSerdeCodeGenerationEnabled, binder -> jsonBinder(binder).addModuleBinding().to(AfterburnerModule.class)), new SmileModule(), new JaxrsModule(true), new MBeanModule(), new JmxModule(), new JmxHttpModule(), new LogJmxModule(), new TraceTokenModule(), new JsonEventModule(), new HttpEventModule(), new ServerSecurityModule(), new AccessControlModule(), new EventListenerModule(), new ServerMainModule(sqlParserOptions), new GracefulShutdownModule(), new WarningCollectorModule(), new TempStorageModule(), new QueryPrerequisitesManagerModule(), new NodeTtlFetcherManagerModule(), new ClusterTtlProviderManagerModule());
    modules.addAll(getAdditionalModules());
    Bootstrap app = new Bootstrap(modules.build());
    try {
        Injector injector = app.initialize();
        injector.getInstance(PluginManager.class).loadPlugins();
        ServerConfig serverConfig = injector.getInstance(ServerConfig.class);
        if (!serverConfig.isResourceManager()) {
            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));
        // TODO: thrift server port should be announced by discovery server similar to http/https ports
        updateThriftServerPort(injector.getInstance(Announcer.class), injector.getInstance(DriftServer.class));
        injector.getInstance(StaticFunctionNamespaceStore.class).loadFunctionNamespaceManagers();
        injector.getInstance(SessionPropertyDefaults.class).loadConfigurationManager();
        injector.getInstance(ResourceGroupManager.class).loadConfigurationManager();
        if (!serverConfig.isResourceManager()) {
            injector.getInstance(AccessControlManager.class).loadSystemAccessControl();
        }
        injector.getInstance(PasswordAuthenticatorManager.class).loadPasswordAuthenticator();
        injector.getInstance(EventListenerManager.class).loadConfiguredEventListener();
        injector.getInstance(TempStorageManager.class).loadTempStorages();
        injector.getInstance(QueryPrerequisitesManager.class).loadQueryPrerequisites();
        injector.getInstance(NodeTtlFetcherManager.class).loadNodeTtlFetcher();
        injector.getInstance(ClusterTtlProviderManager.class).loadClusterTtlProvider();
        injector.getInstance(Announcer.class).start();
        log.info("======== SERVER STARTED ========");
    } catch (Throwable e) {
        log.error(e);
        System.exit(1);
    }
}
Also used : Module(com.google.inject.Module) SqlParserOptions(com.facebook.presto.sql.parser.SqlParserOptions) DriftServer(com.facebook.drift.server.DriftServer) MBeanModule(org.weakref.jmx.guice.MBeanModule) ClusterTtlProviderManagerModule(com.facebook.presto.ttl.clusterttlprovidermanagers.ClusterTtlProviderManagerModule) JaxrsModule(com.facebook.airlift.jaxrs.JaxrsModule) JmxHttpModule(com.facebook.airlift.jmx.JmxHttpModule) EventListenerManager(com.facebook.presto.eventlistener.EventListenerManager) DriftNettyServerTransport(com.facebook.drift.transport.netty.server.DriftNettyServerTransport) WarningCollectorModule(com.facebook.presto.execution.warnings.WarningCollectorModule) PrestoSystemRequirements.verifySystemTimeIsReasonable(com.facebook.presto.server.PrestoSystemRequirements.verifySystemTimeIsReasonable) Map(java.util.Map) QueryPrerequisitesManagerModule(com.facebook.presto.dispatcher.QueryPrerequisitesManagerModule) Splitter(com.google.common.base.Splitter) ServiceAnnouncement(com.facebook.airlift.discovery.client.ServiceAnnouncement) ClusterTtlProviderManager(com.facebook.presto.ttl.clusterttlprovidermanagers.ClusterTtlProviderManager) ServiceAnnouncement.serviceAnnouncement(com.facebook.airlift.discovery.client.ServiceAnnouncement.serviceAnnouncement) JsonModule(com.facebook.airlift.json.JsonModule) ConditionalModule.installModuleIf(com.facebook.airlift.configuration.ConditionalModule.installModuleIf) SmileModule(com.facebook.airlift.json.smile.SmileModule) Set(java.util.Set) JsonBinder.jsonBinder(com.facebook.airlift.json.JsonBinder.jsonBinder) ServiceAnnouncementBuilder(com.facebook.airlift.discovery.client.ServiceAnnouncement.ServiceAnnouncementBuilder) TempStorageModule(com.facebook.presto.storage.TempStorageModule) AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) HttpEventModule(com.facebook.airlift.event.client.HttpEventModule) List(java.util.List) Catalog(com.facebook.presto.metadata.Catalog) PasswordAuthenticatorManager(com.facebook.presto.server.security.PasswordAuthenticatorManager) NodeTtlFetcherManager(com.facebook.presto.ttl.nodettlfetchermanagers.NodeTtlFetcherManager) JsonEventModule(com.facebook.airlift.event.client.JsonEventModule) JmxModule(com.facebook.airlift.jmx.JmxModule) Joiner(com.google.common.base.Joiner) NodeSchedulerConfig(com.facebook.presto.execution.scheduler.NodeSchedulerConfig) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) Logger(com.facebook.airlift.log.Logger) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) QueryPrerequisitesManager(com.facebook.presto.dispatcher.QueryPrerequisitesManager) AccessControlManager(com.facebook.presto.security.AccessControlManager) TempStorageManager(com.facebook.presto.storage.TempStorageManager) Announcer(com.facebook.airlift.discovery.client.Announcer) TraceTokenModule(com.facebook.airlift.tracetoken.TraceTokenModule) LinkedHashMap(java.util.LinkedHashMap) StaticCatalogStore(com.facebook.presto.metadata.StaticCatalogStore) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) AccessControlModule(com.facebook.presto.security.AccessControlModule) PrestoSystemRequirements.verifyJvmRequirements(com.facebook.presto.server.PrestoSystemRequirements.verifyJvmRequirements) LogJmxModule(com.facebook.airlift.log.LogJmxModule) ResourceGroupManager(com.facebook.presto.execution.resourceGroups.ResourceGroupManager) LinkedHashSet(java.util.LinkedHashSet) EventListenerModule(com.facebook.presto.eventlistener.EventListenerModule) ServerSecurityModule(com.facebook.presto.server.security.ServerSecurityModule) HttpServerModule(com.facebook.airlift.http.server.HttpServerModule) CatalogManager(com.facebook.presto.metadata.CatalogManager) Injector(com.google.inject.Injector) NodeTtlFetcherManagerModule(com.facebook.presto.ttl.nodettlfetchermanagers.NodeTtlFetcherManagerModule) DiscoveryModule(com.facebook.airlift.discovery.client.DiscoveryModule) StaticFunctionNamespaceStore(com.facebook.presto.metadata.StaticFunctionNamespaceStore) NodeModule(com.facebook.airlift.node.NodeModule) AccessControlManager(com.facebook.presto.security.AccessControlManager) JmxModule(com.facebook.airlift.jmx.JmxModule) LogJmxModule(com.facebook.airlift.log.LogJmxModule) DiscoveryModule(com.facebook.airlift.discovery.client.DiscoveryModule) ClusterTtlProviderManagerModule(com.facebook.presto.ttl.clusterttlprovidermanagers.ClusterTtlProviderManagerModule) JsonEventModule(com.facebook.airlift.event.client.JsonEventModule) PasswordAuthenticatorManager(com.facebook.presto.server.security.PasswordAuthenticatorManager) TempStorageModule(com.facebook.presto.storage.TempStorageModule) TempStorageManager(com.facebook.presto.storage.TempStorageManager) Announcer(com.facebook.airlift.discovery.client.Announcer) Injector(com.google.inject.Injector) QueryPrerequisitesManager(com.facebook.presto.dispatcher.QueryPrerequisitesManager) StaticCatalogStore(com.facebook.presto.metadata.StaticCatalogStore) NodeModule(com.facebook.airlift.node.NodeModule) StaticFunctionNamespaceStore(com.facebook.presto.metadata.StaticFunctionNamespaceStore) ResourceGroupManager(com.facebook.presto.execution.resourceGroups.ResourceGroupManager) LogJmxModule(com.facebook.airlift.log.LogJmxModule) JsonModule(com.facebook.airlift.json.JsonModule) EventListenerManager(com.facebook.presto.eventlistener.EventListenerManager) TraceTokenModule(com.facebook.airlift.tracetoken.TraceTokenModule) HttpServerModule(com.facebook.airlift.http.server.HttpServerModule) Module(com.google.inject.Module) MBeanModule(org.weakref.jmx.guice.MBeanModule) ClusterTtlProviderManagerModule(com.facebook.presto.ttl.clusterttlprovidermanagers.ClusterTtlProviderManagerModule) JaxrsModule(com.facebook.airlift.jaxrs.JaxrsModule) JmxHttpModule(com.facebook.airlift.jmx.JmxHttpModule) WarningCollectorModule(com.facebook.presto.execution.warnings.WarningCollectorModule) QueryPrerequisitesManagerModule(com.facebook.presto.dispatcher.QueryPrerequisitesManagerModule) JsonModule(com.facebook.airlift.json.JsonModule) SmileModule(com.facebook.airlift.json.smile.SmileModule) TempStorageModule(com.facebook.presto.storage.TempStorageModule) AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) HttpEventModule(com.facebook.airlift.event.client.HttpEventModule) JsonEventModule(com.facebook.airlift.event.client.JsonEventModule) JmxModule(com.facebook.airlift.jmx.JmxModule) TraceTokenModule(com.facebook.airlift.tracetoken.TraceTokenModule) AccessControlModule(com.facebook.presto.security.AccessControlModule) LogJmxModule(com.facebook.airlift.log.LogJmxModule) EventListenerModule(com.facebook.presto.eventlistener.EventListenerModule) ServerSecurityModule(com.facebook.presto.server.security.ServerSecurityModule) HttpServerModule(com.facebook.airlift.http.server.HttpServerModule) NodeTtlFetcherManagerModule(com.facebook.presto.ttl.nodettlfetchermanagers.NodeTtlFetcherManagerModule) DiscoveryModule(com.facebook.airlift.discovery.client.DiscoveryModule) NodeModule(com.facebook.airlift.node.NodeModule) JmxHttpModule(com.facebook.airlift.jmx.JmxHttpModule) MBeanModule(org.weakref.jmx.guice.MBeanModule) WarningCollectorModule(com.facebook.presto.execution.warnings.WarningCollectorModule) ImmutableList(com.google.common.collect.ImmutableList) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) NodeSchedulerConfig(com.facebook.presto.execution.scheduler.NodeSchedulerConfig) Logger(com.facebook.airlift.log.Logger) NodeTtlFetcherManagerModule(com.facebook.presto.ttl.nodettlfetchermanagers.NodeTtlFetcherManagerModule) HttpEventModule(com.facebook.airlift.event.client.HttpEventModule) ClusterTtlProviderManager(com.facebook.presto.ttl.clusterttlprovidermanagers.ClusterTtlProviderManager) ServerSecurityModule(com.facebook.presto.server.security.ServerSecurityModule) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) DriftServer(com.facebook.drift.server.DriftServer) QueryPrerequisitesManagerModule(com.facebook.presto.dispatcher.QueryPrerequisitesManagerModule) EventListenerModule(com.facebook.presto.eventlistener.EventListenerModule) AccessControlModule(com.facebook.presto.security.AccessControlModule) JaxrsModule(com.facebook.airlift.jaxrs.JaxrsModule) CatalogManager(com.facebook.presto.metadata.CatalogManager) SmileModule(com.facebook.airlift.json.smile.SmileModule) NodeTtlFetcherManager(com.facebook.presto.ttl.nodettlfetchermanagers.NodeTtlFetcherManager)

Example 5 with JaxrsModule

use of com.facebook.airlift.jaxrs.JaxrsModule in project presto by prestodb.

the class TestHttpBackupStore method setup.

@BeforeMethod
public void setup() throws Exception {
    temporary = createTempDir();
    Map<String, String> properties = ImmutableMap.<String, String>builder().put("backup.http.uri", "http://localhost:8080").build();
    Bootstrap app = new Bootstrap(new TestingNodeModule(), new TestingHttpServerModule(), new JsonModule(), new JaxrsModule(true), binder -> jaxrsBinder(binder).bind(TestingHttpBackupResource.class), override(new HttpBackupModule()).with(new TestingModule()));
    Injector injector = app.setRequiredConfigurationProperties(properties).doNotInitializeLogging().quiet().initialize();
    lifeCycleManager = injector.getInstance(LifeCycleManager.class);
    store = injector.getInstance(BackupStore.class);
}
Also used : TestingHttpServerModule(com.facebook.airlift.http.server.testing.TestingHttpServerModule) TestingNodeModule(com.facebook.airlift.node.testing.TestingNodeModule) JaxrsModule(com.facebook.airlift.jaxrs.JaxrsModule) JsonModule(com.facebook.airlift.json.JsonModule) LifeCycleManager(com.facebook.airlift.bootstrap.LifeCycleManager) Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

Bootstrap (com.facebook.airlift.bootstrap.Bootstrap)5 JaxrsModule (com.facebook.airlift.jaxrs.JaxrsModule)5 JsonModule (com.facebook.airlift.json.JsonModule)5 Injector (com.google.inject.Injector)4 TestingHttpServerModule (com.facebook.airlift.http.server.testing.TestingHttpServerModule)3 TestingNodeModule (com.facebook.airlift.node.testing.TestingNodeModule)3 TraceTokenModule (com.facebook.airlift.tracetoken.TraceTokenModule)3 LifeCycleManager (com.facebook.airlift.bootstrap.LifeCycleManager)2 HttpServerModule (com.facebook.airlift.http.server.HttpServerModule)2 JmxModule (com.facebook.airlift.jmx.JmxModule)2 TestingJmxModule (com.facebook.airlift.jmx.testing.TestingJmxModule)2 LogJmxModule (com.facebook.airlift.log.LogJmxModule)2 Logger (com.facebook.airlift.log.Logger)2 NodeModule (com.facebook.airlift.node.NodeModule)2 Module (com.google.inject.Module)2 MBeanModule (org.weakref.jmx.guice.MBeanModule)2 ConditionalModule.installModuleIf (com.facebook.airlift.configuration.ConditionalModule.installModuleIf)1 ConfigBinder.configBinder (com.facebook.airlift.configuration.ConfigBinder.configBinder)1 Announcer (com.facebook.airlift.discovery.client.Announcer)1 DiscoveryBinder.discoveryBinder (com.facebook.airlift.discovery.client.DiscoveryBinder.discoveryBinder)1