io.dropwizard.configuration.FileConfigurationSourceProvider Java Examples

The following examples show how to use io.dropwizard.configuration.FileConfigurationSourceProvider. 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 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
Source File: CassandraTaskFactoryTest.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
@Before
public void beforeEach() throws Exception {
    MockitoAnnotations.initMocks(this);
    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);

    taskFactory = new CassandraTaskFactory(executorDriver);
}
 
Example #9
Source File: ClusterTaskOfferRequirementProviderTest.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();
    ServiceConfig initial = config.getServiceConfig();

    clusterTaskConfig = config.getClusterTaskConfig();

    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 = new CuratorStateStore(
            config.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.getServiceConfig().getName(),
            server.getConnectString(),
            config,
            new ConfigValidator(),
            stateStore);
    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    when(mockCapabilities.supportsNamedVips()).thenReturn(true);
    configuration = new ConfigurationManager(
            new CassandraDaemonTask.Factory(mockCapabilities),
            configurationManager);

    provider = new ClusterTaskOfferRequirementProvider();
}
 
Example #10
Source File: CassandraDaemonStepTest.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
@Before
public void beforeEach() throws Exception {
    MockitoAnnotations.initMocks(this);
    server = new TestingServer();
    server.start();

    Capabilities mockCapabilities = mock(Capabilities.class);
    when(mockCapabilities.supportsNamedVips()).thenReturn(true);
    taskFactory = new CassandraDaemonTask.Factory(mockCapabilities);

    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 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());

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

    cassandraState = new CassandraState(
            new ConfigurationManager(taskFactory, configurationManager),
            clusterTaskConfig,
            stateStore);
}
 
Example #11
Source File: CassandraSchedulerTest.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
private void beforeHelper(String configName) throws Exception {
    MockitoAnnotations.initMocks(this);
    mesosConfig = Mockito.mock(MesosConfig.class);

    client = Mockito.mock(SchedulerClient.class);
    Mockito.when(mockFuture.get()).thenReturn(true);
    Mockito.when(mockStage.toCompletableFuture()).thenReturn(mockFuture);
    backup = Mockito.mock(BackupManager.class);
    restore = Mockito.mock(RestoreManager.class);
    cleanup = Mockito.mock(CleanupManager.class);
    repair = Mockito.mock(RepairManager.class);
    upgrade = Mockito.mock(UpgradeSSTableManager.class);
    seeds = Mockito.mock(SeedsManager.class);
    capabilities = Mockito.mock(Capabilities.class);

    executorService = Executors.newSingleThreadScheduledExecutor();
    frameworkId = TestUtils.generateFrameworkId();

    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(configName).getFile());

    stateStore = new CuratorStateStore(
            "/" + config.getServiceConfig().getName(),
            server.getConnectString());

    DefaultConfigurationManager defaultConfigurationManager
            = 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);
    configurationManager = new ConfigurationManager(
            new CassandraDaemonTask.Factory(mockCapabilities),
            defaultConfigurationManager);
    cassandraState = new CassandraState(
            configurationManager,
            configurationManager.getTargetConfig().getClusterTaskConfig(),
            stateStore);

    offerRequirementProvider = new PersistentOfferRequirementProvider(defaultConfigurationManager);
    scheduler = new CassandraScheduler(
            configurationManager,
            mesosConfig,
            offerRequirementProvider,
            cassandraState,
            client,
            backup,
            restore,
            cleanup,
            repair,
            upgrade,
            true,
            seeds,
            executorService,
            stateStore,
            defaultConfigurationManager,
            capabilities);

    masterInfo = TestUtils.generateMasterInfo();

    driver = new QueuedSchedulerDriver();
    scheduler.setSchedulerDriver(driver);
    scheduler.registered(driver, frameworkId, masterInfo);
}
 
Example #12
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();
}
 
