Search in sources :

Example 1 with SingularityConfiguration

use of com.hubspot.singularity.config.SingularityConfiguration in project Singularity by HubSpot.

the class SingularityService method initialize.

@Override
public void initialize(final Bootstrap<T> bootstrap) {
    if (!Strings.isNullOrEmpty(System.getProperty(SINGULARITY_DEFAULT_CONFIGURATION_PROPERTY))) {
        bootstrap.setConfigurationSourceProvider(new MergingSourceProvider(bootstrap.getConfigurationSourceProvider(), System.getProperty(SINGULARITY_DEFAULT_CONFIGURATION_PROPERTY), bootstrap.getObjectMapper(), new YAMLFactory()));
    }
    final Iterable<? extends Module> additionalModules = checkNotNull(getGuiceModules(bootstrap), "getGuiceModules() returned null");
    final Iterable<? extends Bundle> additionalBundles = checkNotNull(getDropwizardBundles(bootstrap), "getDropwizardBundles() returned null");
    final Iterable<? extends ConfiguredBundle<T>> additionalConfiguredBundles = checkNotNull(getDropwizardConfiguredBundles(bootstrap), "getDropwizardConfiguredBundles() returned null");
    guiceBundle = GuiceBundle.defaultBuilder(SingularityConfiguration.class).modules(new SingularityServiceModule()).modules(new SingularityAuthModule()).modules(additionalModules).build();
    bootstrap.addBundle(guiceBundle);
    bootstrap.addBundle(new CorsBundle());
    bootstrap.addBundle(new ViewBundle<>());
    bootstrap.addBundle(new AssetsBundle("/assets/static/", "/static/"));
    bootstrap.addBundle(new AssetsBundle("/assets/api-docs/", "/api-docs/", "index.html", "api-docs"));
    bootstrap.addBundle(new MigrationsBundle<SingularityConfiguration>() {

        @Override
        public DataSourceFactory getDataSourceFactory(final SingularityConfiguration configuration) {
            return configuration.getDatabaseConfiguration().get();
        }
    });
    for (Bundle bundle : additionalBundles) {
        bootstrap.addBundle(bundle);
    }
    for (ConfiguredBundle<T> configuredBundle : additionalConfiguredBundles) {
        bootstrap.addBundle(configuredBundle);
    }
    bootstrap.getObjectMapper().registerModule(new ProtobufModule());
    bootstrap.getObjectMapper().registerModule(new GuavaModule());
    bootstrap.getObjectMapper().setSerializationInclusion(Include.NON_NULL);
    bootstrap.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
Also used : DataSourceFactory(io.dropwizard.db.DataSourceFactory) CorsBundle(com.hubspot.singularity.bundles.CorsBundle) GuiceBundle(com.hubspot.dropwizard.guicier.GuiceBundle) MigrationsBundle(io.dropwizard.migrations.MigrationsBundle) ViewBundle(io.dropwizard.views.ViewBundle) AssetsBundle(io.dropwizard.assets.AssetsBundle) ConfiguredBundle(io.dropwizard.ConfiguredBundle) Bundle(io.dropwizard.Bundle) AssetsBundle(io.dropwizard.assets.AssetsBundle) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) MergingSourceProvider(com.hubspot.singularity.config.MergingSourceProvider) CorsBundle(com.hubspot.singularity.bundles.CorsBundle) ProtobufModule(com.hubspot.jackson.datatype.protobuf.ProtobufModule) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) SingularityConfiguration(com.hubspot.singularity.config.SingularityConfiguration)

Example 2 with SingularityConfiguration

use of com.hubspot.singularity.config.SingularityConfiguration 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());
    }
    if (customConfigSetup != null) {
        customConfigSetup.apply(configuration);
    }
    mainBinder.bind(SingularityConfiguration.class).toInstance(configuration);
    mainBinder.install(Modules.override(new SingularityMainModule(configuration)).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();
            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(new TypeLiteral<Optional<Raven>>() {
            }).toInstance(Optional.<Raven>absent());
            binder.bind(new TypeLiteral<Optional<SentryConfiguration>>() {
            }).toInstance(Optional.<SentryConfiguration>absent());
            binder.bind(HttpServletRequest.class).toProvider(new Provider<HttpServletRequest>() {

                @Override
                public HttpServletRequest get() {
                    throw new OutOfScopeException("testing");
                }
            });
        }
    }));
    mainBinder.install(Modules.override(new SingularityMesosModule()).with(new Module() {

        @Override
        public void configure(Binder 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);
        }
    }));
    mainBinder.install(new SingularityDataModule());
    mainBinder.install(new SingularitySchedulerModule());
    mainBinder.install(new SingularityTranscoderModule());
    mainBinder.install(new SingularityHistoryModule(configuration));
    mainBinder.install(new SingularityZkMigrationsModule());
    mainBinder.install(new SingularityEventModule(configuration));
    // Auth module bits
    mainBinder.bind(SingularityAuthenticator.class).to(SingularityTestAuthenticator.class);
    mainBinder.bind(SingularityAuthDatastore.class).to(SingularityDisabledAuthDatastore.class);
    mainBinder.bind(SingularityAuthorizationHelper.class).in(Scopes.SINGLETON);
    mainBinder.bind(SingularityTestAuthenticator.class).in(Scopes.SINGLETON);
    mainBinder.bind(DeployResource.class);
    mainBinder.bind(RequestResource.class);
    mainBinder.bind(TaskResource.class);
    mainBinder.bind(SlaveResource.class);
    mainBinder.bind(RackResource.class);
    mainBinder.bind(PriorityResource.class);
}
Also used : Raven(net.kencochrane.raven.Raven) MesosClient(com.hubspot.mesos.client.MesosClient) 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) OutOfScopeException(com.google.inject.OutOfScopeException) SingularityAuthorizationHelper(com.hubspot.singularity.auth.SingularityAuthorizationHelper) 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) ProtobufModule(com.hubspot.jackson.datatype.protobuf.ProtobufModule) 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)

