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/09/29 13:24:08 UTC

[1/2] karaf-cellar git commit: [KARAF-4708] Properly handle cluster bundles in Resolved state, i.e. trigger stop for local one only if it is currently Active

Repository: karaf-cellar
Updated Branches:
  refs/heads/master e1599e088 -> e519b3acb


[KARAF-4708] Properly handle cluster bundles in Resolved state, i.e.
trigger stop for local one only if it is currently Active


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

Branch: refs/heads/master
Commit: 1b133bc60583373fcfef04fff5ec7fda6c12afb2
Parents: e1599e0
Author: Sergiy Shyrkov <ss...@jahia.com>
Authored: Mon Sep 12 23:25:29 2016 +0200
Committer: Jean-Baptiste Onofr� <jb...@apache.org>
Committed: Thu Sep 29 14:57:46 2016 +0200

----------------------------------------------------------------------
 .../karaf/cellar/bundle/BundleEventHandler.java | 20 ++++++++++++++--
 .../karaf/cellar/bundle/BundleSupport.java      | 25 ++++++++++++++------
 .../karaf/cellar/bundle/BundleSynchronizer.java | 19 +++++++++++++++
 3 files changed, 55 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/1b133bc6/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 86b8654..2da1cca 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
@@ -22,10 +22,12 @@ import org.apache.karaf.cellar.core.event.EventType;
 import org.apache.karaf.features.Feature;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
+import org.osgi.framework.wiring.FrameworkWiring;
 import org.osgi.service.cm.Configuration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
@@ -105,8 +107,22 @@ public class BundleEventHandler extends BundleSupport implements EventHandler<Cl
                         }
                     }
                 } else if (event.getType() == Bundle.RESOLVED) {
-                    stopBundle(event.getSymbolicName(), event.getVersion());
-                    LOGGER.debug("CELLAR BUNDLE: stopping {}/{}", event.getSymbolicName(), event.getVersion());
+                    if (!isInstalled(event.getLocation())) {
+                        installBundleFromLocation(event.getLocation());
+                        LOGGER.debug("CELLAR BUNDLE: installing {}/{}", event.getSymbolicName(), event.getVersion());
+                    }
+                    Bundle b = findBundle(event.getLocation());
+                    if (b != null) {
+                        if (b.getState() == Bundle.ACTIVE) {
+                            LOGGER.debug("CELLAR BUNDLE: stopping bundle {}/{} on node", event.getSymbolicName(), event.getVersion());
+                            stopBundle(event.getSymbolicName(), event.getVersion());
+                        } else if (b.getState() == Bundle.INSTALLED) {
+                            LOGGER.debug("CELLAR BUNDLE: resolving bundle {}/{} on node", event.getSymbolicName(), event.getVersion());
+                            getBundleContext().getBundle(0).adapt(FrameworkWiring.class).resolveBundles(Collections.singleton(b));
+                        }
+                    } else {
+                        LOGGER.warn("CELLAR BUNDLE: unable to find bundle located {} on node", event.getLocation());
+                    }
                 }
             } else
                 LOGGER.trace("CELLAR BUNDLE: bundle {} is marked BLOCKED INBOUND for cluster group {}", event.getSymbolicName(), event.getSourceGroup().getName());

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/1b133bc6/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 b2509f7..fd3f81f 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
@@ -43,13 +43,7 @@ public class BundleSupport extends CellarSupport {
     }
 
     public boolean isInstalled(String location) {
-        Bundle[] bundles = getBundleContext().getBundles();
-        for (Bundle bundle : bundles) {
-            if (bundle.getLocation().equals(location)) {
-                return true;
-            }
-        }
-        return false;
+        return findBundle(location) != null;
     }
 
     public boolean isStarted(String location) {
@@ -173,4 +167,21 @@ public class BundleSupport extends CellarSupport {
 		this.featuresService = featureService;
 	}
 
+    /**
+     * Finds locally installed bundle by its location.
+     * 
+     * @param location
+     *            the location of the bundle to be found
+     * @return locally installed bundle for the specified location or <code>null</code> if there is no matching bundle installed
+     */
+    protected Bundle findBundle(String location) {
+        Bundle[] bundles = getBundleContext().getBundles();
+        for (Bundle bundle : bundles) {
+            if (bundle.getLocation().equals(location)) {
+                return bundle;
+            }
+        }
+        return null;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/1b133bc6/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java
----------------------------------------------------------------------
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java
index ae16895..8547ab1 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java
@@ -24,12 +24,14 @@ import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.BundleReference;
+import org.osgi.framework.wiring.FrameworkWiring;
 import org.osgi.service.cm.Configuration;
 import org.osgi.util.tracker.ServiceTracker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
+import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Map;
 import java.util.Set;
@@ -162,6 +164,23 @@ public class BundleSynchronizer extends BundleSupport implements Synchronizer {
                                         } else {
                                             LOGGER.debug("CELLAR BUNDLE: bundle located {} already started on node", state.getLocation());
                                         }
+                                    } else if (state.getStatus() == Bundle.RESOLVED) {
+                                        if (!isInstalled(state.getLocation())) {
+                                            LOGGER.debug("CELLAR BUNDLE: installing bundle located {} on node", state.getLocation());
+                                            installBundleFromLocation(state.getLocation());
+                                        }
+                                        Bundle b = findBundle(state.getLocation());
+                                        if (b != null) {
+                                            if (b.getState() == Bundle.ACTIVE) {
+                                                LOGGER.debug("CELLAR BUNDLE: stopping bundle {}/{} on node", symbolicName, version);
+                                                stopBundle(symbolicName, version);
+                                            } else if (b.getState() == Bundle.INSTALLED) {
+                                                LOGGER.debug("CELLAR BUNDLE: resolving bundle {}/{} on node", symbolicName, version);
+                                                getBundleContext().getBundle(0).adapt(FrameworkWiring.class).resolveBundles(Collections.singleton(b));
+                                            }
+                                        } else {
+                                            LOGGER.warn("CELLAR BUNDLE: unable to find bundle located {} on node", state.getLocation());
+                                        }
                                     }
                                 } catch (BundleException e) {
                                     LOGGER.error("CELLAR BUNDLE: failed to pull bundle {}", id, e);


[2/2] karaf-cellar git commit: [KARAF-4708] This closes #37

Posted by jb...@apache.org.
[KARAF-4708] This closes #37


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

Branch: refs/heads/master
Commit: e519b3acb8259a5532a77a2f5354216a5fab537f
Parents: e1599e0 1b133bc
Author: Jean-Baptiste Onofr� <jb...@apache.org>
Authored: Thu Sep 29 14:59:41 2016 +0200
Committer: Jean-Baptiste Onofr� <jb...@apache.org>
Committed: Thu Sep 29 14:59:41 2016 +0200

----------------------------------------------------------------------
 .../karaf/cellar/bundle/BundleEventHandler.java | 20 ++++++++++++++--
 .../karaf/cellar/bundle/BundleSupport.java      | 25 ++++++++++++++------
 .../karaf/cellar/bundle/BundleSynchronizer.java | 19 +++++++++++++++
 3 files changed, 55 insertions(+), 9 deletions(-)
----------------------------------------------------------------------