use of org.osgi.service.cm.Configuration in project karaf by apache.
the class SecuredCommandConfigTransformer method configurationEvent.
@Override
public void configurationEvent(ConfigurationEvent event) {
if (!event.getPid().startsWith(PROXY_COMMAND_ACL_PID_PREFIX))
return;
try {
switch(event.getType()) {
case ConfigurationEvent.CM_DELETED:
deleteServiceGuardConfig(event.getPid(), event.getPid().substring(PROXY_COMMAND_ACL_PID_PREFIX.length()));
break;
case ConfigurationEvent.CM_UPDATED:
Configuration config = configAdmin.getConfiguration(event.getPid(), null);
generateServiceGuardConfig(config);
refreshTheAffectedShellCommandBundle(event, config);
break;
}
} catch (Exception e) {
LOGGER.error("Problem processing Configuration Event {}", event, e);
}
}
use of org.osgi.service.cm.Configuration in project karaf by apache.
the class ConfigRepositoryImpl method updateStorage.
protected void updateStorage(String pid, Dictionary<String, Object> props) throws IOException {
if (storage != null) {
Configuration cfg = configAdmin.getConfiguration(pid, null);
// Initialize cfgFile with default location. Value gets overwritten when the existing configuration references a correct location.
File cfgFile = new File(storage, pid + ".cfg");
if (cfg != null) {
Dictionary<String, Object> oldProps = cfg.getProperties();
if (oldProps != null && oldProps.get(FILEINSTALL_FILE_NAME) != null) {
try {
cfgFile = getCfgFileFromProperties(oldProps);
if (cfgFile == null) {
throw new IOException("The configuration value '" + oldProps.get(FILEINSTALL_FILE_NAME) + "' for '" + FILEINSTALL_FILE_NAME + "' does not represent a valid file location.");
}
} catch (URISyntaxException | MalformedURLException e) {
throw new IOException(e);
}
}
}
LOGGER.trace("Update {}", cfgFile.getName());
// update the cfg file
Properties properties = new Properties(cfgFile);
for (Enumeration<String> keys = props.keys(); keys.hasMoreElements(); ) {
String key = keys.nextElement();
if (!Constants.SERVICE_PID.equals(key) && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key) && !FILEINSTALL_FILE_NAME.equals(key)) {
if (props.get(key) != null) {
properties.put(key, props.get(key).toString());
}
}
}
// remove "removed" properties from the cfg file
ArrayList<String> propertiesToRemove = new ArrayList<>();
for (String key : properties.keySet()) {
if (props.get(key) == null && !Constants.SERVICE_PID.equals(key) && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key) && !FILEINSTALL_FILE_NAME.equals(key)) {
propertiesToRemove.add(key);
}
}
for (String key : propertiesToRemove) {
properties.remove(key);
}
// save the cfg file
storage.mkdirs();
properties.save();
}
}
use of org.osgi.service.cm.Configuration in project karaf by apache.
the class ConfigManagedServiceFactoryTest method createNewFactoryConfig.
@Test
public void createNewFactoryConfig() throws Exception {
executeCommand("config:edit --factory myconfig2\n" + "config:property-set test1 data1\n" + "config:update", new RolePrincipal("manager"));
Configuration config = configAdmin.listConfigurations("(service.factorypid=myconfig2)")[0];
assertEquals("data1", config.getProperties().get("test1"));
}
use of org.osgi.service.cm.Configuration in project karaf by apache.
the class JdbcServiceImpl method delete.
@Override
public void delete(String name) throws Exception {
String filter = String.format("(%s=%s)", DataSourceFactory.JDBC_DATASOURCE_NAME, name);
Configuration[] configs = configAdmin.listConfigurations(filter);
for (Configuration config : configs) {
config.delete();
}
}
use of org.osgi.service.cm.Configuration in project karaf by apache.
the class JdbcServiceImpl method create.
@Override
public void create(String name, String driverName, String driverClass, String databaseName, String url, String user, String password, String databaseType) throws Exception {
if (driverName == null && driverClass == null) {
throw new IllegalStateException("No driverName or driverClass supplied");
}
if (datasources().contains(name)) {
throw new IllegalArgumentException("There is already a DataSource with the name " + name);
}
Dictionary<String, String> properties = new Hashtable<>();
properties.put(DataSourceFactory.JDBC_DATASOURCE_NAME, name);
put(properties, DataSourceFactory.OSGI_JDBC_DRIVER_NAME, driverName);
put(properties, DataSourceFactory.OSGI_JDBC_DRIVER_CLASS, driverClass);
put(properties, DataSourceFactory.JDBC_DATABASE_NAME, databaseName);
put(properties, DataSourceFactory.JDBC_URL, url);
put(properties, DataSourceFactory.JDBC_USER, user);
put(properties, DataSourceFactory.JDBC_PASSWORD, password);
put(properties, "dataSourceType", databaseType);
Configuration config = configAdmin.createFactoryConfiguration("org.ops4j.datasource", null);
config.update(properties);
}
Aggregations