com.netflix.config.DynamicConfiguration Java Examples

The following examples show how to use com.netflix.config.DynamicConfiguration. 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: ConfigUtil.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
public static ConcurrentCompositeConfiguration createLocalConfig(List<ConfigModel> configModelList) {
  ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration();

  duplicateCseConfigToServicecomb(config,
      new ConcurrentMapConfiguration(new SystemConfiguration()),
      "configFromSystem");
  duplicateCseConfigToServicecomb(config,
      convertEnvVariable(new ConcurrentMapConfiguration(new EnvironmentConfiguration())),
      "configFromEnvironment");
  // If there is extra configurations, add it into config.
  EXTRA_CONFIG_MAP.entrySet()
      .stream()
      .filter(mapEntry -> !mapEntry.getValue().isEmpty())
      .forEachOrdered(configMapEntry -> duplicateCseConfigToServicecomb(config,
          new ConcurrentMapConfiguration(configMapEntry.getValue()),
          configMapEntry.getKey()));
  // we have already copy the cse config to the serviceComb config when we load the config from local yaml files
  // hence, we do not need duplicate copy it.
  config.addConfiguration(new DynamicConfiguration(
          new MicroserviceConfigurationSource(configModelList), new NeverStartPollingScheduler()),
      "configFromYamlFile");
  duplicateCseConfigToServicecombAtFront(config,
      new ConcurrentMapConfiguration(ConfigMapping.getConvertedMap(config)),
      "configFromMapping");
  return config;
}
 
Example #2
Source File: TestYAMLConfigurationSource.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testFullOperation() {
  // configuration from system properties
  ConcurrentMapConfiguration configFromSystemProperties =
      new ConcurrentMapConfiguration(new SystemConfiguration());
  // configuration from yaml file
  DynamicConfiguration configFromYamlFile =
      new DynamicConfiguration(yamlConfigSource(), new NeverStartPollingScheduler());
  // create a hierarchy of configuration that makes
  // 1) dynamic configuration source override system properties
  ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
  finalConfig.addConfiguration(configFromYamlFile, "yamlConfig");
  finalConfig.addConfiguration(configFromSystemProperties, "systemEnvConfig");
  Assert.assertEquals(0.5, finalConfig.getDouble("trace.handler.sampler.percent"), 0.5);

  Object o = finalConfig.getProperty("zq");
  @SuppressWarnings("unchecked")
  List<Map<String, Object>> listO = (List<Map<String, Object>>) o;
  Assert.assertEquals(3, listO.size());
}
 
Example #3
Source File: TestConfigUtil.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void duplicateServiceCombConfigToCseListValue() {
  List<String> list = Arrays.asList("a", "b");

  AbstractConfiguration config = new DynamicConfiguration();
  config.addProperty("cse.list", list);
  Deencapsulation.invoke(ConfigUtil.class, "duplicateCseConfigToServicecomb", config);

  Object result = config.getProperty("servicecomb.list");
  assertThat(result, instanceOf(List.class));
  assertThat(result, equalTo(list));
}
 
Example #4
Source File: TestConfigUtil.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertEnvVariable() {
  String someProperty = "cse_service_registry_address";
  AbstractConfiguration config = new DynamicConfiguration();
  config.addProperty(someProperty, "testing");
  AbstractConfiguration result = ConfigUtil.convertEnvVariable(config);
  assertThat(result.getString("cse.service.registry.address"), equalTo("testing"));
  assertThat(result.getString("cse_service_registry_address"), equalTo("testing"));
}
 
Example #5
Source File: TestAbstractPropertiesLoader.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testExtendedClassCompatible() {
  Configuration configuration = new DynamicConfiguration();
  configuration.setProperty(CONFIG_SERVICE_DESCRIPTION_KEY + AbstractPropertiesLoader.EXTENDED_CLASS, "invalidClass");

  AbstractPropertiesLoader loader = MicroservicePropertiesLoader.INSTANCE;
  try {
    loader.loadProperties(configuration);
    Assert.fail("Must throw exception");
  } catch (Error e) {
    Assert.assertEquals(ClassNotFoundException.class, e.getCause().getClass());
    Assert.assertEquals("invalidClass", e.getCause().getMessage());
  }
}
 
Example #6
Source File: ApplicationPropertiesConfigurations.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public AbstractConfiguration addApplicationPropertiesSource() {
    // Normally, the DB Table would be already created and populated.
    // In this case, we'll do it just before creating the archaius config source that uses it
    initDatabase();
    PolledConfigurationSource source = new DynamoDbConfigurationSource(amazonDynamoDb);
    return new DynamicConfiguration(source, new FixedDelayPollingScheduler());
}
 
