Repository: karaf-cellar Updated Branches: refs/heads/cellar-3.0.x dfbd13f74 -> 952b657a2
[KARAF-3617] Fix config sync pulling behavior Avoid the synchronizers to broadcast cluster events. Fix log message in the synchronizers. Project: http://git-wip-us.apache.org/repos/asf/karaf-cellar/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf-cellar/commit/952b657a Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/952b657a Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/952b657a Branch: refs/heads/cellar-3.0.x Commit: 952b657a27eaff1e34f24a1b90b494890d521169 Parents: dfbd13f Author: Jean-Baptiste Onofré <[email protected]> Authored: Mon Mar 16 02:03:01 2015 +0100 Committer: Jean-Baptiste Onofré <[email protected]> Committed: Mon Mar 16 02:03:01 2015 +0100 ---------------------------------------------------------------------- .../karaf/cellar/bundle/BundleSynchronizer.java | 23 +----------- .../resources/OSGI-INF/blueprint/blueprint.xml | 1 - .../config/ConfigurationSynchronizer.java | 38 +++++--------------- .../resources/OSGI-INF/blueprint/blueprint.xml | 1 - .../cellar/features/FeaturesSynchronizer.java | 2 +- .../karaf/cellar/obr/ObrUrlSynchronizer.java | 4 +-- 6 files changed, 12 insertions(+), 57 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/952b657a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java ---------------------------------------------------------------------- diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java index 68b586d..851ded0 100644 --- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java +++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java @@ -41,8 +41,6 @@ public class BundleSynchronizer extends BundleSupport implements Synchronizer { private static final transient Logger LOGGER = LoggerFactory.getLogger(BundleSynchronizer.class); - private EventProducer eventProducer; - public void init() { Set<Group> groups = groupManager.listLocalGroups(); if (groups != null && !groups.isEmpty()) { @@ -75,7 +73,7 @@ public class BundleSynchronizer extends BundleSupport implements Synchronizer { } } if (policy != null && policy.equalsIgnoreCase("node")) { - LOGGER.debug("CELLAR BUNDLE: sync policy is set as 'cluster' for cluster group " + group.getName()); + LOGGER.debug("CELLAR BUNDLE: sync policy is set as 'node' for cluster group " + group.getName()); push(group); } } @@ -135,12 +133,6 @@ public class BundleSynchronizer extends BundleSupport implements Synchronizer { @Override public void push(Group group) { - // check if the producer is ON - if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) { - LOGGER.debug("CELLAR BUNDLE: cluster event producer is OFF"); - return; - } - if (group != null) { String groupName = group.getName(); LOGGER.debug("CELLAR BUNDLE: pushing bundles to cluster group {}", groupName); @@ -195,11 +187,6 @@ public class BundleSynchronizer extends BundleSupport implements Synchronizer { existingState.getStatus() != bundleState.getStatus()) { // update the distributed map clusterBundles.put(id, bundleState); - - // broadcast the event - ClusterBundleEvent event = new ClusterBundleEvent(symbolicName, version, bundleLocation, status); - event.setSourceGroup(group); - eventProducer.produce(event); } } else LOGGER.trace("CELLAR BUNDLE: bundle {} is marked BLOCKED OUTBOUND for cluster group {}", bundleLocation, groupName); @@ -233,12 +220,4 @@ public class BundleSynchronizer extends BundleSupport implements Synchronizer { return "disabled"; } - public EventProducer getEventProducer() { - return eventProducer; - } - - public void setEventProducer(EventProducer eventProducer) { - this.eventProducer = eventProducer; - } - } http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/952b657a/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 0742ab5..ec986e7 100644 --- a/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -35,7 +35,6 @@ <property name="groupManager" ref="groupManager"/> <property name="clusterManager" ref="clusterManager"/> <property name="bundleContext" ref="blueprintBundleContext"/> - <property name="eventProducer" ref="eventProducer"/> </bean> <service ref="synchronizer" interface="org.apache.karaf.cellar.core.Synchronizer"> <service-properties> http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/952b657a/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java ---------------------------------------------------------------------- diff --git a/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java b/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java index 9b4c0f2..307ae19 100644 --- a/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java +++ b/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSynchronizer.java @@ -38,8 +38,6 @@ public class ConfigurationSynchronizer extends ConfigurationSupport implements S private static final transient Logger LOGGER = LoggerFactory.getLogger(ConfigurationSynchronizer.class); - private EventProducer eventProducer; - public ConfigurationSynchronizer() { // nothing to do } @@ -76,7 +74,7 @@ public class ConfigurationSynchronizer extends ConfigurationSupport implements S } } if (policy != null && policy.equalsIgnoreCase("node")) { - LOGGER.debug("CELLAR CONFIG: sync policy is set as 'cluster' for cluster group " + group.getName()); + LOGGER.debug("CELLAR CONFIG: sync policy is set as 'node' for cluster group " + group.getName()); push(group); } } @@ -97,25 +95,25 @@ public class ConfigurationSynchronizer extends ConfigurationSupport implements S try { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); - for (String clusterConfiguration : clusterConfigurations.keySet()) { - if (isAllowed(group, Constants.CATEGORY, clusterConfiguration, EventType.INBOUND)) { - Dictionary clusterDictionary = clusterConfigurations.get(clusterConfiguration); + for (String pid : clusterConfigurations.keySet()) { + if (isAllowed(group, Constants.CATEGORY, pid, EventType.INBOUND)) { + Dictionary clusterDictionary = clusterConfigurations.get(pid); try { // update the local configuration if needed - Configuration localConfiguration = configurationAdmin.getConfiguration(clusterConfiguration, null); + Configuration localConfiguration = configurationAdmin.getConfiguration(pid, null); Dictionary localDictionary = localConfiguration.getProperties(); if (localDictionary == null) localDictionary = new Properties(); localDictionary = filter(localDictionary); - if (!equals(localDictionary, clusterDictionary)) { - localConfiguration.update(localDictionary); - persistConfiguration(configurationAdmin, clusterConfiguration, localDictionary); + if (!equals(clusterDictionary, localDictionary)) { + localConfiguration.update((Dictionary) clusterDictionary); + persistConfiguration(configurationAdmin, pid, clusterDictionary); } } catch (IOException ex) { LOGGER.error("CELLAR CONFIG: failed to read local configuration", ex); } - } else LOGGER.trace("CELLAR CONFIG: configuration with PID {} is marked BLOCKED INBOUND for cluster group {}", clusterConfiguration, groupName); + } else LOGGER.trace("CELLAR CONFIG: configuration with PID {} is marked BLOCKED INBOUND for cluster group {}", pid, groupName); } } finally { Thread.currentThread().setContextClassLoader(originalClassLoader); @@ -130,12 +128,6 @@ public class ConfigurationSynchronizer extends ConfigurationSupport implements S */ public void push(Group group) { - // check if the producer is ON - if (eventProducer.getSwitch().getStatus().equals(SwitchStatus.OFF)) { - LOGGER.debug("CELLAR CONFIG: cluster event producer is OFF"); - return; - } - if (group != null) { String groupName = group.getName(); LOGGER.debug("CELLAR CONFIG: pushing configurations to cluster group {}", groupName); @@ -155,10 +147,6 @@ public class ConfigurationSynchronizer extends ConfigurationSupport implements S localDictionary = filter(localDictionary); // update the configurations in the cluster group clusterConfigurations.put(pid, dictionaryToProperties(localDictionary)); - // broadcast the cluster event - ClusterConfigurationEvent event = new ClusterConfigurationEvent(pid); - event.setSourceGroup(group); - eventProducer.produce(event); } else LOGGER.trace("CELLAR CONFIG: configuration with PID {} is marked BLOCKED OUTBOUND for cluster group {}", pid, groupName); } @@ -196,12 +184,4 @@ public class ConfigurationSynchronizer extends ConfigurationSupport implements S return "disabled"; } - public EventProducer getEventProducer() { - return eventProducer; - } - - public void setEventProducer(EventProducer eventProducer) { - this.eventProducer = eventProducer; - } - } http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/952b657a/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml index de653da..1baf760 100644 --- a/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -43,7 +43,6 @@ <property name="configurationAdmin" ref="configurationAdmin"/> <property name="groupManager" ref="groupManager"/> <property name="clusterManager" ref="clusterManager"/> - <property name="eventProducer" ref="eventProducer"/> <property name="storage" value="${storage}"/> </bean> <service ref="synchronizer" interface="org.apache.karaf.cellar.core.Synchronizer"> http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/952b657a/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSynchronizer.java ---------------------------------------------------------------------- diff --git a/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSynchronizer.java b/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSynchronizer.java index c772ff9..bdf901b 100644 --- a/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSynchronizer.java +++ b/features/src/main/java/org/apache/karaf/cellar/features/FeaturesSynchronizer.java @@ -72,7 +72,7 @@ public class FeaturesSynchronizer extends FeaturesSupport implements Synchronize } } if (policy != null && policy.equalsIgnoreCase("node")) { - LOGGER.debug("CELLAR FEATURE: sync policy is set as 'cluster' for cluster group " + group.getName()); + LOGGER.debug("CELLAR FEATURE: sync policy is set as 'node' for cluster group " + group.getName()); push(group); } } http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/952b657a/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlSynchronizer.java ---------------------------------------------------------------------- diff --git a/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlSynchronizer.java b/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlSynchronizer.java index 09eac27..73be384 100644 --- a/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlSynchronizer.java +++ b/obr/src/main/java/org/apache/karaf/cellar/obr/ObrUrlSynchronizer.java @@ -18,7 +18,6 @@ import org.apache.felix.bundlerepository.Resource; import org.apache.karaf.cellar.core.Configurations; import org.apache.karaf.cellar.core.Group; import org.apache.karaf.cellar.core.Synchronizer; -import org.apache.karaf.cellar.core.event.EventProducer; import org.apache.karaf.cellar.core.event.EventType; import org.osgi.service.cm.Configuration; import org.slf4j.Logger; @@ -70,7 +69,7 @@ public class ObrUrlSynchronizer extends ObrSupport implements Synchronizer { } } if (policy != null && policy.equalsIgnoreCase("node")) { - LOGGER.debug("CELLAR OBR: sync policy is set as 'cluster' for cluster group " + group.getName()); + LOGGER.debug("CELLAR OBR: sync policy is set as 'node' for cluster group " + group.getName()); push(group); } } @@ -128,7 +127,6 @@ public class ObrUrlSynchronizer extends ObrSupport implements Synchronizer { for (Resource resource : resources) { ObrBundleInfo info = new ObrBundleInfo(resource.getPresentationName(), resource.getSymbolicName(), resource.getVersion().toString()); clusterBundles.add(info); - // TODO fire event to the other nodes ? } } else { LOGGER.trace("CELLAR OBR: URL {} is marked BLOCKED OUTBOUND for cluster group {}", repository.getURI().toString(), groupName);
