io.dropwizard.configuration.SubstitutingSourceProvider Java Examples

The following examples show how to use io.dropwizard.configuration.SubstitutingSourceProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfigValidatorTest.java    From dcos-cassandra-service with Apache License 2.0 6 votes vote down vote up
@Test
public void testPrincipal() throws Exception {
  MutableSchedulerConfiguration mutable = factory.build(
    new SubstitutingSourceProvider(
      new FileConfigurationSourceProvider(),
      new EnvironmentVariableSubstitutor(false, true)),
    Resources.getResource("scheduler.yml").getFile());
  final ServiceConfig serviceConfig = mutable.getServiceConfig();
  final ServiceConfig updated = ServiceConfig.create(serviceConfig.getName(),
    serviceConfig.getId(),
    serviceConfig.getVersion(),
    serviceConfig.getUser(),
    serviceConfig.getCluster(),
    serviceConfig.getRole(),
    serviceConfig.getPrincipal() + "asdf",
    serviceConfig.getFailoverTimeoutS(),
    serviceConfig.getSecret(),
    serviceConfig.isCheckpoint());
  mutable.setServiceConfig(updated);
  final ConfigValidator configValidator = new ConfigValidator();
  final List<ConfigValidationError> validate =
    configValidator.validate(configuration.createConfig(), mutable.createConfig());
  Assert.assertTrue(validate.size() == 1);
}
 
Example #2
Source File: TimbuctooV4.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void initialize(Bootstrap<TimbuctooConfiguration> bootstrap) {
  //bundles
  activeMqBundle = new ActiveMQBundle();
  bootstrap.addBundle(activeMqBundle);
  bootstrap.addBundle(new MultiPartBundle());
  bootstrap.addBundle(new AssetsBundle("/static", "/static", "index.html"));
  /*
   * Make it possible to use environment variables in the config.
   * see: http://www.dropwizard.io/0.9.1/docs/manual/core.html#environment-variables
   */
  bootstrap.setConfigurationSourceProvider(
    new SubstitutingSourceProvider(
      bootstrap.getConfigurationSourceProvider(),
      new EnvironmentVariableSubstitutor(true)
    ));
}
 
Example #3
Source File: PublicApi.java    From pay-publicapi with MIT License 6 votes vote down vote up
@Override
public void initialize(Bootstrap<PublicApiConfig> bootstrap) {
    bootstrap.setConfigurationSourceProvider(
            new SubstitutingSourceProvider(
                    bootstrap.getConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false)
            )
    );
    bootstrap.addBundle(new JedisBundle<PublicApiConfig>() {
        @Override
        public JedisFactory getJedisFactory(PublicApiConfig configuration) {
            return configuration.getJedisFactory();
        }
    });
    bootstrap.getObjectMapper().getSubtypeResolver().registerSubtypes(LogstashConsoleAppenderFactory.class);
    bootstrap.getObjectMapper().getSubtypeResolver().registerSubtypes(GovUkPayDropwizardRequestJsonLogLayoutFactory.class);
}
 
Example #4
Source File: BlockExplorerApp.java    From fabric-api with Apache License 2.0 6 votes vote down vote up
@Override
    public void initialize(Bootstrap<BlockExplorerConfiguration> bootstrap) {
        bootstrap.setConfigurationSourceProvider(
                new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
                        new EnvironmentVariableSubstitutor()
                )
        );
        hyperLedgerBundle = new HyperLedgerBundle<BlockExplorerConfiguration>() {
            @Override
            protected HyperLedgerConfiguration getSupernodeConfiguration(BlockExplorerConfiguration configuration) {
                return configuration.getHyperLedger();
//                return configuration.getGRPCConnectedHyperLedger();
            }
        };
        bootstrap.addBundle(hyperLedgerBundle);
        bootstrap.getObjectMapper().registerModule(new JSR310Module());
    }
 
