Java Code Examples for com.typesafe.config.ConfigFactory#parseResources()

The following examples show how to use com.typesafe.config.ConfigFactory#parseResources() . 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: GoogleCloudStorageSinkConfigurationTest.java    From divolte-collector with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetryConfiguration() {
    final ValidatedConfiguration vc = new ValidatedConfiguration(() -> ConfigFactory.parseResources(
        "gcs-sink.conf"));

    // Check that we generate the retry policy that matches the settings.
    final GoogleCloudStorageRetryConfiguration retrySettings = vc.configuration().getSinkConfiguration("gcs", GoogleCloudStorageSinkConfiguration.class).retrySettings;
    final RetryPolicy<?> retryPolicy = retrySettings.createRetryPolicy();

    assertEquals(8, retryPolicy.getMaxRetries());
    assertEquals(Duration.of(138, SECONDS), retryPolicy.getMaxDuration());
    assertEquals(Duration.of(19, SECONDS), retryPolicy.getDelay());
    assertEquals(2.2, retryPolicy.getDelayFactor(), DEFAULT_DELTA);
    assertEquals(Duration.of(25, SECONDS), retryPolicy.getMaxDelay());
    assertEquals(1925, retryPolicy.getJitter().toMillis(), DEFAULT_DELTA);
}
 
Example 2
Source File: ServerLimitsTest.java    From xio with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadGoodValues() {
  //when limits are read
  ServerLimits limits = new ServerLimits(ConfigFactory.parseResources("limits.conf"));

  // then the values are correct
  assertEquals(501, limits.maxConnections());
  assertEquals(9601, limits.maxFrameSize());
  assertEquals(Duration.ofSeconds(61), limits.maxReadIdleTime());
  assertEquals(Duration.ofSeconds(62), limits.maxWriteIdleTime());
  assertEquals(Duration.ofSeconds(63), limits.maxAllIdleTime());
  assertEquals(10001D, limits.globalHardReqPerSec(), 0);
  assertEquals(10000D, limits.globalSoftReqPerSec(), 0);
  assertEquals(25, limits.rateLimiterPoolSize());
  assertEquals(501.0D, limits.softReqPerSec(), 0);
  assertEquals(551.0D, limits.hardReqPerSec(), 0);
  ImmutableMap<String, List<Double>> crlo = limits.clientRateLimitOverride();
  assertEquals(2, crlo.size());
  assertEquals(Lists.newArrayList(500D, 550D), crlo.get("1.2.3.4"));
  assertEquals(Lists.newArrayList(1000D, 1500D), crlo.get("2.2.2.2"));
}
 
Example 3
Source File: ServerLimitsTest.java    From xio with Apache License 2.0 5 votes vote down vote up
@Test(expected = RuntimeException.class)
public void readBadValues() {
  // when limits are read
  // and maxConnections is greater than ServerLimits.MAX_CONNECTION_LIMIT
  new ServerLimits(ConfigFactory.parseResources("limits_over_max_limit.conf"));
  // then fail fast
}
 
Example 4
Source File: ValidatedConfigurationTest.java    From divolte-collector with Apache License 2.0 5 votes vote down vote up
@Test
public void sourceAndSinkNamesCannotCollide() {
    final ValidatedConfiguration vc = new ValidatedConfiguration(() -> ConfigFactory.parseResources("source-sink-collisions.conf"));

    assertFalse(vc.isValid());
    assertEquals(1, vc.errors().size());
    assertTrue(
            vc.errors()
              .get(0)
              .startsWith("Property 'divolte.' Source and sink names cannot collide (must be globally unique). The following names were both used as source and as sink: [foo, bar].."));
}
 
Example 5
Source File: SchemaRegistryTest.java    From divolte-collector with Apache License 2.0 5 votes vote down vote up
@Test
public void testSinkCorrectlyAssociatedWithSchema() {
    final ValidatedConfiguration vc = new ValidatedConfiguration(() -> ConfigFactory.parseResources("schema-registry-with-confluent.conf"));
    final SchemaRegistry registry = new SchemaRegistry(vc);
    // This throws an exception if the sink is unknown.
    registry.getSchemaBySinkName("kafka");
}
 
