[KARAF-2204] cluster:feature-url-add, cluster:feature-url-remove and 
corresponding MBeans now support installAll and uninstallAll option

git-svn-id: 
https://svn.apache.org/repos/asf/karaf/cellar/branches/cellar-2.3.x@1496473 
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/bdcd6539
Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/bdcd6539
Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/bdcd6539

Branch: refs/heads/cellar-2.3.x
Commit: bdcd65390970e4553d9476e4ca901e7b6cbcd57a
Parents: 634170c
Author: jbonofre <jbonofre@13f79535-47bb-0310-9956-ffa450edef68>
Authored: Tue Jun 25 13:55:07 2013 +0000
Committer: jbonofre <jbonofre@13f79535-47bb-0310-9956-ffa450edef68>
Committed: Tue Jun 25 13:55:07 2013 +0000

----------------------------------------------------------------------
 .../cellar/features/ClusterRepositoryEvent.java | 19 ++++++++++++++++
 .../cellar/features/RepositoryEventHandler.java |  4 ++--
 .../cellar/features/shell/UrlAddCommand.java    |  5 +++++
 .../cellar/features/shell/UrlRemoveCommand.java |  5 +++++
 .../cellar/management/CellarFeaturesMBean.java  | 23 +++++++++++++++++++-
 .../internal/CellarFeaturesMBeanImpl.java       | 12 ++++++++++
 6 files changed, 65 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/bdcd6539/features/src/main/java/org/apache/karaf/cellar/features/ClusterRepositoryEvent.java
----------------------------------------------------------------------
diff --git 
a/features/src/main/java/org/apache/karaf/cellar/features/ClusterRepositoryEvent.java
 