Example #5
Source File: BlockExplorerApp.java    From fabric-api-archive with Apache License 2.0 6 votes vote down vote up
@Override
    public void initialize(Bootstrap<BlockExplorerConfiguration> bootstrap) {
        bootstrap.setConfigurationSourceProvider(
                new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
                        new EnvironmentVariableSubstitutor()
                )
        );
        hyperLedgerBundle = new HyperLedgerBundle<BlockExplorerConfiguration>() {
            @Override
            protected HyperLedgerConfiguration getSupernodeConfiguration(BlockExplorerConfiguration configuration) {
                return configuration.getHyperLedger();
//                return configuration.getGRPCConnectedHyperLedger();
            }
        };
        bootstrap.addBundle(hyperLedgerBundle);
        bootstrap.getObjectMapper().registerModule(new JSR310Module());
    }
 
Example #6
Source File: ConfigValidatorTest.java    From dcos-cassandra-service with Apache License 2.0 6 votes vote down vote up
@Test
public void testRole() throws Exception {

    MutableSchedulerConfiguration mutable = factory.build(
      new SubstitutingSourceProvider(
        new FileConfigurationSourceProvider(),
        new EnvironmentVariableSubstitutor(false, true)),
      Resources.getResource("scheduler.yml").getFile());
  final ServiceConfig serviceConfig = mutable.getServiceConfig();
  final ServiceConfig updated = ServiceConfig.create(serviceConfig.getName(),
    serviceConfig.getId(),
    serviceConfig.getVersion(),
    serviceConfig.getUser(),
    serviceConfig.getCluster(),
    serviceConfig.getRole() + "qwerty",
    serviceConfig.getPrincipal(),
    serviceConfig.getFailoverTimeoutS(),
    serviceConfig.getSecret(),
    serviceConfig.isCheckpoint());
  mutable.setServiceConfig(updated);
  final ConfigValidator configValidator = new ConfigValidator();
  final List<ConfigValidationError> validate = configValidator.validate(configuration.createConfig(),mutable.createConfig());
  Assert.assertTrue(validate.size() == 1);
}
 
Example #7
Source File: ConfigValidatorTest.java    From dcos-cassandra-service with Apache License 2.0 6 votes vote down vote up
@Test
public void testCluster() throws Exception {
  MutableSchedulerConfiguration mutable = factory.build(
    new SubstitutingSourceProvider(
      new FileConfigurationSourceProvider(),
      new EnvironmentVariableSubstitutor(false, true)),
    Resources.getResource("scheduler.yml").getFile());
  final ServiceConfig serviceConfig = mutable.getServiceConfig();
  final ServiceConfig updated = ServiceConfig.create(serviceConfig.getName(),
    serviceConfig.getId(),
    serviceConfig.getVersion(),
    serviceConfig.getUser(),
    serviceConfig.getCluster() + "1234",
    serviceConfig.getRole(),
    serviceConfig.getPrincipal(),
    serviceConfig.getFailoverTimeoutS(),
    serviceConfig.getSecret(),
    serviceConfig.isCheckpoint());
  mutable.setServiceConfig(updated);
  final ConfigValidator configValidator = new ConfigValidator();
  final List<ConfigValidationError> validate = configValidator.validate(configuration.createConfig(), mutable.createConfig());
  Assert.assertTrue(validate.size() == 1);
}
 
Example #8
Source File: ConfigValidatorTest.java    From dcos-cassandra-service with Apache License 2.0 6 votes vote down vote up
@Test
public void testName() throws Exception {
  MutableSchedulerConfiguration mutable = factory.build(
    new SubstitutingSourceProvider(
      new FileConfigurationSourceProvider(),
      new EnvironmentVariableSubstitutor(false, true)),
    Resources.getResource("scheduler.yml").getFile());
  mutable.getCassandraConfig().getApplication().writeDaemonConfiguration(Paths.get(".").resolve("cassandra.yaml"));
  final ServiceConfig serviceConfig = mutable.getServiceConfig();
  final ServiceConfig updated = ServiceConfig.create("yo",
    serviceConfig.getId(),
    serviceConfig.getVersion(),
    serviceConfig.getUser(),
    serviceConfig.getCluster(),
    serviceConfig.getRole(),
    serviceConfig.getPrincipal(),
    serviceConfig.getFailoverTimeoutS(),
    serviceConfig.getSecret(),
    serviceConfig.isCheckpoint());
  mutable.setServiceConfig(updated);
  final ConfigValidator configValidator = new ConfigValidator();
  final List<ConfigValidationError> validate = configValidator.validate(
    configuration.createConfig(),
    mutable.createConfig());
  Assert.assertTrue(validate.size() == 1);
}
 
