com.netflix.config.ConcurrentMapConfiguration Java Examples

The following examples show how to use com.netflix.config.ConcurrentMapConfiguration. 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: EagleMailClient.java    From Eagle with Apache License 2.0 6 votes vote down vote up
public EagleMailClient(AbstractConfiguration configuration) {
	try {
		ConcurrentMapConfiguration con = (ConcurrentMapConfiguration)configuration;
		velocityEngine = new VelocityEngine();
		velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
		velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
		velocityEngine.init();

		con.setProperty("mail.transport.protocol", "smtp");
		final Properties config = con.getProperties();
		if(Boolean.parseBoolean(config.getProperty(AUTH_CONFIG))){
			session = Session.getDefaultInstance(config, new Authenticator() {
				protected PasswordAuthentication getPasswordAuthentication() {
					return new PasswordAuthentication(config.getProperty(USER_CONFIG), config.getProperty(PWD_CONFIG));
				}
			});
		}
		else session = Session.getDefaultInstance(config, new Authenticator() {});
		final String debugMode =  config.getProperty(DEBUG_CONFIG, "false");
		final boolean debug =  Boolean.parseBoolean(debugMode);
		session.setDebug(debug);
	} catch (Exception e) {
           LOG.error("Failed connect to smtp server",e);
	}
}
 
Example #4
Source File: ConfigurationBuilder.java    From chassis with Apache License 2.0 6 votes vote down vote up
private void initModuleConfiguration() {
    if (!scanModuleConfigurations) {
        this.moduleDefaultConfiguration = new ConcurrentMapConfiguration();
        return;
    }
    HashMap<String, Object> base = new HashMap<>();
    Set<Class<?>> types = reflections
            .getTypesAnnotatedWith(PropertySource.class);
    for (Class<?> type : types) {
        PropertySource propertySource = type
                .getAnnotation(PropertySource.class);
        String[] propertiesFiles = propertySource.value();
        for (String propertyFile : propertiesFiles) {
            Properties properties = new Properties();
            try (InputStream is = resourceLoader.getResource(SystemPropertyUtils.resolvePlaceholders(propertyFile))
                    .getInputStream()) {
                properties.load(is);
                LOGGER.debug("Initializing module properties from path " + propertyFile);
            } catch (Exception e) {
                BootstrapException.resourceLoadingFailed(propertyFile, e);
            }
            join(base, properties, propertyFile, propertiesFiles);
        }
    }
    this.moduleDefaultConfiguration = new ConcurrentMapConfiguration(base);
}
 
Example #5
Source File: ConfigUtil.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
private static void createDynamicWatchedConfiguration(
    ConcurrentCompositeConfiguration localConfiguration,
    ConfigCenterConfigurationSource configCenterConfigurationSource) {
  ConcurrentMapConfiguration injectConfig = new ConcurrentMapConfiguration();
  localConfiguration.addConfigurationAtFront(injectConfig, "extraInjectConfig");
  configCenterConfigurationSource.addUpdateListener(new ServiceCombPropertyUpdateListener(injectConfig));

  DynamicWatchedConfiguration configFromConfigCenter =
      new DynamicWatchedConfiguration(configCenterConfigurationSource);
  duplicateCseConfigToServicecomb(configFromConfigCenter);
  localConfiguration.addConfigurationAtFront(configFromConfigCenter, "configCenterConfig");
}
 
Example #6
Source File: DynamicPropertiesTest.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUpClass() throws Exception {
  tearDown();
  configuration = new ConcurrentMapConfiguration();
  writeInitialConfig();
  dynamicProperties = new DynamicPropertiesImpl(configuration);
}
 
Example #7
Source File: DefautConfiguration.java    From resilient-transport-service with Apache License 2.0 5 votes vote down vote up
@RefreshScope
@Bean
public AbstractConfiguration archaiusConfiguration() throws Exception {

    LOGGER.info("Enable Archaius Configuration");
    ConcurrentMapConfiguration concurrentMapConfiguration = new ConcurrentMapConfiguration();

    return concurrentMapConfiguration;
}
 
Example #8
Source File: CuratorFrameworkBuilder.java    From chassis with Apache License 2.0 5 votes vote down vote up
private ConcurrentCompositeConfiguration buildConfiguration() {
    ConcurrentCompositeConfiguration configuration = new ConcurrentCompositeConfiguration();
    configuration.addConfiguration(new ConcurrentMapConfiguration(new SystemConfiguration()));
    configuration.addConfiguration(this.configuration);
    configuration.addConfiguration(defaults);
    return configuration;
}
 
Example #9
Source File: ConfigurationBuilder.java    From chassis with Apache License 2.0 5 votes vote down vote up
/**
 * Build the Configuration
 *
 * @return the configuration
 */