Example #13
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 #14
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 #15
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 #16
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 #17
Source File: ConfigurationManagerTest.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
@Test
public void serializeDeserializeExecutorConfig() throws Exception {
    MutableSchedulerConfiguration mutable = configurationFactory.build(
            new SubstitutingSourceProvider(
                    new FileConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false, true)),
            Resources.getResource("scheduler.yml").getFile());
    final CassandraSchedulerConfiguration original = mutable.createConfig();
    final CuratorFrameworkConfig curatorConfig = mutable.getCuratorConfig();

    mutable.setCassandraConfig(
            mutable.getCassandraConfig()
                    .mutable().setJmxPort(8000).setCpus(0.6).setMemoryMb(10000).build());

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

    StateStore stateStore = new CuratorStateStore(
            original.getServiceConfig().getName(),
            server.getConnectString(),
            retryPolicy);

    DefaultConfigurationManager configurationManager =
            new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
                    original.getServiceConfig().getName(),
                    connectString,
                    original,
                    new ConfigValidator(),
                    stateStore);

    configurationManager.store(original);
    ConfigurationManager manager = new ConfigurationManager(taskFactory, configurationManager);
    CassandraSchedulerConfiguration targetConfig =
            (CassandraSchedulerConfiguration)configurationManager.getTargetConfig();

    ExecutorConfig expectedExecutorConfig = new ExecutorConfig(
            "export LD_LIBRARY_PATH=$MESOS_SANDBOX/libmesos-bundle/lib:$LD_LIBRARY_PATH && export MESOS_NATIVE_JAVA_LIBRARY=$(ls $MESOS_SANDBOX/libmesos-bundle/lib/libmesos-*.so) && ./executor/bin/cassandra-executor server executor/conf/executor.yml",
            new ArrayList<>(),
            0.1,
            768,
            512,
            9000,
            "./jre",
            URI.create("https://downloads.mesosphere.com/java/jre-8u121-linux-x64.tar.gz"),
            URI.create("https://s3-us-west-2.amazonaws.com/cassandra-framework-dev/testing/executor.zip"),
            URI.create("https://s3-us-west-2.amazonaws.com/cassandra-framework-dev/testing/apache-cassandra-2.2.5-bin.tar.gz"),
            URI.create("http://downloads.mesosphere.com/libmesos-bundle/libmesos-bundle-1.8.8-1.0.3-rc1-1.tar.gz"),
            false);

    manager.start();

    assertEquals(original.getCassandraConfig(), targetConfig.getCassandraConfig());

    assertEquals(expectedExecutorConfig, targetConfig.getExecutorConfig());

    manager.stop();
}
 
Example #18
Source File: ConfigurationManagerTest.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
@Test
public void applyConfigUpdate() throws Exception {
    MutableSchedulerConfiguration mutable = configurationFactory.build(
            new SubstitutingSourceProvider(
                    new FileConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false, true)),
            Resources.getResource("scheduler.yml").getFile());
    final CassandraSchedulerConfiguration original = 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(
            original.getServiceConfig().getName(),
            server.getConnectString(),
            retryPolicy);
    DefaultConfigurationManager configurationManager
            = new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
            original.getServiceConfig().getName(),
            connectString,
            original,
            new ConfigValidator(),
            stateStore);
    ConfigurationManager manager = new ConfigurationManager(taskFactory, configurationManager);
    CassandraSchedulerConfiguration targetConfig =
      (CassandraSchedulerConfiguration)configurationManager.getTargetConfig();

    manager.start();

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

    manager.stop();

    ExecutorConfig updatedExecutorConfig = new ExecutorConfig(
            "/command/line",
            new ArrayList<>(),
            1.2,
            345,
            901,
            17,
            "/java/home",
            URI.create("/jre/location"), URI.create("/executor/location"),
            URI.create("/cassandra/location"),
            URI.create("/libmesos/location"),
            false);
    int updatedServers = original.getServers() + 10;
    int updatedSeeds = original.getSeeds() + 5;

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

    mutable.setSeeds(updatedSeeds);
    mutable.setServers(updatedServers);
    mutable.setExecutorConfig(updatedExecutorConfig);

    mutable.setCassandraConfig(
      mutable.getCassandraConfig()
    .mutable().setJmxPort(8000).setCpus(0.6).setMemoryMb(10000).build());

    CassandraSchedulerConfiguration updated = mutable.createConfig();

    configurationManager =
            new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
            original.getServiceConfig().getName(),
            connectString,
            updated,
            new ConfigValidator(),
            stateStore);
    configurationManager.store(updated);
    manager = new ConfigurationManager(taskFactory, configurationManager);
    targetConfig = (CassandraSchedulerConfiguration)configurationManager.getTargetConfig();

    manager.start();

    assertEquals(updated.getCassandraConfig(), targetConfig.getCassandraConfig());

    assertEquals(updatedExecutorConfig, targetConfig.getExecutorConfig());

    assertEquals(updatedServers, targetConfig.getServers());

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

    StateStore stateStore = new CuratorStateStore(
            original.getServiceConfig().getName(),
            server.getConnectString(),
            retryPolicy);
    DefaultConfigurationManager configurationManager =
            new DefaultConfigurationManager(CassandraSchedulerConfiguration.class,
            original.getServiceConfig().getName(),
            connectString,
            original,
            new ConfigValidator(),
            stateStore);
    ConfigurationManager manager = new ConfigurationManager(taskFactory, configurationManager);
    CassandraSchedulerConfiguration targetConfig = (CassandraSchedulerConfiguration)configurationManager.getTargetConfig();
    assertEquals("cassandra", original.getServiceConfig().getName());
    assertEquals("cassandra-role", original.getServiceConfig().getRole());
    assertEquals("cassandra-cluster", original.getServiceConfig().getCluster());
    assertEquals("cassandra-principal",
            original.getServiceConfig().getPrincipal());
    assertEquals("", original.getServiceConfig().getSecret());

    manager.start();

    assertEquals(original.getCassandraConfig(), targetConfig.getCassandraConfig());
    assertEquals(original.getExecutorConfig(), targetConfig.getExecutorConfig());
    assertEquals(original.getServers(), targetConfig.getServers());
    assertEquals(original.getSeeds(), targetConfig.getSeeds());
}