Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
Expand Down Expand Up @@ -134,6 +135,31 @@ public Properties getProperties() {
return result;
}

@Override
public Map<String, Map<String, String>> getPropertiesBySource() {
final Map<String, Map<String, String>> result = new HashMap<>();
final Map<String, String> systemProps = new HashMap<>();

properties.stringPropertyNames().forEach(key -> systemProps.put(key, properties.getProperty(key)));
result.put("SystemProperties", systemProps);

final Map<String, Map<String, String>> runtimeBySource = RuntimeConfigRegistry.getAllBySource();
runtimeBySource.forEach((source, props) -> {
final Map<String, String> filteredProps = new HashMap<>();
props.forEach((key, value) -> {
if (!systemProps.containsKey(key)) {
filteredProps.put(key, value);
}
});

if (!filteredProps.isEmpty()) {
result.put(source, filteredProps);
}
});

return result;
}

private Properties loadPropertiesFromFileOrSystemProperties() {
// Chicken-egg problem. It would be nice to have the property in e.g. KillbillServerConfig,
// but we need to build the ConfigSource first...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.exceptions.EncryptionOperationNotPossibleException;
import org.killbill.billing.osgi.api.OSGIConfigProperties;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.testng.Assert;

import static org.killbill.billing.platform.config.DefaultKillbillConfigSource.ENVIRONMENT_VARIABLE_PREFIX;

Expand Down Expand Up @@ -68,6 +68,25 @@ public void testGetProperties() throws URISyntaxException, IOException {
Assert.assertEquals(configSource.getProperties().getProperty("1"), "A");
}

@Test(groups = "fast")
public void testGetPropertiesBySource() throws URISyntaxException, IOException {
final Map<String, String> configuration = new HashMap<>();
configuration.put("org.killbill.dao.user", "root");
configuration.put("org.killbill.dao.password", "password");

final OSGIConfigProperties configSource = new DefaultKillbillConfigSource(null, configuration);

final Map<String, Map<String, String>> propsBySource = configSource.getPropertiesBySource();

Assert.assertNotNull(propsBySource);
Assert.assertFalse(propsBySource.isEmpty());

final Map<String, String> defaultProps = propsBySource.get("SystemProperties");
Assert.assertNotNull(defaultProps);
Assert.assertEquals(defaultProps.get("org.killbill.dao.user"), "root");
Assert.assertEquals(defaultProps.get("org.killbill.dao.password"), "password");
}

@Test(groups = "fast")
public void testFromEnvVariableName() throws IOException, URISyntaxException {
final DefaultKillbillConfigSource configSource = new DefaultKillbillConfigSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.killbill.billing.osgi.api;

import java.util.Map;
import java.util.Properties;

/**
Expand All @@ -28,13 +29,26 @@
public interface OSGIConfigProperties {

/**
* Retrieves the value of the given property.
*
* @param propertyName the system property name
* @return the value of the property
*/
public String getString(final String propertyName);

/**
* @return all knows system properties (for the JVM)
* Returns all runtime resolved properties as a flat {@link Properties} object.
*
* @return all known configuration properties
*/
public Properties getProperties();

/**
* Returns all runtime resolved properties grouped by their respective source.
* Each key in the outer map represents the source name (e.g., "SystemProperties", "KillbillServerConfig", "CatalogConfig"),
* and the corresponding value is a map of property names to values loaded from that source.
*
* @return a map of configuration sources to their respective key-value property sets.
*/
public Map<String, Map<String, String>> getPropertiesBySource();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.killbill.billing.osgi.libs.killbill;

import java.util.Map;
import java.util.Properties;

import org.killbill.billing.osgi.api.OSGIConfigProperties;
Expand Down Expand Up @@ -59,4 +60,14 @@ public Properties executeWithService(final OSGIConfigProperties service) {
}
});
}

@Override
public Map<String, Map<String, String>> getPropertiesBySource() {
return withServiceTracker(killbillTracker, new APICallback<>(OSGIConfigProperties.class.getName()) {
@Override
public Map<String, Map<String, String>> executeWithService(final OSGIConfigProperties service) {
return service.getPropertiesBySource();
}
});
}
}
Loading