brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [4/9] brooklyn-server git commit: fix bundle install issue if already osgi-installed, and tidy
Date Tue, 26 Sep 2017 12:17:09 GMT
fix bundle install issue if already osgi-installed, and tidy

take the URL from the existing osgi-installed bundle.
much better logging.


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/277cb22a
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/277cb22a
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/277cb22a

Branch: refs/heads/master
Commit: 277cb22aa6b8553bb5369dfd4d1d5eba2185a858
Parents: 87a2852
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Thu Sep 21 11:35:25 2017 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Thu Sep 21 13:17:07 2017 +0100

----------------------------------------------------------------------
 .../core/catalog/internal/CatalogUtils.java     |  4 +-
 .../core/mgmt/ha/OsgiArchiveInstaller.java      | 97 +++++++++++++-------
 2 files changed, 67 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/277cb22a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
index 973f56d..471ce64 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
@@ -215,8 +215,8 @@ public class CatalogUtils {
             }
             if (log.isDebugEnabled()) { 
                 logDebugOrTraceIfRebinding(log, 
-                    "Registered {} bundles in {}",
-                    new Object[]{libraries.size(), Time.makeTimeStringRounded(timer)});
+                    "Registered {} bundle{} in {}",
+                    new Object[]{libraries.size(), Strings.s(libraries.size()), Time.makeTimeStringRounded(timer)});
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/277cb22a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
index 15430e5..f00b96f 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
@@ -129,52 +129,85 @@ class OsgiArchiveInstaller {
     }
     
     private synchronized void makeLocalZipFileFromInputStreamOrUrl() {
+        Maybe<Bundle> existingOsgiInstalledBundle = Maybe.absent();
+        Maybe<ManagedBundle> existingBrooklynInstalledBundle = Maybe.absent();
         if (zipIn==null) {
-            Maybe<Bundle> installedBundle = Maybe.absent();
             if (suppliedKnownBundleMetadata!=null) {
-                // if no input stream, look for a URL and/or a matching bundle
+                // if no input stream (zipIn), look for a URL and/or a matching bundle
                 if (!suppliedKnownBundleMetadata.isNameResolved()) {
-                    ManagedBundle mbFromUrl = osgiManager.getManagedBundleFromUrl(suppliedKnownBundleMetadata.getUrl());
-                    if (mbFromUrl!=null) {
+                    existingBrooklynInstalledBundle = Maybe.ofDisallowingNull(osgiManager.getManagedBundleFromUrl(suppliedKnownBundleMetadata.getUrl()));
+                    if (existingBrooklynInstalledBundle.isPresent()) {
                         // user supplied just a URL (eg brooklyn.libraries), but we recognise
it,
                         // so don't try to reload it, just record the info we know about
it to retrieve the bundle
-                        ((BasicManagedBundle)suppliedKnownBundleMetadata).setSymbolicName(mbFromUrl.getSymbolicName());
-                        ((BasicManagedBundle)suppliedKnownBundleMetadata).setVersion(mbFromUrl.getSuppliedVersionString());
+                        ((BasicManagedBundle)suppliedKnownBundleMetadata).setSymbolicName(existingBrooklynInstalledBundle.get().getSymbolicName());
+                        ((BasicManagedBundle)suppliedKnownBundleMetadata).setVersion(existingBrooklynInstalledBundle.get().getSuppliedVersionString());
                     }
                 }
-                if (installedBundle.isAbsent() && suppliedKnownBundleMetadata.getOsgiUniqueUrl()!=null)
{
-                    installedBundle = Osgis.bundleFinder(osgiManager.framework).requiringFromUrl(suppliedKnownBundleMetadata.getOsgiUniqueUrl()).find();
+                if (existingOsgiInstalledBundle.isAbsent() && suppliedKnownBundleMetadata.getOsgiUniqueUrl()!=null)
{
+                    existingOsgiInstalledBundle = Osgis.bundleFinder(osgiManager.framework).requiringFromUrl(suppliedKnownBundleMetadata.getOsgiUniqueUrl()).find();
                 }
-                if (installedBundle.isAbsent() && suppliedKnownBundleMetadata.getUrl()!=null)
{
-                    installedBundle = Osgis.bundleFinder(osgiManager.framework).requiringFromUrl(suppliedKnownBundleMetadata.getUrl()).find();
+                if (existingOsgiInstalledBundle.isAbsent() && suppliedKnownBundleMetadata.getUrl()!=null)
{
+                    existingOsgiInstalledBundle = Osgis.bundleFinder(osgiManager.framework).requiringFromUrl(suppliedKnownBundleMetadata.getUrl()).find();
                 }
-                if (installedBundle.isAbsent() && suppliedKnownBundleMetadata.isNameResolved())
{
-                    installedBundle = Osgis.bundleFinder(osgiManager.framework).symbolicName(suppliedKnownBundleMetadata.getSymbolicName()).version(suppliedKnownBundleMetadata.getSuppliedVersionString()).find();
+                if (existingOsgiInstalledBundle.isAbsent() && suppliedKnownBundleMetadata.isNameResolved())
{
+                    existingOsgiInstalledBundle = Osgis.bundleFinder(osgiManager.framework).symbolicName(suppliedKnownBundleMetadata.getSymbolicName()).version(suppliedKnownBundleMetadata.getSuppliedVersionString()).find();
                 }
-                if (suppliedKnownBundleMetadata.getUrl()!=null) {
-                    if (installedBundle.isAbsent() || force) {
-                        // reload 
-                        zipIn = ResourceUtils.create(mgmt()).getResourceFromUrl(suppliedKnownBundleMetadata.getUrl());
+                if (existingOsgiInstalledBundle.isPresent()) {
+                    if (existingBrooklynInstalledBundle.isAbsent()) {
+                        // try to find as brooklyn bundle based on knowledge of OSGi bundle
+                        existingBrooklynInstalledBundle = Maybe.ofDisallowingNull(osgiManager.getManagedBundle(new
VersionedName(existingOsgiInstalledBundle.get())));
                     }
-                }
-            }
-            
-            if (zipIn==null) {
-                if (installedBundle.isPresent()) {
-                    // no way to install (no url), or no need to install (not forced); just
ignore it
-                    result.metadata = osgiManager.getManagedBundle(new VersionedName(installedBundle.get()));
-                    if (result.metadata==null) {
-                        // low-level installed bundle
-                        result.metadata = new BasicManagedBundle(installedBundle.get().getSymbolicName(),
installedBundle.get().getVersion().toString(),
-                            suppliedKnownBundleMetadata!=null ? suppliedKnownBundleMetadata.getUrl()
: null);
+                    if (suppliedKnownBundleMetadata.getUrl()==null) { 
+                        // installer did not supply a usable URL, just coords
+                        // but bundle is installed at least to OSGi
+                        if (existingBrooklynInstalledBundle.isPresent()) {
+                            log.debug("Detected bundle "+suppliedKnownBundleMetadata+" installed
to Brooklyn already; no URL or stream supplied, so re-using existing installation");
+                            // if bundle is brooklyn-managed simply say "already installed"
+                            result.metadata = existingBrooklynInstalledBundle.get();
+                            result.setIgnoringAlreadyInstalled();
+                            return;
+                            
+                        } else {
+                            // if bundle is not brooklyn-managed we want to make it be so
+                            // and for that we need to find a URL.
+                            // some things declare usable locations, though these might be
maven and 
+                            String candidateUrl = existingOsgiInstalledBundle.get().getLocation();
+                            log.debug("Detected bundle "+suppliedKnownBundleMetadata+" installed
to OSGi but not Brooklyn; trying to find a URL to get bundle binary, candidate "+candidateUrl);
+                            if (Strings.isBlank(candidateUrl)) {
+                                throw new IllegalArgumentException("No input stream available
and no URL could be found: no way to promote "+suppliedKnownBundleMetadata+" from "+existingOsgiInstalledBundle.get()+"
to Brooklyn management");
+                            }
+                            try {
+                                // do this in special try block, not below, so we can give
a better error
+                                // (the user won't understnad the URL)
+                                zipIn = ResourceUtils.create(mgmt()).getResourceFromUrl(candidateUrl);
+                            } catch (Exception e) {
+                                Exceptions.propagateIfFatal(e);
+                                throw new IllegalArgumentException("Could not find binary
for already installed OSGi bundle "+existingOsgiInstalledBundle.get()+" (location "+candidateUrl+")
when trying to promote "+suppliedKnownBundleMetadata+" to Brooklyn management", e);
+                            }
+                        }
                     }
+                } else if (suppliedKnownBundleMetadata.getUrl()==null) {
+                    // not installed anywhere and no URL
+                    throw new IllegalArgumentException("No input stream available and no
URL could be found: no way to install "+suppliedKnownBundleMetadata);
+                }
+                
+                assert zipIn!=null || suppliedKnownBundleMetadata.getUrl()!=null : "should
have found a stream or inferred a URL";
+                
+                if (zipIn!=null) {
+                    // found input stream for existing osgi bundle
+                } else if (existingBrooklynInstalledBundle.isAbsent() || force) {
+                    // reload 
+                    zipIn = ResourceUtils.create(mgmt()).getResourceFromUrl(suppliedKnownBundleMetadata.getUrl());
+                } else {
+                    // already installed, not forced, just say already installed
+                    // (even if snapshot as this is a reference by URL, not uploaded content)

+                    result.metadata = existingBrooklynInstalledBundle.get();
                     result.setIgnoringAlreadyInstalled();
                     return;
                 }
-                result.metadata = suppliedKnownBundleMetadata;
-                throw new IllegalArgumentException("No input stream available and no URL
could be found; nothing to install");
             }
-            result.bundle = installedBundle.orNull();
+            
+            result.bundle = existingOsgiInstalledBundle.orNull();
         }
         
         zipFile = Os.newTempFile("brooklyn-bundle-transient-"+suppliedKnownBundleMetadata,
"zip");
@@ -372,7 +405,7 @@ class OsgiArchiveInstaller {
                 ((BasicManagedBundle)result.getMetadata()).setPersistenceNeeded(true);
                 mgmt().getRebindManager().getChangeListener().onChanged(result.getMetadata());
             }
-            log.debug(result.message + " (in osgi container)");
+            log.debug(result.message + " (partial): OSGi bundle installed, with bundle start
and Brooklyn management to follow");
             // can now delete and close (copy has been made and is available from OsgiManager)
             zipFile.delete();
             zipFile = null;
@@ -511,7 +544,7 @@ class OsgiArchiveInstaller {
                         log.debug(result.message+", all items: "+result.typesInstalled);
                     }
                 } else {
-                    log.debug(result.message+" (into Brooklyn), with no catalog items");
+                    log.debug(result.message+" (complete): bundle started and now managed
by Brooklyn, though no catalog items found (may have installed other bundles though)");
                 }
             }
 


Mime
View raw message