Example #9
Source File: Main.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<CassandraExecutorConfiguration> bootstrap) {
    super.initialize(bootstrap);

    bootstrap.addBundle(new Java8Bundle());
    bootstrap.setConfigurationSourceProvider(
            new SubstitutingSourceProvider(
                    bootstrap.getConfigurationSourceProvider(),
                    new StrSubstitutor(
                            new EnvironmentVariableLookup(false))));
}
 
Example #10
Source File: TranslationService.java    From talk-kafka-zipkin with MIT License 5 votes vote down vote up
@Override
public void initialize(Bootstrap<TranslationServiceConfiguration> bootstrap) {
	// Enable variable substitution with environment variables
	bootstrap.setConfigurationSourceProvider(
			new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
					new EnvironmentVariableSubstitutor(false)));
}
 
Example #11
Source File: MainDc.java    From SeaCloudsPlatform with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<DCConfiguration> bootstrap) {
    
    bootstrap.setConfigurationSourceProvider(
            new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false)
            )
    );
    
}
 
Example #12
Source File: DashboardApplication.java    From SeaCloudsPlatform with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<DashboardConfiguration> bootstrap) {

    // Setting configuration from env variables
    bootstrap.setConfigurationSourceProvider(
            new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false)
            )
    );

    // Routing static assets files
    bootstrap.addBundle(new AssetsBundle("/webapp", "/", "index.html"));

    // Routing API documentation
    bootstrap.addBundle(new SwaggerBundle<DashboardConfiguration>() {
        @Override
        protected SwaggerBundleConfiguration getSwaggerBundleConfiguration(DashboardConfiguration configuration) {
            SwaggerBundleConfiguration swaggerBundleConfiguration = configuration.getSwaggerBundleConfiguration();
            swaggerBundleConfiguration.setTitle("SeaClouds REST API");
            swaggerBundleConfiguration.setDescription("This API allows to manage all the project functionality");
            swaggerBundleConfiguration.setResourcePackage("eu.seaclouds.platform.dashboard.rest");
            swaggerBundleConfiguration.setContact("[email protected]");
            swaggerBundleConfiguration.setLicense("Apache 2.0");
            swaggerBundleConfiguration.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0");
            return swaggerBundleConfiguration;
        }
    });
}
 
Example #13
Source File: FoxtrotServer.java    From foxtrot with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<FoxtrotServerConfiguration> bootstrap) {
    bootstrap.setConfigurationSourceProvider(
            new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false)));
    bootstrap.addBundle(new AssetsBundle("/console/echo/", "/", "browse-events.htm", "console"));
    bootstrap.addBundle(new OorBundle<FoxtrotServerConfiguration>() {
        public boolean withOor() {
            return false;
        }
    });

    final SwaggerBundleConfiguration swaggerBundleConfiguration = getSwaggerBundleConfiguration();

    bootstrap.addBundle(new SwaggerBundle<FoxtrotServerConfiguration>() {
        @Override
        protected SwaggerBundleConfiguration getSwaggerBundleConfiguration(FoxtrotServerConfiguration configuration) {
            return swaggerBundleConfiguration;
        }
    });

    bootstrap.addBundle(GuiceBundle.<FoxtrotServerConfiguration>builder()
                                .enableAutoConfig("com.flipkart.foxtrot")
                                .modules(
                                        new FoxtrotModule())
                                .useWebInstallers()
                                .printDiagnosticInfo()
                                .build(Stage.PRODUCTION));
    bootstrap.addCommand(new InitializerCommand());
    configureObjectMapper(bootstrap.getObjectMapper());
}
 
