You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2016/10/17 12:02:52 UTC

karaf-cellar git commit: [KARAF-4729] Fix cluster feature repo refresh action

Repository: karaf-cellar
Updated Branches:
  refs/heads/master bbe948805 -> 76c1aa5f8


[KARAF-4729] Fix cluster feature repo refresh action


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

Branch: refs/heads/master
Commit: 76c1aa5f8befe2a23b53994f722d63683d787d32
Parents: bbe9488
Author: Jean-Baptiste Onofr� <jb...@apache.org>
Authored: Mon Oct 17 14:02:30 2016 +0200
Committer: Jean-Baptiste Onofr� <jb...@apache.org>
Committed: Mon Oct 17 14:02:30 2016 +0200

----------------------------------------------------------------------
 .../cellar/features/RepositoryEventHandler.java | 15 +++++++--
 .../management/CellarFeaturesMBean.java         |  3 +-
 .../internal/CellarFeaturesMBeanImpl.java       | 27 +++++++++-------
 .../features/shell/RepoRefreshCommand.java      | 34 +++++++++++---------
 4 files changed, 47 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/76c1aa5f/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 0f0ea2d..e7bfc29 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
@@ -17,12 +17,14 @@ import org.apache.karaf.cellar.core.control.BasicSwitch;
 import org.apache.karaf.cellar.core.control.Switch;
 import org.apache.karaf.cellar.core.control.SwitchStatus;
 import org.apache.karaf.cellar.core.event.EventHandler;
+import org.apache.karaf.features.Repository;
 import org.apache.karaf.features.RepositoryEvent;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.net.URI;
+import java.util.ArrayList;
 
 /**
  * Handler for cluster features repository event.
@@ -80,11 +82,18 @@ public class RepositoryEventHandler extends FeaturesSupport implements EventHand
         String uri = event.getId();
         RepositoryEvent.EventType type = event.getType();
         try {
-            // TODO check if isAllowed
             if (RepositoryEvent.EventType.RepositoryAdded.equals(type)) {
                 if (event.getRefresh() != null && event.getRefresh()) {
-                    LOGGER.debug("CELLAR FEATURE: refresh repository {}", uri);
-                    featuresService.refreshRepository(new URI(uri));
+                    if (uri == null) {
+                        Repository[] repositories = featuresService.listRepositories();
+                        for (Repository repository : repositories) {
+                            LOGGER.debug("CELLAR FEATURE: refresh repository {}", repository.getURI().toString());
+                            featuresService.refreshRepository(repository.getURI());
+                        }
+                    } else {
+                        LOGGER.debug("CELLAR FEATURE: refresh repository {}", uri);
+                        featuresService.refreshRepository(new URI(uri));
+                    }
                 } else {
                     if (!isRepositoryRegisteredLocally(uri)) {
                         LOGGER.debug("CELLAR FEATURE: adding repository URI {}", uri);

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/76c1aa5f/features/src/main/java/org/apache/karaf/cellar/features/management/CellarFeaturesMBean.java
----------------------------------------------------------------------
diff --git a/features/src/main/java/org/apache/karaf/cellar/features/management/CellarFeaturesMBean.java b/features/src/main/java/org/apache/karaf/cellar/features/management/CellarFeaturesMBean.java
index 10ffd81..9e0fbcb 100644
--- a/features/src/main/java/org/apache/karaf/cellar/features/management/CellarFeaturesMBean.java
+++ b/features/src/main/java/org/apache/karaf/cellar/features/management/CellarFeaturesMBean.java
@@ -75,10 +75,9 @@ public interface CellarFeaturesMBean {
      *
      * @param group the cluster group name.
      * @param repository the features repository name or URL.
-     * @param version the features repository version.
      * @throws Exception
      */
