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-1157] Improve the cluster:sync command and fix default property names
Date Sun, 11 Jan 2015 15:17:29 GMT
Repository: karaf-cellar
Updated Branches:
  refs/heads/cellar-2.3.x 5ed6e332c -> 6ec9d8c16


[KARAF-1157] Improve the cluster:sync command and fix default property names


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

Branch: refs/heads/cellar-2.3.x
Commit: 6ec9d8c169ed073014af9f220a3041863ace14a3
Parents: 5ed6e33
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Sun Jan 11 15:49:51 2015 +0100
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Sun Jan 11 16:17:06 2015 +0100

----------------------------------------------------------------------
 assembly/src/main/resources/groups.cfg          |   4 +-
 assembly/src/main/resources/node.cfg            |   2 +-
 .../resources/OSGI-INF/blueprint/blueprint.xml  |   6 +-
 .../resources/OSGI-INF/blueprint/blueprint.xml  |   6 +-
 .../resources/OSGI-INF/blueprint/blueprint.xml  |   6 +-
 .../resources/OSGI-INF/blueprint/blueprint.xml  |   6 +-
 shell/pom.xml                                   |  10 ++
 .../apache/karaf/cellar/shell/SyncCommand.java  | 131 ++++++++++++++++---
 .../OSGI-INF/blueprint/shell-cluster.xml        |   2 +
 9 files changed, 149 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/6ec9d8c1/assembly/src/main/resources/groups.cfg
----------------------------------------------------------------------
diff --git a/assembly/src/main/resources/groups.cfg b/assembly/src/main/resources/groups.cfg
index 1b9d592..1bedaa0 100644
--- a/assembly/src/main/resources/groups.cfg
+++ b/assembly/src/main/resources/groups.cfg
@@ -49,7 +49,5 @@ default.features.blacklist.outbound = config,management,hazelcast,cellar*
 #
 default.bundle.sync = cluster
 default.config.sync = cluster
-default.feature.sync = cluster
-default.feature.repositories.sync = cluster
+default.features.sync = cluster
 default.obr.urls.sync = cluster
-default.obr.bundles.sync = cluster
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/6ec9d8c1/assembly/src/main/resources/node.cfg
----------------------------------------------------------------------
diff --git a/assembly/src/main/resources/node.cfg b/assembly/src/main/resources/node.cfg
index 024a548..2ac4090 100644
--- a/assembly/src/main/resources/node.cfg
+++ b/assembly/src/main/resources/node.cfg
@@ -9,7 +9,7 @@ groups = default
 #
 bundle.listener = false
 config.listener = false
-feature.listener = false
+features.listener = false
 event.listener = true;
 
 #

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/6ec9d8c1/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 add5c38..1f04eb0 100644
--- a/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -35,7 +35,11 @@
         <property name="bundleContext" ref="blueprintBundleContext"/>
         <property name="featuresService" ref="featuresService"/>
     </bean>
-    <service ref="synchronizer" interface="org.apache.karaf.cellar.core.Synchronizer"/>
+    <service ref="synchronizer" interface="org.apache.karaf.cellar.core.Synchronizer">
+        <service-properties>
+            <entry key="resource" value="bundle"/>
+        </service-properties>
+    </service>
 
     <!-- Cluster Bundle Event Handler -->
     <bean id="eventHandler" class="org.apache.karaf.cellar.bundle.BundleEventHandler"

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/6ec9d8c1/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 ee5db17..d83f7e9 100644
--- a/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/config/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -36,7 +36,11 @@
         <property name="eventProducer" ref="eventProducer"/>
         <property name="storage" value="${storage}"/>
     </bean>
-    <service ref="synchronizer" interface="org.apache.karaf.cellar.core.Synchronizer"/>
+    <service ref="synchronizer" interface="org.apache.karaf.cellar.core.Synchronizer">
+        <service-properties>
+            <entry key="resource" value="config"/>
+        </service-properties>
+    </service>
 
     <!-- Cluster Event Handler -->
     <bean id="eventHandler" class="org.apache.karaf.cellar.config.ConfigurationEventHandler"

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/6ec9d8c1/features/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/features/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/features/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index bf4100f..bab0aca 100644
--- a/features/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/features/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -33,7 +33,11 @@
         <property name="configurationAdmin" ref="configurationAdmin"/>
         <property name="featuresService" ref="featuresService"/>
     </bean>
