io.dropwizard.configuration.ConfigurationFactory Java Examples

The following examples show how to use io.dropwizard.configuration.ConfigurationFactory. 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: MacroBaseConfTest.java    From macrobase with Apache License 2.0 6 votes vote down vote up
@Test
public void testParsing() throws Exception {
    ConfigurationFactory<MacroBaseConf> cfFactory = new YamlConfigurationFactory<>(MacroBaseConf.class,
                                                                               null,
                                                                               Jackson.newObjectMapper(),
                                                                               "");
    MacroBaseConf conf = cfFactory.build(new File("src/test/resources/conf/simple.yaml"));


    assertEquals((Double) 0.1, conf.getDouble("this.is.a.double"));
    assertEquals((Integer) 100, conf.getInt("this.is.an.integer"));
    assertEquals((Long) 10000000000000L, conf.getLong("this.is.a.long"));
    assertEquals("Test", conf.getString("this.is.a.string"));

    List<String> stringList = Lists.newArrayList("T1", "T2", "T3", "T4");
    assertArrayEquals(stringList.toArray(), conf.getStringList("this.is.a.stringList").toArray());
    assertArrayEquals(stringList.toArray(), conf.getStringList("this.is.a.stringList.without.spaces").toArray());
    assertArrayEquals(stringList.toArray(), conf.getStringList("this.is.a.stringList.with.mixed.spaces").toArray());
}
 
Example #2
Source File: GuiceBundle.java    From soabase with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(Bootstrap<?> bootstrap)
{
    final InjectableValues injectableValues = new InjectableValues()
    {
        @Override
        public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty, Object beanInstance)
        {
            return null;
        }
    };
    final ConfigurationFactoryFactory<? extends Configuration> configurationFactoryFactory = bootstrap.getConfigurationFactoryFactory();
    ConfigurationFactoryFactory factoryFactory = new ConfigurationFactoryFactory()
    {
        @Override
        public ConfigurationFactory create(Class klass, Validator validator, ObjectMapper objectMapper, String propertyPrefix)
        {
            objectMapper.setInjectableValues(injectableValues);
            //noinspection unchecked
            return configurationFactoryFactory.create(klass, validator, objectMapper, propertyPrefix);
        }
    };
    //noinspection unchecked
    bootstrap.setConfigurationFactoryFactory(factoryFactory);
}
 
Example #3
Source File: ConfigurationManagerTest.java    From dcos-cassandra-service with Apache License 2.0 6 votes vote down vote up
@Before
public void beforeAll() throws Exception {
    server = new TestingServer();
    server.start();
    Capabilities mockCapabilities = Mockito.mock(Capabilities.class);
    when(mockCapabilities.supportsNamedVips()).thenReturn(true);
    taskFactory = new CassandraDaemonTask.Factory(mockCapabilities);
    configurationFactory = new ConfigurationFactory<>(
                    MutableSchedulerConfiguration.class,
                    BaseValidator.newValidator(),
                    Jackson.newObjectMapper()
                            .registerModule(new GuavaModule())
                            .registerModule(new Jdk8Module()),
                    "dw");
    connectString = server.getConnectString();
}
 
Example #4
Source File: BaseRoleConnectHelper.java    From emodb with Apache License 2.0 5 votes vote down vote up
protected EmoConfiguration getConfigurationFromResource()  throws Exception {
    URL url = BaseRoleConnectHelper.class.getResource(_configFileResource);
    Preconditions.checkNotNull(url, _configFileResource);
    File file = new File (url.toURI());
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    ObjectMapper mapper = EmoServiceObjectMapperFactory.build(new YAMLFactory());

    ConfigurationFactory<EmoConfiguration> configFactory = new ConfigurationFactory<>(EmoConfiguration.class, validator, mapper, "dw");
    return configFactory.build(file);
}
 
Example #5
Source File: AbstractResourceTest.java    From monasca-common with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a configuration object read in from the {@code fileName}.
 */
protected <T extends Configuration> T getConfiguration(String filename,
    Class<T> configurationClass) throws Exception {
  final ConfigurationFactory<T> configurationFactory = new ConfigurationFactory<>(
      configurationClass, validator, objectMapper, "dw");
  if (filename != null) {
    final File file = new File(Resources.getResource(filename).getFile());
    if (!file.exists())
      throw new FileNotFoundException("File " + file + " not found");
    return configurationFactory.build(file);
  }

  return configurationFactory.build();
}
 