-    void refreshRepository(String group, String repository, String version) throws Exception;
+    void refreshRepository(String group, String repository) throws Exception;
 
     /**
      * Install a feature in a cluster group.

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/76c1aa5f/features/src/main/java/org/apache/karaf/cellar/features/management/internal/CellarFeaturesMBeanImpl.java
----------------------------------------------------------------------
diff --git a/features/src/main/java/org/apache/karaf/cellar/features/management/internal/CellarFeaturesMBeanImpl.java b/features/src/main/java/org/apache/karaf/cellar/features/management/internal/CellarFeaturesMBeanImpl.java
index 8f0cc94..cfe0e6c 100644
--- a/features/src/main/java/org/apache/karaf/cellar/features/management/internal/CellarFeaturesMBeanImpl.java
+++ b/features/src/main/java/org/apache/karaf/cellar/features/management/internal/CellarFeaturesMBeanImpl.java
@@ -461,7 +461,7 @@ public class CellarFeaturesMBeanImpl extends StandardMBean implements CellarFeat
     }
 
     @Override
-    public void refreshRepository(String groupName, String nameOrUrl, String version) throws Exception {
+    public void refreshRepository(String groupName, String nameOrUrl) throws Exception {
         // check if the group exists
         Group group = groupManager.findGroupByName(groupName);
         if (group == null) {
@@ -476,20 +476,25 @@ public class CellarFeaturesMBeanImpl extends StandardMBean implements CellarFeat
         ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
         try {
-            // get the cluster features repositories
-            Map<String, String> clusterFeaturesRepositories = clusterManager.getMap(Constants.REPOSITORIES_MAP + Configurations.SEPARATOR + groupName);
-
-            URI uri = featuresService.getRepositoryUriFor(nameOrUrl, version);
-            if (uri == null) {
-                uri = new URI(nameOrUrl);
-            }
+            String uri = null;
+            if (nameOrUrl != null) {
+                // get the cluster features repositories
+                Map<String, String> clusterFeaturesRepositories = clusterManager.getMap(Constants.REPOSITORIES_MAP + Configurations.SEPARATOR + groupName);
+
+                for (Map.Entry<String, String> entry : clusterFeaturesRepositories.entrySet()) {
+                    if (entry.getKey().equals(nameOrUrl) || entry.getValue().equals(nameOrUrl)) {
+                        uri = entry.getKey();
+                        break;
+                    }
+                }
 
-            if (clusterFeaturesRepositories.get(uri) == null) {
-                throw new IllegalArgumentException("Features repository " + nameOrUrl + " doesn't exist in cluster group " + groupName);
+                if (uri == null) {
+                    throw new IllegalArgumentException("Features repository " + nameOrUrl + " doesn't exist in cluster group " + groupName);
+                }
             }
 
             // broadcast the cluster event
-            ClusterRepositoryEvent event = new ClusterRepositoryEvent(uri.toString(), RepositoryEvent.EventType.RepositoryAdded);
+            ClusterRepositoryEvent event = new ClusterRepositoryEvent(uri, RepositoryEvent.EventType.RepositoryAdded);
             event.setRefresh(true);
             event.setSourceGroup(group);
             event.setSourceNode(clusterManager.getNode());

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/76c1aa5f/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoRefreshCommand.java
----------------------------------------------------------------------
diff --git a/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoRefreshCommand.java b/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoRefreshCommand.java
index 3b4033d..cbb370c 100644
--- a/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoRefreshCommand.java
+++ b/features/src/main/java/org/apache/karaf/cellar/features/shell/RepoRefreshCommand.java
@@ -41,13 +41,10 @@ public class RepoRefreshCommand extends CellarCommandSupport {
     @Completion(AllGroupsCompleter.class)
     String groupName;
 
-    @Argument(index = 1, name = "name/url", description = "Shortcut name of the features repository or the full URL", required = true, multiValued = false)
+    @Argument(index = 1, name = "name/url", description = "Shortcut name of the features repository or the full URL", required = false, multiValued = false)
     @Completion(AvailableRepoNameCompleter.class)
     String nameOrUrl;
 
-    @Argument(index = 2, name = "version", description = "The version of the features repository if using features repository name as first argument. It should be empty if using the URL.", required = false, multiValued = false)
-    String version;
-
     @Reference
     private EventProducer eventProducer;
 
@@ -72,21 +69,26 @@ public class RepoRefreshCommand extends CellarCommandSupport {
         ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
         try {
-            // get the cluster features repositories
-            Map<String, String> clusterFeaturesRepositories = clusterManager.getMap(Constants.REPOSITORIES_MAP + Configurations.SEPARATOR + groupName);
-
-            URI uri = featuresService.getRepositoryUriFor(nameOrUrl, version);
-            if (uri == null) {
-                uri = new URI(nameOrUrl);
-            }
-
-            if (clusterFeaturesRepositories.get(uri) == null) {
-                System.err.println("Features repository " + nameOrUrl + " doesn't exist in cluster group " + groupName);
-                return null;
+            String uri = null;
+            if (nameOrUrl != null) {
+                // get the cluster features repositories
+                Map<String, String> clusterFeaturesRepositories = clusterManager.getMap(Constants.REPOSITORIES_MAP + Configurations.SEPARATOR + groupName);
+
+                for (Map.Entry<String, String> entry : clusterFeaturesRepositories.entrySet()) {
+                    if (entry.getKey().equals(nameOrUrl) || entry.getValue().equals(nameOrUrl)) {
+                        uri = entry.getKey();
+                        break;
+                    }
+                }
+
+                if (uri == null) {
+                    System.err.println("Features repository " + nameOrUrl + " doesn't exist in cluster group " + groupName);
+                    return null;
+                }
             }
 
             // broadcast the cluster event
-            ClusterRepositoryEvent event = new ClusterRepositoryEvent(uri.toString(), RepositoryEvent.EventType.RepositoryAdded);
+            ClusterRepositoryEvent event = new ClusterRepositoryEvent(uri, RepositoryEvent.EventType.RepositoryAdded);
             event.setRefresh(true);
             event.setSourceGroup(group);
             event.setSourceNode(clusterManager.getNode());