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; }
@Override public void updateConfiguration(WatchedUpdateResult watchedUpdateResult) { Map<String, Object> adds = watchedUpdateResult.getAdded(); if (adds != null) { for (String add : adds.keySet()) { if (add.startsWith(CONFIG_CSE_PREFIX)) { String key = CONFIG_SERVICECOMB_PREFIX + add.substring(add.indexOf(".") + 1); injectConfig.addProperty(key, adds.get(add)); } } } Map<String, Object> deletes = watchedUpdateResult.getDeleted(); if (deletes != null) { for (String delete : deletes.keySet()) { if (delete.startsWith(CONFIG_CSE_PREFIX)) { injectConfig.clearProperty(CONFIG_SERVICECOMB_PREFIX + delete.substring(delete.indexOf(".") + 1)); } } } Map<String, Object> changes = watchedUpdateResult.getChanged(); if (changes != null) { for (String change : changes.keySet()) { if (change.startsWith(CONFIG_CSE_PREFIX)) { String key = CONFIG_SERVICECOMB_PREFIX + change.substring(change.indexOf(".") + 1); injectConfig.setProperty(key, changes.get(change)); } } } } }
public void addProperty(String key, Object value) throws ValidationException { if (value == null) { throw new NullPointerException("Value for property " + key + " is null"); } fireEvent(EVENT_ADD_PROPERTY, key, value, true); addPropertyImpl(key, value); fireEvent(EVENT_ADD_PROPERTY, key, value, false); }
protected void addPropertyImpl(String key, Object value) { Object previousValue = null; if (isDelimiterParsingDisabled() || ((value instanceof String) && ((String) value).indexOf(getListDelimiter()) < 0)) { previousValue = map.putIfAbsent(key, value); if (previousValue != null) { addPropertyValues(key, value, isDelimiterParsingDisabled() ? '\0' : getListDelimiter()); } } else { addPropertyValues(key, value, isDelimiterParsingDisabled() ? '\0' : getListDelimiter()); } }
/** * Load resource configName.properties first. Then load configName-deploymentEnvironment.properties * into the system wide configuration. For example, if configName is "application", and deployment environment * is "test", this API will first load "application.properties", then load "application-test.properties" to * override any property that also exist in "application.properties". * * @param configName prefix of the properties file name. * @throws IOException * @see DeploymentContext#getDeploymentEnvironment() */ public static void loadCascadedPropertiesFromResources(String configName) throws IOException { Properties props = loadCascadedProperties(configName); if (instance instanceof AggregatedConfiguration) { ConcurrentMapConfiguration config = new ConcurrentMapConfiguration(); config.loadProperties(props); ((AggregatedConfiguration) instance).addConfiguration(config, configName); } else { ConfigurationUtils.loadProperties(props, instance); } }
public static void main(String[] args) { new SampleApplication(); ConcurrentCompositeConfiguration myConfiguration = (ConcurrentCompositeConfiguration) DynamicPropertyFactory.getInstance().getBackingConfigurationSource(); ConcurrentMapConfiguration subConfig = new ConcurrentMapConfiguration(); subConfig.setProperty("com.netflix.config.samples.SampleApp.SampleBean.name", "A Coffee Bean from Cuba"); myConfiguration.setProperty("com.netflix.config.samples.sampleapp.prop1", "value1"); myConfiguration.addConfiguration(subConfig); System.out.println("Started SampleApplication. Launch JConsole to inspect and update properties."); System.out.println("To see how callback work, update property com.netflix.config.samples.SampleApp.SampleBean.sensitiveBeanData from BaseConfigBean in JConsole"); SampleBean sampleBean = new SampleBean(); // this should show the bean taking properties from two different sources // property "com.netflix.config.samples.SampleApp.SampleBean.numSeeds" is from sampleapp.properites // property "com.netflix.config.samples.SampleApp.SampleBean.name" is from subConfig added above System.out.println("SampleBean:" + sampleBean); System.out.println(sampleBean.getName()); } }
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());
private static String getNextLoad(Configuration propConfig, String... nextLoadPropertyKeys) { String nextLoadKeyToUse = null; for (String key: nextLoadPropertyKeys) { if (propConfig.getProperty(key) != null) { nextLoadKeyToUse = key; break; } } // there is no next load for this properties file if (nextLoadKeyToUse == null) { return null; } // make a copy of current existing properties ConcurrentMapConfiguration config = new ConcurrentMapConfiguration(); // need to have all the properties to interpolate next load property value copyProperties(ConfigurationManager.getConfigInstance(), config); copyProperties(propConfig, config); // In case this is a list of files to load, always treat the value as a list List<Object> list = config.getList(nextLoadKeyToUse); StringBuilder sb = new StringBuilder(); for (Object value: list) { sb.append(value).append(","); } String nextLoad = sb.toString(); propConfig.clearProperty(nextLoadKeyToUse); return nextLoad; }
/** * Load properties into the configuration. This method iterates through * the entries of the properties and call {@link #setProperty(String, Object)} for * non-null key/value. */ public void loadProperties(Properties props) { for (Map.Entry<Object, Object> entry: props.entrySet()) { String key = (String) entry.getKey(); Object value = entry.getValue(); if (key != null && value != null) { setProperty(key, value); } } }
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(PASSWORD_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); } }
/** * Adds the specified value for the given property. This method supports * single values and containers (e.g. collections or arrays) as well. In the * latter case, {@link #addPropertyDirect(String, Object)} will be called for each * element. * * @param key the property key * @param value the value object * @param delimiter the list delimiter character */ private void addPropertyValues(String key, Object value, char delimiter) { Iterator it = PropertyConverter.toIterator(value, delimiter); while (it.hasNext()) { addPropertyDirect(key, it.next()); } }
.clone(); copy.clearConfigurationListeners(); copy.configList = new LinkedList<AbstractConfiguration>();
/** * Load resource configName.properties first. Then load configName-deploymentEnvironment.properties * into the system wide configuration. For example, if configName is "application", and deployment environment * is "test", this API will first load "application.properties", then load "application-test.properties" to * override any property that also exist in "application.properties". * * @param configName prefix of the properties file name. * @throws IOException * @see DeploymentContext#getDeploymentEnvironment() */ public static void loadCascadedPropertiesFromResources(String configName) throws IOException { Properties props = loadCascadedProperties(configName); if (instance instanceof AggregatedConfiguration) { ConcurrentMapConfiguration config = new ConcurrentMapConfiguration(); config.loadProperties(props); ((AggregatedConfiguration) instance).addConfiguration(config, configName); } else { ConfigurationUtils.loadProperties(props, instance); } }
public static void main(String[] args) { new SampleApplication(); ConcurrentCompositeConfiguration myConfiguration = (ConcurrentCompositeConfiguration) DynamicPropertyFactory.getInstance().getBackingConfigurationSource(); ConcurrentMapConfiguration subConfig = new ConcurrentMapConfiguration(); subConfig.setProperty("com.netflix.config.samples.SampleApp.SampleBean.name", "A Coffee Bean from Cuba"); myConfiguration.setProperty("com.netflix.config.samples.sampleapp.prop1", "value1"); myConfiguration.addConfiguration(subConfig); System.out.println("Started SampleApplication. Launch JConsole to inspect and update properties."); System.out.println("To see how callback work, update property com.netflix.config.samples.SampleApp.SampleBean.sensitiveBeanData from BaseConfigBean in JConsole"); SampleBean sampleBean = new SampleBean(); // this should show the bean taking properties from two different sources // property "com.netflix.config.samples.SampleApp.SampleBean.numSeeds" is from sampleapp.properites // property "com.netflix.config.samples.SampleApp.SampleBean.name" is from subConfig added above System.out.println("SampleBean:" + sampleBean); System.out.println(sampleBean.getName()); } }
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()); con.addProperty(MAIL_AUTH, authValue.unwrapped()); con.addProperty(MAIL_USER, eagleProps.get(CONF_KEY_MAIL_USER).unwrapped()); con.addProperty(MAIL_PASSWORD, eagleProps.get(CONF_KEY_MAIL_PASSWORD).unwrapped()); con.addProperty("mail.smtp.socketFactory.port", "465"); con.addProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); con.addProperty(MAIL_TLS_ENABLE, tlsValue.unwrapped()); con.addProperty(MAIL_DEBUG, debugValue.unwrapped());
private static String getNextLoad(Configuration propConfig, String... nextLoadPropertyKeys) { String nextLoadKeyToUse = null; for (String key: nextLoadPropertyKeys) { if (propConfig.getProperty(key) != null) { nextLoadKeyToUse = key; break; } } // there is no next load for this properties file if (nextLoadKeyToUse == null) { return null; } // make a copy of current existing properties ConcurrentMapConfiguration config = new ConcurrentMapConfiguration(); // need to have all the properties to interpolate next load property value copyProperties(ConfigurationManager.getConfigInstance(), config); copyProperties(propConfig, config); // In case this is a list of files to load, always treat the value as a list List<Object> list = config.getList(nextLoadKeyToUse); StringBuilder sb = new StringBuilder(); for (Object value: list) { sb.append(value).append(","); } String nextLoad = sb.toString(); propConfig.clearProperty(nextLoadKeyToUse); return nextLoad; } }
protected void addPropertyImpl(String key, Object value) { Object previousValue = null; if (isDelimiterParsingDisabled() || ((value instanceof String) && ((String) value).indexOf(getListDelimiter()) < 0)) { previousValue = map.putIfAbsent(key, value); if (previousValue != null) { addPropertyValues(key, value, isDelimiterParsingDisabled() ? '\0' : getListDelimiter()); } } else { addPropertyValues(key, value, isDelimiterParsingDisabled() ? '\0' : getListDelimiter()); } }
/** * Load properties into the configuration. This method iterates through * the entries of the properties and call {@link #setProperty(String, Object)} for * non-null key/value. */ public void loadProperties(Properties props) { for (Map.Entry<Object, Object> entry: props.entrySet()) { String key = (String) entry.getKey(); Object value = entry.getValue(); if (key != null && value != null) { setProperty(key, value); } } }
/** * Adds the specified value for the given property. This method supports * single values and containers (e.g. collections or arrays) as well. In the * latter case, {@link #addPropertyDirect(String, Object)} will be called for each * element. * * @param key the property key * @param value the value object * @param delimiter the list delimiter character */ private void addPropertyValues(String key, Object value, char delimiter) { Iterator it = PropertyConverter.toIterator(value, delimiter); while (it.hasNext()) { addPropertyDirect(key, it.next()); } }
.clone(); copy.clearConfigurationListeners(); copy.configList = new LinkedList<AbstractConfiguration>();