Github user geomacy commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/842#discussion_r140829916
--- Diff:
core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java
---
@@ -129,58 +133,115 @@ private synchronized void init() {
}
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 (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
--- End diff --
text ends just with `and` - did you mean to put something more?
---