-    <service ref="synchronizer" interface="org.apache.karaf.cellar.core.Synchronizer"/>
+    <service ref="synchronizer" interface="org.apache.karaf.cellar.core.Synchronizer">
+        <service-properties>
+            <entry key="resource" value="feature"/>
+        </service-properties>
+    </service>
 
     <!-- Features Event Handler -->
     <bean id="featuresHandler" class="org.apache.karaf.cellar.features.FeaturesEventHandler"

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/6ec9d8c1/obr/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/obr/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/obr/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index ee5629e..25ca774 100644
--- a/obr/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/obr/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -36,7 +36,11 @@
         <property name="groupManager" ref="groupManager"/>
         <property name="configurationAdmin" ref="configurationAdmin"/>
     </bean>
-    <service ref="obrUrlSynchronizer" interface="org.apache.karaf.cellar.core.Synchronizer"/>
+    <service ref="obrUrlSynchronizer" interface="org.apache.karaf.cellar.core.Synchronizer">
+        <service-properties>
+            <entry key="resource" value="obr.urls"/>
+        </service-properties>
+    </service>
 
     <!-- OBR URL Event Handler -->
     <bean id="obrUrlEventHandler" class="org.apache.karaf.cellar.obr.ObrUrlEventHandler"

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/6ec9d8c1/shell/pom.xml
----------------------------------------------------------------------
diff --git a/shell/pom.xml b/shell/pom.xml
index 3587eb6..b6c6998 100644
--- a/shell/pom.xml
+++ b/shell/pom.xml
@@ -56,6 +56,16 @@
 
         <!-- Internal Dependencies -->
         <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.karaf.cellar</groupId>
             <artifactId>org.apache.karaf.cellar.core</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/6ec9d8c1/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 ba62510..1b68afb 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
@@ -13,36 +13,135 @@
  */
 package org.apache.karaf.cellar.shell;
 
+import org.apache.felix.gogo.commands.Argument;
 import org.apache.felix.gogo.commands.Command;
+import org.apache.felix.gogo.commands.Option;
 import org.apache.karaf.cellar.core.Group;
 import org.apache.karaf.cellar.core.Synchronizer;
-import org.osgi.framework.InvalidSyntaxException;
+import org.apache.karaf.cellar.core.Configurations;
 import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
 
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Properties;
 import java.util.Set;
 
