use of io.airlift.event.client.EventModule in project airlift by airlift.
the class HttpEventModule method configure.
@Override
public void configure(Binder binder) {
// for backwards compatibility
binder.install(new EventModule());
binder.bind(JsonEventWriter.class).in(Scopes.SINGLETON);
binder.bind(HttpEventClient.class).in(Scopes.SINGLETON);
newSetBinder(binder, EventClient.class).addBinding().to(Key.get(HttpEventClient.class)).in(Scopes.SINGLETON);
newExporter(binder).export(EventClient.class).withGeneratedName();
discoveryBinder(binder).bindHttpSelector("collector");
// bind the http client
httpClientBinder(binder).bindHttpClient("event", ForEventClient.class);
// Kick off the binding of Set<EventTypeMetadata> in case no events are bound
newSetBinder(binder, new TypeLiteral<EventTypeMetadata<?>>() {
});
}
use of io.airlift.event.client.EventModule in project carbondata by apache.
the class CarbondataConnectorFactory method create.
@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context) {
requireNonNull(config, "config is null");
try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
Bootstrap app = new Bootstrap(new EventModule(), new MBeanModule(), new JsonModule(), new CarbondataModule(catalogName), new HiveS3Module(catalogName), new HiveMetastoreModule(catalogName, Optional.ofNullable(null)), new HiveSecurityModule(), new HiveAuthenticationModule(), new HiveProcedureModule(), binder -> {
javax.management.MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
binder.bind(javax.management.MBeanServer.class).toInstance(new RebindSafeMBeanServer(platformMBeanServer));
binder.bind(NodeVersion.class).toInstance(new NodeVersion(context.getNodeManager().getCurrentNode().getVersion()));
binder.bind(NodeManager.class).toInstance(context.getNodeManager());
binder.bind(TypeManager.class).toInstance(context.getTypeManager());
binder.bind(PageIndexerFactory.class).toInstance(context.getPageIndexerFactory());
binder.bind(PageSorter.class).toInstance(context.getPageSorter());
configBinder(binder).bindConfig(CarbonTableConfig.class);
});
Injector injector = app.strictConfig().doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
setCarbonEnum();
LifeCycleManager lifeCycleManager = injector.getInstance(LifeCycleManager.class);
HiveMetadataFactory metadataFactory = injector.getInstance(HiveMetadataFactory.class);
HiveTransactionManager transactionManager = injector.getInstance(HiveTransactionManager.class);
ConnectorSplitManager splitManager = injector.getInstance(ConnectorSplitManager.class);
ConnectorPageSourceProvider connectorPageSource = injector.getInstance(ConnectorPageSourceProvider.class);
ConnectorPageSinkProvider pageSinkProvider = injector.getInstance(ConnectorPageSinkProvider.class);
ConnectorNodePartitioningProvider connectorDistributionProvider = injector.getInstance(ConnectorNodePartitioningProvider.class);
HiveSessionProperties hiveSessionProperties = injector.getInstance(HiveSessionProperties.class);
HiveTableProperties hiveTableProperties = injector.getInstance(HiveTableProperties.class);
HiveAnalyzeProperties hiveAnalyzeProperties = injector.getInstance(HiveAnalyzeProperties.class);
ConnectorAccessControl accessControl = new PartitionsAwareAccessControl(injector.getInstance(ConnectorAccessControl.class));
Set<Procedure> procedures = injector.getInstance(Key.get(new TypeLiteral<Set<Procedure>>() {
}));
return new HiveConnector(lifeCycleManager, metadataFactory, transactionManager, new ClassLoaderSafeConnectorSplitManager(splitManager, classLoader), new ClassLoaderSafeConnectorPageSourceProvider(connectorPageSource, classLoader), new ClassLoaderSafeConnectorPageSinkProvider(pageSinkProvider, classLoader), new ClassLoaderSafeNodePartitioningProvider(connectorDistributionProvider, classLoader), ImmutableSet.of(), procedures, hiveSessionProperties.getSessionProperties(), HiveSchemaProperties.SCHEMA_PROPERTIES, hiveTableProperties.getTableProperties(), hiveAnalyzeProperties.getAnalyzeProperties(), accessControl, classLoader);
} catch (Exception e) {
throwIfUnchecked(e);
throw new RuntimeException(e);
}
}
use of io.airlift.event.client.EventModule in project carbondata by apache.
the class InternalCarbonDataConnectorFactory method createConnector.
public static Connector createConnector(String catalogName, Map<String, String> config, ConnectorContext context, Module module, Optional<HiveMetastore> metastore) {
requireNonNull(config, "config is null");
ClassLoader classLoader = InternalCarbonDataConnectorFactory.class.getClassLoader();
try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
Bootstrap app = new Bootstrap(new EventModule(), new MBeanModule(), new ConnectorObjectNameGeneratorModule(catalogName, "io.prestosql.plugin.carbondata", "presto.plugin.carbondata"), new JsonModule(), new CarbondataModule(), new HiveS3Module(), new HiveGcsModule(), new HiveAzureModule(), installModuleIf(RubixEnabledConfig.class, RubixEnabledConfig::isCacheEnabled, new RubixModule()), new HiveMetastoreModule(metastore), new HiveSecurityModule(catalogName), new HiveAuthenticationModule(), new HiveProcedureModule(), new MBeanServerModule(), binder -> {
binder.bind(NodeVersion.class).toInstance(new NodeVersion(context.getNodeManager().getCurrentNode().getVersion()));
binder.bind(NodeManager.class).toInstance(context.getNodeManager());
binder.bind(VersionEmbedder.class).toInstance(context.getVersionEmbedder());
binder.bind(TypeManager.class).toInstance(context.getTypeManager());
binder.bind(PageIndexerFactory.class).toInstance(context.getPageIndexerFactory());
binder.bind(PageSorter.class).toInstance(context.getPageSorter());
binder.bind(CatalogName.class).toInstance(new CatalogName(catalogName));
configBinder(binder).bindConfig(CarbonTableConfig.class);
}, binder -> newSetBinder(binder, EventListener.class), module);
Injector injector = app.strictConfig().doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
if (injector.getInstance(RubixEnabledConfig.class).isCacheEnabled()) {
// RubixInitializer needs ConfigurationInitializers, hence kept outside RubixModule
RubixInitializer rubixInitializer = injector.getInstance(RubixInitializer.class);
rubixInitializer.initializeRubix(context.getNodeManager());
}
LifeCycleManager lifeCycleManager = injector.getInstance(LifeCycleManager.class);
HiveMetadataFactory metadataFactory = injector.getInstance(HiveMetadataFactory.class);
HiveTransactionManager transactionManager = injector.getInstance(HiveTransactionManager.class);
ConnectorSplitManager splitManager = injector.getInstance(ConnectorSplitManager.class);
ConnectorPageSourceProvider connectorPageSource = injector.getInstance(ConnectorPageSourceProvider.class);
ConnectorPageSinkProvider pageSinkProvider = injector.getInstance(ConnectorPageSinkProvider.class);
ConnectorNodePartitioningProvider connectorDistributionProvider = injector.getInstance(ConnectorNodePartitioningProvider.class);
HiveSessionProperties hiveSessionProperties = injector.getInstance(HiveSessionProperties.class);
HiveTableProperties hiveTableProperties = injector.getInstance(HiveTableProperties.class);
HiveAnalyzeProperties hiveAnalyzeProperties = injector.getInstance(HiveAnalyzeProperties.class);
ConnectorAccessControl accessControl = new ClassLoaderSafeConnectorAccessControl(new SystemTableAwareAccessControl(injector.getInstance(ConnectorAccessControl.class)), classLoader);
Set<Procedure> procedures = injector.getInstance(Key.get(new TypeLiteral<Set<Procedure>>() {
}));
Set<SystemTable> systemTables = injector.getInstance(Key.get(new TypeLiteral<Set<SystemTable>>() {
}));
Set<EventListener> eventListeners = injector.getInstance(Key.get(new TypeLiteral<Set<EventListener>>() {
})).stream().map(listener -> new ClassLoaderSafeEventListener(listener, classLoader)).collect(toImmutableSet());
return new CarbonDataConnector(lifeCycleManager, metadataFactory, transactionManager, new ClassLoaderSafeConnectorSplitManager(splitManager, classLoader), new ClassLoaderSafeConnectorPageSourceProvider(connectorPageSource, classLoader), new ClassLoaderSafeConnectorPageSinkProvider(pageSinkProvider, classLoader), new ClassLoaderSafeNodePartitioningProvider(connectorDistributionProvider, classLoader), systemTables, procedures, eventListeners, hiveSessionProperties.getSessionProperties(), HiveSchemaProperties.SCHEMA_PROPERTIES, hiveTableProperties.getTableProperties(), hiveAnalyzeProperties.getAnalyzeProperties(), accessControl, classLoader);
}
}
use of io.airlift.event.client.EventModule in project airlift by airlift.
the class TestHttpServerModule method testServer.
@Test
public void testServer() throws Exception {
Map<String, String> properties = new ImmutableMap.Builder<String, String>().put("http-server.http.port", "0").put("http-server.log.path", new File(tempDir, "http-request.log").getAbsolutePath()).build();
Bootstrap app = new Bootstrap(new HttpServerModule(), new TestingNodeModule(), new EventModule(), binder -> {
binder.bind(Servlet.class).annotatedWith(TheServlet.class).to(DummyServlet.class);
newSetBinder(binder, Filter.class, TheServlet.class).addBinding().to(DummyFilter.class).in(Scopes.SINGLETON);
httpServerBinder(binder).bindResource("/", "webapp/user").withWelcomeFile("user-welcome.txt");
httpServerBinder(binder).bindResource("/", "webapp/user2");
httpServerBinder(binder).bindResource("path", "webapp/user").withWelcomeFile("user-welcome.txt");
httpServerBinder(binder).bindResource("path", "webapp/user2");
});
Injector injector = app.setRequiredConfigurationProperties(properties).doNotInitializeLogging().initialize();
HttpServerInfo httpServerInfo = injector.getInstance(HttpServerInfo.class);
HttpServer server = injector.getInstance(HttpServer.class);
server.start();
try (HttpClient client = new JettyHttpClient()) {
// test servlet bound correctly
URI httpUri = httpServerInfo.getHttpUri();
StatusResponse response = client.execute(prepareGet().setUri(httpUri).build(), createStatusResponseHandler());
assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK);
// test filter bound correctly
response = client.execute(prepareGet().setUri(httpUri.resolve("/filter")).build(), createStatusResponseHandler());
assertEquals(response.getStatusCode(), HttpServletResponse.SC_PAYMENT_REQUIRED);
// test http resources
assertResource(httpUri, client, "", "welcome user!");
assertResource(httpUri, client, "user-welcome.txt", "welcome user!");
assertResource(httpUri, client, "user.txt", "user");
assertResource(httpUri, client, "user2.txt", "user2");
assertRedirect(httpUri, client, "path", "/path/");
assertResource(httpUri, client, "path/", "welcome user!");
assertResource(httpUri, client, "path/user-welcome.txt", "welcome user!");
assertResource(httpUri, client, "path/user.txt", "user");
assertResource(httpUri, client, "path/user2.txt", "user2");
} finally {
server.stop();
}
}
use of io.airlift.event.client.EventModule in project airlift by airlift.
the class TestHttpServerModule method testHttpServerUri.
@Test
public void testHttpServerUri() throws Exception {
Map<String, String> properties = new ImmutableMap.Builder<String, String>().put("http-server.http.port", "0").put("http-server.log.path", new File(tempDir, "http-request.log").getAbsolutePath()).build();
Bootstrap app = new Bootstrap(new HttpServerModule(), new TestingNodeModule(), new EventModule(), binder -> binder.bind(Servlet.class).annotatedWith(TheServlet.class).to(DummyServlet.class));
Injector injector = app.setRequiredConfigurationProperties(properties).doNotInitializeLogging().initialize();
NodeInfo nodeInfo = injector.getInstance(NodeInfo.class);
HttpServer server = injector.getInstance(HttpServer.class);
assertNotNull(server);
server.start();
try {
HttpServerInfo httpServerInfo = injector.getInstance(HttpServerInfo.class);
assertNotNull(httpServerInfo);
assertNotNull(httpServerInfo.getHttpUri());
assertEquals(httpServerInfo.getHttpUri().getScheme(), "http");
assertEquals(httpServerInfo.getHttpUri().getHost(), nodeInfo.getInternalAddress());
assertNull(httpServerInfo.getHttpsUri());
} catch (Exception e) {
server.stop();
}
}
Aggregations