Example #6
Source File: TestUtils.java    From oxd with Apache License 2.0 5 votes vote down vote up
public static OxdServerConfiguration parseConfiguration(String pathToYaml) throws IOException, ConfigurationException {

        File file = new File(pathToYaml);
        if (!file.exists()) {
            System.out.println("Failed to find yml configuration file. Please check " + pathToYaml);
            System.exit(1);
        }

        DefaultConfigurationFactoryFactory<OxdServerConfiguration> configurationFactoryFactory = new DefaultConfigurationFactoryFactory<>();
        ConfigurationFactory<OxdServerConfiguration> configurationFactory = configurationFactoryFactory.create(OxdServerConfiguration.class, Validators.newValidatorFactory().getValidator(), Jackson.newObjectMapper(), "dw");
        return configurationFactory.build(file);
    }
 
Example #7
Source File: Cli.java    From oxd with Apache License 2.0 5 votes vote down vote up
private static OxdServerConfiguration parseConfiguration(String pathToYaml) throws IOException, ConfigurationException {
    if (StringUtils.isBlank(pathToYaml)) {
        System.out.println("Path to yml configuration file is not specified. Exit!");
        System.exit(1);
    }
    File file = new File(pathToYaml);
    if (!file.exists()) {
        System.out.println("Failed to find yml configuration file. Please check " + pathToYaml);
        System.exit(1);
    }

    DefaultConfigurationFactoryFactory<OxdServerConfiguration> configurationFactoryFactory = new DefaultConfigurationFactoryFactory<>();
    ConfigurationFactory<OxdServerConfiguration> configurationFactory = configurationFactoryFactory.create(OxdServerConfiguration.class, Validators.newValidatorFactory().getValidator(), Jackson.newObjectMapper(), "dw");
    return configurationFactory.build(file);
}
 
Example #8
Source File: CloudWatchReporterFactoryTest.java    From dropwizard-metrics-cloudwatch with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyConfigurable() throws Exception {
    ObjectMapper mapper = Jackson.newObjectMapper();

    // dropwizard 0.9.1 changed the validation wiring a bit..
    Class<ValidatedValueUnwrapper> optValidatorClazz = (Class<ValidatedValueUnwrapper>) Class
            .forName("io.dropwizard.validation.valuehandling.OptionalValidatedValueUnwrapper");

    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    if (optValidatorClazz != null) {
        validator = Validation.byProvider(HibernateValidator.class).configure()
                .addValidatedValueHandler(optValidatorClazz.newInstance())
                .buildValidatorFactory().getValidator();
    }

    ConfigurationFactory<CloudWatchReporterFactory> configFactory =
            new ConfigurationFactory<>(CloudWatchReporterFactory.class,
                    validator, mapper, "dw");
    CloudWatchReporterFactory f = configFactory.build(new File(Resources.getResource("cw.yml").getFile()));

    assertEquals("[env=default]", f.getGlobalDimensions().toString());
    assertEquals("us-east-1", f.getAwsRegion());
    assertEquals("a.b", f.getNamespace());
    assertEquals("XXXXX", f.getAwsSecretKey());
    assertEquals("11111", f.getAwsAccessKeyId());
    assertEquals("p.neustar.biz", f.getAwsClientConfiguration().getProxyHost());
    assertNull(f.getAwsClientConfiguration().getProxyUsername());
}
 
Example #9
Source File: ClientExample.java    From alchemy with MIT License 5 votes vote down vote up
private static AlchemyClient buildClient(String configurationFile) throws Exception {
    final Validator validator = BaseValidator.newValidator();
    final ObjectMapper mapper = Jackson.newObjectMapper();
    mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
    final ConfigurationFactory<AlchemyClientConfiguration> configurationFactory =
        new DefaultConfigurationFactoryFactory<AlchemyClientConfiguration>().create(
            AlchemyClientConfiguration.class,
            validator,
            mapper,
            "");

    return new AlchemyClient(
        configurationFactory.build(new File(configurationFile))
    );
}
 
Example #10
Source File: AdminConsoleAppBuilder.java    From soabase with Apache License 2.0 5 votes vote down vote up
public AdminConsoleAppBuilder<T> withConfigurationClass(final Class<T> configurationClass)
{
    factoryFactory = new ConfigurationFactoryFactory<T>()
    {
        @Override
        public ConfigurationFactory<T> create(Class<T> klass, Validator validator, ObjectMapper objectMapper, String propertyPrefix)
        {
            return new YamlConfigurationFactory<>(configurationClass, validator, objectMapper, propertyPrefix);
        }
    };
    return this;
}
 
