karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject karaf-cellar git commit: [KARAF-2168] Rename sync properties and usage
Date Thu, 20 Nov 2014 20:15:40 GMT
Repository: karaf-cellar
Updated Branches:
  refs/heads/master d9c6169e5 -> 732fc6e71


[KARAF-2168] Rename sync properties and usage


Project: http://git-wip-us.apache.org/repos/asf/karaf-cellar/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-cellar/commit/732fc6e7
Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/732fc6e7
Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/732fc6e7

Branch: refs/heads/master
Commit: 732fc6e71a611f73613578ae062731ef3370ffa5
Parents: d9c6169
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Thu Nov 20 21:15:10 2014 +0100
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Thu Nov 20 21:15:10 2014 +0100

----------------------------------------------------------------------
 assembly/src/main/resources/groups.cfg          | 42 ++++++++++-----
 assembly/src/main/resources/node.cfg            |  3 +-
 .../karaf/cellar/bundle/BundleSynchronizer.java | 49 ++++++++++++------
 .../config/ConfigurationSynchronizer.java       | 47 ++++++++++++-----
 .../apache/karaf/cellar/core/Synchronizer.java  | 13 +++--
 .../karaf/cellar/event/LocalEventListener.java  | 27 ++++++++++
 .../cellar/features/FeaturesSynchronizer.java   | 48 +++++++++++------
 .../hazelcast/CellarMembershipListener.java     |  5 +-
 .../cellar/hazelcast/HazelcastGroupManager.java |  5 +-
 .../management/internal/CellarMBeanImpl.java    |  5 +-
 .../karaf/cellar/obr/ObrUrlSynchronizer.java    | 54 +++++++++++++++-----
 .../apache/karaf/cellar/shell/SyncCommand.java  |  7 +--
 12 files changed, 214 insertions(+), 91 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/732fc6e7/assembly/src/main/resources/groups.cfg
----------------------------------------------------------------------
diff --git a/assembly/src/main/resources/groups.cfg b/assembly/src/main/resources/groups.cfg
index 6ec1834..475cf27 100644
--- a/assembly/src/main/resources/groups.cfg
+++ b/assembly/src/main/resources/groups.cfg
@@ -3,6 +3,17 @@
 #
 groups = default
 
+#
+# Filtering of the bundles in the default cluster group
+#
+default.bundle.whitelist.inbound = *
+default.bundle.whitelist.outbound = *
+default.bundle.blacklist.inbound = *.xml
+default.bundle.blacklist.outbound = *.xml
+
+#
+# Filtering of the configurations in the default cluster group
+#
 default.config.whitelist.inbound = *
 default.config.whitelist.outbound = *
 default.config.blacklist.inbound = org.apache.felix.fileinstall*, \
@@ -17,20 +28,27 @@ default.config.blacklist.outbound = org.apache.felix.fileinstall*, \
                                     org.apache.karaf.shell, \
                                     org.ops4j.pax.logging, \
                                     org.ops4j.pax.web
-default.config.sync = true
-
+#
+# Filtering of the features in the default cluster group
+#
 default.feature.whitelist.inbound = *
 default.feature.whitelist.outbound = *
 default.feature.blacklist.inbound = config,management,hazelcast,cellar*
 default.feature.blacklist.outbound = config,management,hazelcast,cellar*
-default.feature.sync = true
-default.feature.repositories.sync = true
 