Example 6
Source File: ValidatedConfigurationTest.java    From divolte-collector with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReportMissingSourcesAndSinks() {
    final ValidatedConfiguration vc = new ValidatedConfiguration(() -> ConfigFactory.parseResources("missing-sources-sinks.conf"));

    assertFalse(vc.isValid());
    assertEquals(1, vc.errors().size());
    assertTrue(
            vc.errors()
              .get(0)
              .startsWith("Property 'divolte.' The following sources and/or sinks were used in a mapping but never defined: [missing-sink, missing-source].."));
}
 
Example 7
Source File: GoogleCloudStorageSinkConfigurationTest.java    From divolte-collector with Apache License 2.0 5 votes vote down vote up
@Test
public void testJitterFactorSuppressesJitterDelayDefault() {
    final ValidatedConfiguration vc = new ValidatedConfiguration(() -> ConfigFactory.parseResources("gcs-jitter-factor.conf"));
    assertTrue(vc.isValid());

    final GoogleCloudStorageRetryConfiguration retrySettings = vc.configuration().getSinkConfiguration("gcs", GoogleCloudStorageSinkConfiguration.class).retrySettings;
    assertEquals(Optional.empty(), retrySettings.jitterDelay);
    assertEquals(0.1, retrySettings.jitterFactor.orElseThrow(IllegalStateException::new), DEFAULT_DELTA);
}
 
Example 8
Source File: RetentionTestDataGenerator.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * @param testTempDirPath under which all test files are created on the FileSystem
 * @param testSetupConfPath setup config file path in classpath
 */
public RetentionTestDataGenerator(Path testTempDirPath, Path testSetupConfPath, FileSystem fs) {
  this.fs = fs;
  this.testTempDirPath = testTempDirPath;
  this.setupConfig =
      ConfigFactory.parseResources(PathUtils.getPathWithoutSchemeAndAuthority(testSetupConfPath).toString());
  if (!this.setupConfig.hasPath(DATA_GENERATOR_KEY)) {
    throw new RuntimeException(String.format("Failed to load setup config at %s", testSetupConfPath.toString()));
  }
}
 
Example 9
Source File: SharedResourcesBrokerFactory.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
private static Config addSystemConfigurationToConfig(Config config) {
  Map<String, String> confMap = Maps.newHashMap();
  addBrokerKeys(confMap, System.getenv().entrySet());
  addBrokerKeys(confMap, System.getProperties().entrySet());

  Config systemConfig = ConfigFactory.parseMap(confMap);

  Config tmpConfig = config.withFallback(systemConfig);
  String brokerConfPath = DEFAULT_BROKER_CONF_FILE;
  if (tmpConfig.hasPath(BROKER_CONF_FILE_KEY)) {
    brokerConfPath = tmpConfig.getString(BROKER_CONF_FILE_KEY);
  }

  Config resourceConfig = ConfigFactory.parseResources(SharedResourcesBrokerFactory.class, brokerConfPath);

  config = config.withFallback(resourceConfig).withFallback(systemConfig);

  if (ConfigUtils.getBoolean(config, LOAD_HADOOP_CONFIGURATION, true)) {
    Map<String, String> hadoopConfMap = Maps.newHashMap();
    Configuration hadoopConf = new Configuration();
    hadoopConf.addResource("gobblin-site.xml");
    addBrokerKeys(hadoopConfMap, hadoopConf);
    config = config.withFallback(ConfigFactory.parseMap(hadoopConfMap));
  }

  return config;
}
 
