io.dropwizard.validation.BaseValidator Java Examples

The following examples show how to use io.dropwizard.validation.BaseValidator. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #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: 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);
}