b/features/src/main/java/org/apache/karaf/cellar/features/ClusterRepositoryEvent.java
index 550da74..26afd17 100644
--- 
a/features/src/main/java/org/apache/karaf/cellar/features/ClusterRepositoryEvent.java
+++ 
b/features/src/main/java/org/apache/karaf/cellar/features/ClusterRepositoryEvent.java
@@ -23,6 +23,9 @@ public class ClusterRepositoryEvent extends Event {
 
     private EventType type;
 
+    private Boolean install;
+    private Boolean uninstall;
+
     public ClusterRepositoryEvent(String id, EventType type) {
         super(id);
         this.type = type;
@@ -32,4 +35,20 @@ public class ClusterRepositoryEvent extends Event {
         return type;
     }
 
+    public Boolean getInstall() {
+        return install;
+    }
+
+    public void setInstall(Boolean install) {
+        this.install = install;
+    }
+
+    public Boolean getUninstall() {
+        return uninstall;
+    }
+
+    public void setUninstall(Boolean uninstall) {
+        this.uninstall = uninstall;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/bdcd6539/features/src/main/java/org/apache/karaf/cellar/features/RepositoryEventHandler.java
----------------------------------------------------------------------
diff --git 
a/features/src/main/java/org/apache/karaf/cellar/features/RepositoryEventHandler.java
 
b/features/src/main/java/org/apache/karaf/cellar/features/RepositoryEventHandler.java
index 8db3282..faa4343 100644
--- 
a/features/src/main/java/org/apache/karaf/cellar/features/RepositoryEventHandler.java
+++ 
b/features/src/main/java/org/apache/karaf/cellar/features/RepositoryEventHandler.java
@@ -71,14 +71,14 @@ public class RepositoryEventHandler extends FeaturesSupport 
implements EventHand
             if (RepositoryEvent.EventType.RepositoryAdded.equals(type)) {
                 if (!isRepositoryRegisteredLocally(uri)) {
                     LOGGER.debug("CELLAR FEATURES: adding repository URI {}", 
uri);
-                    featuresService.addRepository(new URI(uri));
+                    featuresService.addRepository(new URI(uri), 
event.getInstall());
                 } else {
                     LOGGER.debug("CELLAR FEATURES: repository URI {} is 
already registered locally");
                 }
             } else {
                 if (isRepositoryRegisteredLocally(uri)) {
                     LOGGER.debug("CELLAR FEATURES: removing repository URI 
{}", uri);
-                    featuresService.removeRepository(new URI(uri));
+                    featuresService.removeRepository(new URI(uri), 
event.getUninstall());
                 } else {
                     LOGGER.debug("CELLAR FEATURES: repository URI {} is not 
registered locally");
                 }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/bdcd6539/features/src/main/java/org/apache/karaf/cellar/features/shell/UrlAddCommand.java
----------------------------------------------------------------------
diff --git 
a/features/src/main/java/org/apache/karaf/cellar/features/shell/UrlAddCommand.java
 
b/features/src/main/java/org/apache/karaf/cellar/features/shell/UrlAddCommand.java
index 1688f2c..0070acf 100644
--- 
a/features/src/main/java/org/apache/karaf/cellar/features/shell/UrlAddCommand.java
+++ 
b/features/src/main/java/org/apache/karaf/cellar/features/shell/UrlAddCommand.java
@@ -15,6 +15,7 @@ package org.apache.karaf.cellar.features.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.Configurations;
 import org.apache.karaf.cellar.core.Group;
 import org.apache.karaf.cellar.core.control.SwitchStatus;
@@ -39,6 +40,9 @@ public class UrlAddCommand extends FeatureCommandSupport {
     @Argument(index = 1, name = "urls", description = "One or more features 
repository URLs separated by whitespaces", required = true, multiValued = true)
     List<String> urls;
 
+    @Option(name = "-i", aliases = { "--install-all" }, description = "Install 
all features contained in the repository URLs", required = false, multiValued = 
false)
+    boolean install;
+
     private EventProducer eventProducer;
 
     @Override
@@ -119,6 +123,7 @@ public class UrlAddCommand extends FeatureCommandSupport {
                     // broadcast the cluster event
                     ClusterRepositoryEvent event = new 
ClusterRepositoryEvent(url, RepositoryEvent.EventType.RepositoryAdded);
                     event.setSourceGroup(group);
+                    event.setInstall(install);
                     eventProducer.produce(event);
                 } else {
                     System.err.println("Repository URL " + url + " already 
registered");

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/bdcd6539/features/src/main/java/org/apache/karaf/cellar/features/shell/UrlRemoveCommand.java
----------------------------------------------------------------------
diff --git 
a/features/src/main/java/org/apache/karaf/cellar/features/shell/UrlRemoveCommand.java
 
b/features/src/main/java/org/apache/karaf/cellar/features/shell/UrlRemoveCommand.java
index 9aeb589..6a8ec78 100644
--- 
a/features/src/main/java/org/apache/karaf/cellar/features/shell/UrlRemoveCommand.java
+++ 
b/features/src/main/java/org/apache/karaf/cellar/features/shell/UrlRemoveCommand.java
@@ -15,6 +15,7 @@ package org.apache.karaf.cellar.features.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.Configurations;
 import org.apache.karaf.cellar.core.Group;
 import org.apache.karaf.cellar.core.control.SwitchStatus;
@@ -39,6 +40,9 @@ public class UrlRemoveCommand extends FeatureCommandSupport {
     @Argument(index = 1, name = "urls", description = "One or more repository 
URLs separated by whitespaces", required = true, multiValued = true)
     List<String> urls;
 
+    @Option(name = "-u", aliases = { "--uninstall-all" }, description = 
"Uninstall all features contained in the repository URLs", required = false, 
multiValued = false)
+    boolean uninstall;
+
     private EventProducer eventProducer;
 
     @Override
@@ -115,6 +119,7 @@ public class UrlRemoveCommand extends FeatureCommandSupport 
{
 
                 // broadcast a cluster event
                 ClusterRepositoryEvent event = new ClusterRepositoryEvent(url, 
RepositoryEvent.EventType.RepositoryRemoved);
+                event.setUninstall(uninstall);
                 event.setSourceGroup(group);
                 eventProducer.produce(event);
             } else {

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/bdcd6539/management/src/main/java/org/apache/karaf/cellar/management/CellarFeaturesMBean.java
----------------------------------------------------------------------
diff --git 
a/management/src/main/java/org/apache/karaf/cellar/management/CellarFeaturesMBean.java
 
b/management/src/main/java/org/apache/karaf/cellar/management/CellarFeaturesMBean.java
index 807f71f..c611752 100644
--- 
a/management/src/main/java/org/apache/karaf/cellar/management/CellarFeaturesMBean.java
+++ 
b/management/src/main/java/org/apache/karaf/cellar/management/CellarFeaturesMBean.java
@@ -31,7 +31,18 @@ public interface CellarFeaturesMBean {
     void addUrl(String group, String url) throws Exception;
 
     /**
-     * Remove a features repository URL in a cluster group.
+     * Add a features repository URL in a cluster group, eventually installing 
all features
+     * defined in the repository.
+     *
+     * @param group the cluster group name.
+     * @param url the features repository URL.
+     * @param install true to install all features defined in the repository, 
false else.
+     * @throws Exception in case of add failure.
+     */
+    void addUrl(String group, String url, boolean install) throws Exception;
+
+    /**
+     * Remove a features repository URL from a cluster group.
      *
      * @param group the cluster group name.
      * @param url the features repository URL.
@@ -40,6 +51,16 @@ public interface CellarFeaturesMBean {
     void removeUrl(String group, String url) throws Exception;
 
     /**
+     * Remove a features repository URL from a cluster group.
+     *
+     * @param group the cluster group name.
+     * @param url the features repository URL.
+     * @param uninstall true to uninstall all features defined in the 
repository, false else.
+     * @throws Exception in case of remove failure.
+     */
+    void removeUrl(String group, String url, boolean uninstall) throws 
Exception;
+
+    /**
      * Install a feature in a cluster group.
      *
      * @param group the cluster group name.

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/bdcd6539/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarFeaturesMBeanImpl.java
----------------------------------------------------------------------
diff --git 
a/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarFeaturesMBeanImpl.java
 
b/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarFeaturesMBeanImpl.java
index 18a1d23..7110e5e 100644
--- 
a/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarFeaturesMBeanImpl.java
+++ 
b/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarFeaturesMBeanImpl.java
@@ -302,6 +302,11 @@ public class CellarFeaturesMBeanImpl extends StandardMBean 
implements CellarFeat
 
     @Override
     public void addUrl(String groupName, String url) throws Exception {
+        this.addUrl(groupName, url, false);
+    }
+
+    @Override
+    public void addUrl(String groupName, String url, boolean install) throws 
Exception {
         // check if the group exists
         Group group = groupManager.findGroupByName(groupName);
         if (group == null) {
@@ -373,6 +378,7 @@ public class CellarFeaturesMBeanImpl extends StandardMBean 
implements CellarFeat
 
                 // broadcast the cluster event
                 ClusterRepositoryEvent event = new ClusterRepositoryEvent(url, 
RepositoryEvent.EventType.RepositoryAdded);
+                event.setInstall(install);
                 event.setSourceGroup(group);
                 eventProducer.produce(event);
             } else {
@@ -385,6 +391,11 @@ public class CellarFeaturesMBeanImpl extends StandardMBean 
implements CellarFeat
 
     @Override
     public void removeUrl(String groupName, String url) throws Exception {
+        this.removeUrl(groupName, url, false);
+    }
+
+    @Override
+    public void removeUrl(String groupName, String url, boolean uninstall) 
throws Exception {
         // check if the group exists
         Group group = groupManager.findGroupByName(groupName);
         if (group == null) {
@@ -453,6 +464,7 @@ public class CellarFeaturesMBeanImpl extends StandardMBean 
implements CellarFeat
 
             // broadcast a cluster event
             ClusterRepositoryEvent event = new ClusterRepositoryEvent(url, 
RepositoryEvent.EventType.RepositoryRemoved);
+            event.setUninstall(uninstall);
             event.setSourceGroup(group);
             eventProducer.produce(event);
         } else {

Reply via email to