@Before public void setupOrg() { originalShardSize = ConfigurationManager.getConfigInstance().getProperty( GraphFig.SHARD_SIZE ); originalShardTimeout = ConfigurationManager.getConfigInstance().getProperty( GraphFig.SHARD_CACHE_TIMEOUT ); originalShardDelta = ConfigurationManager.getConfigInstance().getProperty( GraphFig.SHARD_MIN_DELTA ); ConfigurationManager.getConfigInstance().setProperty( GraphFig.SHARD_SIZE, 10000 ); final long cacheTimeout = 1000; //set our cache timeout to the above value ConfigurationManager.getConfigInstance().setProperty( GraphFig.SHARD_CACHE_TIMEOUT, cacheTimeout ); final long minDelta = ( long ) ( cacheTimeout * 2.5 ); ConfigurationManager.getConfigInstance().setProperty( GraphFig.SHARD_MIN_DELTA, minDelta ); // get the system property of the UUID to use. If one is not set, use the defualt String uuidString = System.getProperty( "org.id", "80a42760-b699-11e3-a5e2-0800200c9a66" ); scope = new ApplicationScopeImpl( IdGenerator.createId(UUIDGenerator.newTimeUUID(), "test" ) ); reporter = Slf4jReporter.forRegistry( registry ).outputTo(logger).convertRatesTo( TimeUnit.SECONDS ) .convertDurationsTo( TimeUnit.MILLISECONDS ).build(); reporter.start( 10, TimeUnit.SECONDS ); }
public static AbstractConfiguration convertEnvVariable(AbstractConfiguration source) { Iterator<String> keys = source.getKeys(); while (keys.hasNext()) { String key = keys.next(); String[] separatedKey = key.split(CONFIG_KEY_SPLITER); if (separatedKey.length == 1) { continue; } String newKey = String.join(".", separatedKey); source.addProperty(newKey, source.getProperty(key)); } return source; }
@Override protected Properties mergeProperties() throws IOException { Properties properties = super.mergeProperties(); AbstractConfiguration config = ConfigurationManager.getConfigInstance(); Iterator<String> iter = config.getKeys(); while (iter.hasNext()) { String key = iter.next(); Object value = config.getProperty(key); properties.put(key, value); } return properties; }
private static void duplicateCseConfigToServicecomb(AbstractConfiguration source) { Iterator<String> keys = source.getKeys(); while (keys.hasNext()) { String key = keys.next(); if (!key.startsWith(CONFIG_CSE_PREFIX)) { continue; } String servicecombKey = CONFIG_SERVICECOMB_PREFIX + key.substring(key.indexOf(".") + 1); if (!source.containsKey(servicecombKey)) { source.addProperty(servicecombKey, source.getProperty(key)); } else { LOGGER .warn( "Key {} with an ambiguous item {} exists, it's recommended to use only one of them.", key, servicecombKey); } } }
@Override public Object getProperty(String key) { return config.getProperty(key); }
@Override public Object getProperty(String key) { return config.getProperty(key); }
public Object getHystrixConfig(String key, Object value) { return hystrixConfig.getProperty(key); }
@Override public String format() { return ConfigurationManager.getConfigInstance().getProperty(propertyName).toString(); } }
public static <T> T getNamedInstance(Class<T> type, String name) { ApplicationContext context = (ApplicationContext) ConfigurationManager .getConfigInstance().getProperty(APPLICATION_CONTEXT); return context != null && context.containsBean(name) ? context .getBean(name, type) : null; }
public static <T> T getNamedInstance(Class<T> type, String name) { ApplicationContext context = (ApplicationContext) ConfigurationManager .getConfigInstance() .getProperty(APPLICATION_CONTEXT); return context != null && context.containsBean(name) ? context .getBean(name, type) : null; }
public static AbstractConfiguration convertEnvVariable(AbstractConfiguration source) { Iterator<String> keys = source.getKeys(); while (keys.hasNext()) { String key = keys.next(); String[] separatedKey = key.split(CONFIG_KEY_SPLITER); if (separatedKey.length == 1) { continue; } String newKey = String.join(".", separatedKey); source.addProperty(newKey, source.getProperty(key)); } return source; }
/** * Returns an object from the store described by the key. If the value is a * Collection object, replace it with the first object in the collection. * * @param key The property key. * * @return value Value, transparently resolving a possible collection dependency. */ protected Object resolveContainerStore(String key) { Object value = getProperty(key); if (value != null) { if (value instanceof Collection) { Collection<?> collection = (Collection<?>) value; value = collection.isEmpty() ? null : collection.iterator().next(); } else if (value.getClass().isArray() && Array.getLength(value) > 0) { value = Array.get(value, 0); } } return value; }
/** * Returns an object from the store described by the key. If the value is a * Collection object, replace it with the first object in the collection. * * @param key The property key. * * @return value Value, transparently resolving a possible collection dependency. */ protected Object resolveContainerStore(String key) { Object value = getProperty(key); if (value != null) { if (value instanceof Collection) { Collection<?> collection = (Collection<?>) value; value = collection.isEmpty() ? null : collection.iterator().next(); } else if (value.getClass().isArray() && Array.getLength(value) > 0) { value = Array.get(value, 0); } } return value; }
@Override protected Properties mergeProperties() throws IOException { Properties properties = super.mergeProperties(); AbstractConfiguration config = ConfigurationManager.getConfigInstance(); Iterator<String> iter = config.getKeys(); while (iter.hasNext()) { String key = iter.next(); Object value = config.getProperty(key); properties.put(key, value); } return properties; }
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // get list of properties TreeSet<String> properties = new TreeSet<String>(); AbstractConfiguration config = ConfigurationManager.getConfigInstance(); Iterator<String> keys = config.getKeys(); while (keys.hasNext()) { String key = keys.next(); Object value = config.getProperty(key); if ("aws.accessId".equals(key) || "aws.secretKey".equals(key) || "experiments-service.secret".equals(key) || "java.class.path".equals(key) || key.contains("framework.securityDefinition") || key.contains("password") || key.contains("secret")) { value = "*****"; } properties.add(key + "=" + value.toString()); } // write them out in sorted order for (String line : properties) { resp.getWriter().append(line).println(); } } }
private static void duplicateCseConfigToServicecomb(AbstractConfiguration source) { Iterator<String> keys = source.getKeys(); while (keys.hasNext()) { String key = keys.next(); if (!key.startsWith(CONFIG_CSE_PREFIX)) { continue; } String servicecombKey = CONFIG_SERVICECOMB_PREFIX + key.substring(key.indexOf(".") + 1); if (!source.containsKey(servicecombKey)) { source.addProperty(servicecombKey, source.getProperty(key)); } else { LOGGER .warn( "Key {} with an ambiguous item {} exists, it's recommended to use only one of them.", key, servicecombKey); } } }
@Override public String getString(String key) { try { String values[] = config.getStringArray(key); if (values == null) { return null; } if (values.length == 0) { return config.getString(key); } else if (values.length == 1) { return values[0]; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < values.length; i++) { sb.append(values[i]); if (i != values.length - 1) { sb.append(","); } } return sb.toString(); } catch (Exception e) { Object v = config.getProperty(key); if (v != null) { return String.valueOf(v); } else { return null; } } }
public static List<Property> getAllProperties() { final AbstractConfiguration configInstance = ConfigurationManager.getConfigInstance(); List<Property> properties = new ArrayList<Property>(); Iterator keys = null; try { keys = configInstance.getKeys(); } catch (Exception e) { LOG.error("Exception fetching all property keys ", e); } Set<String> maskedResources = MaskedResourceHelper.getMaskedPropertiesSet(); while (keys.hasNext()) { final String key = (String) keys.next(); try { Object value = null; // mask the specified properties if (maskedResources.contains(key)) { value = MaskedResourceHelper.MASKED_PROPERTY_VALUE; } else { value = configInstance.getProperty(key); } Property property = new Property(key, value.toString(), null); properties.add(property); } catch (Exception e) { LOG.info("Exception fetching property value for key " + key, e); } } return properties; }
/** * Triggers the contained configurations to perform a reload check if * necessary. This method is called when a property of this combined * configuration is accessed and the {@code forceReloadCheck} property * is set to <b>true</b>. * * @see #setForceReloadCheck(boolean) * @since 1.6 */ protected void performReloadCheck() { for (ConfigData cd : configurations) { try { // simply retrieve a property; this is enough for // triggering a reload cd.getConfiguration().getProperty(PROP_RELOAD_CHECK); } catch (Exception ex) { if (!ignoreReloadExceptions) { throw new ConfigurationRuntimeException(ex); } } } }
/** * Triggers the contained configurations to perform a reload check if * necessary. This method is called when a property of this combined * configuration is accessed and the {@code forceReloadCheck} property * is set to <b>true</b>. * * @see #setForceReloadCheck(boolean) * @since 1.6 */ protected void performReloadCheck() { for (ConfigData cd : configurations) { try { // simply retrieve a property; this is enough for // triggering a reload cd.getConfiguration().getProperty(PROP_RELOAD_CHECK); } catch (Exception ex) { if (!ignoreReloadExceptions) { throw new ConfigurationRuntimeException(ex); } } } }