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 2013/12/18 13:30:09 UTC

[18/50] git commit: [KARAF-2251] - Cellar: features:install ignores incoming and outgoing blacklist

[KARAF-2251] - Cellar: features:install ignores incoming and outgoing blacklist


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

Branch: refs/heads/cellar-2.2.x
Commit: 0a5acf66774cf5c369489f33d51344f3eec355f6
Parents: 8b599ba
Author: anierbeck <an...@13f79535-47bb-0310-9956-ffa450edef68>
Authored: Tue Mar 26 16:30:25 2013 +0000
Committer: anierbeck <an...@13f79535-47bb-0310-9956-ffa450edef68>
Committed: Tue Mar 26 16:30:25 2013 +0000

----------------------------------------------------------------------
 bundle/pom.xml                                  |  7 +++
 .../karaf/cellar/bundle/BundleEventHandler.java | 50 +++++++++++++++++++-
 .../resources/OSGI-INF/blueprint/blueprint.xml  |  2 +
 3 files changed, 57 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/0a5acf66/bundle/pom.xml
----------------------------------------------------------------------
diff --git a/bundle/pom.xml b/bundle/pom.xml
index 7cd34a2..51da528 100644
--- a/bundle/pom.xml
+++ b/bundle/pom.xml
@@ -42,6 +42,7 @@
             org.apache.karaf.shell.console;version="[2.2,3)",
             org.apache.karaf.shell.console.commands;version="[2.2,3)",
             org.apache.karaf.shell.console.completer;version="[2.2,3)",
+            org.apache.karaf.features;version="[2.2,3)",
             org.osgi*,
             org.slf4j;resolution:=optional
         </osgi.import>
@@ -64,6 +65,12 @@
             <artifactId>org.apache.felix.configadmin</artifactId>
         </dependency>
 
+        <!-- Karaf features -->
+        <dependency>
+            <groupId>org.apache.karaf.features</groupId>
+            <artifactId>org.apache.karaf.features.core</artifactId>
+        </dependency>
+
         <!-- Logging Dependencies -->
         <dependency>
             <groupId>org.slf4j</groupId>

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/0a5acf66/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleEventHandler.java
----------------------------------------------------------------------
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleEventHandler.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleEventHandler.java
index 8833e78..d9ccac3 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleEventHandler.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleEventHandler.java
@@ -13,12 +13,18 @@
  */
 package org.apache.karaf.cellar.bundle;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.karaf.cellar.core.Configurations;
 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.cellar.core.event.EventType;
+import org.apache.karaf.features.BundleInfo;
+import org.apache.karaf.features.Feature;
+import org.apache.karaf.features.FeaturesService;
 import org.osgi.framework.BundleEvent;
 import org.osgi.framework.BundleException;
 import org.osgi.service.cm.Configuration;
@@ -32,6 +38,8 @@ public class BundleEventHandler extends BundleSupport implements EventHandler<Re
     public static final String SWITCH_ID = "org.apache.karaf.cellar.bundle.handler";
 
     private final Switch eventSwitch = new BasicSwitch(SWITCH_ID);
+    
+    private FeaturesService featureService;
 
     /**
      * Handles remote bundle events.
@@ -54,6 +62,13 @@ public class BundleEventHandler extends BundleSupport implements EventHandler<Re
         try {
             //Check if the pid is marked as local.
             if (isAllowed(event.getSourceGroup(), Constants.CATEGORY, event.getLocation(), EventType.INBOUND)) {
+            	//check the features first
+            	List<Feature> matchingFeatures = retrieveFeature(event);
+            	for (Feature feature : matchingFeatures) {
+					if (!isAllowed(event.getSourceGroup(), "features", feature.getName(), EventType.INBOUND)) {
+						LOGGER.warn("CELLAR BUNDLE: bundle {} is contained in a feature marked as BLOCKED INBOUND", event.getLocation());
+					}
+				}
                 if (event.getType() == BundleEvent.INSTALLED) {
                     LOGGER.debug("CELLAR BUNDLE: installing bundle {} from {}", event.getId(), event.getLocation());
                     installBundleFromLocation(event.getLocation());
@@ -73,10 +88,27 @@ public class BundleEventHandler extends BundleSupport implements EventHandler<Re
             } else LOGGER.warn("CELLAR BUNDLE: bundle {} is marked as BLOCKED INBOUND", event.getLocation());
         } catch (BundleException e) {
             LOGGER.error("CELLAR BUNDLE: failed to handle bundle event", e);
-        }
+        } catch (Exception e) {
+        	LOGGER.error("CELLAR BUNDLE: failed to handle bundle event", e);
+		}
     }
 
-    /**
+    private List<Feature> retrieveFeature(RemoteBundleEvent event) throws Exception {
+    	Feature[] features = featureService.listFeatures();
+    	List<Feature> matchingFeatures = new ArrayList<Feature>();
+    	for (Feature feature : features) {
+			List<BundleInfo> bundles = feature.getBundles();
+			for (BundleInfo bundleInfo : bundles) {
+				String location = bundleInfo.getLocation();
+				if (location.equalsIgnoreCase(event.getLocation())) {
+					matchingFeatures.add(feature);
+				}
+			}
+		}
+		return matchingFeatures;
+	}
+
+	/**
      * Initialization Method.
      */
     public void init() {
@@ -112,4 +144,18 @@ public class BundleEventHandler extends BundleSupport implements EventHandler<Re
         return RemoteBundleEvent.class;
     }
 
+	/**
+	 * @return the featureService
+	 */
+	public FeaturesService getFeatureService() {
+		return featureService;
+	}
+
+	/**
+	 * @param featureService the featureService to set
+	 */
+	public void setFeatureService(FeaturesService featureService) {
+		this.featureService = featureService;
+	}
+
 }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/0a5acf66/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 dad9030..b0b10fe 100644
--- a/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -42,6 +42,7 @@
         <property name="clusterManager" ref="clusterManager"/>
         <property name="groupManager" ref="groupManager"/>
         <property name="bundleContext" ref="blueprintBundleContext"/>
+        <property name="featuresService" ref="featuresService"/>
     </bean>
     <service ref="eventHandler" interface="org.apache.karaf.cellar.core.event.EventHandler">
         <service-properties>
@@ -54,5 +55,6 @@
     <reference id="groupManager" interface="org.apache.karaf.cellar.core.GroupManager"/>
     <reference id="configurationAdmin" interface="org.osgi.service.cm.ConfigurationAdmin"/>
     <reference id="eventProducer" interface="org.apache.karaf.cellar.core.event.EventProducer"/>
+    <reference id="featuresService" interface="org.apache.karaf.features.FeaturesService"/>
 
 </blueprint>