-@Command(scope = "cluster", name = "sync", description = "Force the call of all cluster synchronizers
available")
+@Command(scope = "cluster", name = "sync", description = "Manipulate the synchronizers")
 public class SyncCommand extends ClusterCommandSupport {
 
+    @Option(name = "-g", aliases = { "--group" }, description = "The cluster group name",
required = false, multiValued = false)
+    private String groupName;
+
+    @Option(name = "-b", aliases = { "--bundle" }, description = "Cluster bundle support",
required = false, multiValued = false)
+    private boolean bundleSync = false;
+
+    @Option(name = "-c", aliases = { "--config" }, description = "Cluster config support",
required = false, multiValued = false)
+    private boolean configSync = false;
+
+    @Option(name = "-f", aliases = { "--feature" }, description = "Cluster feature support",
required = false, multiValued = false)
+    private boolean featuresSync = false;
+
+    @Option(name = "-o", aliases = { "--obr" }, description = "Cluster OBR support", required
= false, multiValued = false)
+    private boolean obrSync = false;
+
+    @Argument(name = "policy", description = "The definition of the sync policy for the given
cluster resource", required = false, multiValued = false)
+    private String policy;
+
+    private ConfigurationAdmin configurationAdmin;
+
     @Override
     protected Object doExecute() throws Exception {
-        Set<Group> localGroups = groupManager.listLocalGroups();
-        for (Group group : localGroups) {
-            System.out.println("Synchronizing cluster group " + group.getName());
-            try {
-                ServiceReference[] serviceReferences = bundleContext.getAllServiceReferences("org.apache.karaf.cellar.core.Synchronizer",
null);
-                if (serviceReferences != null && serviceReferences.length > 0)
{
-                    for (ServiceReference ref : serviceReferences) {
-                        Synchronizer synchronizer = (Synchronizer) bundleContext.getService(ref);
-                        synchronizer.sync(group);
-                        bundleContext.ungetService(ref);
-                    }
-                }
-            } catch (InvalidSyntaxException e) {
-                // ignore
+        boolean allResources = false;
+        // if the user didn't provide any resource, we consider all
+        if (!bundleSync && !configSync && !featuresSync && !obrSync)
{
+            allResources = true;
+        }
+        Set<Group> groups;
+        if (groupName == null || groupName.isEmpty()) {
+            groups = groupManager.listLocalGroups();
+        } else {
+            groups = new HashSet<Group>();
+            if (groupManager.findGroupByName(groupName) == null) {
+                System.err.println("Cluster group " + groupName + " doesn't exist");
+                return null;
+            }
+            groups.add(groupManager.findGroupByName(groupName));
+        }
+        if (policy == null || policy.isEmpty()) {
+            // we are in sync mode
+            // constructing the target cluster groups
+            for (Group group : groups) {
+                System.out.println("Synchronizing cluster group " + group.getName());
+                if (bundleSync || allResources) {
+                    doSync("bundle", group);
+                }
+                if (configSync || allResources) {
+                    doSync("config", group);
+                }
+                if (featuresSync || allResources) {
+                    doSync("feature", group);
+                }
+                if (obrSync || allResources) {
+                    doSync("obr.urls", group);
+                }
+            }
+        } else {
+            // we are in set mode
+            if (!policy.equalsIgnoreCase("cluster") && !policy.equalsIgnoreCase("node")
&& !policy.equalsIgnoreCase("disabled")) {
+                System.err.println("The sync policy " + policy + " is not valid. Valid sync
policies are: cluster, node, disabled");
+                return null;
+            }
+            for (Group group : groups) {
+                System.out.println("Updating sync policy for cluster group " + group.getName());
+                if (bundleSync || allResources) {
+                    updateSync("bundle", group, policy);
+                }
+                if (configSync || allResources) {
+                    updateSync("config", group, policy);
+                }
+                if (featuresSync || allResources) {
+                    updateSync("feature", group, policy);
+                }
+                if (obrSync || allResources) {
+                    updateSync("obr.urls", group, policy);
+                }
             }
         }
         return null;
     }
 
+    private void doSync(String resource, Group group) throws Exception {
+        // looking for the resource synchronizer
+        System.out.print("\t" + resource + ": ");
+        ServiceReference[] references = bundleContext.getAllServiceReferences(Synchronizer.class.getName(),
"(resource=" + resource + ")");
+        if (references != null && references.length > 0) {
+            for (ServiceReference reference : references) {
+                Synchronizer synchronizer = (Synchronizer) bundleContext.getService(reference);
+                synchronizer.sync(group);
+                bundleContext.ungetService(reference);
+            }
+            System.out.println("done");
+        } else {
+            System.out.println("No synchronizer found for " + resource);
+        }
+    }
+
+    private void updateSync(String resource, Group group, String policy) throws Exception
{
+        System.out.print("\t" + resource + ": ");
+        Configuration configuration = configurationAdmin.getConfiguration(Configurations.GROUP,
null);
+        if (configuration != null) {
+            Dictionary properties = configuration.getProperties();
+            if (properties == null)
+                properties = new Properties();
+            properties.put(group.getName() + "." + resource + ".sync", policy);
+            configuration.update(properties);
+            System.out.println("done");
+        }
+    }
+
+    public void setConfigurationAdmin(ConfigurationAdmin configurationAdmin) {
+        this.configurationAdmin = configurationAdmin;
+    }
 }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/6ec9d8c1/shell/src/main/resources/OSGI-INF/blueprint/shell-cluster.xml
----------------------------------------------------------------------
diff --git a/shell/src/main/resources/OSGI-INF/blueprint/shell-cluster.xml b/shell/src/main/resources/OSGI-INF/blueprint/shell-cluster.xml
index 84a8f80..729ac8b 100644
--- a/shell/src/main/resources/OSGI-INF/blueprint/shell-cluster.xml
+++ b/shell/src/main/resources/OSGI-INF/blueprint/shell-cluster.xml
@@ -31,6 +31,7 @@
             <action class="org.apache.karaf.cellar.shell.SyncCommand">
                 <property name="clusterManager" ref="clusterManager"/>
                 <property name="groupManager" ref="groupManager"/>
+                <property name="configurationAdmin" ref="configurationAdmin"/>
             </action>
         </command>
         <command name="cluster/consumer-start">
@@ -186,6 +187,7 @@
     <reference id="clusterManager" interface="org.apache.karaf.cellar.core.ClusterManager"
availability="optional"/>
     <reference id="groupManager" interface="org.apache.karaf.cellar.core.GroupManager"
availability="optional"/>
     <reference id="executionContext" interface="org.apache.karaf.cellar.core.command.ExecutionContext"
availability="optional"/>
+    <reference id="configurationAdmin" interface="org.osgi.service.cm.ConfigurationAdmin"/>
 
     <bean id="allNodesCompleter" class="org.apache.karaf.cellar.core.shell.completer.AllNodeCompleter">
         <property name="clusterManager" ref="clusterManager"/>


Mime
View raw message