Example 3 with SingularityConfiguration

use of com.hubspot.singularity.config.SingularityConfiguration in project Singularity by HubSpot.

the class SingularityAuthorizationHelperTest method buildAuthDisabledConfig.

public static SingularityConfiguration buildAuthDisabledConfig() {
    AuthConfiguration authConfiguration = new AuthConfiguration();
    authConfiguration.setEnabled(false);
    SingularityConfiguration configuration = new SingularityConfiguration();
    configuration.setAuthConfiguration(authConfiguration);
    configuration.setMesosConfiguration(new MesosConfiguration());
    return configuration;
}
Also used : MesosConfiguration(com.hubspot.singularity.config.MesosConfiguration) AuthConfiguration(com.hubspot.singularity.config.AuthConfiguration) SingularityConfiguration(com.hubspot.singularity.config.SingularityConfiguration)

Example 4 with SingularityConfiguration

use of com.hubspot.singularity.config.SingularityConfiguration in project Singularity by HubSpot.

the class SingularityAuthorizationHelperTest method buildAuthEnabledConfig.

public static SingularityConfiguration buildAuthEnabledConfig(Set<String> requiredGroups, Set<String> adminGroups, Set<String> jitaGroups) {
    AuthConfiguration authConfiguration = new AuthConfiguration();
    authConfiguration.setEnabled(true);
    authConfiguration.setRequiredGroups(requiredGroups);
    authConfiguration.setAdminGroups(adminGroups);
    authConfiguration.setJitaGroups(jitaGroups);
    SingularityConfiguration configuration = new SingularityConfiguration();
    configuration.setAuthConfiguration(authConfiguration);
    configuration.setMesosConfiguration(new MesosConfiguration());
    return configuration;
}
Also used : MesosConfiguration(com.hubspot.singularity.config.MesosConfiguration) AuthConfiguration(com.hubspot.singularity.config.AuthConfiguration) SingularityConfiguration(com.hubspot.singularity.config.SingularityConfiguration)

Example 5 with SingularityConfiguration

use of com.hubspot.singularity.config.SingularityConfiguration in project Singularity by HubSpot.

the class SingularityTestModule method getSingularityConfigurationForTestingServer.

private static SingularityConfiguration getSingularityConfigurationForTestingServer(final TestingServer ts) {
    SingularityConfiguration config = new SingularityConfiguration();
    config.setLoadBalancerUri("test");
    MesosConfiguration mc = new MesosConfiguration();
    mc.setDefaultCpus(1);
    mc.setDefaultMemory(128);
    mc.setDefaultDisk(1024);
    config.setMesosConfiguration(mc);
    config.setSmtpConfiguration(new SMTPConfiguration());
    ZooKeeperConfiguration zookeeperConfiguration = new ZooKeeperConfiguration();
    zookeeperConfiguration.setQuorum(ts.getConnectString());
    config.setZooKeeperConfiguration(zookeeperConfiguration);
    config.setConsiderTaskHealthyAfterRunningForSeconds(0);
    return config;
}
Also used : SMTPConfiguration(com.hubspot.singularity.config.SMTPConfiguration) MesosConfiguration(com.hubspot.singularity.config.MesosConfiguration) SingularityConfiguration(com.hubspot.singularity.config.SingularityConfiguration) ZooKeeperConfiguration(com.hubspot.singularity.config.ZooKeeperConfiguration)

Aggregations

SingularityConfiguration (com.hubspot.singularity.config.SingularityConfiguration)5 MesosConfiguration (com.hubspot.singularity.config.MesosConfiguration)3 GuiceBundle (com.hubspot.dropwizard.guicier.GuiceBundle)2 ProtobufModule (com.hubspot.jackson.datatype.protobuf.ProtobufModule)2 AuthConfiguration (com.hubspot.singularity.config.AuthConfiguration)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)1 Binder (com.google.inject.Binder)1 Module (com.google.inject.Module)1 OutOfScopeException (com.google.inject.OutOfScopeException)1 TypeLiteral (com.google.inject.TypeLiteral)1 DropwizardModule (com.hubspot.dropwizard.guicier.DropwizardModule)1 MesosClient (com.hubspot.mesos.client.MesosClient)1 SingularityAbort (com.hubspot.singularity.SingularityAbort)1 SingularityMainModule (com.hubspot.singularity.SingularityMainModule)1 SingularityTestAuthenticator (com.hubspot.singularity.SingularityTestAuthenticator)1 SingularityAuthorizationHelper (com.hubspot.singularity.auth.SingularityAuthorizationHelper)1 SingularityAuthenticator (com.hubspot.singularity.auth.authenticator.SingularityAuthenticator)1 SingularityAuthDatastore (com.hubspot.singularity.auth.datastore.SingularityAuthDatastore)1