Example #14
Source File: VerifyServiceProviderApplication.java    From verify-service-provider with MIT License 5 votes vote down vote up
@Override
public void initialize(Bootstrap<VerifyServiceProviderConfiguration> bootstrap) {
    // Enable variable substitution with environment variables
    bootstrap.setConfigurationSourceProvider(
        new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
            new EnvironmentVariableSubstitutor(false)
        )
    );
    IdaSamlBootstrap.bootstrap();
    bootstrap.getObjectMapper().setDateFormat(StdDateFormat.getInstance());
    bootstrap.addBundle(hubMetadataBundle);
    bootstrap.addBundle(msaMetadataBundle);
    bootstrap.addCommand(new ComplianceToolMode(bootstrap.getObjectMapper(), bootstrap.getValidatorFactory().getValidator(), this));
    bootstrap.addBundle(new LogstashBundle());
}
 
Example #15
Source File: ServerApplication.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void initialize(final Bootstrap<AppConfig> bootstrap) {
  // This bootstrap will replace ${...} values in YML configuration with environment
  // variable values. Without it, all values in the YML configuration are treated as literals.
  bootstrap.setConfigurationSourceProvider(
      new SubstitutingSourceProvider(
          bootstrap.getConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false)));

  // From: https://www.dropwizard.io/0.7.1/docs/manual/jdbi.html
  // By adding the JdbiExceptionsBundle to your application, Dropwizard will automatically unwrap
  // ant thrown SQLException or DBIException instances. This is critical for debugging, since
  // otherwise only the common wrapper exception’s stack trace is logged.
  bootstrap.addBundle(new JdbiExceptionsBundle());
  bootstrap.addBundle(new RateLimitBundle(new InMemoryRateLimiterFactory()));

  // Note, websocket endpoint is instantiated dynamically on every new connection and does
  // not allow for constructor injection. To inject objects, we use 'userProperties' of the
  // socket configuration that can then be retrieved from a websocket session.
  gameConnectionWebsocket =
      ServerEndpointConfig.Builder.create(
              GameConnectionWebSocket.class, WebsocketPaths.GAME_CONNECTIONS)
          .build();

  playerConnectionWebsocket =
      ServerEndpointConfig.Builder.create(
              PlayerConnectionWebSocket.class, WebsocketPaths.PLAYER_CONNECTIONS)
          .build();

  bootstrap.addBundle(new WebsocketBundle(gameConnectionWebsocket, playerConnectionWebsocket));
}
 
Example #16
Source File: App.java    From hawkular-apm with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<AppConfiguration> bootstrap) {
    bootstrap.setConfigurationSourceProvider(
            new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor()));

    bootstrap.addBundle(new ZipkinBundle<AppConfiguration>(getName()) {
        @Override
        public ZipkinFactory getZipkinFactory(AppConfiguration configuration) {
            return configuration.getZipkinFactory();
        }
    });
}
 
Example #17
Source File: VerifyServiceProviderConfigurationTest.java    From verify-service-provider with MIT License 5 votes vote down vote up
@Test
public void shouldNotComplainWhenConfiguredCorrectly() throws Exception {
    environmentHelper.setEnv(new HashMap<String, String>() {{
        put("PORT", "50555");
        put("LOG_LEVEL", "ERROR");
        put("VERIFY_ENVIRONMENT", "COMPLIANCE_TOOL");
        put("MSA_METADATA_URL", "some-msa-metadata-url");
        put("MSA_ENTITY_ID", "some-msa-entity-id");
        put("SERVICE_ENTITY_IDS", "[\"http://some-service-entity-id\"]");
        put("SAML_SIGNING_KEY", TEST_RP_PRIVATE_SIGNING_KEY);
        put("SAML_PRIMARY_ENCRYPTION_KEY", TEST_RP_PRIVATE_ENCRYPTION_KEY);
        put("SAML_SECONDARY_ENCRYPTION_KEY", TEST_RP_PRIVATE_ENCRYPTION_KEY);
        put("CLOCK_SKEW", "PT30s");
        put("EUROPEAN_IDENTITY_ENABLED", "false");
        put("HUB_CONNECTOR_ENTITY_ID", "etc");
        put("TRUST_ANCHOR_URI", "etc");
        put("METADATA_SOURCE_URI", "etc");
        put("TRUSTSTORE_PATH", "etc");
        put("TRUSTSTORE_PASSWORD", "etc");
    }});

    factory.build(
        new SubstitutingSourceProvider(
            new FileConfigurationSourceProvider(),
            new EnvironmentVariableSubstitutor(false)
        ),
            ResourceHelpers.resourceFilePath("verify-service-provider-with-msa.yml")
    );
    environmentHelper.cleanEnv();
}
 
