use of io.fabric8.karaf.core.properties.PlaceholderResolver in project fabric8 by jboss-fuse.
the class FabricServiceImpl method substituteConfigurations.
/**
* Performs substitution to configuration based on the registered {@link PlaceholderResolver} instances.
*/
public Map<String, Map<String, String>> substituteConfigurations(final Map<String, Map<String, String>> configurations) {
final Map<String, PlaceholderResolver> resolversSnapshot = new HashMap<String, PlaceholderResolver>(placeholderResolvers);
// Check that all resolvers are available
Set<String> requiredSchemes = getSchemesForProfileConfigurations(configurations);
Set<String> availableSchemes = resolversSnapshot.keySet();
if (!availableSchemes.containsAll(requiredSchemes)) {
StringBuilder sb = new StringBuilder();
sb.append("Missing Placeholder Resolvers:");
for (String scheme : requiredSchemes) {
if (!availableSchemes.contains(scheme)) {
sb.append(" ").append(scheme);
}
}
throw new FabricException(sb.toString());
}
final Map<String, Map<String, String>> mutableConfigurations = new HashMap<>();
for (Entry<String, Map<String, String>> entry : configurations.entrySet()) {
String key = entry.getKey();
Map<String, String> value = new HashMap<>(entry.getValue());
mutableConfigurations.put(key, value);
}
final FabricService fabricService = this;
for (Map.Entry<String, Map<String, String>> entry : mutableConfigurations.entrySet()) {
final String pid = entry.getKey();
Map<String, String> props = entry.getValue();
Map<String, String> original = new HashMap<>(props);
for (Map.Entry<String, String> e : original.entrySet()) {
final String key = e.getKey();
final String value = e.getValue();
try {
props.put(key, InterpolationHelper.substVars(value, key, null, props, new InterpolationHelper.SubstitutionCallback() {
public String getValue(String toSubstitute) {
if (toSubstitute != null && toSubstitute.contains(":")) {
String scheme = toSubstitute.substring(0, toSubstitute.indexOf(":"));
return resolversSnapshot.get(scheme).resolve(fabricService, mutableConfigurations, pid, key, toSubstitute);
}
return substituteBundleProperty(toSubstitute, bundleContext);
}
}));
} catch (EncryptionOperationNotPossibleException exception) {
LOGGER.warn("Error resolving " + key, exception);
}
}
}
return mutableConfigurations;
}
use of io.fabric8.karaf.core.properties.PlaceholderResolver in project fabric8 by jboss-fuse.
the class ContainerPlaceholderResolverTest method testResolveNameContainerAttributes.
@Test
public void testResolveNameContainerAttributes() throws Exception {
PlaceholderResolver resolver = getContainerPlaceholderResolver();
assertEquals(ip, resolver.resolve(fabricService, null, null, null, "container:root/ip"));
assertEquals(localhostname, resolver.resolve(fabricService, null, null, null, "container:root/localhostname"));
assertEquals(bindaddress, resolver.resolve(fabricService, null, null, null, "container:root/bindaddress"));
assertEquals(containerResolver, resolver.resolve(fabricService, null, null, null, "container:root/resolver"));
verify(fabricService);
verify(dataStore);
}
use of io.fabric8.karaf.core.properties.PlaceholderResolver in project fabric8 by jboss-fuse.
the class ContainerPlaceholderResolverTest method testResolveCurrentAttributes.
@Test
public void testResolveCurrentAttributes() throws Exception {
PlaceholderResolver resolver = getContainerPlaceholderResolver();
assertEquals(ip, resolver.resolve(fabricService, null, null, null, "container:ip"));
assertEquals(localhostname, resolver.resolve(fabricService, null, null, null, "container:localhostname"));
assertEquals(bindaddress, resolver.resolve(fabricService, null, null, null, "container:bindaddress"));
assertEquals(containerResolver, resolver.resolve(fabricService, null, null, null, "container:resolver"));
verify(fabricService);
verify(dataStore);
}
use of io.fabric8.karaf.core.properties.PlaceholderResolver in project fabric8 by fabric8io.
the class Fabric8PropertyEvaluator method evaluate.
@Override
public String evaluate(String key, Dictionary<String, String> dictionary) {
PlaceholderResolver res = resolver.get();
String value = null;
if (res != null) {
value = res.resolve(key);
}
return value != null ? value : dictionary.get(key);
}
Aggregations