Search in sources :

Example 1 with DmaIdListModule

use of com.codecademy.eventhub.list.DmaIdListModule in project EventHub by Codecademy.

the class ShardedEventIndexTest method getShardedEventIndexProvider.

private Provider<ShardedEventIndex> getShardedEventIndexProvider() {
    Properties prop = new Properties();
    prop.put("eventhub.directory", getTempDirectory());
    prop.put("eventhub.eventindex.initialNumEventIdsPerDay", "1");
    Injector injector = createInjectorFor(prop, new DmaIdListModule(), new ShardedEventIndexModule());
    return injector.getProvider(ShardedEventIndex.class);
}
Also used : Injector(com.google.inject.Injector) DmaIdListModule(com.codecademy.eventhub.list.DmaIdListModule) Properties(java.util.Properties)

Example 2 with DmaIdListModule

use of com.codecademy.eventhub.list.DmaIdListModule in project EventHub by Codecademy.

the class EventHubTest method getInjector.

private Injector getInjector() {
    Properties prop = new Properties();
    prop.put("eventhub.directory", getTempDirectory());
    prop.put("eventhub.eventindex.initialNumEventIdsPerDay", "10");
    prop.put("eventhub.usereventindex.numPointersPerIndexEntry", "2");
    prop.put("eventhub.usereventindex.numIndexEntryPerFile", "2");
    prop.put("eventhub.usereventindex.indexEntryFileCacheSize", "2");
    prop.put("eventhub.usereventindex.numRecordsPerBlock", "2");
    prop.put("eventhub.usereventindex.numBlocksPerFile", "2");
    prop.put("eventhub.usereventindex.blockCacheSize", "2");
    prop.put("eventhub.journaleventstorage.numMetaDataPerFile", "10");
    prop.put("eventhub.journaleventstorage.metaDataFileCacheSize", "10");
    prop.put("eventhub.journaleventstorage.journalFileSize", "1024");
    prop.put("eventhub.journaleventstorage.journalWriteBatchSize", "1024");
    prop.put("eventhub.cachedeventstorage.recordCacheSize", "10");
    prop.put("eventhub.bloomfilteredeventstorage.bloomFilterSize", "64");
    prop.put("eventhub.bloomfilteredeventstorage.numHashes", "1");
    prop.put("eventhub.bloomfilteredeventstorage.numMetaDataPerFile", "10");
    prop.put("eventhub.bloomfilteredeventstorage.metaDataFileCacheSize", "10");
    prop.put("eventhub.journaluserstorage.numMetaDataPerFile", "10");
    prop.put("eventhub.journaluserstorage.metaDataFileCacheSize", "10");
    prop.put("eventhub.journaluserstorage.journalFileSize", "1024");
    prop.put("eventhub.journaluserstorage.journalWriteBatchSize", "1024");
    prop.put("eventhub.cacheduserstorage.recordCacheSize", "10");
    prop.put("eventhub.bloomfiltereduserstorage.numMetaDataPerFile", "10");
    prop.put("eventhub.bloomfiltereduserstorage.metaDataFileCacheSize", "10");
    prop.put("eventhub.bloomfiltereduserstorage.bloomFilterSize", "64");
    prop.put("eventhub.bloomfiltereduserstorage.numHashes", "1");
    return createInjectorFor(new Properties(), new EventHubModule(prop), new DmaIdListModule(), new ShardedEventIndexModule(), new DatedEventIndexModule(), new PropertiesIndexModule(), new UserEventIndexModule(), new EventStorageModule(), new UserStorageModule());
}
Also used : UserEventIndexModule(com.codecademy.eventhub.index.UserEventIndexModule) DmaIdListModule(com.codecademy.eventhub.list.DmaIdListModule) PropertiesIndexModule(com.codecademy.eventhub.index.PropertiesIndexModule) ShardedEventIndexModule(com.codecademy.eventhub.index.ShardedEventIndexModule) EventStorageModule(com.codecademy.eventhub.storage.EventStorageModule) UserStorageModule(com.codecademy.eventhub.storage.UserStorageModule) Properties(java.util.Properties) DatedEventIndexModule(com.codecademy.eventhub.index.DatedEventIndexModule)

Example 3 with DmaIdListModule

use of com.codecademy.eventhub.list.DmaIdListModule in project EventHub by Codecademy.

the class EventHubHandler method main.