public AbstractConfiguration build() {
    initApplicationFileConfiguration();
    initAppVersion();
    initApplicationConfiguration();
    initModuleConfiguration();

    ConcurrentCompositeConfiguration finalConfiguration = new ConcurrentCompositeConfiguration();
    if (addSystemConfigs) {
        finalConfiguration.addConfiguration(new ConcurrentMapConfiguration(new SystemConfiguration()));
    }

    finalConfiguration.addProperty(BootstrapConfigKeys.APP_VERSION_KEY.getPropertyName(), appVersion);

    addServerInstanceProperties(finalConfiguration);

    if (applicationConfiguration == null) {
        LOGGER.warn("\n\n    ****** Default configuration being used ******\n    client application \"" + appName + "\" is being configured with modules defaults. Defaults should only be used in development environments.\n    In non-developement environments, a configuration provider should be used to configure the client application and it should define ALL required configuration properties.\n");
        finalConfiguration.addConfiguration(applicationFileConfiguration);
        finalConfiguration.addConfiguration(moduleDefaultConfiguration);
    } else {
        finalConfiguration.addConfiguration(applicationConfiguration);
        finalConfiguration.addConfiguration(applicationFileConfiguration);
    }

    finalConfiguration.setProperty(BootstrapConfigKeys.APP_VERSION_KEY.getPropertyName(), appVersion);

    configureArchaius(finalConfiguration);

    logConfiguration(finalConfiguration);

    return finalConfiguration;
}
 
Example #10
Source File: ConfigurationBuilder.java    From chassis with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private void initApplicationFileConfiguration() {
    if (applicationPropertiesPath == null) {
        LOGGER.debug("No client application properties to configure. Skipping...");
        applicationFileConfiguration = new ConcurrentMapConfiguration();
        return;
    }

    this.applicationFileConfiguration = new ConcurrentCompositeConfiguration();

    String path = SystemPropertyUtils.resolvePlaceholders(applicationPropertiesPath);
    LOGGER.debug("Configuring client application properties from path " + applicationPropertiesPath);

    Map applicationProperties = new Properties();

    if (SystemUtils.IS_OS_WINDOWS) {
        if (path.startsWith("file://")) {
            if (!path.startsWith("file:///")) {
                path = path.replaceFirst(Pattern.quote("file://"), "file:///");
            }
        }
    }

    try (InputStream is = resourceLoader.getResource(path).getInputStream()) {
        ((Properties) applicationProperties).load(is);
    } catch (Exception e) {
        BootstrapException.resourceLoadingFailed(path, applicationPropertiesPath, e);
    }

    Map environmentApplicationProperties = getEnvironmentSpecificProperties(path);
    if (environmentApplicationProperties != null) {
        ((ConcurrentCompositeConfiguration) this.applicationFileConfiguration).addConfiguration(new ConcurrentMapConfiguration(environmentApplicationProperties));
    }
    ((ConcurrentCompositeConfiguration) this.applicationFileConfiguration).addConfiguration(new ConcurrentMapConfiguration(applicationProperties));

    if (applicationFileConfiguration.containsKey(BootstrapConfigKeys.PUBLISH_DEFAULTS_KEY.getPropertyName())) {
        this.publishDefaults = applicationFileConfiguration.getBoolean(BootstrapConfigKeys.PUBLISH_DEFAULTS_KEY.getPropertyName());
    }
}
 
Example #11
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 #12
Source File: ConfigUtil.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
ServiceCombPropertyUpdateListener(ConcurrentMapConfiguration injectConfig) {
  this.injectConfig = injectConfig;
}
 
Example #13
Source File: AlertEmailSender.java    From Eagle with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
	int count = 0;
	boolean success = false;
	while(count++ < MAX_RETRY_COUNT && !success){
		LOG.info("Sending email, tried: " + count+", max: "+MAX_RETRY_COUNT);
		try {
			final EagleMailClient client;
			if (eagleProps != null) {
				ConcurrentMapConfiguration con = new ConcurrentMapConfiguration();					
				con.addProperty(MAIL_HOST, eagleProps.get(CONF_KEY_MAIL_HOST).unwrapped());
				con.addProperty(MAIL_PORT, eagleProps.get(CONF_KEY_MAIL_PORT).unwrapped());
				if (eagleProps.get(CONF_KEY_MAIL_DEBUG) != null) {
					con.addProperty(MAIL_DEBUG, eagleProps.get(CONF_KEY_MAIL_DEBUG).unwrapped());
				}
				client = new EagleMailClient(con);
			}
			else {
				client = new EagleMailClient();
			}
			String env = "prod";
			if (eagleProps != null && eagleProps.get("env") != null) {
				env = (String) eagleProps.get("env").unwrapped();
			}
			LOG.info("Env is: " + env);
			final VelocityContext context = new VelocityContext();
			generateCommonContext(context);
			LOG.info("After calling generateCommonContext...");
			additionalContext(context, env);
			
			if (recipents == null || recipents.equals("")) {
				LOG.error("Recipients is null, skip sending emails ");
				return;
			}
			String title = subject;
			if (!env.trim().equals("prod")) {
				title = "[" + env + "]" + title; 				
			}
			success = client.send(sender, recipents, cc, title, configFileName, context, null);
			LOG.info("Success of sending email: " + success);
			if(!success && count < MAX_RETRY_COUNT) {
				LOG.info("Sleep for a while before retrying");
				Thread.sleep(10*1000);
			}
		}
		catch (Exception e){
			LOG.warn("Sending mail exception", e);
		}
	}

	if(success){
		sentSuccessfully = true;
           LOG.info(String.format("Successfully send email, thread: %s",threadName));
	}else{
		LOG.warn(String.format("Fail sending email after tries %s times, thread: %s",MAX_RETRY_COUNT,threadName));
	}
}
 
Example #14
Source File: EagleMailClient.java    From Eagle with Apache License 2.0 4 votes vote down vote up
public EagleMailClient() {
	this(new ConcurrentMapConfiguration());
}