Example 10
Source File: SparkSwagger.java    From spark-swagger with Apache License 2.0 5 votes vote down vote up
private SparkSwagger(final Service spark, final String confPath, final String version) {
    this.spark = spark;
    this.version = version;
    this.swagger = new Swagger();
    this.config = ConfigFactory.parseResources(confPath != null ? confPath : SparkSwagger.CONF_FILE_NAME);
    this.apiPath = this.config.getString("spark-swagger.basePath");
    this.swagger.setBasePath(this.apiPath);
    this.swagger.setExternalDocs(ExternalDocs.newBuilder().build());
    this.swagger.setHost(getHost());
    this.swagger.setInfo(getInfo());
    configDocRoute();
}
 
Example 11
Source File: ValidatedConfigurationTest.java    From divolte-collector with Apache License 2.0 5 votes vote down vote up
@Test
public void mappingsForConfluentSinksMustHaveSameConfluentId() {
    final ValidatedConfiguration vc = new ValidatedConfiguration(() -> ConfigFactory.parseResources("kafka-sink-confluent-with-confluent-id-conflict.conf"));
    assertFalse(vc.isValid());
    assertEquals(1, vc.errors().size());
    assertTrue(
        vc.errors()
            .get(0)
            .startsWith("Property 'divolte.' Any sink can only use one confluent identifier. The following sinks have multiple mappings with different 'confluent_id' attributes: [kafka]..")
    );
}
 
Example 12
Source File: ValidatedConfigurationTest.java    From divolte-collector with Apache License 2.0 5 votes vote down vote up
@Test
public void sharedSinksCannotHaveDifferentSchemas() {
    final ValidatedConfiguration vc = new ValidatedConfiguration(() -> ConfigFactory.parseResources("multiple-mappings-different-schema-shared-sink.conf"));

    assertFalse(vc.isValid());
    assertEquals(1, vc.errors().size());
    assertTrue(
            vc.errors()
              .get(0)
              .startsWith("Property 'divolte.' Any sink can only use one schema. The following sinks have multiple mappings with different schema's linked to them: [kafka].."));
}
 
Example 13
Source File: ValidatedConfigurationTest.java    From divolte-collector with Apache License 2.0 5 votes vote down vote up
@Test
public void mappingsForConfluentSinksMustHaveConfluentId() {
    final ValidatedConfiguration vc = new ValidatedConfiguration(() -> ConfigFactory.parseResources("kafka-sink-confluent-without-confluent-id.conf"));
    assertFalse(vc.isValid());
    assertEquals(1, vc.errors().size());
    assertTrue(
        vc.errors()
          .get(0)
          .startsWith("Property 'divolte.' Mappings used by sinks in Confluent-mode must have their 'confluent_id' attribute set. The following mappings are missing this: [test]..")
    );
}
 
Example 14
Source File: ValidatedConfigurationTest.java    From divolte-collector with Apache License 2.0 5 votes vote down vote up
@Test
public void allMappingsForConfluentSinksMustHaveConfluentId() {
    final ValidatedConfiguration vc = new ValidatedConfiguration(() -> ConfigFactory.parseResources("kafka-sink-confluent-partially-without-confluent-id.conf"));
    assertFalse(vc.isValid());
    assertEquals(1, vc.errors().size());
    assertTrue(
        vc.errors()
          .get(0)
          .startsWith("Property 'divolte.' Mappings used by sinks in Confluent-mode must have their 'confluent_id' attribute set. The following mappings are missing this: [test-2]..")
    );
}
 