-default.bundle.whitelist.inbound = *
-default.bundle.whitelist.outbound = *
-default.bundle.blacklist.inbound = *.xml
-default.bundle.blacklist.outbound = *.xml
-default.bundle.sync = true
-
-default.obr.urls.sync = true
-default.obr.bundles.sync = true
+#
+# The following properties define the behavior to use when the node joins the cluster (the
usage of the bootstrap
+# synchronizer), per cluster group and per resource.
+# The following values are accepted:
+# disabled: means that the synchronizer is not used, meaning the node or the cluster are
not updated at all
+# cluster: if the node is the first one in the cluster, it pushes its local state to the
cluster, else it's not the
+#       first node of the cluster, the node will update its local state with the cluster
one (meaning that the cluster
+#       is the master)
+# node: in this case, the node is the master, it means that the cluster state will be overwritten
by the node state.
+#
+default.bundle.sync = cluster
+default.config.sync = cluster
+default.feature.sync = cluster
+default.feature.repositories.sync = cluster
+default.obr.urls.sync = cluster
+default.obr.bundles.sync = cluster

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/732fc6e7/assembly/src/main/resources/node.cfg
----------------------------------------------------------------------
diff --git a/assembly/src/main/resources/node.cfg b/assembly/src/main/resources/node.cfg
index 5db7ba9..36028c9 100644
--- a/assembly/src/main/resources/node.cfg
+++ b/assembly/src/main/resources/node.cfg
@@ -4,12 +4,13 @@
 groups = default
 
 #
-# These properties define if the local event listeners (per resource)
+# The following properties define if the local event listeners (per resource)
 # A local listener listens for local events (like bundle install, etc) and broadcast this
state change to the cluster
 #
 bundle.listener = false
 config.listener = false
 feature.listener = false
+event.listener = true
 
 #
 # Cluster event producer

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/732fc6e7/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 b2ad279..64533c3 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
@@ -47,10 +47,7 @@ public class BundleSynchronizer extends BundleSupport implements Synchronizer
{
         Set<Group> groups = groupManager.listLocalGroups();
         if (groups != null && !groups.isEmpty()) {
             for (Group group : groups) {
-                if (isSyncEnabled(group)) {
-                    pull(group);
-                    push(group);
-                } else LOGGER.debug("CELLAR BUNDLE: sync is disabled for cluster group {}",
group.getName());
+                sync(group);
             }
         }
     }
@@ -60,6 +57,30 @@ public class BundleSynchronizer extends BundleSupport implements Synchronizer
{
     }
 
     /**
+     * Sync the node and cluster states, depending of the sync policy.
+     *
+     * @param group the target cluster group.
+     */
+    @Override
+    public void sync(Group group) {
+        String policy = getSyncPolicy(group);
+        if (policy != null && policy.equalsIgnoreCase("cluster")) {
+            LOGGER.debug("CELLAR BUNDLE: sync policy is set as 'cluster' for cluster group
" + group.getName());
+            if (clusterManager.listNodesByGroup(group).size() == 1 && clusterManager.listNodesByGroup(group).contains(clusterManager.getNode()))
{
+                LOGGER.debug("CELLAR BUNDLE: node is the first and only member of the group,
pushing state");
+                push(group);
+            } else {
+                LOGGER.debug("CELLAR BUNDLE: pulling state");
+                pull(group);
+            }
+        }
+        if (policy != null && policy.equalsIgnoreCase("node")) {
+            LOGGER.debug("CELLAR BUNDLE: sync policy is set as 'cluster' for cluster group
" + group.getName());
+            push(group);
+        }
+    }
+
+    /**
      * Pull the bundles states from a cluster group.
      *
      * @param group the cluster group where to get the bundles states.
@@ -190,28 +211,26 @@ public class BundleSynchronizer extends BundleSupport implements Synchronizer
{
     }
 
     /**
-     * Check if the bundle sync flag is enabled for a cluster group.
+     * Get the bundle sync policy for the given cluster group.
      *
-     * @param group the cluster group to check.
-     * @return true if the sync flag is enabled, false else.
+     * @param group the cluster group.
+     * @return the current bundle sync policy for the given cluster group.
      */
     @Override
-    public Boolean isSyncEnabled(Group group) {
-        Boolean result = Boolean.FALSE;
+    public String getSyncPolicy(Group group) {
         String groupName = group.getName();
-
         try {
-            Configuration configuration = configurationAdmin.getConfiguration(Configurations.GROUP);
+            Configuration configuration = configurationAdmin.getConfiguration(Configurations.GROUP,
null);
             Dictionary<String, Object> properties = configuration.getProperties();
             if (properties != null) {
                 String propertyKey = groupName + Configurations.SEPARATOR + Constants.CATEGORY
+ Configurations.SEPARATOR + Configurations.SYNC;
-                String propertyValue = (String) properties.get(propertyKey);
-                result = Boolean.parseBoolean(propertyValue);
+                return properties.get(propertyKey).toString();
             }
         } catch (IOException e) {
-            LOGGER.error("CELLAR BUNDLE: error while checking if sync is enabled", e);
+            LOGGER.error("CELLAR BUNDLE: error while retrieving the sync policy", e);
         }
-        return result;
+
+        return "disabled";
     }
 
     public EventProducer getEventProducer() {

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/732fc6e7/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 567daad..e52abd7 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
@@ -48,10 +48,7 @@ public class ConfigurationSynchronizer extends ConfigurationSupport implements
S
         Set<Group> groups = groupManager.listLocalGroups();
         if (groups != null && !groups.isEmpty()) {
             for (Group group : groups) {
-                if (isSyncEnabled(group)) {
-                    pull(group);
-                    push(group);
-                } else LOGGER.debug("CELLAR CONFIG: sync is disabled for cluster group {}",
group.getName());
+                sync(group);
             }
         }
     }
@@ -61,6 +58,30 @@ public class ConfigurationSynchronizer extends ConfigurationSupport implements
S
     }
 
     /**
+     * Sync node and cluster states, depending of the sync policy.
+     *
+     * @param group the target cluster group.
+     */
+    @Override
+    public void sync(Group group) {
+        String policy = getSyncPolicy(group);
+        if (policy != null && policy.equalsIgnoreCase("cluster")) {
+            LOGGER.debug("CELLAR CONFIG: sync policy is set as 'cluster' for cluster group
" + group.getName());
+            if (clusterManager.listNodesByGroup(group).size() == 1 && clusterManager.listNodesByGroup(group).contains(clusterManager.getNode()))
{
+                LOGGER.debug("CELLAR CONFIG: node is the first and only member of the group,
pushing state");
+                push(group);
+            } else {
+                LOGGER.debug("CELLAR CONFIG: pulling state");
+                pull(group);
+            }
+        }
+        if (policy != null && policy.equalsIgnoreCase("node")) {
+            LOGGER.debug("CELLAR CONFIG: sync policy is set as 'cluster' for cluster group
" + group.getName());
+            push(group);
+        }
+    }
+
+    /**
      * Pull the configuration from a cluster group to update the local ones.
      *
      * @param group the cluster group where to get the configurations.
@@ -153,28 +174,26 @@ public class ConfigurationSynchronizer extends ConfigurationSupport
implements S
     }
 
     /**
-     * Check if configuration sync flag is enabled for a cluster group.
+     * Get the bundle sync policy for the given cluster group.
      *
      * @param group the cluster group.
-     * @return true if the configuration sync flag is enabled for the cluster group, false
else.
+     * @return the current bundle sync policy for the given cluster group.
      */
     @Override
-    public Boolean isSyncEnabled(Group group) {
-        Boolean result = Boolean.FALSE;
+    public String getSyncPolicy(Group group) {
         String groupName = group.getName();
-
         try {
-            Configuration configuration = configurationAdmin.getConfiguration(Configurations.GROUP);
+            Configuration configuration = configurationAdmin.getConfiguration(Configurations.GROUP,
null);
             Dictionary<String, Object> properties = configuration.getProperties();
             if (properties != null) {
                 String propertyKey = groupName + Configurations.SEPARATOR + Constants.CATEGORY
+ Configurations.SEPARATOR + Configurations.SYNC;
-                String propertyValue = (String) properties.get(propertyKey);
-                result = Boolean.parseBoolean(propertyValue);
+                return properties.get(propertyKey).toString();
             }
         } catch (IOException e) {
-            LOGGER.error("CELLAR CONFIG: error while checking if sync is enabled", e);
+            LOGGER.error("CELLAR CONFIG: error while retrieving the sync policy", e);
         }
-        return result;
+
+        return "disabled";
     }
 
     public EventProducer getEventProducer() {

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/732fc6e7/core/src/main/java/org/apache/karaf/cellar/core/Synchronizer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/karaf/cellar/core/Synchronizer.java b/core/src/main/java/org/apache/karaf/cellar/core/Synchronizer.java
index 2258207..759bc3c 100644
--- a/core/src/main/java/org/apache/karaf/cellar/core/Synchronizer.java
+++ b/core/src/main/java/org/apache/karaf/cellar/core/Synchronizer.java
@@ -33,11 +33,18 @@ public interface Synchronizer {
     public void pull(Group group);
 
     /**
-     * Check if the sync flag is enabled for a given cluster group.
+     * Sync the node and the cluster, depending of the sync policy.
+     *
+     * @param group the target cluster group.
+     */
+    public void sync(Group group);
+
+    /**
+     * Get the sync policy for a given cluster group.
      *
      * @param group the cluster group.
-     * @return true if sync flag is enabled, false else.
+     * @return the current sync policy for the given cluster group.
      */
-    public Boolean isSyncEnabled(Group group);
+    public String getSyncPolicy(Group group);
 
 }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/732fc6e7/event/src/main/java/org/apache/karaf/cellar/event/LocalEventListener.java
----------------------------------------------------------------------
diff --git a/event/src/main/java/org/apache/karaf/cellar/event/LocalEventListener.java b/event/src/main/java/org/apache/karaf/cellar/event/LocalEventListener.java
index 71a9d9f..8550b9d 100644
--- a/event/src/main/java/org/apache/karaf/cellar/event/LocalEventListener.java
+++ b/event/src/main/java/org/apache/karaf/cellar/event/LocalEventListener.java
@@ -13,16 +13,19 @@
  */
 package org.apache.karaf.cellar.event;
 
+import org.apache.karaf.cellar.core.Configurations;
 import org.apache.karaf.cellar.core.Group;
 import org.apache.karaf.cellar.core.control.SwitchStatus;
 import org.apache.karaf.cellar.core.event.EventProducer;
 import org.apache.karaf.cellar.core.event.EventType;
+import org.osgi.service.cm.Configuration;
 import org.osgi.service.event.Event;
 import org.osgi.service.event.EventHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.Serializable;
+import java.util.Dictionary;
 import java.util.Map;
 import java.util.Set;
 
@@ -35,6 +38,11 @@ public class LocalEventListener extends EventSupport implements EventHandler
{
     @Override
     public void handleEvent(Event event) {
 
+        if (!isEnabled()) {
+            LOGGER.debug("CELLAR EVENT: local listener is disabled");
+            return;
+        }
+
         // ignore log entry event
         if (event.getTopic().startsWith("org/osgi/service/log/LogEntry"))
             return;
@@ -82,6 +90,25 @@ public class LocalEventListener extends EventSupport implements EventHandler
{
     }
 
     /**
+     * Check if the local config listener is enabled in the etc/org.apache.karaf.cellar.groups.cfg.
+     *
+     * @return true if enabled, false else.
+     */
+    private boolean isEnabled() {
+        try {
+            Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE,
null);
+            Dictionary<String, Object> properties = configuration.getProperties();
+            if (properties != null) {
+                String value = properties.get(Constants.CATEGORY + Configurations.SEPARATOR
+ Configurations.LISTENER).toString();
+                return Boolean.parseBoolean(value);
+            }
+        } catch (Exception e) {
+            LOGGER.warn("CELLAR EVENT: can't check listener configuration", e);
+        }
+        return false;
+    }
+
+    /**
      * Initialization method.
      */
     public void init() {

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/732fc6e7/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 e6138d4..e7a1bcc 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
@@ -40,14 +40,10 @@ public class FeaturesSynchronizer extends FeaturesSupport implements Synchronize
 
     @Override
     public void init() {
-        super.init();
         Set<Group> groups = groupManager.listLocalGroups();
         if (groups != null && !groups.isEmpty()) {
             for (Group group : groups) {
-                if (isSyncEnabled(group)) {
-                    pull(group);
-                    push(group);
-                } else LOGGER.debug("CELLAR FEATURES: sync is disabled for cluster group
{}", group.getName());
+                sync(group);
             }
         }
     }
@@ -58,6 +54,30 @@ public class FeaturesSynchronizer extends FeaturesSupport implements Synchronize
     }
 
     /**
+     * Sync node and cluster states, depending of the sync policy.
+     *
+     * @param group the target cluster group.
+     */
+    @Override
+    public void sync(Group group) {
+        String policy = getSyncPolicy(group);
+        if (policy != null && policy.equalsIgnoreCase("cluster")) {
+            LOGGER.debug("CELLAR FEATURE: sync policy is set as 'cluster' for cluster group
" + group.getName());
+            if (clusterManager.listNodesByGroup(group).size() == 1 && clusterManager.listNodesByGroup(group).contains(clusterManager.getNode()))
{
+                LOGGER.debug("CELLAR FEATURE: node is the first and only member of the group,
pushing state");
+                push(group);
+            } else {
+                LOGGER.debug("CELLAR FEATURE: pulling state");
+                pull(group);
+            }
+        }
+        if (policy != null && policy.equalsIgnoreCase("node")) {
+            LOGGER.debug("CELLAR FEATURE: sync policy is set as 'cluster' for cluster group
" + group.getName());
+            push(group);
+        }
+    }
+
+    /**
      * Pull the features repositories and features states from a cluster group, and update
the local states.
      *
      * @param group the cluster group.
@@ -178,28 +198,26 @@ public class FeaturesSynchronizer extends FeaturesSupport implements
Synchronize
     }
 
     /**
-     * Check if the sync flag is enabled for a cluster group.
+     * Get the bundle sync policy for the given cluster group.
      *
      * @param group the cluster group.
-     * @return true if the sync flag is enabled, false else.
+     * @return the current bundle sync policy for the given cluster group.
      */
     @Override
-    public Boolean isSyncEnabled(Group group) {
-        Boolean result = Boolean.FALSE;
+    public String getSyncPolicy(Group group) {
         String groupName = group.getName();
-
         try {
-            Configuration configuration = configurationAdmin.getConfiguration(Configurations.GROUP);
+            Configuration configuration = configurationAdmin.getConfiguration(Configurations.GROUP,
null);
             Dictionary<String, Object> properties = configuration.getProperties();
             if (properties != null) {
                 String propertyKey = groupName + Configurations.SEPARATOR + Constants.CATEGORY
+ Configurations.SEPARATOR + Configurations.SYNC;
-                String propertyValue = (String) properties.get(propertyKey);
-                result = Boolean.parseBoolean(propertyValue);
+                return properties.get(propertyKey).toString();
             }
         } catch (IOException e) {
-            LOGGER.error("CELLAR FEATURES: error while checking if sync is enabled", e);
+            LOGGER.error("CELLAR FEATURE: error while retrieving the sync policy", e);
         }
-        return result;
+
+        return "disabled";
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/732fc6e7/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/CellarMembershipListener.java
----------------------------------------------------------------------
diff --git a/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/CellarMembershipListener.java
b/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/CellarMembershipListener.java
index 10b40e6..3d53cbe 100644
--- a/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/CellarMembershipListener.java
+++ b/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/CellarMembershipListener.java
@@ -49,10 +49,7 @@ public class CellarMembershipListener extends HazelcastInstanceAware implements
                 if (groups != null && !groups.isEmpty()) {
                     for (Group group : groups) {
                         for (Synchronizer synchronizer : synchronizers) {
-                            if (synchronizer.isSyncEnabled(group)) {
-                                synchronizer.pull(group);
-                                synchronizer.push(group);
-                            }
+                            synchronizer.sync(group);
                         }
                     }
                 }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/732fc6e7/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java
----------------------------------------------------------------------
diff --git a/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java
b/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java
index 24156b9..106f839 100644
--- a/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java
+++ b/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java
@@ -406,9 +406,8 @@ public class HazelcastGroupManager implements GroupManager, EntryListener,
Confi
                 if (serviceReferences != null && serviceReferences.length > 0)
{
                     for (ServiceReference ref : serviceReferences) {
                         Synchronizer synchronizer = (Synchronizer) bundleContext.getService(ref);
-                        if (synchronizer != null && synchronizer.isSyncEnabled(group))
{
-                            synchronizer.pull(group);
-                            synchronizer.push(group);
+                        if (synchronizer != null) {
+                            synchronizer.sync(group);
                         }
                         bundleContext.ungetService(ref);
                     }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/732fc6e7/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/management/internal/CellarMBeanImpl.java
----------------------------------------------------------------------
diff --git a/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/management/internal/CellarMBeanImpl.java
b/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/management/internal/CellarMBeanImpl.java
index a59d926..027e6be 100644
--- a/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/management/internal/CellarMBeanImpl.java
+++ b/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/management/internal/CellarMBeanImpl.java
@@ -95,10 +95,7 @@ public class CellarMBeanImpl extends StandardMBean implements CellarMBean
{
                 if (serviceReferences != null && serviceReferences.length > 0)
{
                     for (ServiceReference ref : serviceReferences) {
                         Synchronizer synchronizer = (Synchronizer) bundleContext.getService(ref);
-                        if (synchronizer.isSyncEnabled(group)) {
-                            synchronizer.pull(group);
-                            synchronizer.push(group);
-                        }
+                        synchronizer.sync(group);
                         bundleContext.ungetService(ref);
                     }
                 }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/732fc6e7/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 cef49ec..0ae91a6 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
@@ -38,14 +38,10 @@ public class ObrUrlSynchronizer extends ObrSupport implements Synchronizer
{
 
     @Override
     public void init() {
-        super.init();
         Set<Group> groups = groupManager.listLocalGroups();
         if (groups != null && !groups.isEmpty()) {
             for (Group group : groups) {
-                if (isSyncEnabled(group)) {
-                    pull(group);
-                    push(group);
-                } else LOGGER.debug("CELLAR OBR: sync is disabled for group {}", group.getName());
+                sync(group);
             }
         }
     }
@@ -56,6 +52,30 @@ public class ObrUrlSynchronizer extends ObrSupport implements Synchronizer
{
     }
 
     /**
+     * Sync node and cluster states, depending of the sync policy.
+     *
+     * @param group the target cluster group.
+     */
+    @Override
+    public void sync(Group group) {
+        String policy = getSyncPolicy(group);
+        if (policy != null && policy.equalsIgnoreCase("cluster")) {
+            LOGGER.debug("CELLAR OBR: sync policy is set as 'cluster' for cluster group "
+ group.getName());
+            if (clusterManager.listNodesByGroup(group).size() == 1 && clusterManager.listNodesByGroup(group).contains(clusterManager.getNode()))
{
+                LOGGER.debug("CELLAR OBR: node is the first and only member of the group,
pushing state");
+                push(group);
+            } else {
+                LOGGER.debug("CELLAR OBR: pulling state");
+                pull(group);
+            }
+        }
+        if (policy != null && policy.equalsIgnoreCase("node")) {
+            LOGGER.debug("CELLAR OBR: sync policy is set as 'cluster' for cluster group "
+ group.getName());
+            push(group);
+        }
+    }
+
+    /**
      * Pull the OBR URLs from a cluster group to update the local state.
      *
      * @param group the cluster group.
@@ -120,21 +140,27 @@ public class ObrUrlSynchronizer extends ObrSupport implements Synchronizer
{
         }
     }
 
+    /**
+     * Get the bundle sync policy for the given cluster group.
+     *
+     * @param group the cluster group.
+     * @return the current bundle sync policy for the given cluster group.
+     */
     @Override
-    public Boolean isSyncEnabled(Group group) {
-        Boolean result = Boolean.FALSE;
+    public String getSyncPolicy(Group group) {
         String groupName = group.getName();
-
         try {
-            Configuration configuration = configurationAdmin.getConfiguration(Configurations.GROUP);
+            Configuration configuration = configurationAdmin.getConfiguration(Configurations.GROUP,
null);
             Dictionary<String, Object> properties = configuration.getProperties();
-            String propertyKey = groupName + Configurations.SEPARATOR + Constants.URLS_CONFIG_CATEGORY
+ Configurations.SEPARATOR + Configurations.SYNC;
-            String propertyValue = (String) properties.get(propertyKey);
-            result = Boolean.parseBoolean(propertyValue);
+            if (properties != null) {
+                String propertyKey = groupName + Configurations.SEPARATOR + Constants.URLS_CONFIG_CATEGORY
+ Configurations.SEPARATOR + Configurations.SYNC;
+                return properties.get(propertyKey).toString();
+            }
         } catch (IOException e) {
-            LOGGER.error("CELLAR OBR: error while checking if sync is enabled", e);
+            LOGGER.error("CELLAR OBR: error while retrieving the sync policy", e);
         }
-        return result;
+
+        return "disabled";
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/732fc6e7/shell/src/main/java/org/apache/karaf/cellar/shell/SyncCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/karaf/cellar/shell/SyncCommand.java b/shell/src/main/java/org/apache/karaf/cellar/shell/SyncCommand.java
index f5fefa9..04a2f89 100644
--- a/shell/src/main/java/org/apache/karaf/cellar/shell/SyncCommand.java
+++ b/shell/src/main/java/org/apache/karaf/cellar/shell/SyncCommand.java
@@ -34,12 +34,7 @@ public class SyncCommand extends ClusterCommandSupport {
                 if (serviceReferences != null && serviceReferences.length > 0)
{
                     for (ServiceReference ref : serviceReferences) {
                         Synchronizer synchronizer = (Synchronizer) bundleContext.getService(ref);
-                        if (synchronizer.isSyncEnabled(group)) {
-                            System.out.print("    sync " + synchronizer.getClass() + " ...");
-                            synchronizer.pull(group);
-                            synchronizer.push(group);
-                            System.out.println("done");
-                        }
+                        synchronizer.sync(group);
                         bundleContext.ungetService(ref);
                     }
                 }


Mime
View raw message