Example #18
Source File: HelloWorldApplication.java    From dropwizard-consul with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap) {

  bootstrap.setConfigurationSourceProvider(
      new SubstitutingSourceProvider(
          bootstrap.getConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false)));

  bootstrap.addBundle(
      new ConsulBundle<HelloWorldConfiguration>(getName(), false, true) {
        @Override
        public ConsulFactory getConsulFactory(HelloWorldConfiguration configuration) {
          return configuration.getConsulFactory();
        }
      });
}
 
Example #19
Source File: KeystoreApplication.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<KeystoreConfiguration> bootstrap) {
    // Enable variable substitution with environment variables
    bootstrap.setConfigurationSourceProvider(
            new SubstitutingSourceProvider(
                    bootstrap.getConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false)
            )
    );

    bootstrap.addCommand(new TLSTruststoreTestCommand<>(this));
}
 
Example #20
Source File: VerifyServiceProviderConfigurationTest.java    From verify-service-provider with MIT License 5 votes vote down vote up
@Test
public void shouldNotAllowMsaAndEidasConfigTogether() throws Exception {
    Map<String, String> map = ImmutableMap.<String,String>builder()
        .put("PORT", "50555")
        .put("LOG_LEVEL", "ERROR")
        .put("VERIFY_ENVIRONMENT", "COMPLIANCE_TOOL")
        .put("MSA_METADATA_URL", "some-msa-metadata-url")
        .put("MSA_ENTITY_ID", "some-msa-entity-id")
        .put("SERVICE_ENTITY_IDS", "[\"http://some-service-entity-id\"]")
        .put("SAML_SIGNING_KEY", TEST_RP_PRIVATE_SIGNING_KEY)
        .put("SAML_PRIMARY_ENCRYPTION_KEY", TEST_RP_PRIVATE_ENCRYPTION_KEY)
        .put("SAML_SECONDARY_ENCRYPTION_KEY", TEST_RP_PRIVATE_ENCRYPTION_KEY)
        .put("CLOCK_SKEW", "PT30s")
        .put("EUROPEAN_IDENTITY_ENABLED", "false")
        .put("HUB_CONNECTOR_ENTITY_ID", "etc")
        .put("TRUST_ANCHOR_URI", "etc")
        .put("METADATA_SOURCE_URI", "etc")
        .put("TRUSTSTORE_PATH", "etc")
        .put("TRUSTSTORE_PASSWORD", "etc")
        .build();

    String newErrorMessage = "eIDAS and MSA support cannot be set together." +
        " The VSP's eIDAS support is only available when it operates without the MSA";
    assertThatThrownBy(() -> {
            factory.build(
                new SubstitutingSourceProvider(
                    new FileConfigurationSourceProvider(),
                    new StrSubstitutor(map)
                ),
                ResourceHelpers.resourceFilePath("verify-service-provider-with-msa-and-eidas.yml")
            );
        }).isInstanceOf(ConfigurationException.class).hasMessageContaining(newErrorMessage);
}
 
Example #21
Source File: AbstractTrellisApplication.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(final Bootstrap<T> bootstrap) {
    // Allow configuration property substitution from environment variables
    bootstrap.setConfigurationSourceProvider(
            new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
                new EnvironmentVariableSubstitutor(false)));
}
 
