in genie-common-internal/src/main/java/com/netflix/genie/common/internal/util/PropertySourceUtils.java [79:119]
public static Map<String, String> createPropertiesSnapshot(
final Environment environment,
final String prefix
) {
// Obtain properties sources from environment
final PropertySources propertySources;
if (environment instanceof ConfigurableEnvironment) {
propertySources = ((ConfigurableEnvironment) environment).getPropertySources();
} else {
propertySources = new StandardEnvironment().getPropertySources();
}
// Create set of all properties that match the filter pattern
final Set<String> filteredPropertyNames = Sets.newHashSet();
for (final PropertySource<?> propertySource : propertySources) {
if (propertySource instanceof EnumerablePropertySource) {
for (final String propertyName : ((EnumerablePropertySource<?>) propertySource).getPropertyNames()) {
if (propertyName.startsWith(prefix)) {
log.debug("Adding matching property: {}", propertyName);
filteredPropertyNames.add(propertyName);
} else {
log.debug("Ignoring property: {}", propertyName);
}
}
}
}
// Create immutable properties map
final ImmutableMap.Builder<String, String> propertiesMapBuilder = ImmutableMap.builder();
for (final String propertyName : filteredPropertyNames) {
final String propertyValue = environment.getProperty(propertyName);
final String strippedPropertyName = StringUtils.removeStart(propertyName, prefix);
if (StringUtils.isBlank(strippedPropertyName) || StringUtils.isBlank(propertyValue)) {
log.debug("Skipping blank value property: {}", propertyName);
} else {
propertiesMapBuilder.put(strippedPropertyName, propertyValue);
}
}
return propertiesMapBuilder.build();
}