use of org.osgi.service.cm.Configuration in project sling by apache.
the class MockOsgi method setConfigForPid.
private static void setConfigForPid(BundleContext bundleContext, String pid, Dictionary<String, Object> properties) {
ConfigurationAdmin configAdmin = getConfigAdmin(bundleContext);
if (configAdmin == null) {
throw new RuntimeException("ConfigurationAdmin service is not registered in bundle context.");
}
try {
Configuration config = configAdmin.getConfiguration(pid);
config.update(properties);
} catch (IOException ex) {
throw new RuntimeException("Unable to update configuration for pid '" + pid + "'.", ex);
}
}
use of org.osgi.service.cm.Configuration in project sling by apache.
the class OsgiInstallerTestBase method waitForConfiguration.
/**
* Internal method to wait for a configuration
*/
private Configuration waitForConfiguration(final String info, final String pid, final String factoryPid, final boolean shouldBePresent) throws Exception {
final String logKey = factoryPid == null ? "config" : "factory config";
String msg;
if (info == null) {
msg = "";
} else {
msg = info + ": ";
}
Configuration result = null;
final long start = System.currentTimeMillis();
final long end = start + WAIT_FOR_CHANGE_TIMEOUT;
log(LogService.LOG_DEBUG, "Starting " + logKey + " check at " + start + "; ending by " + end);
do {
if (factoryPid != null) {
result = findFactoryConfiguration(factoryPid);
} else {
result = findConfiguration(pid);
}
if ((shouldBePresent && result != null) || (!shouldBePresent && result == null)) {
break;
}
log(LogService.LOG_DEBUG, logKey + " check failed at " + System.currentTimeMillis() + "; sleeping");
sleep(25);
} while (System.currentTimeMillis() < end);
if (shouldBePresent && result == null) {
fail(msg + logKey + " not found (" + (factoryPid != null ? factoryPid : pid) + ")");
} else if (!shouldBePresent && result != null) {
fail(msg + logKey + " is still present (" + (factoryPid != null ? factoryPid : pid) + ")");
}
return result;
}
use of org.osgi.service.cm.Configuration in project sling by apache.
the class OsgiConfigurationManager method deleteOsgiConfigs.
private void deleteOsgiConfigs(List<Configuration> configurations) {
for (Configuration configuration : configurations) {
String pid = configuration.getPid();
try {
configuration.delete();
log.info("Deleted configuration {}", pid);
} catch (IOException e) {
log.warn("Cannot delete configuration {}", pid, e);
}
}
}
use of org.osgi.service.cm.Configuration in project sling by apache.
the class OsgiConfigurationManager method getConfig.
public DistributionConfiguration getConfig(ResourceResolver resolver, DistributionComponentKind kind, String name) {
List<Configuration> configurations = getOsgiConfigurations(kind, name);
if (configurations == null || configurations.isEmpty()) {
return null;
}
if (configurations.size() > 1) {
log.warn("Found more than one configuration of kind: {} and with name: {}", new String[] { kind.getName(), name });
}
Configuration configuration = configurations.get(0);
if (configuration != null) {
@SuppressWarnings("unchecked") Dictionary<String, Object> properties = configuration.getProperties();
Map<String, Object> result = OsgiUtils.fromDictionary(properties);
String factoryPid = PropertiesUtil.toString(result.get(ConfigurationAdmin.SERVICE_FACTORYPID), null);
String type = kind.getType(factoryPid);
result.put(DistributionComponentConstants.PN_TYPE, type);
result = filterBeforeRead(result);
return new DistributionConfiguration(kind, name, result);
}
return null;
}
use of org.osgi.service.cm.Configuration in project sling by apache.
the class DataSourceIT method testDataSourceAsService.
@SuppressWarnings("unchecked")
@Test
public void testDataSourceAsService() throws Exception {
Configuration config = ca.createFactoryConfiguration(PID, null);
Dictionary<String, Object> p = new Hashtable<String, Object>();
p.put("url", "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
p.put("datasource.name", "test");
p.put("initialSize", "5");
p.put("defaultAutoCommit", "default");
p.put("defaultReadOnly", "false");
p.put("datasource.svc.properties", new String[] { "initSQL=SELECT 1" });
p.put("maxActive", 70);
config.update(p);
Filter filter = context.createFilter("(&(objectclass=javax.sql.DataSource)(datasource.name=test))");
ServiceTracker<DataSource, DataSource> st = new ServiceTracker<DataSource, DataSource>(context, filter, null);
st.open();
DataSource ds = st.waitForService(10000);
assertNotNull(ds);
Connection conn = ds.getConnection();
assertNotNull(conn);
//Cannot access directly so access via reflection
assertEquals("70", getProperty(ds, "poolProperties.maxActive"));
assertEquals("5", getProperty(ds, "poolProperties.initialSize"));
assertEquals("SELECT 1", getProperty(ds, "poolProperties.initSQL"));
assertEquals("false", getProperty(ds, "poolProperties.defaultReadOnly"));
assertNull(getProperty(ds, "poolProperties.defaultAutoCommit"));
config = ca.listConfigurations("(datasource.name=test)")[0];
Dictionary dic = config.getProperties();
dic.put("defaultReadOnly", Boolean.TRUE);
config.update(dic);
TimeUnit.MILLISECONDS.sleep(100);
assertEquals("true", getProperty(ds, "poolProperties.defaultReadOnly"));
}
Aggregations