Example #22
Source File: Main.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<MutableSchedulerConfiguration> bootstrap) {
  super.initialize(bootstrap);

  StrSubstitutor strSubstitutor = new StrSubstitutor(new EnvironmentVariableLookup(false));
  strSubstitutor.setEnableSubstitutionInVariables(true);

  bootstrap.addBundle(new Java8Bundle());
  bootstrap.setConfigurationSourceProvider(
    new SubstitutingSourceProvider(
      bootstrap.getConfigurationSourceProvider(),
      strSubstitutor));
}
 
Example #23
Source File: HelloService.java    From talk-kafka-zipkin with MIT License 5 votes vote down vote up
@Override
public void initialize(Bootstrap<HelloServiceConfiguration> bootstrap) {
	// Enable variable substitution with environment variables
	bootstrap.setConfigurationSourceProvider(
			new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
					new EnvironmentVariableSubstitutor(false)));
}
 
Example #24
Source File: ConfigValidatorTest.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeEach() throws Exception {
  factory = new ConfigurationFactory<>(
    MutableSchedulerConfiguration.class,
    BaseValidator.newValidator(),
    Jackson.newObjectMapper().registerModule(new GuavaModule())
      .registerModule(new Jdk8Module()),
    "dw");

  configuration = factory.build(
    new SubstitutingSourceProvider(
      new FileConfigurationSourceProvider(),
      new EnvironmentVariableSubstitutor(false, true)),
    Resources.getResource("scheduler.yml").getFile());
}
 
Example #25
Source File: ConfigurationManagerTest.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
@Test
public void failOnBadServersCount() throws Exception {
    MutableSchedulerConfiguration mutable = configurationFactory.build(
            new SubstitutingSourceProvider(
                    new FileConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false, true)),
            Resources.getResource("scheduler.yml").getFile());
    CassandraSchedulerConfiguration originalConfig = mutable.createConfig();
    final CuratorFrameworkConfig curatorConfig = mutable.getCuratorConfig();
    RetryPolicy retryPolicy =
            (curatorConfig.getOperationTimeout().isPresent()) ?
                    new RetryUntilElapsed(
                            curatorConfig.getOperationTimeoutMs()
                                    .get()
                                    .intValue()
                            , (int) curatorConfig.getBackoffMs()) :
                    new RetryForever((int) curatorConfig.getBackoffMs());

    StateStore stateStore = new CuratorStateStore(
            originalConfig.getServiceConfig().getName(),
            server.getConnectString(),
            retryPolicy);
    DefaultConfigurationManager configurationManager =
            new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
            originalConfig.getServiceConfig().getName(),
            connectString,
            originalConfig,
            new ConfigValidator(),
            stateStore);
    ConfigurationManager manager = new ConfigurationManager(taskFactory, configurationManager);
    CassandraSchedulerConfiguration targetConfig = (CassandraSchedulerConfiguration)configurationManager.getTargetConfig();

    manager.start();

    assertEquals(originalConfig.getCassandraConfig(), targetConfig.getCassandraConfig());
    assertEquals(originalConfig.getExecutorConfig(), targetConfig.getExecutorConfig());
    assertEquals(originalConfig.getServers(), targetConfig.getServers());
    assertEquals(originalConfig.getSeeds(), targetConfig.getSeeds());

    manager.stop();

    int updatedServers = originalConfig.getServers() - 1;
    mutable.setServers(updatedServers);

    configurationManager =
            new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
            originalConfig.getServiceConfig().getName(),
            connectString,
            mutable.createConfig(),
            new ConfigValidator(),
            stateStore);
    manager = new ConfigurationManager(taskFactory, configurationManager);

    manager.start();

    assertEquals(1, configurationManager.getErrors().size());
}
 
