[KARAF-2514] Improve Cellar config, especially around configuration deletion
git-svn-id: https://svn.apache.org/repos/asf/karaf/cellar/branches/cellar-2.3.x@1531337 13f79535-47bb-0310-9956-ffa450edef68 Project: http://git-wip-us.apache.org/repos/asf/karaf-cellar/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf-cellar/commit/fa9efea6 Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/fa9efea6 Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/fa9efea6 Branch: refs/heads/cellar-2.3.x Commit: fa9efea6499f7b9415fe121dfc0ee70f45f1efe0 Parents: 27bd59c Author: jbonofre <jbonofre@13f79535-47bb-0310-9956-ffa450edef68> Authored: Fri Oct 11 16:10:28 2013 +0000 Committer: jbonofre <jbonofre@13f79535-47bb-0310-9956-ffa450edef68> Committed: Fri Oct 11 16:10:28 2013 +0000 ---------------------------------------------------------------------- .../config/ClusterConfigurationEvent.java | 6 ++-- .../config/ConfigurationEventHandler.java | 12 +++---- .../config/LocalConfigurationListener.java | 35 +++++++++----------- 3 files changed, 25 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/fa9efea6/config/src/main/java/org/apache/karaf/cellar/config/ClusterConfigurationEvent.java ---------------------------------------------------------------------- diff --git a/config/src/main/java/org/apache/karaf/cellar/config/ClusterConfigurationEvent.java b/config/src/main/java/org/apache/karaf/cellar/config/ClusterConfigurationEvent.java index eb8c9ef..c90ce1a 100644 --- a/config/src/main/java/org/apache/karaf/cellar/config/ClusterConfigurationEvent.java +++ b/config/src/main/java/org/apache/karaf/cellar/config/ClusterConfigurationEvent.java @@ -20,17 +20,17 @@ import org.apache.karaf.cellar.core.event.Event; */ public class ClusterConfigurationEvent extends Event { - private int type; + private Integer type; public ClusterConfigurationEvent(String id) { super(id); } - public int getType() { + public Integer getType() { return type; } - public void setType(int type) { + public void setType(Integer type) { this.type = type; } http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/fa9efea6/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java ---------------------------------------------------------------------- diff --git a/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java b/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java index f1357f5..ca54078 100644 --- a/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java +++ b/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationEventHandler.java @@ -65,18 +65,18 @@ public class ConfigurationEventHandler extends ConfigurationSupport implements E if (isAllowed(event.getSourceGroup(), Constants.CATEGORY, pid, EventType.INBOUND)) { Properties clusterDictionary = clusterConfigurations.get(pid); - Configuration localConfiguration; try { // update the local configuration - localConfiguration = configurationAdmin.getConfiguration(pid, null); + Configuration[] localConfigurations = configurationAdmin.listConfigurations("(service.pid=" + pid + ")"); if (event.getType() == ConfigurationEvent.CM_DELETED) { - if (localConfiguration.getProperties() != null) { - // delete the properties - localConfiguration.delete(); + // delete the configuration + if (localConfigurations != null && localConfigurations.length > 0) { + localConfigurations[0].delete(); deleteStorage(pid); } } else { if (clusterDictionary != null) { + Configuration localConfiguration = configurationAdmin.getConfiguration(pid, null); Dictionary localDictionary = localConfiguration.getProperties(); if (localDictionary == null) localDictionary = new Properties(); @@ -87,7 +87,7 @@ public class ConfigurationEventHandler extends ConfigurationSupport implements E } } } - } catch (IOException ex) { + } catch (Exception ex) { LOGGER.error("CELLAR CONFIG: failed to update local configuration", ex); } } else LOGGER.debug("CELLAR CONFIG: configuration with PID {} is marked BLOCKED INBOUND for cluster group {}", pid, groupName); http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/fa9efea6/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java ---------------------------------------------------------------------- diff --git a/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java b/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java index bd1dab6..c88fd0d 100644 --- a/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java +++ b/config/src/main/java/org/apache/karaf/cellar/config/LocalConfigurationListener.java @@ -55,17 +55,6 @@ public class LocalConfigurationListener extends ConfigurationSupport implements String pid = event.getPid(); - Dictionary localDictionary = null; - if (event.getType() != ConfigurationEvent.CM_DELETED) { - try { - Configuration conf = configurationAdmin.getConfiguration(pid, null); - localDictionary = conf.getProperties(); - } catch (Exception e) { - LOGGER.error("CELLAR CONFIG: can't retrieve configuration with PID {}", pid, e); - return; - } - } - Set<Group> groups = groupManager.listLocalGroups(); if (groups != null && !groups.isEmpty()) { @@ -77,15 +66,22 @@ public class LocalConfigurationListener extends ConfigurationSupport implements try { if (event.getType() == ConfigurationEvent.CM_DELETED) { - // update the configurations in the cluster group - clusterConfigurations.remove(pid); - // broadcast the cluster event - ClusterConfigurationEvent clusterConfigurationEvent = new ClusterConfigurationEvent(pid); - clusterConfigurationEvent.setType(ConfigurationEvent.CM_DELETED); - clusterConfigurationEvent.setSourceNode(clusterManager.getNode()); - clusterConfigurationEvent.setSourceGroup(group); - eventProducer.produce(clusterConfigurationEvent); + + if (clusterConfigurations.containsKey(pid)) { + // update the configurations in the cluster group + clusterConfigurations.remove(pid); + // broadcast the cluster event + ClusterConfigurationEvent clusterConfigurationEvent = new ClusterConfigurationEvent(pid); + clusterConfigurationEvent.setType(event.getType()); + clusterConfigurationEvent.setSourceNode(clusterManager.getNode()); + clusterConfigurationEvent.setSourceGroup(group); + eventProducer.produce(clusterConfigurationEvent); + } } else { + + Configuration conf = configurationAdmin.getConfiguration(pid, null); + Dictionary localDictionary = conf.getProperties(); + localDictionary = filter(localDictionary); Properties distributedDictionary = clusterConfigurations.get(pid); @@ -95,6 +91,7 @@ public class LocalConfigurationListener extends ConfigurationSupport implements clusterConfigurations.put(pid, dictionaryToProperties(localDictionary)); // broadcast the cluster event ClusterConfigurationEvent clusterConfigurationEvent = new ClusterConfigurationEvent(pid); + clusterConfigurationEvent.setType(event.getType()); clusterConfigurationEvent.setSourceGroup(group); clusterConfigurationEvent.setSourceNode(clusterManager.getNode()); eventProducer.produce(clusterConfigurationEvent);