Example #11
Source File: TestFlexibleConfigurationSourceProvider.java    From soabase with Apache License 2.0 5 votes vote down vote up
@Test
public void testViaDW() throws Exception
{
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    ObjectMapper objectMapper = Jackson.newObjectMapper();
    ConfigurationFactory<MyConfiguration> configurationFactory = new DefaultConfigurationFactoryFactory<MyConfiguration>().create(MyConfiguration.class, validator, objectMapper, "dw");
    MyConfiguration configuration = configurationFactory.build(new FlexibleConfigurationSourceProvider(), "%{\"testValue\": \"override\"}");
    Assert.assertEquals("override", configuration.testValue);
}
 
Example #12
Source File: KafkaConfigTest.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Test
public void ensureKafkaDefaultConfigDeserialization()
    throws IOException, URISyntaxException, ConfigurationException {
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    ObjectMapper mapper = CustomJsonObjectMapperFactory.build(new YAMLFactory());
    ConfigurationFactory configurationFactory = new ConfigurationFactory(KafkaConfiguration.class, validator, mapper, "dw");
    // Make sure that our config files are up to date
    configurationFactory.build(
        new File(KafkaConfiguration.class.getResource("/emodb-kafka-config.yaml").toURI()));
}
 
Example #13
Source File: MegabusConfigTest.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Test
public void ensureMegabusDefaultConfigDeserialization()
    throws IOException, URISyntaxException, ConfigurationException {
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    ObjectMapper mapper = CustomJsonObjectMapperFactory.build(new YAMLFactory());
    ConfigurationFactory configurationFactory = new ConfigurationFactory(MegabusConfiguration.class, validator, mapper, "dw");
    // Make sure that our config files are up to date
    configurationFactory.build(
        new File(MegabusConfiguration.class.getResource("/emodb-megabus-config.yaml").toURI()));
}
 
Example #14
Source File: SdkConfigTest.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Test
public void ensureSdkDefaultConfigDeserialization()
        throws IOException, URISyntaxException, ConfigurationException {
    // This test makes sure that we haven't forgotten to update the emodb sdk default config file when we add/remove properties
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    ObjectMapper mapper = EmoServiceObjectMapperFactory.build(new YAMLFactory());
    ConfigurationFactory configurationFactory = new ConfigurationFactory(EmoConfiguration.class, validator, mapper, "dw");
    // Make sure that our config files are up to date
    configurationFactory.build(
    new File(EmoStartMojo.class.getResource("/emodb-default-config.yaml").toURI()));
}
 
Example #15
Source File: EmoService.java    From emodb with Apache License 2.0 5 votes vote down vote up
private EmoConfiguration loadConfigFile(File configFile)
        throws IOException, ConfigurationException {
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    ObjectMapper mapper = EmoServiceObjectMapperFactory.build(new YAMLFactory());
    ConfigurationFactory<EmoConfiguration> configurationFactory = new ConfigurationFactory(EmoConfiguration.class, validator, mapper, "dw");
    return configurationFactory.build(configFile);
}
 
