Search in sources :

Example 1 with SingularityDbModule

use of com.hubspot.singularity.data.history.SingularityDbModule in project Singularity by HubSpot.

the class SingularityTestModule method configure.

@Override
public void configure(Binder mainBinder) {
    mainBinder.install(new GuiceBundle.GuiceEnforcerModule());
    TestingMesosClient tmc = new TestingMesosClient();
    mainBinder.bind(MesosClient.class).toInstance(tmc);
    mainBinder.bind(TestingMesosClient.class).toInstance(tmc);
    mainBinder.bind(TestingServer.class).toInstance(ts);
    final SingularityConfiguration configuration = getSingularityConfigurationForTestingServer(ts);
    configuration.getMesosConfiguration().setMaster("");
    if (useDBTests) {
        configuration.setDatabaseConfiguration(getDataSourceFactory());
    } else {
        mainBinder.bind(Jdbi.class).toProvider(() -> null);
    }
    if (customConfigSetup != null) {
        customConfigSetup.apply(configuration);
    }
    mainBinder.bind(SingularityConfiguration.class).toInstance(configuration);
    mainBinder.install(Modules.override(new SingularityMainModule(configuration, TestingLoadBalancerClient.class)).with(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bind(SingularityExceptionNotifier.class).toInstance(mock(SingularityExceptionNotifier.class));
            SingularityAbort abort = mock(SingularityAbort.class);
            SingularityMailer mailer = mock(SingularityMailer.class);
            binder.bind(SingularityMailer.class).toInstance(mailer);
            binder.bind(SingularityAbort.class).toInstance(abort);
            TestingLoadBalancerClient tlbc = new TestingLoadBalancerClient(configuration, om);
            binder.bind(LoadBalancerClient.class).toInstance(tlbc);
            binder.bind(TestingLoadBalancerClient.class).toInstance(tlbc);
            if (configuration.isCacheOffers()) {
                binder.bind(OfferCache.class).to(SingularityOfferCache.class);
            } else {
                binder.bind(OfferCache.class).to(SingularityNoOfferCache.class);
            }
            binder.bind(ObjectMapper.class).toInstance(om);
            binder.bind(Environment.class).toInstance(environment);
            binder.bind(HostAndPort.class).annotatedWith(named(HTTP_HOST_AND_PORT)).toInstance(HostAndPort.fromString("localhost:8080"));
            binder.bind(SingularityLifecycleManaged.class).to(SingularityLifecycleManagedTest.class).asEagerSingleton();
            binder.bind(new TypeLiteral<Optional<Raven>>() {
            }).toInstance(Optional.<Raven>empty());
            binder.bind(new TypeLiteral<Optional<SentryConfiguration>>() {
            }).toInstance(Optional.<SentryConfiguration>empty());
            binder.bind(HttpServletRequest.class).toProvider(new Provider<HttpServletRequest>() {

                @Override
                public HttpServletRequest get() {
                    throw new OutOfScopeException("testing");
                }
            });
            binder.bind(SingularityLeaderController.class).to(SingularityTestLeaderController.class).in(Scopes.SINGLETON);
        }
    }));
    mainBinder.install(Modules.override(new SingularityMesosModule()).with(binder -> {
        SingularityMesosExecutorInfoSupport logSupport = mock(SingularityMesosExecutorInfoSupport.class);
        binder.bind(SingularityMesosExecutorInfoSupport.class).toInstance(logSupport);
        SingularityMesosSchedulerClient mockClient = mock(SingularityMesosSchedulerClient.class);
        when(mockClient.isRunning()).thenReturn(true);
        binder.bind(SingularityMesosSchedulerClient.class).toInstance(mockClient);
        Multibinder.newSetBinder(binder, DeployAcceptanceHook.class).addBinding().to(NoopDeployAcceptanceHook.class).in(Scopes.SINGLETON);
    }));
    mainBinder.install(new SingularityDataModule(configuration));
    mainBinder.install(new SingularitySchedulerModule());
    mainBinder.install(new SingularityTranscoderModule());
    mainBinder.install(new SingularityHistoryModule());
    mainBinder.install(new SingularityDbModule(configuration));
    mainBinder.install(new SingularityZkMigrationsModule());
    mainBinder.install(new SingularityEventModule(configuration.getWebhookQueueConfiguration()));
    // Auth module bits
    mainBinder.bind(SingularityAuthenticator.class).to(SingularityTestAuthenticator.class);
    mainBinder.bind(SingularityAuthDatastore.class).to(SingularityDisabledAuthDatastore.class);
    mainBinder.bind(SingularityAuthorizer.class).to(SingularityGroupsAuthorizer.class).in(Scopes.SINGLETON);
    mainBinder.bind(SingularityTestAuthenticator.class).in(Scopes.SINGLETON);
    mainBinder.bind(AuthConfiguration.class).toInstance(configuration.getAuthConfiguration());
    mainBinder.bind(DeployResource.class);
    mainBinder.bind(RequestResource.class);
    mainBinder.bind(TaskResource.class);
    mainBinder.bind(AgentResource.class);
    mainBinder.bind(RackResource.class);
    mainBinder.bind(PriorityResource.class);
}
Also used : SingularityLifecycleManagedTest(com.hubspot.singularity.managed.SingularityLifecycleManagedTest) Module(com.google.inject.Module) LifeCycle(org.eclipse.jetty.util.component.LifeCycle) SingularityAuthDatastore(com.hubspot.singularity.auth.datastore.SingularityAuthDatastore) SingularityTranscoderModule(com.hubspot.singularity.data.transcoders.SingularityTranscoderModule) LoggerFactory(org.slf4j.LoggerFactory) SingularityNoOfferCache(com.hubspot.singularity.mesos.SingularityNoOfferCache) SingularityDisabledAuthDatastore(com.hubspot.singularity.auth.datastore.SingularityDisabledAuthDatastore) SingularityMesosExecutorInfoSupport(com.hubspot.singularity.mesos.SingularityMesosExecutorInfoSupport) SingularityDbModule(com.hubspot.singularity.data.history.SingularityDbModule) SingularityMesosSchedulerClient(com.hubspot.singularity.mesos.SingularityMesosSchedulerClient) HTTP_HOST_AND_PORT(com.hubspot.singularity.SingularityMainModule.HTTP_HOST_AND_PORT) AuthConfiguration(com.hubspot.singularity.config.AuthConfiguration) AgentResource(com.hubspot.singularity.resources.AgentResource) SingularityLifecycleManaged(com.hubspot.singularity.managed.SingularityLifecycleManaged) Raven(net.kencochrane.raven.Raven) RackResource(com.hubspot.singularity.resources.RackResource) SingularityDataModule(com.hubspot.singularity.data.SingularityDataModule) DeployAcceptanceHook(com.hubspot.singularity.hooks.DeployAcceptanceHook) ImmutableSet(com.google.common.collect.ImmutableSet) TaskResource(com.hubspot.singularity.resources.TaskResource) GuiceBundle(com.hubspot.dropwizard.guicier.GuiceBundle) SingularityHistoryModule(com.hubspot.singularity.data.history.SingularityHistoryModule) Set(java.util.Set) SingularityAuthenticator(com.hubspot.singularity.auth.authenticator.SingularityAuthenticator) Multibinder(com.google.inject.multibindings.Multibinder) OfferCache(com.hubspot.singularity.mesos.OfferCache) Stage(com.google.inject.Stage) JavaUtils(com.hubspot.mesos.JavaUtils) SingularityEventModule(com.hubspot.singularity.event.SingularityEventModule) RequestResource(com.hubspot.singularity.resources.RequestResource) Names.named(com.google.inject.name.Names.named) SentryConfiguration(com.hubspot.singularity.config.SentryConfiguration) LoadBalancerClient(com.hubspot.singularity.hooks.LoadBalancerClient) SingularityLifecycleManagedTest(com.hubspot.singularity.managed.SingularityLifecycleManagedTest) SingularityOfferCache(com.hubspot.singularity.mesos.SingularityOfferCache) Logger(ch.qos.logback.classic.Logger) SMTPConfiguration(com.hubspot.singularity.config.SMTPConfiguration) Optional(java.util.Optional) TypeLiteral(com.google.inject.TypeLiteral) PriorityResource(com.hubspot.singularity.resources.PriorityResource) OutOfScopeException(com.google.inject.OutOfScopeException) Modules(com.google.inject.util.Modules) SingularityZkMigrationsModule(com.hubspot.singularity.data.zkmigrations.SingularityZkMigrationsModule) SingularityGroupsAuthorizer(com.hubspot.singularity.auth.SingularityGroupsAuthorizer) LoggerContext(ch.qos.logback.classic.LoggerContext) Function(java.util.function.Function) SingularityLeaderController(com.hubspot.singularity.SingularityLeaderController) HttpServletRequest(javax.servlet.http.HttpServletRequest) Lists(com.google.common.collect.Lists) Binder(com.google.inject.Binder) TestingServer(org.apache.curator.test.TestingServer) SingularityExceptionNotifier(com.hubspot.singularity.sentry.SingularityExceptionNotifier) SingularityAuthorizer(com.hubspot.singularity.auth.SingularityAuthorizer) SingularityConfiguration(com.hubspot.singularity.config.SingularityConfiguration) SingularityMesosModule(com.hubspot.singularity.mesos.SingularityMesosModule) Environment(io.dropwizard.setup.Environment) Jdbi(org.jdbi.v3.core.Jdbi) MetricRegistry(com.codahale.metrics.MetricRegistry) MesosClient(com.hubspot.mesos.client.MesosClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DropwizardModule(com.hubspot.dropwizard.guicier.DropwizardModule) HostAndPort(com.google.common.net.HostAndPort) Scopes(com.google.inject.Scopes) Injector(com.google.inject.Injector) Mockito(org.mockito.Mockito) Level(ch.qos.logback.classic.Level) Provider(com.google.inject.Provider) DataSourceFactory(io.dropwizard.db.DataSourceFactory) SingularityMailer(com.hubspot.singularity.smtp.SingularityMailer) ZooKeeperConfiguration(com.hubspot.singularity.config.ZooKeeperConfiguration) SingularityAbort(com.hubspot.singularity.SingularityAbort) Guice(com.google.inject.Guice) MesosConfiguration(com.hubspot.singularity.config.MesosConfiguration) DeployResource(com.hubspot.singularity.resources.DeployResource) SingularityMainModule(com.hubspot.singularity.SingularityMainModule) SingularityTestAuthenticator(com.hubspot.singularity.SingularityTestAuthenticator) Raven(net.kencochrane.raven.Raven) MesosClient(com.hubspot.mesos.client.MesosClient) Jdbi(org.jdbi.v3.core.Jdbi) SingularityDataModule(com.hubspot.singularity.data.SingularityDataModule) SingularityNoOfferCache(com.hubspot.singularity.mesos.SingularityNoOfferCache) OfferCache(com.hubspot.singularity.mesos.OfferCache) SingularityOfferCache(com.hubspot.singularity.mesos.SingularityOfferCache) SentryConfiguration(com.hubspot.singularity.config.SentryConfiguration) HttpServletRequest(javax.servlet.http.HttpServletRequest) SingularityMesosExecutorInfoSupport(com.hubspot.singularity.mesos.SingularityMesosExecutorInfoSupport) Binder(com.google.inject.Binder) TypeLiteral(com.google.inject.TypeLiteral) SingularityZkMigrationsModule(com.hubspot.singularity.data.zkmigrations.SingularityZkMigrationsModule) SingularityTestAuthenticator(com.hubspot.singularity.SingularityTestAuthenticator) SingularityAuthDatastore(com.hubspot.singularity.auth.datastore.SingularityAuthDatastore) SingularityConfiguration(com.hubspot.singularity.config.SingularityConfiguration) SingularityAuthenticator(com.hubspot.singularity.auth.authenticator.SingularityAuthenticator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoadBalancerClient(com.hubspot.singularity.hooks.LoadBalancerClient) SingularityEventModule(com.hubspot.singularity.event.SingularityEventModule) TestingServer(org.apache.curator.test.TestingServer) GuiceBundle(com.hubspot.dropwizard.guicier.GuiceBundle) SingularityAbort(com.hubspot.singularity.SingularityAbort) SingularityMailer(com.hubspot.singularity.smtp.SingularityMailer) SingularityHistoryModule(com.hubspot.singularity.data.history.SingularityHistoryModule) SingularityDbModule(com.hubspot.singularity.data.history.SingularityDbModule) AuthConfiguration(com.hubspot.singularity.config.AuthConfiguration) OutOfScopeException(com.google.inject.OutOfScopeException) SingularityGroupsAuthorizer(com.hubspot.singularity.auth.SingularityGroupsAuthorizer) SingularityTranscoderModule(com.hubspot.singularity.data.transcoders.SingularityTranscoderModule) SingularityExceptionNotifier(com.hubspot.singularity.sentry.SingularityExceptionNotifier) Environment(io.dropwizard.setup.Environment) SingularityMesosModule(com.hubspot.singularity.mesos.SingularityMesosModule) SingularityMainModule(com.hubspot.singularity.SingularityMainModule) Module(com.google.inject.Module) SingularityTranscoderModule(com.hubspot.singularity.data.transcoders.SingularityTranscoderModule) SingularityDbModule(com.hubspot.singularity.data.history.SingularityDbModule) SingularityDataModule(com.hubspot.singularity.data.SingularityDataModule) SingularityHistoryModule(com.hubspot.singularity.data.history.SingularityHistoryModule) SingularityEventModule(com.hubspot.singularity.event.SingularityEventModule) SingularityZkMigrationsModule(com.hubspot.singularity.data.zkmigrations.SingularityZkMigrationsModule) SingularityMesosModule(com.hubspot.singularity.mesos.SingularityMesosModule) DropwizardModule(com.hubspot.dropwizard.guicier.DropwizardModule) SingularityMainModule(com.hubspot.singularity.SingularityMainModule) SingularityMesosSchedulerClient(com.hubspot.singularity.mesos.SingularityMesosSchedulerClient)

Aggregations

Level (ch.qos.logback.classic.Level)1 Logger (ch.qos.logback.classic.Logger)1 LoggerContext (ch.qos.logback.classic.LoggerContext)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 HostAndPort (com.google.common.net.HostAndPort)1 Binder (com.google.inject.Binder)1 Guice (com.google.inject.Guice)1 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 OutOfScopeException (com.google.inject.OutOfScopeException)1 Provider (com.google.inject.Provider)1 Scopes (com.google.inject.Scopes)1 Stage (com.google.inject.Stage)1 TypeLiteral (com.google.inject.TypeLiteral)1 Multibinder (com.google.inject.multibindings.Multibinder)1 Names.named (com.google.inject.name.Names.named)1 Modules (com.google.inject.util.Modules)1