karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject [48/50] [abbrv] git commit: [KARAF-2514] Improve Cellar config, especially around configuration deletion
Date Wed, 18 Dec 2013 12:23:23 GMT
[KARAF-2514] Improve Cellar config, especially around configuration deletion

git-svn-id: https://svn.apache.org/repos/asf/karaf/cellar/trunk@1531345 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/5fe65839
Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/5fe65839
Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/5fe65839

Branch: refs/heads/master
Commit: 5fe65839e4473d72dae4ac03515441a84fe7a5bc
Parents: ef5dec8
Author: jbonofre <jbonofre@13f79535-47bb-0310-9956-ffa450edef68>
Authored: Fri Oct 11 16:23:41 2013 +0000
Committer: jbonofre <jbonofre@13f79535-47bb-0310-9956-ffa450edef68>
Committed: Fri Oct 11 16:23:41 2013 +0000

----------------------------------------------------------------------
 .../config/ClusterConfigurationEvent.java       |  6 ++--
 .../config/ConfigurationEventHandler.java       | 17 +++++-----
 .../config/LocalConfigurationListener.java      | 34 +++++++++-----------
 3 files changed, 27 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/5fe65839/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 d3eb7ee..9c51e44 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/5fe65839/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 7cf7211..e1d87ad 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
@@ -72,28 +72,29 @@ public class ConfigurationEventHandler extends ConfigurationSupport implements
E
         if (isAllowed(event.getSourceGroup(), Constants.CATEGORY, pid, EventType.INBOUND))
{
 
             Properties clusterDictionary = clusterConfigurations.get(pid);
-            Configuration conf;
             try {
-                conf = configurationAdmin.getConfiguration(pid, null);
+                // update the local configuration
+                Configuration[] localConfigurations = configurationAdmin.listConfigurations("(service.pid="
+ pid + ")");
                 if (event.getType() == ConfigurationEvent.CM_DELETED) {
-                    if (conf.getProperties() != null) {
-                        // delete the properties
-                        conf.delete();
+                    // delete the configuration
+                    if (localConfigurations != null && localConfigurations.length
> 0) {
+                        localConfigurations[0].delete();
                         deleteStorage(pid);
                     }
                 } else {
                     if (clusterDictionary != null) {
-                        Dictionary localDictionary = conf.getProperties();
+                        Configuration localConfiguration = configurationAdmin.getConfiguration(pid,
null);
+                        Dictionary localDictionary = localConfiguration.getProperties();
                         if (localDictionary == null)
                             localDictionary = new Properties();
                         localDictionary = filter(localDictionary);
                         if (!equals(clusterDictionary, localDictionary)) {
-                            conf.update((Dictionary) clusterDictionary);
+                            localConfiguration.update((Dictionary) clusterDictionary);
                             persistConfiguration(configurationAdmin, pid, clusterDictionary);
                         }
                     }
                 }
-            } catch (IOException ex) {
+            } catch (Exception ex) {
                 LOGGER.error("CELLAR CONFIG: failed to read cluster configuration", ex);
             }
         } else LOGGER.debug("CELLAR CONFIG: configuration PID {} is marked BLOCKED INBOUND
for cluster group {}", pid, groupName);

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/5fe65839/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 f35d9fb..83d83aa 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
@@ -52,17 +52,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()) {
@@ -74,15 +63,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);


Mime
View raw message