Example #16
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 #17
Source File: SorStressTest.java    From emodb with Apache License 2.0 4 votes vote down vote up
public static void main(String... args) throws Exception {
    final String DROPWIZARD_PROPERTY_PREFIX = "dw";

    // Load the config.yaml file specified as the first argument.
    ConfigurationFactory<EmoConfiguration> configFactory = new ConfigurationFactory(
            EmoConfiguration.class, Validation.buildDefaultValidatorFactory().getValidator(), Jackson.newObjectMapper(), DROPWIZARD_PROPERTY_PREFIX);
    EmoConfiguration configuration = configFactory.build(new File(args[0]));
    int numWriterThreads = Integer.parseInt(args[1]);
    int numReaderThreads = Integer.parseInt(args[2]);
    String apiKey = configuration.getAuthorizationConfiguration().getAdminApiKey();

    MetricRegistry metricRegistry = new MetricRegistry();
    new LoggingFactory().configure(metricRegistry, "stress");

    CuratorFramework curator = configuration.getZooKeeperConfiguration().newCurator();
    curator.start();

    DataStoreClientFactory dataStoreFactory = DataStoreClientFactory.forClusterAndHttpConfiguration(
            configuration.getCluster(), configuration.getHttpClientConfiguration(), metricRegistry);
    AuthDataStore authDataStore = ServicePoolBuilder.create(AuthDataStore.class)
            .withServiceFactory(dataStoreFactory)
            .withHostDiscovery(new ZooKeeperHostDiscovery(curator, dataStoreFactory.getServiceName(), metricRegistry))
            .withMetricRegistry(metricRegistry)
            .withCachingPolicy(ServiceCachingPolicyBuilder.getMultiThreadedClientPolicy())
            .buildProxy(new ExponentialBackoffRetry(5, 50, 1000, TimeUnit.MILLISECONDS));
    DataStore dataStore = DataStoreAuthenticator.proxied(authDataStore).usingCredentials(apiKey);

    DatabusClientFactory databusFactory = DatabusClientFactory.forClusterAndHttpConfiguration(
            configuration.getCluster(), configuration.getHttpClientConfiguration(), metricRegistry);
    AuthDatabus authDatabus = ServicePoolBuilder.create(AuthDatabus.class)
            .withServiceFactory(databusFactory)
            .withHostDiscovery(new ZooKeeperHostDiscovery(curator, databusFactory.getServiceName(), metricRegistry))
            .withMetricRegistry(metricRegistry)
            .withCachingPolicy(ServiceCachingPolicyBuilder.getMultiThreadedClientPolicy())
            .buildProxy(new ExponentialBackoffRetry(5, 50, 1000, TimeUnit.MILLISECONDS));
    Databus databus = DatabusAuthenticator.proxied(authDatabus).usingCredentials(apiKey);

    final SorStressTest stressTest = new SorStressTest(dataStore, databus);

    if (!dataStore.getTableExists(TABLE)) {
        TableOptions options = new TableOptionsBuilder().setPlacement("ugc_global:ugc").build();
        dataStore.createTable(TABLE, options, ImmutableMap.of("table", TABLE), new AuditBuilder().setLocalHost().build());
    }

    databus.subscribe(SUBSCRIPTION, Conditions.alwaysTrue(), Duration.ofDays(7), Duration.ofDays(1));

    ThreadFactory writerFactory = new ThreadFactoryBuilder().setNameFormat("SoR Writer-%d").build();
    for (int i = 0; i < numWriterThreads; i++) {
        writerFactory.newThread(new Runnable() {
            @Override
            public void run() {
                stressTest.writeDeltas();
            }
        }).start();
    }

    ThreadFactory readerFactory = new ThreadFactoryBuilder().setNameFormat("Databus Reader-%d").build();
    for (int i = 0; i < numReaderThreads; i++) {
        readerFactory.newThread(new Runnable() {
            @Override
            public void run() {
                stressTest.readDatabus();
            }
        }).start();
    }

    ThreadFactory reportFactory = new ThreadFactoryBuilder().setNameFormat("Report-%d").build();
    Executors.newScheduledThreadPool(1, reportFactory).scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            stressTest.report();
        }
    }, 1, 1, TimeUnit.SECONDS);

    ServicePoolProxies.close(dataStore);
    Closeables.close(curator, true);
}
 