Example #26
Source File: ConfigurationManagerTest.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
@Test
public void failOnBadSeedsCount() throws Exception {
    MutableSchedulerConfiguration mutableSchedulerConfiguration = configurationFactory.build(
            new SubstitutingSourceProvider(
                    new FileConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false, true)),
            Resources.getResource("scheduler.yml").getFile());
    CassandraSchedulerConfiguration originalConfig = mutableSchedulerConfiguration.createConfig();
    final CuratorFrameworkConfig curatorConfig = mutableSchedulerConfiguration.getCuratorConfig();
    RetryPolicy retryPolicy =
            (curatorConfig.getOperationTimeout().isPresent()) ?
                    new RetryUntilElapsed(
                            curatorConfig.getOperationTimeoutMs()
                                    .get()
                                    .intValue()
                            , (int) curatorConfig.getBackoffMs()) :
                    new RetryForever((int) curatorConfig.getBackoffMs());

    StateStore stateStore = new CuratorStateStore(
            originalConfig.getServiceConfig().getName(),
            server.getConnectString(),
            retryPolicy);
    DefaultConfigurationManager configurationManager
            = new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
            originalConfig.getServiceConfig().getName(),
            connectString,
            originalConfig,
            new ConfigValidator(),
            stateStore);
    ConfigurationManager manager = new ConfigurationManager(taskFactory, configurationManager);
    CassandraSchedulerConfiguration targetConfig = (CassandraSchedulerConfiguration)configurationManager.getTargetConfig();

    manager.start();

    assertEquals(originalConfig.getCassandraConfig(), targetConfig.getCassandraConfig());
    assertEquals(originalConfig.getExecutorConfig(), targetConfig.getExecutorConfig());
    assertEquals(originalConfig.getServers(), targetConfig.getServers());
    assertEquals(originalConfig.getSeeds(), targetConfig.getSeeds());

    manager.stop();

    int updatedSeeds = originalConfig.getServers() + 1;
    mutableSchedulerConfiguration.setSeeds(updatedSeeds);

    configurationManager =
            new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
            originalConfig.getServiceConfig().getName(),
            connectString,
            mutableSchedulerConfiguration.createConfig(),
            new ConfigValidator(),
            stateStore);
    manager = new ConfigurationManager(taskFactory, configurationManager);
    manager.start();
    assertEquals(1, configurationManager.getErrors().size());
}
 
Example #27
Source File: OxdServerApplication.java    From oxd with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(Bootstrap<OxdServerConfiguration> bootstrap) {
    bootstrap.setConfigurationSourceProvider(new SubstitutingSourceProvider(
            bootstrap.getConfigurationSourceProvider(), new EnvironmentVariableSubstitutor(false)));
}
 
Example #28
Source File: CassandraStateTest.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
@Before
public void beforeEach() throws Exception {
    server = new TestingServer();

    server.start();

    final ConfigurationFactory<MutableSchedulerConfiguration> factory =
            new ConfigurationFactory<>(
                    MutableSchedulerConfiguration.class,
                    BaseValidator.newValidator(),
                    Jackson.newObjectMapper().registerModule(
                            new GuavaModule())
                            .registerModule(new Jdk8Module()),
                    "dw");

    config = factory.build(
            new SubstitutingSourceProvider(
                    new FileConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false, true)),
            Resources.getResource("scheduler.yml").getFile());

    ServiceConfig initial = config.createConfig().getServiceConfig();

    final CassandraSchedulerConfiguration targetConfig = config.createConfig();
    clusterTaskConfig = targetConfig.getClusterTaskConfig();

    final CuratorFrameworkConfig curatorConfig = config.getCuratorConfig();
    RetryPolicy retryPolicy =
            (curatorConfig.getOperationTimeout().isPresent()) ?
                    new RetryUntilElapsed(
                            curatorConfig.getOperationTimeoutMs()
                                    .get()
                                    .intValue()
                            , (int) curatorConfig.getBackoffMs()) :
                    new RetryForever((int) curatorConfig.getBackoffMs());

    stateStore = new CuratorStateStore(
            targetConfig.getServiceConfig().getName(),
            server.getConnectString(),
            retryPolicy);
    stateStore.storeFrameworkId(Protos.FrameworkID.newBuilder().setValue("1234").build());
    identity = new IdentityManager(
            initial,stateStore);

    identity.register("test_id");

    DefaultConfigurationManager configurationManager =
            new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
            config.createConfig().getServiceConfig().getName(),
            server.getConnectString(),
            config.createConfig(),
            new ConfigValidator(),
            stateStore);

    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    when(mockCapabilities.supportsNamedVips()).thenReturn(true);
    configuration = new ConfigurationManager(
            new CassandraDaemonTask.Factory(mockCapabilities),
            configurationManager);

    cassandraState = new CassandraState(
            configuration,
            clusterTaskConfig,
            stateStore);
}
 
