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:11 UTC
[20/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@1461350 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/cf243811
Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/cf243811
Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/cf243811
Branch: refs/heads/cellar-2.2.x
Commit: cf243811e381a275188c058ec44b3926a9b9afa9
Parents: f99c8c8
Author: anierbeck <an...@13f79535-47bb-0310-9956-ffa450edef68>
Authored: Tue Mar 26 22:27:06 2013 +0000
Committer: anierbeck <an...@13f79535-47bb-0310-9956-ffa450edef68>
Committed: Tue Mar 26 22:27:06 2013 +0000
----------------------------------------------------------------------
.../karaf/cellar/bundle/BundleEventHandler.java | 40 ++------------------
.../karaf/cellar/bundle/BundleSupport.java | 36 ++++++++++++++++++
.../cellar/bundle/LocalBundleListener.java | 14 ++++++-
.../resources/OSGI-INF/blueprint/blueprint.xml | 2 +
.../cellar/core/event/EventDispatchTask.java | 8 ++--
5 files changed, 59 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/cf243811/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 d9ccac3..c12eefe 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,7 +13,6 @@
*/
package org.apache.karaf.cellar.bundle;
-import java.util.ArrayList;
import java.util.List;
import org.apache.karaf.cellar.core.Configurations;
@@ -22,7 +21,6 @@ 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;
@@ -33,14 +31,12 @@ import org.slf4j.LoggerFactory;
public class BundleEventHandler extends BundleSupport implements EventHandler<RemoteBundleEvent> {
- private static final Logger LOGGER = LoggerFactory.getLogger(BundleEventHandler.class);
+ static final Logger LOGGER = LoggerFactory.getLogger(BundleEventHandler.class);
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.
*
@@ -63,10 +59,11 @@ public class BundleEventHandler extends BundleSupport implements EventHandler<Re
//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);
+ List<Feature> matchingFeatures = retrieveFeature(event.getLocation());
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());
+ return;
}
}
if (event.getType() == BundleEvent.INSTALLED) {
@@ -93,22 +90,7 @@ public class BundleEventHandler extends BundleSupport implements EventHandler<Re
}
}
- 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() {
@@ -144,18 +126,4 @@ 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/cf243811/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSupport.java
----------------------------------------------------------------------
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSupport.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSupport.java
index c9c9e58..7501323 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSupport.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSupport.java
@@ -14,18 +14,24 @@
package org.apache.karaf.cellar.bundle;
import org.apache.karaf.cellar.core.CellarSupport;
+import org.apache.karaf.features.BundleInfo;
+import org.apache.karaf.features.Feature;
+import org.apache.karaf.features.FeaturesService;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.service.cm.ConfigurationAdmin;
+import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Enumeration;
+import java.util.List;
import java.util.Properties;
public class BundleSupport extends CellarSupport {
protected BundleContext bundleContext;
+ private FeaturesService featuresService;
/**
* Reads a {@code Dictionary} object and creates a property object out of it.
@@ -153,4 +159,34 @@ public class BundleSupport extends CellarSupport {
this.configurationAdmin = configurationAdmin;
}
+ protected List<Feature> retrieveFeature(String bundleLocation) throws Exception {
+ Feature[] features = featuresService.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(bundleLocation)) {
+ matchingFeatures.add(feature);
+ LOGGER.debug("CELLAR BUNDLE: found a feature {} containing bundle: {}", feature.getName(), bundleLocation);
+ }
+ }
+ }
+ return matchingFeatures;
+ }
+
+ /**
+ * @return the featuresService
+ */
+ public FeaturesService getFeaturesService() {
+ return featuresService;
+ }
+
+ /**
+ * @param featuresService the featuresService to set
+ */
+ public void setFeaturesService(FeaturesService featureService) {
+ this.featuresService = featureService;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/cf243811/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java
----------------------------------------------------------------------
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java
index c9d0fed..e6c702d 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java
@@ -19,6 +19,7 @@ import org.apache.karaf.cellar.core.Node;
import org.apache.karaf.cellar.core.control.SwitchStatus;
import org.apache.karaf.cellar.core.event.EventProducer;
import org.apache.karaf.cellar.core.event.EventType;
+import org.apache.karaf.features.Feature;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;
import org.osgi.framework.SynchronousBundleListener;
@@ -92,11 +93,22 @@ public class LocalBundleListener extends BundleSupport implements SynchronousBun
bundles.put(symbolicName + "/" + version, state);
}
+ // check the features first
+ List<Feature> matchingFeatures = retrieveFeature(bundleLocation);
+ for (Feature feature : matchingFeatures) {
+ if (!isAllowed(group, "features", feature.getName(), EventType.OUTBOUND)) {
+ LOGGER.warn("CELLAR BUNDLE: bundle {} is contained in a feature marked as BLOCKED OUTBOUND", bundleLocation);
+ return;
+ }
+ }
+
// broadcast the cluster event
RemoteBundleEvent remoteBundleEvent = new RemoteBundleEvent(symbolicName, version, bundleLocation, type);
remoteBundleEvent.setSourceGroup(group);
eventProducer.produce(remoteBundleEvent);
- } finally {
+ } catch (Exception e) {
+ LOGGER.error("CELLAR BUNDLE: failed to create bundle event", e);
+ } finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/cf243811/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 b0b10fe..a309212 100644
--- a/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/bundle/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -22,6 +22,7 @@
<property name="configurationAdmin" ref="configurationAdmin"/>
<property name="bundleContext" ref="blueprintBundleContext"/>
<property name="eventProducer" ref="eventProducer"/>
+ <property name="featuresService" ref="featuresService"/>
</bean>
<!-- Bundle Synchronizer -->
@@ -32,6 +33,7 @@
<property name="clusterManager" ref="clusterManager"/>
<property name="eventProducer" ref="eventProducer"/>
<property name="bundleContext" ref="blueprintBundleContext"/>
+ <property name="featuresService" ref="featuresService"/>
</bean>
<service ref="synchronizer" interface="org.apache.karaf.cellar.core.Synchronizer"/>
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/cf243811/core/src/main/java/org/apache/karaf/cellar/core/event/EventDispatchTask.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/karaf/cellar/core/event/EventDispatchTask.java b/core/src/main/java/org/apache/karaf/cellar/core/event/EventDispatchTask.java
index a8fef15..f14a261 100644
--- a/core/src/main/java/org/apache/karaf/cellar/core/event/EventDispatchTask.java
+++ b/core/src/main/java/org/apache/karaf/cellar/core/event/EventDispatchTask.java
@@ -69,13 +69,13 @@ public class EventDispatchTask<E extends Event> implements Runnable {
public void run() {
try {
- boolean dispathced = false;
+ boolean dispatched = false;
- for (long delay = 0; delay < timeout && !dispathced; delay += interval) {
+ for (long delay = 0; delay < timeout && !dispatched; delay += interval) {
EventHandler handler = handlerRegistry.getHandler(event);
if (handler != null) {
handler.handle(event);
- dispathced = true;
+ dispatched = true;
} else {
try {
Thread.sleep(interval);
@@ -84,7 +84,7 @@ public class EventDispatchTask<E extends Event> implements Runnable {
}
}
}
- if (!dispathced) {
+ if (!dispatched) {
LOGGER.warn("Failed to retrieve handler for event {}", event.getClass());
}
}catch(Exception ex) {