Example #18
Source File: ScanUploadTest.java    From emodb with Apache License 2.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
    // Load the config.yaml file specified as the first argument.
    ConfigurationFactory<EmoConfiguration> configFactory = new ConfigurationFactory<>(
            EmoConfiguration.class, validatorFactory.getValidator(), Jackson.newObjectMapper(),
            "dw");
    File configFile = new File(args[0]);
    EmoConfiguration configuration = configFactory.build(configFile);
    String ddlFilePath = args[1];
    File scanUploadDir = new File(args[2]);

    checkArgument(scanUploadDir.isDirectory(), "Not a valid directory: %s", scanUploadDir);
    checkArgument(configuration.getServiceMode() == EmoServiceMode.SCANNER,
            "Not configured for scanner: %s", configuration.getServiceMode());

    // To prevent conflicting with EmoDB running on this same server adjust the host and admin ports.
    updatePortsToAvoidCollision(configuration.getServerFactory());

    HostAndPort hostAndPort = new SelfHostAndPortModule().provideSelfHostAndPort(configuration.getServerFactory());
    MetricRegistry metricRegistry = new MetricRegistry();
    configuration.getLoggingFactory().configure(metricRegistry, "scan");

    DataStore dataStore = null;

    try (CuratorFramework curator = configuration.getZooKeeperConfiguration().newCurator()) {
        curator.start();

        DataStoreClientFactory dataStoreFactory = DataStoreClientFactory.forClusterAndHttpConfiguration(
                configuration.getCluster(), configuration.getHttpClientConfiguration(), metricRegistry);
        dataStore = ServicePoolBuilder.create(DataStore.class)
                .withServiceFactory(dataStoreFactory.usingCredentials(configuration.getScanner().get().getScannerApiKey().get()))
                .withHostDiscovery(new ZooKeeperHostDiscovery(curator, dataStoreFactory.getServiceName(), metricRegistry))
                .withCachingPolicy(ServiceCachingPolicyBuilder.getMultiThreadedClientPolicy())
                .withMetricRegistry(metricRegistry)
                .buildProxy(new ExponentialBackoffRetry(5, 50, 1000, TimeUnit.MILLISECONDS));

        ScanUploadTest test = new ScanUploadTest(dataStore);
        test.createAndPopulateTestTables();
        test.scanToDirectory(configuration, ddlFilePath, configFile, scanUploadDir, hostAndPort, validatorFactory, metricRegistry);
        test.validateScanResults(scanUploadDir);
    } finally {
        if (dataStore != null) {
            ServicePoolProxies.close(dataStore);
        }
    }
}
 
Example #19
Source File: QueueStressTest.java    From emodb with Apache License 2.0 4 votes vote down vote up
public static void main(String... args) throws Exception {
    final String DROPWIZARD_PROPERTY_PREFIX = "dw";

    // Load the config.yaml file specified as the first argument.
    ConfigurationFactory<EmoConfiguration> configFactory = new ConfigurationFactory(
            EmoConfiguration.class, Validation.buildDefaultValidatorFactory().getValidator(), Jackson.newObjectMapper(), DROPWIZARD_PROPERTY_PREFIX);
    EmoConfiguration configuration = configFactory.build(new File(args[0]));
    int numWriterThreads = Integer.parseInt(args[1]);
    int numReaderThreads = Integer.parseInt(args[2]);
    String adminApiKey = configuration.getAuthorizationConfiguration().getAdminApiKey();

    MetricRegistry metricRegistry = new MetricRegistry();
    new LoggingFactory().configure(metricRegistry, "stress");

    CuratorFramework curator = configuration.getZooKeeperConfiguration().newCurator();
    curator.start();

    QueueClientFactory queueFactory = QueueClientFactory.forClusterAndHttpConfiguration(
            configuration.getCluster(), configuration.getHttpClientConfiguration(), metricRegistry);
    AuthQueueService authQueueService = ServicePoolBuilder.create(AuthQueueService.class)
            .withServiceFactory(queueFactory)
            .withHostDiscovery(new ZooKeeperHostDiscovery(curator, queueFactory.getServiceName(), metricRegistry))
            .withMetricRegistry(metricRegistry)
            .withCachingPolicy(ServiceCachingPolicyBuilder.getMultiThreadedClientPolicy())
            .buildProxy(new ExponentialBackoffRetry(5, 50, 1000, TimeUnit.MILLISECONDS));
    QueueService queueService = QueueServiceAuthenticator.proxied(authQueueService)
            .usingCredentials(adminApiKey);

    final QueueStressTest stressTest = new QueueStressTest(queueService);

    ThreadFactory writerFactory = new ThreadFactoryBuilder().setNameFormat("Writer-%d").build();
    for (int i = 0; i < numWriterThreads; i++) {
        writerFactory.newThread(new Runnable() {
            @Override
            public void run() {
                stressTest.write();
            }
        }).start();
    }

    ThreadFactory readerFactory = new ThreadFactoryBuilder().setNameFormat("Reader-%d").build();
    for (int i = 0; i < numReaderThreads; i++) {
        readerFactory.newThread(new Runnable() {
            @Override
            public void run() {
                stressTest.read();
            }
        }).start();
    }

    ThreadFactory reportFactory = new ThreadFactoryBuilder().setNameFormat("Report-%d").build();
    Executors.newScheduledThreadPool(1, reportFactory).scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            stressTest.report();
        }
    }, 1, 1, TimeUnit.SECONDS);

    // Run forever
}
 
Example #20
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 #21
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 #22
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 #23
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 #24
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 #25
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 #26
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);
}