Example #29
Source File: ServiceConfigResourceTest.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeAll() throws Exception {

    server = new TestingServer();

    server.start();

    final ConfigurationFactory<MutableSchedulerConfiguration> factory =
            new ConfigurationFactory<>(
                    MutableSchedulerConfiguration.class,
                    BaseValidator.newValidator(),
                    Jackson.newObjectMapper().registerModule(
                            new GuavaModule())
                            .registerModule(new Jdk8Module()),
                    "dw");

    config = factory.build(
            new SubstitutingSourceProvider(
                    new FileConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false, true)),
            Resources.getResource("scheduler.yml").getFile());

    final CuratorFrameworkConfig curatorConfig = config.getCuratorConfig();
    RetryPolicy retryPolicy =
            (curatorConfig.getOperationTimeout().isPresent()) ?
                    new RetryUntilElapsed(
                            curatorConfig.getOperationTimeoutMs()
                                    .get()
                                    .intValue()
                            , (int) curatorConfig.getBackoffMs()) :
                    new RetryForever((int) curatorConfig.getBackoffMs());

    stateStore = new CuratorStateStore(
            config.createConfig().getServiceConfig().getName(),
            server.getConnectString(),
            retryPolicy);

    final CassandraSchedulerConfiguration configuration = config.createConfig();
    try {
        final ConfigValidator configValidator = new ConfigValidator();
        final DefaultConfigurationManager defaultConfigurationManager =
                new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
                configuration.getServiceConfig().getName(),
                server.getConnectString(),
                configuration,
                configValidator,
                stateStore);
        Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
        when(mockCapabilities.supportsNamedVips()).thenReturn(true);
        configurationManager = new ConfigurationManager(
                new CassandraDaemonTask.Factory(mockCapabilities),
                defaultConfigurationManager);
    } catch (ConfigStoreException e) {
        throw new RuntimeException(e);
    }
}
 
Example #30
Source File: ConfigurationResourceTest.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeAll() throws Exception {
    server = new TestingServer();
    server.start();
    final ConfigurationFactory<MutableSchedulerConfiguration> factory =
            new ConfigurationFactory<>(
                    MutableSchedulerConfiguration.class,
                    BaseValidator.newValidator(),
                    Jackson.newObjectMapper().registerModule(
                            new GuavaModule())
                            .registerModule(new Jdk8Module()),
                    "dw");
    MutableSchedulerConfiguration mutable = factory.build(
            new SubstitutingSourceProvider(
                    new FileConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false, true)),
            Resources.getResource("scheduler.yml").getFile());
    config = mutable.createConfig();

    final CuratorFrameworkConfig curatorConfig = mutable.getCuratorConfig();
    RetryPolicy retryPolicy =
            (curatorConfig.getOperationTimeout().isPresent()) ?
                    new RetryUntilElapsed(
                            curatorConfig.getOperationTimeoutMs()
                                    .get()
                                    .intValue()
                            , (int) curatorConfig.getBackoffMs()) :
                    new RetryForever((int) curatorConfig.getBackoffMs());

    StateStore stateStore = new CuratorStateStore(
            config.getServiceConfig().getName(),
            server.getConnectString(),
            retryPolicy);
    configurationManager =
            new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
            config.getServiceConfig().getName(),
            server.getConnectString(),
            config,
            new ConfigValidator(),
            stateStore);
    config = (CassandraSchedulerConfiguration) configurationManager.getTargetConfig();
}