karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anierb...@apache.org
Subject svn commit: r1461206 - in /karaf/cellar/branches/cellar-2.2.x/bundle: pom.xml src/main/java/org/apache/karaf/cellar/bundle/BundleEventHandler.java src/main/resources/OSGI-INF/blueprint/blueprint.xml
Date Tue, 26 Mar 2013 16:30:25 GMT
Author: anierbeck
Date: Tue Mar 26 16:30:25 2013
New Revision: 1461206

URL: http://svn.apache.org/r1461206
Log:
[KARAF-2251] - Cellar: features:install ignores incoming and outgoing blacklist

Modified:
    karaf/cellar/branches/cellar-2.2.x/bundle/pom.xml
    karaf/cellar/branches/cellar-2.2.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleEventHandler.java
    karaf/cellar/branches/cellar-2.2.x/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml

Modified: karaf/cellar/branches/cellar-2.2.x/bundle/pom.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/bundle/pom.xml?rev=1461206&r1=1461205&r2=1461206&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/bundle/pom.xml (original)
+++ karaf/cellar/branches/cellar-2.2.x/bundle/pom.xml Tue Mar 26 16:30:25 2013
@@ -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>

Modified: karaf/cellar/branches/cellar-2.2.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleEventHandler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleEventHandler.java?rev=1461206&r1=1461205&r2=1461206&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleEventHandler.java
(original)
+++ karaf/cellar/branches/cellar-2.2.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleEventHandler.java
Tue Mar 26 16:30:25 2013
@@ -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 
     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 
         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 
             } 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 
         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;
+	}
+
 }

Modified: karaf/cellar/branches/cellar-2.2.x/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=1461206&r1=1461205&r2=1461206&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
(original)
+++ karaf/cellar/branches/cellar-2.2.x/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
Tue Mar 26 16:30:25 2013
@@ -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>



Mime
View raw message