Example #7
Source File: ArchaiusPropertyRegister.java    From tenacity with Apache License 2.0 5 votes vote down vote up
public void register(BreakerboxConfiguration breakerboxConfiguration) {
    if (breakerboxConfiguration.getUrls().isEmpty()) {
        return;
    }

    final TenacityPollingScheduler tenacityPollingScheduler = new TenacityPollingScheduler(
            Ints.checkedCast(breakerboxConfiguration.getInitialDelay().toMilliseconds()),
            Ints.checkedCast(breakerboxConfiguration.getDelay().toMilliseconds()),
            true);

    final CountDownLatch countDownLatch = new CountDownLatch(1);

    if (breakerboxConfiguration.isWaitForInitialLoad()) {
        tenacityPollingScheduler.addPollListener((eventType, lastResult, exception) -> countDownLatch.countDown());
    }

    final DynamicConfiguration dynConfig = new DynamicConfiguration(
            new URLConfigurationSource(breakerboxConfiguration.getUrls().split(",")),
            tenacityPollingScheduler);

    ConfigurationManager.getConfigInstance();
    ConfigurationManager.loadPropertiesFromConfiguration(dynConfig);

    if (breakerboxConfiguration.isWaitForInitialLoad()) {
        final Duration duration = breakerboxConfiguration.getWaitForInitialLoad();
        try {
            final boolean success = countDownLatch.await(duration.getQuantity(), duration.getUnit());
            LOGGER.info("Breakerbox initial configuration load: {}", success ? "SUCCESS" : "FAILURE");
        } catch (Exception err) {
            LOGGER.warn("Failed waiting for Breakerbox initial load", err);
        }
    }
}
 
Example #8
Source File: SSLOptionTest.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@Test
public void testSSLOptionYaml() {
  // configuration from yaml files: default microservice.yaml
  DynamicConfiguration configFromYamlFile =
      new DynamicConfiguration(yamlConfigSource(), new FixedDelayPollingScheduler());
  // configuration from system properties
  ConcurrentMapConfiguration configFromSystemProperties =
      new ConcurrentMapConfiguration(new SystemConfiguration());

  // create a hierarchy of configuration that makes
  // 1) dynamic configuration source override system properties
  ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
  finalConfig.addConfiguration(configFromSystemProperties, "systemEnvConfig");
  finalConfig.addConfiguration(configFromYamlFile, "configFromYamlFile");
  ConfigurationManager.install(finalConfig);

  SSLOption option = SSLOption.buildFromYaml("server");

  String protocols = option.getProtocols();
  option.setProtocols(protocols);
  Assert.assertEquals("TLSv1.2,TLSv1.1,TLSv1,SSLv2Hello", protocols);

  String ciphers = option.getCiphers();
  option.setCiphers(ciphers);
  Assert.assertEquals(
      "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_DSS_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_RSA_WITH_AES_128_CBC_SH"
          +
          "A,TLS_DHE_DSS_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA",
      ciphers);

  boolean authPeer = option.isAuthPeer();
  option.setAuthPeer(authPeer);
  Assert.assertEquals(true, authPeer);

  boolean checkCNHost = option.isCheckCNHost();
  option.setCheckCNHost(checkCNHost);
  Assert.assertEquals(true, checkCNHost);

  boolean checkCNWhite = option.isCheckCNWhite();
  option.setCheckCNWhite(checkCNWhite);
  Assert.assertEquals(true, checkCNWhite);

  String checkCNWhiteFile = option.getCheckCNWhiteFile();
  option.setCheckCNWhiteFile(checkCNWhiteFile);
  Assert.assertEquals("white.list", checkCNWhiteFile);

  boolean allowRenegociate = option.isAllowRenegociate();
  option.setAllowRenegociate(allowRenegociate);
  Assert.assertEquals(false, allowRenegociate);

  String storePath = option.getStorePath();
  option.setStorePath(storePath);
  Assert.assertEquals("internal", storePath);

  String trustStore = option.getTrustStore();
  option.setTrustStore(trustStore);
  Assert.assertEquals("trust.jks", trustStore);

  String trustStoreType = option.getTrustStoreType();
  option.setTrustStoreType(trustStoreType);
  Assert.assertEquals("JKS", trustStoreType);

  String trustStoreValue = option.getTrustStoreValue();
  option.setTrustStoreValue(trustStoreValue);
  Assert.assertEquals("Changeme_123", trustStoreValue);

  String keyStore = option.getKeyStore();
  option.setKeyStore(keyStore);
  Assert.assertEquals("server.p12", keyStore);

  String keyStoreType = option.getKeyStoreType();
  option.setKeyStoreType(keyStoreType);
  Assert.assertEquals("PKCS12", keyStoreType);

  String keyStoreValue = option.getKeyStoreValue();
  option.setKeyStoreValue(keyStoreValue);
  Assert.assertEquals("Changeme_123", keyStoreValue);

  String crl = option.getCrl();
  option.setCrl(crl);
  Assert.assertEquals("revoke.crl", crl);

  option.setSslCustomClass("123");

  SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
  Assert.assertArrayEquals(custom.decode("123".toCharArray()), "123".toCharArray());
}
 
Example #9
Source File: ApplicationPropertiesConfigurations.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public AbstractConfiguration addApplicationPropertiesSource() {
    PolledConfigurationSource source = new JDBCConfigurationSource(h2DataSource, "select distinct key, value from properties", "key", "value");
    return new DynamicConfiguration(source, new FixedDelayPollingScheduler());
}
 
Example #10
Source File: ApplicationPropertiesConfigurations.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public AbstractConfiguration addApplicationPropertiesSource() throws IOException {
    URL configPropertyURL = (new ClassPathResource("other-config.properties")).getURL();
    PolledConfigurationSource source = new URLConfigurationSource(configPropertyURL);
    return new DynamicConfiguration(source, new FixedDelayPollingScheduler());
}