Example 15
Source File: TypesafeConfigExamples.java    From StubbornJava with MIT License 4 votes vote down vote up
public static void main(String[] args) {
    // {{start:resource}}
    Config defaultConfig = ConfigFactory.parseResources("defaults.conf");
    // {{end:resource}}

    // {{start:fallback}}
    Config fallbackConfig = ConfigFactory.parseResources("overrides.conf")
                                         .withFallback(defaultConfig)
                                         .resolve();
    // {{end:fallback}}

    // {{start:text}}
    log.info("name: {}", defaultConfig.getString("conf.name"));
    log.info("name: {}", fallbackConfig.getString("conf.name"));
    log.info("title: {}", defaultConfig.getString("conf.title"));
    log.info("title: {}", fallbackConfig.getString("conf.title"));
    // {{end:text}}

    // {{start:resolved}}
    log.info("combined: {}", fallbackConfig.getString("conf.combined"));
    // {{end:resolved}}

    // {{start:durations}}
    log.info("redis.ttl minutes: {}", fallbackConfig.getDuration("redis.ttl", TimeUnit.MINUTES));
    log.info("redis.ttl seconds: {}", fallbackConfig.getDuration("redis.ttl", TimeUnit.SECONDS));
    // {{end:durations}}

    // {{start:memorySize}}
    // Any path in the configuration can be treated as a separate Config object.
    Config uploadService = fallbackConfig.getConfig("uploadService");
    log.info("maxChunkSize bytes: {}", uploadService.getMemorySize("maxChunkSize").toBytes());
    log.info("maxFileSize bytes: {}", uploadService.getMemorySize("maxFileSize").toBytes());
    // {{end:memorySize}}

    // {{start:whitelist}}
    List<Integer> whiteList = fallbackConfig.getIntList("conf.nested.whitelistIds");
    log.info("whitelist: {}", whiteList);
    List<String> whiteListStrings = fallbackConfig.getStringList("conf.nested.whitelistIds");
    log.info("whitelist as Strings: {}", whiteListStrings);
    // {{end:whitelist}}


    // {{start:booleans}}
    log.info("yes: {}", fallbackConfig.getBoolean("featureFlags.featureA"));
    log.info("true: {}", fallbackConfig.getBoolean("featureFlags.featureB"));
    // {{end:booleans}}
}
 
Example 16
Source File: ValidatedConfigurationTest.java    From divolte-collector with Apache License 2.0 4 votes vote down vote up
@Test
public void mappingsCanContainConfluentId() {
    final ValidatedConfiguration vc = new ValidatedConfiguration(() -> ConfigFactory.parseResources("mapping-configuration-confluent-id.conf"));
    assertTrue(vc.isValid());
}
 
Example 17
Source File: HoconConverterUtil.java    From streams with Apache License 2.0 4 votes vote down vote up
public Object convert(Object object, Class outClass, String hoconResource) {
  Config hocon = ConfigFactory.parseResources(hoconResource);
  return convert(object, outClass, hocon, null);
}
 
Example 18
Source File: HoconConverterUtil.java    From streams with Apache License 2.0 4 votes vote down vote up
public Object convert(Object object, Class outClass, String hoconResource, String outPath) {
  Config hocon = ConfigFactory.parseResources(hoconResource);
  return convert(object, outClass, hocon, outPath);
}
 
Example 19
Source File: TypesafeConfigExamples.java    From StubbornJava with MIT License 4 votes vote down vote up
public static void main(String[] args) {
    // {{start:resource}}
    Config defaultConfig = ConfigFactory.parseResources("defaults.conf");
    // {{end:resource}}

    // {{start:fallback}}
    Config fallbackConfig = ConfigFactory.parseResources("overrides.conf")
                                         .withFallback(defaultConfig)
                                         .resolve();
    // {{end:fallback}}

    // {{start:text}}
    log.info("name: {}", defaultConfig.getString("conf.name"));
    log.info("name: {}", fallbackConfig.getString("conf.name"));
    log.info("title: {}", defaultConfig.getString("conf.title"));
    log.info("title: {}", fallbackConfig.getString("conf.title"));
    // {{end:text}}

    // {{start:resolved}}
    log.info("combined: {}", fallbackConfig.getString("conf.combined"));
    // {{end:resolved}}

    // {{start:durations}}
    log.info("redis.ttl minutes: {}", fallbackConfig.getDuration("redis.ttl", TimeUnit.MINUTES));
    log.info("redis.ttl seconds: {}", fallbackConfig.getDuration("redis.ttl", TimeUnit.SECONDS));
    // {{end:durations}}

    // {{start:memorySize}}
    // Any path in the configuration can be treated as a separate Config object.
    Config uploadService = fallbackConfig.getConfig("uploadService");
    log.info("maxChunkSize bytes: {}", uploadService.getMemorySize("maxChunkSize").toBytes());
    log.info("maxFileSize bytes: {}", uploadService.getMemorySize("maxFileSize").toBytes());
    // {{end:memorySize}}

    // {{start:whitelist}}
    List<Integer> whiteList = fallbackConfig.getIntList("conf.nested.whitelistIds");
    log.info("whitelist: {}", whiteList);
    List<String> whiteListStrings = fallbackConfig.getStringList("conf.nested.whitelistIds");
    log.info("whitelist as Strings: {}", whiteListStrings);
    // {{end:whitelist}}


    // {{start:booleans}}
    log.info("yes: {}", fallbackConfig.getBoolean("featureFlags.featureA"));
    log.info("true: {}", fallbackConfig.getBoolean("featureFlags.featureB"));
    // {{end:booleans}}
}
 
