@Override public RestlerConfig getConfiguration() { ObjectMapper objectMapper = Jackson.newObjectMapper(); ValidatorFactory validatorFactory = Validation .byProvider(HibernateValidator.class) .configure() .addValidatedValueHandler(new OptionalValidatedValueUnwrapper()) .buildValidatorFactory(); final ConfigurationFactory<RestlerConfig> configurationFactory = new DefaultConfigurationFactoryFactory<RestlerConfig>().create(RestlerConfig.class, validatorFactory.getValidator(), objectMapper, "dw"); try { return configurationFactory.build(new FileConfigurationSourceProvider(), TEST_CONFIG_FILE); } catch (Exception e) { throw new RuntimeException("Cannot get test configuration", e); } }
@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(); }
@Override public Statement apply(final Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { File yamlFile = new File(Resources.getResource("keywhiz-test.yaml").getFile()); Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); ObjectMapper objectMapper = KeywhizService.customizeObjectMapper(Jackson.newObjectMapper()); KeywhizConfig config = new ConfigurationFactory<>(KeywhizConfig.class, validator, objectMapper, "dw") .build(yamlFile); DataSource dataSource = config.getDataSourceFactory() .build(new MetricRegistry(), "db-migrations"); Flyway flyway = new Flyway(); flyway.setDataSource(dataSource); flyway.setLocations(config.getMigrationsDir()); flyway.clean(); flyway.migrate(); DSLContext dslContext = DSLContexts.databaseAgnostic(dataSource); DbSeedCommand.doImport(dslContext); base.evaluate(); } }; }
@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); }
@Test public void testParsing() throws Exception { ConfigurationFactory<MacroBaseConf> cfFactory = new ConfigurationFactory<>(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()); }
/** * Builds a Configuration object from the file path given. It uses the {@link io.dropwizard.configuration.ConfigurationFactory} * to build the configuration. * * @param possibleFilename The path to the configuration. * @return A configuration object loaded form the filename given. */ private Config buildFromFile(String possibleFilename) { File configFile = new File(possibleFilename); Preconditions.checkArgument(configFile.exists(), "File must exist at: " + configFile.getAbsolutePath()); try { return new ConfigurationFactory<>( configClass, Validation.buildDefaultValidatorFactory().getValidator(), Jackson.newObjectMapper(), "graceland") .build(configFile); } catch (Exception e) { String msg = "Unknown exception triggered when attempting to build config from file:" + "\n" + "\t* Configuration Class: " + configClass.getCanonicalName() + "\n" + "\t* File: " + configFile.getAbsolutePath(); throw new RuntimeException(msg, e); } }
public static OregamiConfiguration createConfiguration(String configFilename) { ConfigurationFactory<OregamiConfiguration> factory = new ConfigurationFactory<>( OregamiConfiguration.class, Validation.buildDefaultValidatorFactory().getValidator(), Jackson.newObjectMapper(), "" ); OregamiConfiguration configuration; try { configuration = factory.build(new File(configFilename)); } catch (Exception e) { throw new RuntimeException(e); } System.out.println(ToStringBuilder.reflectionToString(configuration, ToStringStyle.MULTI_LINE_STYLE)); System.out.println(ToStringBuilder.reflectionToString(configuration.getDatabaseConfiguration(), ToStringStyle.MULTI_LINE_STYLE)); return configuration; }
public SupportedMsaVersions loadSupportedMsaVersions(final URL url) { final ConfigurationFactory<SupportedMsaVersions> factory = supportedMsaVersionsFactoryFactory.create( SupportedMsaVersions.class, buildDefaultValidatorFactory().getValidator(), objectMapper, ""); try { SupportedMsaVersions supportedMsaVersions = factory.build( configurationSourceProvider, url.toString()); return supportedMsaVersions; } catch (IOException | ConfigurationException e) { throw propagate(e); } }
public FileBackedConfigDataSource( ConfigConfiguration configuration, ConfigurationFactory<T> configurationFactory, String dataDirectory) { this.configuration = configuration; this.configurationFactory = configurationFactory; this.dataDirectory = dataDirectory; }
@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()); }
private EmoConfiguration loadConfigFile(File configFile) throws IOException, ConfigurationException { Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); ObjectMapper mapper = CustomJsonObjectMapperFactory.build(new YAMLFactory()); ConfigurationFactory<EmoConfiguration> configurationFactory = new ConfigurationFactory(EmoConfiguration.class, validator, mapper, "dw"); return configurationFactory.build(configFile); }
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 = CustomJsonObjectMapperFactory.build(new YAMLFactory()); ConfigurationFactory<EmoConfiguration> configFactory = new ConfigurationFactory<>(EmoConfiguration.class, validator, mapper, "dw"); return configFactory.build(file); }
@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 = CustomJsonObjectMapperFactory.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())); }
@Override public ConfigurationFactory<T> create( final Class<T> klass, final Validator validator, final ObjectMapper objectMapper, final String propertyPrefix ) { return new ImportableConfigurationFactory<T>( klass, validator, configureObjectMapper(objectMapper.copy()), propertyPrefix ); }
/** * Parses the given configuration file and returns a configuration object. * * @param configurationFileName The name of the configuration file. * @return A configuration object. * @throws IOException The IO error that contains detail information. * @throws ConfigurationException The configuration error that contains detail information. */ public static ApiConfiguration parse(String configurationFileName) throws IOException, ConfigurationException { if (StringUtils.isBlank(configurationFileName)) { throw new IllegalArgumentException("Configuration file cannot be blank"); } ObjectMapper objectMapper = null; if (configurationFileName.endsWith("yml") || configurationFileName.endsWith("yaml")) { objectMapper = Jackson.newObjectMapper(new YAMLFactory()); } else if (configurationFileName.endsWith("json")) { objectMapper = Jackson.newObjectMapper(new JsonFactory()); } else { throw new IllegalArgumentException("Unrecognized configuration file type"); } ValidatorFactory validatorFactory = Validation .byProvider(HibernateValidator.class) .configure() .addValidatedValueHandler(new OptionalValidatedValueUnwrapper()) .buildValidatorFactory(); final ConfigurationFactory<ApiConfiguration> configurationFactory = new DefaultConfigurationFactoryFactory<ApiConfiguration>() .create(ApiConfiguration.class, validatorFactory.getValidator(), objectMapper, "dw"); final File file = new File(configurationFileName); if (!file.exists()) { throw new FileNotFoundException("Configuration file " + configurationFileName + " not found"); } return configurationFactory.build(file); }
@Test public void parsesLDAPLookupCorrectly() throws Exception { File yamlFile = new File(Resources.getResource("fixtures/keywhiz-ldap-lookup-test.yaml").getFile()); Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); ObjectMapper objectMapper = bootstrap.getObjectMapper().copy(); LdapLookupConfig lookupConfig = new ConfigurationFactory<>(LdapLookupConfig.class, validator, objectMapper, "dw") .build(yamlFile); assertThat(lookupConfig.getRequiredRoles()).containsOnly("keywhizAdmins"); assertThat(lookupConfig.getRoleBaseDN()).isEqualTo("ou=ApplicationAccess,dc=test,dc=com"); assertThat(lookupConfig.getUserBaseDN()).isEqualTo("ou=people,dc=test,dc=com"); assertThat(lookupConfig.getUserAttribute()).isEqualTo("uid"); }
static Injector createInjector() { KeywhizService service = new KeywhizService(); Bootstrap<KeywhizConfig> bootstrap = new Bootstrap<>(service); service.initialize(bootstrap); File yamlFile = new File(Resources.getResource("keywhiz-test.yaml").getFile()); Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); ObjectMapper objectMapper = bootstrap.getObjectMapper().copy(); KeywhizConfig config; try { config = new ConfigurationFactory<>(KeywhizConfig.class, validator, objectMapper, "dw") .build(yamlFile); } catch (IOException | ConfigurationException e) { throw Throwables.propagate(e); } Environment environment = new Environment(service.getName(), objectMapper, validator, bootstrap.getMetricRegistry(), bootstrap.getClassLoader()); Injector injector = Guice.createInjector(new ServiceModule(config, environment)); service.setInjector(injector); return injector; }
@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); }
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; }
@Before public void setupTest() throws Exception { azureTableConfiguration = new ConfigurationFactory<>( AzureTableConfiguration.class, Validation.buildDefaultValidatorFactory().getValidator(), Jackson.newObjectMapper(), "dw.").build(new File(Resources.getResource("azure-test.yml").toURI())); }
@Override public ConfigurationFactory<T> create( Class<T> klass, Validator validator, ObjectMapper objectMapper, String propertyPrefix) { return new HoconConfigurationFactory<>(klass, validator, objectMapper, propertyPrefix); }
@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()); }
public static PersistenceConfig createConfiguration(File configFile) { ConfigurationFactory<PersistenceConfig> factory = new ConfigurationFactory<>(PersistenceConfig.class, Validation.buildDefaultValidatorFactory().getValidator(), Jackson.newObjectMapper(), ""); PersistenceConfig configuration; try { configuration = factory.build(configFile); } catch (Exception e) { throw new RuntimeException(e); } return configuration; }
/** * 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(); }
@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); }
@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); } }
@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(); }
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); }
@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); }
@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(); }
@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); }
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 }
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); } } }
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.standardDays(7), Duration.standardDays(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); }
/** * Creates a Jetty server for an application that can be started / stopped in-process * * @param config An application configuration instance (with properties set) * @param applicationClass The {@link io.dropwizard.Application} implementation class * @param <T> The configuration class * @return A Jetty server */ @SuppressWarnings("unchecked") public static <T extends Configuration> DropWizardServer<T> createServer( T config, Class<? extends Application<T>> applicationClass) throws Exception { // Create application final Application<T> application = applicationClass.getConstructor().newInstance(); // Create bootstrap final ServerCommand<T> serverCommand = new ServerCommand<T>(application); final Bootstrap<T> bootstrap = new Bootstrap<T>(application); bootstrap.addCommand(serverCommand); // Write a temporary config file File tmpConfigFile = new File( System.getProperty("java.io.tmpdir"), config.getClass().getCanonicalName() + "_" + System.currentTimeMillis()); tmpConfigFile.deleteOnExit(); bootstrap.getObjectMapper().writeValue(tmpConfigFile, config); // Parse configuration ConfigurationFactory<T> configurationFactory = bootstrap.getConfigurationFactoryFactory() .create((Class<T>) config.getClass(), bootstrap.getValidatorFactory().getValidator(), bootstrap.getObjectMapper(), "dw"); final T builtConfig = configurationFactory.build( bootstrap.getConfigurationSourceProvider(), tmpConfigFile.getAbsolutePath()); // Configure logging builtConfig.getLoggingFactory() .configure(bootstrap.getMetricRegistry(), bootstrap.getApplication().getName()); // Environment final Environment environment = new Environment(bootstrap.getApplication().getName(), bootstrap.getObjectMapper(), bootstrap.getValidatorFactory().getValidator(), bootstrap.getMetricRegistry(), bootstrap.getClassLoader()); // Initialize environment builtConfig.getMetricsFactory().configure(environment.lifecycle(), bootstrap.getMetricRegistry()); // Server final Server server = builtConfig.getServerFactory().build(environment); server.addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener() { @Override public void lifeCycleStopped(LifeCycle event) { builtConfig.getLoggingFactory().stop(); } }); return new DropWizardServer(builtConfig, bootstrap, application, environment, server, environment.metrics()); }
/** * Creates a Jetty server for an application that can be started / stopped in-process * * @param config * An application configuration instance (with properties set) * @param applicationClass * The {@link io.dropwizard.Application} implementation class * @param <T> * The configuration class * @return * A Jetty server */ @SuppressWarnings("unchecked") public static <T extends Configuration> DropWizardServer<T> createServer(T config, Class<? extends Application<T>> applicationClass) throws Exception { // Create application final Application<T> application = applicationClass.getConstructor().newInstance(); // Create bootstrap final ServerCommand<T> serverCommand = new ServerCommand<T>(application); final Bootstrap<T> bootstrap = new Bootstrap<T>(application); bootstrap.addCommand(serverCommand); // Write a temporary config file File tmpConfigFile = new File( System.getProperty("java.io.tmpdir"), config.getClass().getCanonicalName() + "_" + System.currentTimeMillis()); tmpConfigFile.deleteOnExit(); bootstrap.getObjectMapper().writeValue(tmpConfigFile, config); // Parse configuration ConfigurationFactory<T> configurationFactory = bootstrap.getConfigurationFactoryFactory() .create((Class<T>) config.getClass(), bootstrap.getValidatorFactory().getValidator(), bootstrap.getObjectMapper(), "dw"); final T builtConfig = configurationFactory.build( bootstrap.getConfigurationSourceProvider(), tmpConfigFile.getAbsolutePath()); // Configure logging builtConfig.getLoggingFactory() .configure(bootstrap.getMetricRegistry(), bootstrap.getApplication().getName()); // Environment final Environment environment = new Environment(bootstrap.getApplication().getName(), bootstrap.getObjectMapper(), bootstrap.getValidatorFactory().getValidator(), bootstrap.getMetricRegistry(), bootstrap.getClassLoader()); // Initialize environment builtConfig.getMetricsFactory().configure(environment.lifecycle(), bootstrap.getMetricRegistry()); // Server final Server server = builtConfig.getServerFactory().build(environment); server.addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener() { @Override public void lifeCycleStopped(LifeCycle event) { builtConfig.getLoggingFactory().stop(); } }); return new DropWizardServer(builtConfig, bootstrap, application, environment, server, environment.metrics()); }
@Override public ConfigurationFactory<T> get() { return factory; }
@Override public ConfigurationFactory create(final Class klass, final Validator validator, final ObjectMapper objectMapper, final String propertyPrefix) { return new EnvironmentConfigurationFactory<>(klass, validator, objectMapper, propertyPrefix, new DefaultEnvironmentProvider()); }