use of org.osgi.service.cm.ConfigurationAdmin in project ddf by codice.
the class CswSubscriptionEndpoint method getSubscriptionConfiguration.
private Configuration getSubscriptionConfiguration(String subscriptionUuid) {
String methodName = "getSubscriptionConfiguration";
LOGGER.trace("ENTERING: {}", methodName);
String filterStr = getSubscriptionUuidFilter(subscriptionUuid);
LOGGER.debug("filterStr = {}", filterStr);
Configuration config = null;
try {
org.osgi.framework.Filter filter = getBundleContext().createFilter(filterStr);
LOGGER.debug("filter.toString() = {}", filter.toString());
ConfigurationAdmin configAdmin = getConfigAdmin();
if (configAdmin != null) {
Configuration[] configs = configAdmin.listConfigurations(filter.toString());
if (configs == null) {
LOGGER.debug("Did NOT find a configuration for filter {}", filterStr);
} else if (configs.length != 1) {
LOGGER.debug("Found multiple configurations for filter {}", filterStr);
} else {
LOGGER.debug("Found exactly one configuration for filter {}", filterStr);
config = configs[0];
}
}
} catch (InvalidSyntaxException e) {
LOGGER.debug("Invalid syntax for filter used for searching configuration instances", e);
} catch (IOException e) {
LOGGER.debug("IOException trying to list configurations for filter {}", filterStr, e);
}
LOGGER.trace("EXITING: {}", methodName);
return config;
}
use of org.osgi.service.cm.ConfigurationAdmin in project camel by apache.
the class CamelBlueprintHelper method setPersistentFileForConfigAdmin.
// pick up persistent file configuration
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void setPersistentFileForConfigAdmin(BundleContext bundleContext, String pid, String fileName, final Dictionary props, String symbolicName, Set<Long> bpEvents, boolean expectReload) throws IOException, InterruptedException {
if (pid != null) {
if (fileName == null) {
throw new IllegalArgumentException("The persistent file should not be null");
} else {
File load = new File(fileName);
LOG.debug("Loading properties from OSGi config admin file: {}", load);
org.apache.felix.utils.properties.Properties cfg = new org.apache.felix.utils.properties.Properties(load);
for (Object key : cfg.keySet()) {
props.put(key, cfg.get(key));
}
ConfigurationAdmin configAdmin = CamelBlueprintHelper.getOsgiService(bundleContext, ConfigurationAdmin.class);
if (configAdmin != null) {
// ensure we update
// we *have to* use "null" as 2nd arg to have correct bundle location for Configuration object
final Configuration config = configAdmin.getConfiguration(pid, null);
LOG.info("Updating ConfigAdmin {} by overriding properties {}", config, props);
// be CREATED again
if (expectReload) {
CamelBlueprintHelper.waitForBlueprintContainer(bpEvents, bundleContext, symbolicName, BlueprintEvent.CREATED, new Runnable() {
@Override
public void run() {
try {
config.update(props);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
});
} else {
config.update(props);
}
}
}
}
}
use of org.osgi.service.cm.ConfigurationAdmin in project camel by apache.
the class KuraRouter method start.
// Lifecycle
@Override
public void start(BundleContext bundleContext) throws Exception {
try {
this.bundleContext = bundleContext;
log.debug("Initializing bundle {}.", bundleContext.getBundle().getBundleId());
camelContext = createCamelContext();
camelContext.addRoutes(this);
ConfigurationAdmin configurationAdmin = requiredService(ConfigurationAdmin.class);
Configuration camelKuraConfig = configurationAdmin.getConfiguration(camelXmlRoutesPid());
if (camelKuraConfig != null && camelKuraConfig.getProperties() != null) {
Object routePropertyValue = camelKuraConfig.getProperties().get(camelXmlRoutesProperty());
if (routePropertyValue != null) {
InputStream routesXml = new ByteArrayInputStream(routePropertyValue.toString().getBytes());
RoutesDefinition loadedRoutes = camelContext.loadRoutesDefinition(routesXml);
camelContext.addRouteDefinitions(loadedRoutes.getRoutes());
}
}
beforeStart(camelContext);
log.debug("About to start Camel Kura router: {}", getClass().getName());
camelContext.start();
producerTemplate = camelContext.createProducerTemplate();
consumerTemplate = camelContext.createConsumerTemplate();
log.debug("Bundle {} started.", bundleContext.getBundle().getBundleId());
} catch (Throwable e) {
String errorMessage = "Problem when starting Kura module " + getClass().getName() + ":";
log.warn(errorMessage, e);
// Print error to the Kura console.
System.err.println(errorMessage);
e.printStackTrace();
throw e;
}
}
use of org.osgi.service.cm.ConfigurationAdmin in project opennms by OpenNMS.
the class HeartbeatSinkPerfIT method setUp.
@Before
public void setUp() throws Exception {
Hashtable<String, Object> kafkaConfig = new Hashtable<String, Object>();
kafkaConfig.put("bootstrap.servers", kafkaServer.getKafkaConnectString());
ConfigurationAdmin configAdmin = mock(ConfigurationAdmin.class, RETURNS_DEEP_STUBS);
when(configAdmin.getConfiguration(KafkaSinkConstants.KAFKA_CONFIG_PID).getProperties()).thenReturn(kafkaConfig);
messageDispatcherFactory.setConfigAdmin(configAdmin);
messageDispatcherFactory.init();
System.setProperty(String.format("%sbootstrap.servers", KafkaSinkConstants.KAFKA_CONFIG_SYS_PROP_PREFIX), kafkaServer.getKafkaConnectString());
System.setProperty(String.format("%sauto.offset.reset", KafkaSinkConstants.KAFKA_CONFIG_SYS_PROP_PREFIX), "earliest");
consumerManager.afterPropertiesSet();
}
use of org.osgi.service.cm.ConfigurationAdmin in project opennms by OpenNMS.
the class HeartbeatSinkIT method setUp.
@Before
public void setUp() throws Exception {
Hashtable<String, Object> kafkaConfig = new Hashtable<String, Object>();
kafkaConfig.put("bootstrap.servers", kafkaServer.getKafkaConnectString());
ConfigurationAdmin configAdmin = mock(ConfigurationAdmin.class, RETURNS_DEEP_STUBS);
when(configAdmin.getConfiguration(KafkaSinkConstants.KAFKA_CONFIG_PID).getProperties()).thenReturn(kafkaConfig);
remoteMessageDispatcherFactory.setConfigAdmin(configAdmin);
remoteMessageDispatcherFactory.init();
System.setProperty(String.format("%sbootstrap.servers", KafkaSinkConstants.KAFKA_CONFIG_SYS_PROP_PREFIX), kafkaServer.getKafkaConnectString());
System.setProperty(String.format("%sauto.offset.reset", KafkaSinkConstants.KAFKA_CONFIG_SYS_PROP_PREFIX), "earliest");
consumerManager.afterPropertiesSet();
}
Aggregations