public static void main(String[] args) throws Exception {
    Properties properties = new Properties();
    properties.load(EventHub.class.getClassLoader().getResourceAsStream("hub.properties"));
    properties.load(EventHubHandler.class.getClassLoader().getResourceAsStream("web.properties"));
    properties.putAll(System.getProperties());
    Injector injector = Guice.createInjector(Modules.override(new DmaIdListModule(), new DatedEventIndexModule(), new ShardedEventIndexModule(), new PropertiesIndexModule(), new UserEventIndexModule(), new EventStorageModule(), new UserStorageModule(), new EventHubModule(properties)).with(new Module()));
    final EventHubHandler eventHubHandler = injector.getInstance(EventHubHandler.class);
    int port = injector.getInstance(Key.get(Integer.class, Names.named("eventhubhandler.port")));
    final Server server = new Server(port);
    @SuppressWarnings("ConstantConditions") String webDir = EventHubHandler.class.getClassLoader().getResource("frontend").toExternalForm();
    HashLoginService loginService = new HashLoginService();
    loginService.putUser(properties.getProperty("eventhubhandler.username"), new Password(properties.getProperty("eventhubhandler.password")), new String[] { "user" });
    server.addBean(loginService);
    ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
    Constraint constraint = new Constraint();
    constraint.setName("auth");
    constraint.setAuthenticate(true);
    constraint.setRoles(new String[] { "user", "admin" });
    ConstraintMapping mapping = new ConstraintMapping();
    mapping.setPathSpec("/*");
    mapping.setConstraint(constraint);
    securityHandler.setConstraintMappings(Collections.singletonList(mapping));
    securityHandler.setAuthenticator(new BasicAuthenticator());
    securityHandler.setLoginService(loginService);
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed(false);
    resourceHandler.setWelcomeFiles(new String[] { "main.html" });
    resourceHandler.setResourceBase(webDir);
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { new JsonpCallbackHandler(eventHubHandler), securityHandler });
    server.setHandler(handlers);
    securityHandler.setHandler(resourceHandler);
    server.start();
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

        @Override
        public void run() {
            if (server.isStarted()) {
                try {
                    server.stop();
                    eventHubHandler.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }, "Stop Jetty Hook"));
    server.join();
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) UserEventIndexModule(com.codecademy.eventhub.index.UserEventIndexModule) Server(org.eclipse.jetty.server.Server) Constraint(org.eclipse.jetty.util.security.Constraint) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) Properties(java.util.Properties) HashLoginService(org.eclipse.jetty.security.HashLoginService) BasicAuthenticator(org.eclipse.jetty.security.authentication.BasicAuthenticator) Injector(com.google.inject.Injector) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) DatedEventIndexModule(com.codecademy.eventhub.index.DatedEventIndexModule) Password(org.eclipse.jetty.util.security.Password) ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) PropertiesIndexModule(com.codecademy.eventhub.index.PropertiesIndexModule) EventHubModule(com.codecademy.eventhub.EventHubModule) Constraint(org.eclipse.jetty.util.security.Constraint) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) DmaIdListModule(com.codecademy.eventhub.list.DmaIdListModule) ShardedEventIndexModule(com.codecademy.eventhub.index.ShardedEventIndexModule) EventStorageModule(com.codecademy.eventhub.storage.EventStorageModule) UserStorageModule(com.codecademy.eventhub.storage.UserStorageModule) DatedEventIndexModule(com.codecademy.eventhub.index.DatedEventIndexModule) UserEventIndexModule(com.codecademy.eventhub.index.UserEventIndexModule) PropertiesIndexModule(com.codecademy.eventhub.index.PropertiesIndexModule) EventHubModule(com.codecademy.eventhub.EventHubModule) DmaIdListModule(com.codecademy.eventhub.list.DmaIdListModule) UserStorageModule(com.codecademy.eventhub.storage.UserStorageModule) ShardedEventIndexModule(com.codecademy.eventhub.index.ShardedEventIndexModule) EventStorageModule(com.codecademy.eventhub.storage.EventStorageModule)

Aggregations

DmaIdListModule (com.codecademy.eventhub.list.DmaIdListModule)3 Properties (java.util.Properties)3 DatedEventIndexModule (com.codecademy.eventhub.index.DatedEventIndexModule)2 PropertiesIndexModule (com.codecademy.eventhub.index.PropertiesIndexModule)2 ShardedEventIndexModule (com.codecademy.eventhub.index.ShardedEventIndexModule)2 UserEventIndexModule (com.codecademy.eventhub.index.UserEventIndexModule)2 EventStorageModule (com.codecademy.eventhub.storage.EventStorageModule)2 UserStorageModule (com.codecademy.eventhub.storage.UserStorageModule)2 Injector (com.google.inject.Injector)2 EventHubModule (com.codecademy.eventhub.EventHubModule)1 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 ConstraintMapping (org.eclipse.jetty.security.ConstraintMapping)1 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)1 HashLoginService (org.eclipse.jetty.security.HashLoginService)1 BasicAuthenticator (org.eclipse.jetty.security.authentication.BasicAuthenticator)1 Server (org.eclipse.jetty.server.Server)1 HandlerList (org.eclipse.jetty.server.handler.HandlerList)1 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)1 Constraint (org.eclipse.jetty.util.security.Constraint)1