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 2012/05/03 19:28:08 UTC

svn commit: r1333563 - in /karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell: FeatureCommandSupport.java InstallFeatureCommand.java UninstallFeatureCommand.java

Author: jbonofre
Date: Thu May  3 17:28:08 2012
New Revision: 1333563

URL: http://svn.apache.org/viewvc?rev=1333563&view=rev
Log:
[KARAF-1314] Check if a feature exists in the given group for cluster:feature-* commands

Modified:
    karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/FeatureCommandSupport.java
    karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/InstallFeatureCommand.java
    karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/UninstallFeatureCommand.java

Modified: karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/FeatureCommandSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/FeatureCommandSupport.java?rev=1333563&r1=1333562&r2=1333563&view=diff
==============================================================================
--- karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/FeatureCommandSupport.java (original)
+++ karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/FeatureCommandSupport.java Thu May  3 17:28:08 2012
@@ -88,6 +88,38 @@ public abstract class FeatureCommandSupp
         return result;
     }
 
+    /**
+     * Check if a feature is present in the distributed map.
+     *
+     * @param groupName the target cluster group.
+     * @param feature   the target feature name.
+     * @param version   the target feature version.
+     * @return true if the feature exists in the distributed map, false else
+     */
+    public boolean featureExists(String groupName, String feature, String version) {
+        ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+            Map<FeatureInfo, Boolean> distributedFeatures = clusterManager.getMap(Constants.FEATURES + Configurations.SEPARATOR + groupName);
+
+            if (distributedFeatures == null)
+                return false;
+
+            for (FeatureInfo distributedFeature : distributedFeatures.keySet()) {
+                if (version == null) {
+                    if (distributedFeature.getName().equals(feature))
+                        return true;
+                } else {
+                    if (distributedFeature.getName().equals(feature) && distributedFeature.getVersion().equals(version))
+                        return true;
+                }
+            }
+
+            return false;
+        } finally {
+            Thread.currentThread().setContextClassLoader(originalClassLoader);
+        }
+    }
 
     public BundleContext getBundleContext() {
         return bundleContext;

Modified: karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/InstallFeatureCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/InstallFeatureCommand.java?rev=1333563&r1=1333562&r2=1333563&view=diff
==============================================================================
--- karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/InstallFeatureCommand.java (original)
+++ karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/InstallFeatureCommand.java Thu May  3 17:28:08 2012
@@ -50,6 +50,14 @@ public class InstallFeatureCommand exten
             return null;
         }
 
+        // check if the feature exists in the map
+        if (!featureExists(groupName, feature, version)) {
+            if (version != null)
+                System.err.println("Feature " + feature + "/" + version + " doesn't exist for the cluster group " + groupName);
+            else System.err.println("Feature " + feature + " doesn't exist for the cluster group " + groupName);
+            return null;
+        }
+
         // update the distributed map
         updateFeatureStatus(groupName, feature, version, true);
 

Modified: karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/UninstallFeatureCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/UninstallFeatureCommand.java?rev=1333563&r1=1333562&r2=1333563&view=diff
==============================================================================
--- karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/UninstallFeatureCommand.java (original)
+++ karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/UninstallFeatureCommand.java Thu May  3 17:28:08 2012
@@ -50,6 +50,14 @@ public class UninstallFeatureCommand ext
             return null;
         }
 
+        // check if the feature exists in the map
+        if (!featureExists(groupName, feature, version)) {
+            if (version != null)
+                System.err.println("Feature " + feature + "/" + version + " doesn't exist for the cluster group " + groupName);
+            else System.err.println("Feature " + feature + " doesn't exist for the cluster group " + groupName);
+            return null;
+        }
+
         // update the distributed map
         updateFeatureStatus(groupName, feature, version, true);