Example 20
Source File: XConfig.java    From xrpc with Apache License 2.0 4 votes vote down vote up
/**
 * Construct a config object using the provided configuration, falling back on the default
 * configuration values <a
 * href="https://github.com/Nordstrom/xrpc/blob/master/src/main/resources/com/nordstrom/xrpc/xrpc.conf">here</a>.
 *
 * @throws RuntimeException if there is an error reading one of path_to_cert or path_to_key
 */
public XConfig(Config configOverrides) {
  Config defaultConfig = ConfigFactory.parseResources(this.getClass(), "xrpc.conf");
  Config config = configOverrides.withFallback(defaultConfig);

  readerIdleTimeout = config.getInt("reader_idle_timeout_seconds");
  writerIdleTimeout = config.getInt("writer_idle_timeout_seconds");
  allIdleTimeout = config.getInt("all_idle_timeout_seconds");
  workerNameFormat = config.getString("worker_name_format");
  bossThreadCount = config.getInt("boss_thread_count");
  workerThreadCount = config.getInt("worker_thread_count");
  asyncHealthCheckThreadCount = config.getInt("async_health_check_thread_count");
  long maxPayloadBytesLong = config.getBytes("max_payload_bytes");
  Preconditions.checkArgument(
      maxPayloadBytesLong <= Integer.MAX_VALUE,
      String.format(
          "value %d for max_payload_bytes must be less than or equal to %d",
          maxPayloadBytesLong, Integer.MAX_VALUE));
  maxPayloadBytes = (int) maxPayloadBytesLong;
  maxConnections = config.getInt("max_connections");
  rateLimiterPoolSize = config.getInt("rate_limiter_pool_size");
  softReqPerSec = config.getDouble("soft_req_per_sec");
  hardReqPerSec = config.getDouble("hard_req_per_sec");
  adminRoutesEnableInfo = config.getBoolean("admin_routes.enable_info");
  adminRoutesEnableUnsafe = config.getBoolean("admin_routes.enable_unsafe");
  defaultContentType = config.getString("default_content_type");
  globalSoftReqPerSec = config.getDouble("global_soft_req_per_sec");
  globalHardReqPerSec = config.getDouble("global_hard_req_per_sec");
  port = config.getInt("server.port");
  slf4jReporter = config.getBoolean("slf4j_reporter");
  jmxReporter = config.getBoolean("jmx_reporter");
  consoleReporter = config.getBoolean("console_reporter");
  slf4jReporterPollingRate = config.getInt("slf4j_reporter_polling_rate");
  consoleReporterPollingRate = config.getInt("console_reporter_polling_rate");
  enableWhiteList = config.getBoolean("enable_white_list");
  enableBlackList = config.getBoolean("enable_black_list");

  ipBlackList =
      ImmutableSet.<String>builder().addAll(config.getStringList("ip_black_list")).build();
  ipWhiteList =
      ImmutableSet.<String>builder().addAll(config.getStringList("ip_white_list")).build();

  corsConfig = buildCorsConfig(config.getConfig("cors"));

  sslContext = SslContextFactory.buildServerContext(buildTlsConfig(config.getConfig("tls")));

  populateClientOverrideList(config.getObjectList("req_per_second_override"));
}