You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2017/10/27 11:26:06 UTC
[1/9] brooklyn-server git commit: WIP - allow types from different
bundles if equivalent
Repository: brooklyn-server
Updated Branches:
refs/heads/master 9045005dd -> e73ee2912
WIP - allow types from different bundles if equivalent
previously this was only allowed if older bundle was a wrapper, or if it was forced;
this could cause problems if such a disallowed addition was forced and then you tried to rebind!
now it stores the bundle from which a registered type comes, so we can sensibly have several types.
we could even allow them to be different - which would of course cause chaos for users,
but if we allow multi-tenant catalogs it will be essential (we simply have to filter for visible
types when looking at the registry, and prevent bundle name collisions - eg by prefixing with tenant)
though for now we don't allow them to be different.
needs testing and test cases still
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/c380e6be
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/c380e6be
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/c380e6be
Branch: refs/heads/master
Commit: c380e6becf3100311620f569fd77b2f1facbc4a0
Parents: 05d6ee0
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Oct 24 17:38:43 2017 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Oct 24 17:38:43 2017 +0100
----------------------------------------------------------------------
.../core/mgmt/ha/OsgiArchiveInstaller.java | 1 +
.../core/typereg/BasicBrooklynTypeRegistry.java | 144 +++++++++++++------
.../core/typereg/BasicRegisteredType.java | 4 +-
3 files changed, 101 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c380e6be/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 f4c2a10..0351838 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
@@ -377,6 +377,7 @@ class OsgiArchiveInstaller {
}
}
if (canUpdate()) {
+
result.bundle = osgiManager.framework.getBundleContext().getBundle(result.getMetadata().getOsgiUniqueUrl());
if (result.getBundle()==null) {
log.warn("Brooklyn thought is was already managing bundle "+result.getMetadata().getVersionedName()+" but it's not installed to framework; reinstalling it");
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c380e6be/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
index 565e3f0..6c14ecf 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
@@ -20,8 +20,10 @@ package org.apache.brooklyn.core.typereg;
import java.util.Collection;
import java.util.Map;
+import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;
+import java.util.stream.Collectors;
import javax.annotation.Nullable;
@@ -37,8 +39,6 @@ import org.apache.brooklyn.api.typereg.RegisteredTypeLoadingContext;
import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
import org.apache.brooklyn.core.catalog.internal.CatalogItemBuilder;
import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
-import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
-import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.collections.MutableSet;
@@ -62,7 +62,7 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
private static final Logger log = LoggerFactory.getLogger(BasicBrooklynTypeRegistry.class);
private ManagementContext mgmt;
- private Map<String,RegisteredType> localRegisteredTypes = MutableMap.of();
+ private Map<String,Map<String,RegisteredType>> localRegisteredTypesAndContainingBundles = MutableMap.of();
public BasicBrooklynTypeRegistry(ManagementContext mgmt) {
this.mgmt = mgmt;
@@ -76,12 +76,14 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
private Iterable<RegisteredType> getAllWithoutCatalog(Predicate<? super RegisteredType> filter) {
// TODO thread safety
// TODO optimisation? make indexes and look up?
- return Iterables.filter(localRegisteredTypes.values(), filter);
+ return localRegisteredTypesAndContainingBundles.values().stream().
+ flatMap(m -> m.values().stream()).filter(filter::apply).collect(Collectors.toList());
}
private Maybe<RegisteredType> getExactWithoutLegacyCatalog(String symbolicName, String version, RegisteredTypeLoadingContext constraint) {
// TODO look in any nested/private registries
- RegisteredType item = localRegisteredTypes.get(symbolicName+":"+version);
+ Map<String, RegisteredType> m = localRegisteredTypesAndContainingBundles.get(symbolicName+":"+version);
+ RegisteredType item = m!=null && !m.isEmpty() ? m.values().iterator().next() : null;
return RegisteredTypes.tryValidate(item, constraint);
}
@@ -368,12 +370,51 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
if (!type.getId().equals(type.getSymbolicName()+":"+type.getVersion()))
Asserts.fail("Registered type "+type+" has ID / symname mismatch");
- RegisteredType oldType = mgmt.getTypeRegistry().get(type.getId());
- if (oldType==null || canForce || BrooklynVersionSyntax.isSnapshot(oldType.getVersion())) {
- log.debug("Inserting "+type+" into "+this);
- localRegisteredTypes.put(type.getId(), type);
- } else {
- assertSameEnoughToAllowReplacing(oldType, type);
+ Map<String, RegisteredType> knownMatchingTypesByBundles = localRegisteredTypesAndContainingBundles.get(type.getId());
+ if (knownMatchingTypesByBundles!=null && !knownMatchingTypesByBundles.isEmpty()) {
+ for (RegisteredType existingT: knownMatchingTypesByBundles.values()) {
+ String reasonForDetailedCheck = null;
+ if (Objects.equals(existingT.getContainingBundle(), type.getContainingBundle())) {
+ // they are in the same bundle; is force replacement allowed?
+ if (canForce) {
+ log.debug("Addition of "+type+" to replace "+existingT+" allowed because force is on");
+ continue;
+ }
+ if (BrooklynVersionSyntax.isSnapshot(type.getVersion())) {
+ if (existingT.getContainingBundle()!=null) {
+ if (BrooklynVersionSyntax.isSnapshot(VersionedName.fromString(existingT.getContainingBundle()).getVersionString())) {
+ log.debug("Addition of "+type+" to replace "+existingT+" allowed because both are snapshot");
+ continue;
+ } else {
+ reasonForDetailedCheck = "the containing bundle "+existingT.getContainingBundle()+" is not a SNAPSHOT and addition is not forced";
+ }
+ } else {
+ // can this occur?
+ reasonForDetailedCheck = "the containing bundle of the type is unknown (cannot confirm it is snapshot)";
+ }
+ } else {
+ reasonForDetailedCheck = "the type is not a SNAPSHOT and addition is not forced";
+ }
+ } else {
+ reasonForDetailedCheck = type.getId()+" is defined in different bundle";
+ }
+ assertSameEnoughToAllowReplacing(existingT, type, reasonForDetailedCheck);
+ }
+ }
+
+ log.debug("Inserting "+type+" into "+this);
+ Map<String, RegisteredType> m = localRegisteredTypesAndContainingBundles.get(type.getId());
+ if (m==null) {
+ synchronized (localRegisteredTypesAndContainingBundles) {
+ m = localRegisteredTypesAndContainingBundles.get(type.getId());
+ if (m==null) {
+ m = MutableMap.of();
+ localRegisteredTypesAndContainingBundles.put(type.getId(), m);
+ }
+ }
+ }
+ synchronized (m) {
+ m.put(type.getContainingBundle(), type);
}
}
@@ -384,7 +425,7 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
* This is needed when replacing an unresolved item with a resolved one or vice versa;
* the {@link RegisteredType#equals(Object)} check is too strict.
*/
- private boolean assertSameEnoughToAllowReplacing(RegisteredType oldType, RegisteredType type) {
+ private boolean assertSameEnoughToAllowReplacing(RegisteredType oldType, RegisteredType type, String reasonForDetailedCheck) {
/* The bundle checksum check prevents swapping a different bundle at the same name+version.
* For SNAPSHOT and forced-updates, this method doesn't apply, so we can assume here that
* either the bundle checksums are the same,
@@ -416,13 +457,13 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
if (!oldType.getVersionedName().equals(type.getVersionedName())) {
// different name - shouldn't even come here
- throw new IllegalStateException("Cannot add "+type+" to catalog; different "+oldType+" is already present");
+ throw new IllegalStateException("Cannot add "+type+" to catalog; different "+oldType+" is already present ("+reasonForDetailedCheck+")");
}
if (Objects.equals(oldType.getContainingBundle(), type.getContainingBundle())) {
// if named bundles equal then contents must be the same (due to bundle checksum); bail out early
if (!samePlan(oldType, type)) {
String msg = "Cannot add "+type+" to catalog; different plan in "+oldType+" from same bundle "+
- type.getContainingBundle()+" is already present";
+ type.getContainingBundle()+" is already present and "+reasonForDetailedCheck;
log.debug(msg+"\n"+
"Plan being added is:\n"+type.getPlan()+"\n"+
"Plan already present is:\n"+oldType.getPlan() );
@@ -430,7 +471,7 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
}
if (oldType.getKind()!=RegisteredTypeKind.UNRESOLVED && type.getKind()!=RegisteredTypeKind.UNRESOLVED &&
!Objects.equals(oldType.getKind(), type.getKind())) {
- throw new IllegalStateException("Cannot add "+type+" to catalog; different kind in "+oldType+" from same bundle is already present");
+ throw new IllegalStateException("Cannot add "+type+" to catalog; different kind in "+oldType+" from same bundle is already present and "+reasonForDetailedCheck);
}
return true;
}
@@ -438,8 +479,7 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
// different bundles, either anonymous or same item in two named bundles
if (!samePlan(oldType, type)) {
// if plan is different, fail
- String msg = "Cannot add "+type+" in "+type.getContainingBundle()+" to catalog; different plan in "+oldType+" from bundle "+
- oldType.getContainingBundle()+" is already present (throwing)";
+ String msg = "Cannot add "+type+" to catalog; it is different to "+oldType+", and "+reasonForDetailedCheck+" (throwing)";
log.debug(msg+"\n"+
"Plan being added from "+type.getContainingBundle()+" is:\n"+type.getPlan()+"\n"+
"Plan already present from "+oldType.getContainingBundle()+" is:\n"+oldType.getPlan() );
@@ -448,45 +488,31 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
if (oldType.getKind()!=RegisteredTypeKind.UNRESOLVED && type.getKind()!=RegisteredTypeKind.UNRESOLVED &&
!Objects.equals(oldType.getKind(), type.getKind())) {
// if kind is different and both resolved, fail
- throw new IllegalStateException("Cannot add "+type+" in "+type.getContainingBundle()+" to catalog; different kind in "+oldType+" from bundle "+
- oldType.getContainingBundle()+" is already present");
+ throw new IllegalStateException("Cannot add "+type+" to catalog; it is a different kind to "+oldType+", and "
+ + reasonForDetailedCheck);
}
- // now if old is a wrapper bundle (or old, no bundle), allow it -- metadata may be different here
- // but we'll allow that, probably the user is updating their catalog to the new format.
- // icons might change, maybe a few other things (but any such errors can be worked around),
- // and more useful to be able to upload the same BOM or replace an anonymous BOM with a named bundle.
- // crucially if old is a wrapper bundle the containing bundle won't actually be needed for anything,
- // so this is safe in terms of search paths etc.
- if (oldType.getContainingBundle()==null) {
- // if old type wasn't from a bundle, let it be replaced by a bundle
- return true;
- }
- // bundle is changing; was old bundle a wrapper?
- OsgiManager osgi = ((ManagementContextInternal)mgmt).getOsgiManager().orNull();
- if (osgi==null) {
- // shouldn't happen, as we got a containing bundle, but just in case
- return true;
- }
- if (BasicBrooklynCatalog.isNoBundleOrSimpleWrappingBundle(mgmt,
- osgi.getManagedBundle(VersionedName.fromString(oldType.getContainingBundle())))) {
- // old was a wrapper bundle; allow it
- return true;
- }
-
- throw new IllegalStateException("Cannot add "+type+" in "+type.getContainingBundle()+" to catalog; "
- + "item is already present in different bundle "+oldType.getContainingBundle());
+ // it is the same plan as a type in another bundle;
+ // previously we allowed only when the other bundle was a wrapper or no bundle
+ // (or it was forced - which was guaranteed to cause problems on rebind!);
+ // but now we always allow it, and we track which bundles things come from
+ return true;
}
private boolean samePlan(RegisteredType oldType, RegisteredType type) {
return RegisteredTypes.arePlansEquivalent(oldType, type);
}
+ /** removes registered type with the given ID from the local in-memory catalog
+ * (ignores bundle, deletes from all bundles if present in multiple;
+ * falls back to removing from legacy catalog if not known here in any bundles)
+ * @throws NoSuchElementException if not found */
@Beta // API stabilising
public void delete(VersionedName type) {
- RegisteredType registeredTypeRemoved = localRegisteredTypes.remove(type.toString());
- if (registeredTypeRemoved != null) {
- return ;
+ synchronized (localRegisteredTypesAndContainingBundles) {
+ if (localRegisteredTypesAndContainingBundles.remove(type.toString()) != null) {
+ return;
+ }
}
// legacy deletion (may call back to us, but max once)
@@ -498,10 +524,34 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
// throw new NoSuchElementException("No catalog item found with id "+type);
}
+ /** removes the given registered type in the noted bundle;
+ * if not known in that bundle tries deleting from legacy catalog.
+ * @throws NoSuchElementException if not found */
public void delete(RegisteredType type) {
- delete(type.getVersionedName());
+ Map<String, RegisteredType> m = localRegisteredTypesAndContainingBundles.get(type.getId());
+ if (m!=null) {
+ RegisteredType removedItem = m.remove(type.getContainingBundle());
+ if (m.isEmpty()) {
+ synchronized (localRegisteredTypesAndContainingBundles) {
+ m = localRegisteredTypesAndContainingBundles.get(type.getId());
+ if (m!=null && m.isEmpty()) {
+ localRegisteredTypesAndContainingBundles.remove(type.getId());
+ } else {
+ // either removed in parallel or no longer empty
+ }
+ }
+ if (removedItem==null) {
+ throw new NoSuchElementException("Requested to delete "+type+" from "+type.getContainingBundle()+", "
+ + "but that type was not known in that bundle, it is in "+m.keySet()+" instead");
+ }
+ }
+ } else {
+ // try legacy delete
+ delete(type.getVersionedName());
+ }
}
+ /** as {@link #delete(VersionedName)} */
@Beta // API stabilising
public void delete(String id) {
delete(VersionedName.fromString(id));
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c380e6be/core/src/main/java/org/apache/brooklyn/core/typereg/BasicRegisteredType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicRegisteredType.java b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicRegisteredType.java
index f76a9f4..8bb0908 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicRegisteredType.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicRegisteredType.java
@@ -30,6 +30,7 @@ import org.apache.brooklyn.util.collections.MutableSet;
import org.apache.brooklyn.util.core.config.ConfigBag;
import org.apache.brooklyn.util.javalang.JavaClassNames;
import org.apache.brooklyn.util.osgi.VersionedName;
+import org.apache.brooklyn.util.text.Strings;
import com.google.common.annotations.Beta;
import com.google.common.base.Objects;
@@ -155,9 +156,10 @@ public class BasicRegisteredType implements RegisteredType {
@Override
public String toString() {
return JavaClassNames.simpleClassName(this)+"["+getId()+
+ (Strings.isNonBlank(getContainingBundle()) ? ";"+getContainingBundle() : "")+
(isDisabled() ? ";DISABLED" : "")+
(isDeprecated() ? ";deprecated" : "")+
- (getPlan()!=null ? ";"+getPlan().getPlanFormat() : "")+
+ (getPlan()!=null && getPlan().getPlanFormat()!=null ? ";"+getPlan().getPlanFormat() : "")+
"]";
}
[5/9] brooklyn-server git commit: pass known version metadata in so
we get the user's version, not the osgified version
Posted by al...@apache.org.
pass known version metadata in so we get the user's version, not the osgified version
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/d1795856
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/d1795856
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/d1795856
Branch: refs/heads/master
Commit: d1795856f0776df6aace712dd5df613115f19b65
Parents: 7b45a56
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Wed Oct 25 17:07:23 2017 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Wed Oct 25 17:07:23 2017 +0100
----------------------------------------------------------------------
.../brooklyn/core/catalog/internal/BasicBrooklynCatalog.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d1795856/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
index 74ee09e..a79fec6 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
@@ -62,6 +62,7 @@ import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
import org.apache.brooklyn.core.mgmt.internal.CampYamlParser;
import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
import org.apache.brooklyn.core.typereg.BasicBrooklynTypeRegistry;
+import org.apache.brooklyn.core.typereg.BasicManagedBundle;
import org.apache.brooklyn.core.typereg.BasicRegisteredType;
import org.apache.brooklyn.core.typereg.BasicTypeImplementationPlan;
import org.apache.brooklyn.core.typereg.BrooklynTypePlanTransformer;
@@ -1502,7 +1503,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
OsgiBundleInstallationResult result = null;
try {
- result = osgiManager.get().install(null, new FileInputStream(bf), true, true, forceUpdate).get();
+ result = osgiManager.get().install(new BasicManagedBundle(vn.getSymbolicName(), vn.getVersionString(), null), new FileInputStream(bf), true, true, forceUpdate).get();
} catch (FileNotFoundException e) {
throw Exceptions.propagate(e);
} finally {
[8/9] brooklyn-server git commit: tidy OsgiManager passed in internal
code
Posted by al...@apache.org.
tidy OsgiManager passed in internal code
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/ed498fd0
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/ed498fd0
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/ed498fd0
Branch: refs/heads/master
Commit: ed498fd06db921c403be261172ee00de1ef6ae90
Parents: 081212f
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Oct 27 10:23:53 2017 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Oct 27 10:23:53 2017 +0100
----------------------------------------------------------------------
.../brooklyn/core/catalog/internal/BasicBrooklynCatalog.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ed498fd0/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
index a79fec6..810ffc1 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
@@ -1440,7 +1440,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
Maybe<OsgiManager> osgiManager = ((ManagementContextInternal)mgmt).getOsgiManager();
if (osgiManager.isPresent() && AUTO_WRAP_CATALOG_YAML_AS_BUNDLE) {
// wrap in a bundle to be managed; need to get bundle and version from yaml
- OsgiBundleInstallationResult result = addItemsOsgi(yaml, forceUpdate, osgiManager);
+ OsgiBundleInstallationResult result = addItemsOsgi(yaml, forceUpdate, osgiManager.get());
return toLegacyCatalogItems(result.getTypesInstalled());
// if all items pertaining to an older anonymous catalog.bom bundle have been overridden
@@ -1457,7 +1457,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
Maybe<OsgiManager> osgiManager = ((ManagementContextInternal)mgmt).getOsgiManager();
if (osgiManager.isPresent() && AUTO_WRAP_CATALOG_YAML_AS_BUNDLE) {
// wrap in a bundle to be managed; need to get bundle and version from yaml
- return addItemsOsgi(yaml, forceUpdate, osgiManager);
+ return addItemsOsgi(yaml, forceUpdate, osgiManager.get());
// if all items pertaining to an older anonymous catalog.bom bundle have been overridden
// we delete those later; see list of wrapper bundles kept in OsgiManager
@@ -1472,7 +1472,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
return result;
}
- protected OsgiBundleInstallationResult addItemsOsgi(String yaml, boolean forceUpdate, Maybe<OsgiManager> osgiManager) {
+ protected OsgiBundleInstallationResult addItemsOsgi(String yaml, boolean forceUpdate, OsgiManager osgiManager) {
Map<?, ?> cm = BasicBrooklynCatalog.getCatalogMetadata(yaml);
if(cm == null) {
@@ -1503,7 +1503,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
OsgiBundleInstallationResult result = null;
try {
- result = osgiManager.get().install(new BasicManagedBundle(vn.getSymbolicName(), vn.getVersionString(), null), new FileInputStream(bf), true, true, forceUpdate).get();
+ result = osgiManager.install(new BasicManagedBundle(vn.getSymbolicName(), vn.getVersionString(), null), new FileInputStream(bf), true, true, forceUpdate).get();
} catch (FileNotFoundException e) {
throw Exceptions.propagate(e);
} finally {
[2/9] brooklyn-server git commit: fix type registry access
synchronization and tweak minor load semantics
Posted by al...@apache.org.
fix type registry access synchronization and tweak minor load semantics
synchronization pointed out in PR, fixed.
also changed one bug, and it shares code with synch fixes so done here; the bug is:
until recently, if the same type were added from multiple bundles only the last one were kept.
on rebind the "last one added" might be different, so there was inconsistency.
previous commit means we keep all of them, and take the _first_ one added, and while
we could change it to have the same semantics (last one) it seems better to resolve
the rebind inconsistency, so now it takes from the "best" bundle, which is
the first alpha and preferring highest version.
use predictable resolution when multiple instances found
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/54dcb0c6
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/54dcb0c6
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/54dcb0c6
Branch: refs/heads/master
Commit: 54dcb0c641026039767a033f204bff4fd521f1d5
Parents: c380e6b
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Wed Oct 25 14:10:59 2017 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Wed Oct 25 14:10:59 2017 +0100
----------------------------------------------------------------------
.../CatalogOsgiVersionMoreEntityTest.java | 8 +-
.../catalog/internal/BasicBrooklynCatalog.java | 9 +-
.../core/typereg/BasicBrooklynTypeRegistry.java | 155 +++++++++++--------
.../brooklyn/util/osgi/VersionedName.java | 16 ++
.../brooklyn/util/osgi/VersionedNameTest.java | 28 ++++
5 files changed, 142 insertions(+), 74 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/54dcb0c6/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
index e1e4b55..241a658 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
@@ -151,8 +151,8 @@ public class CatalogOsgiVersionMoreEntityTest extends AbstractYamlTest implement
}
@Test
- /** TODO this test works if we assume most recent version wins, but semantics TBC */
- public void testMoreEntityV2ThenV1GivesV1() throws Exception {
+ /** Now assumes highest version wins regardless of install order */
+ public void testMoreEntityV1AndV2GivesV2() throws Exception {
TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), "/brooklyn/osgi/brooklyn-test-osgi-more-entities_0.1.0.jar");
TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), "/brooklyn/osgi/brooklyn-test-osgi-more-entities_0.2.0.jar");
TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), "/brooklyn/osgi/brooklyn-test-osgi-entities.jar");
@@ -163,8 +163,8 @@ public class CatalogOsgiVersionMoreEntityTest extends AbstractYamlTest implement
Entity app = createAndStartApplication("services: [ { type: 'more-entity:1.0' } ]");
Entity moreEntity = Iterables.getOnlyElement(app.getChildren());
- OsgiVersionMoreEntityTest.assertV1EffectorCall(moreEntity);
- OsgiVersionMoreEntityTest.assertV1MethodCall(moreEntity);
+ OsgiVersionMoreEntityTest.assertV2EffectorCall(moreEntity);
+ OsgiVersionMoreEntityTest.assertV2MethodCall(moreEntity);
}
/** unlike {@link #testMoreEntityV2ThenV1GivesV1()} this test should always work,
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/54dcb0c6/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
index 8dd361b..10880c0 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
@@ -950,8 +950,13 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
}
if (version==null) {
- // use this as default version when nothing specified
- version = BasicBrooklynCatalog.NO_VERSION;
+ if (containingBundle!=null) {
+ version = containingBundle.getVersionedName().getVersionString();
+ }
+ if (version==null) {
+ // use this as default version when nothing specified or inferrable from containing bundle
+ version = BasicBrooklynCatalog.NO_VERSION;
+ }
}
if (sourcePlanYaml==null) {
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/54dcb0c6/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
index 6c14ecf..7dc98fd 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
@@ -23,6 +23,8 @@ import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
@@ -42,9 +44,11 @@ import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.collections.MutableSet;
+import org.apache.brooklyn.util.concurrent.Locks;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.guava.Maybe;
import org.apache.brooklyn.util.osgi.VersionedName;
+import org.apache.brooklyn.util.osgi.VersionedName.VersionedNameStringComparator;
import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
import org.apache.brooklyn.util.text.Identifiers;
import org.apache.brooklyn.util.text.Strings;
@@ -56,6 +60,7 @@ import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
+import com.google.common.collect.Ordering;
public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
@@ -63,6 +68,16 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
private ManagementContext mgmt;
private Map<String,Map<String,RegisteredType>> localRegisteredTypesAndContainingBundles = MutableMap.of();
+ /**
+ * Thread synch model is pretty simple, as follows:
+ * - get a read lock on this if looking at localRegisteredTypesAndContainingBundles
+ * or any of the maps contained within;
+ * - get a write lock on this if changing the map above or any of the maps within.
+ *
+ * There is potential for finer grained locking to allow reads/writes of different inner
+ * maps but coordinating that is tricky and does not seem worth it.
+ */
+ private ReadWriteLock localRegistryLock = new ReentrantReadWriteLock();
public BasicBrooklynTypeRegistry(ManagementContext mgmt) {
this.mgmt = mgmt;
@@ -74,19 +89,26 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
}
private Iterable<RegisteredType> getAllWithoutCatalog(Predicate<? super RegisteredType> filter) {
- // TODO thread safety
// TODO optimisation? make indexes and look up?
- return localRegisteredTypesAndContainingBundles.values().stream().
- flatMap(m -> m.values().stream()).filter(filter::apply).collect(Collectors.toList());
+ return Locks.withLock(localRegistryLock.readLock(),
+ () -> localRegisteredTypesAndContainingBundles.values().stream().
+ flatMap(m -> m.values().stream()).filter(filter::apply).collect(Collectors.toList()) );
}
private Maybe<RegisteredType> getExactWithoutLegacyCatalog(String symbolicName, String version, RegisteredTypeLoadingContext constraint) {
- // TODO look in any nested/private registries
- Map<String, RegisteredType> m = localRegisteredTypesAndContainingBundles.get(symbolicName+":"+version);
- RegisteredType item = m!=null && !m.isEmpty() ? m.values().iterator().next() : null;
+ RegisteredType item = Locks.withLock(localRegistryLock.readLock(),
+ ()-> getBestValue(localRegisteredTypesAndContainingBundles.get(symbolicName+":"+version)) );
return RegisteredTypes.tryValidate(item, constraint);
}
+ private RegisteredType getBestValue(Map<String, RegisteredType> m) {
+ if (m==null) return null;
+ if (m.isEmpty()) return null;
+ if (m.size()==1) return m.values().iterator().next();
+ // get the highest version of first alphabetical - to have a canonical order
+ return m.get( Ordering.from(VersionedNameStringComparator.INSTANCE).max(m.keySet()) );
+ }
+
@SuppressWarnings("deprecation")
@Override
public Iterable<RegisteredType> getMatching(Predicate<? super RegisteredType> filter) {
@@ -370,52 +392,46 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
if (!type.getId().equals(type.getSymbolicName()+":"+type.getVersion()))
Asserts.fail("Registered type "+type+" has ID / symname mismatch");
- Map<String, RegisteredType> knownMatchingTypesByBundles = localRegisteredTypesAndContainingBundles.get(type.getId());
- if (knownMatchingTypesByBundles!=null && !knownMatchingTypesByBundles.isEmpty()) {
- for (RegisteredType existingT: knownMatchingTypesByBundles.values()) {
- String reasonForDetailedCheck = null;
- if (Objects.equals(existingT.getContainingBundle(), type.getContainingBundle())) {
- // they are in the same bundle; is force replacement allowed?
- if (canForce) {
- log.debug("Addition of "+type+" to replace "+existingT+" allowed because force is on");
- continue;
- }
- if (BrooklynVersionSyntax.isSnapshot(type.getVersion())) {
- if (existingT.getContainingBundle()!=null) {
- if (BrooklynVersionSyntax.isSnapshot(VersionedName.fromString(existingT.getContainingBundle()).getVersionString())) {
- log.debug("Addition of "+type+" to replace "+existingT+" allowed because both are snapshot");
- continue;
+ Locks.withLock(localRegistryLock.writeLock(),
+ () -> {
+ Map<String, RegisteredType> knownMatchingTypesByBundles = localRegisteredTypesAndContainingBundles.get(type.getId());
+ if (knownMatchingTypesByBundles==null) {
+ knownMatchingTypesByBundles = MutableMap.of();
+ localRegisteredTypesAndContainingBundles.put(type.getId(), knownMatchingTypesByBundles);
+ }
+
+ for (RegisteredType existingT: knownMatchingTypesByBundles.values()) {
+ String reasonForDetailedCheck = null;
+ if (Objects.equals(existingT.getContainingBundle(), type.getContainingBundle())) {
+ // they are in the same bundle; is force replacement allowed?
+ if (canForce) {
+ log.debug("Addition of "+type+" to replace "+existingT+" allowed because force is on");
+ continue;
+ }
+ if (BrooklynVersionSyntax.isSnapshot(type.getVersion())) {
+ if (existingT.getContainingBundle()!=null) {
+ if (BrooklynVersionSyntax.isSnapshot(VersionedName.fromString(existingT.getContainingBundle()).getVersionString())) {
+ log.debug("Addition of "+type+" to replace "+existingT+" allowed because both are snapshot");
+ continue;
+ } else {
+ reasonForDetailedCheck = "the containing bundle "+existingT.getContainingBundle()+" is not a SNAPSHOT and addition is not forced";
+ }
} else {
- reasonForDetailedCheck = "the containing bundle "+existingT.getContainingBundle()+" is not a SNAPSHOT and addition is not forced";
+ // can this occur?
+ reasonForDetailedCheck = "the containing bundle of the type is unknown (cannot confirm it is snapshot)";
}
} else {
- // can this occur?
- reasonForDetailedCheck = "the containing bundle of the type is unknown (cannot confirm it is snapshot)";
+ reasonForDetailedCheck = "the type is not a SNAPSHOT and addition is not forced";
}
} else {
- reasonForDetailedCheck = "the type is not a SNAPSHOT and addition is not forced";
+ reasonForDetailedCheck = type.getId()+" is defined in different bundle";
}
- } else {
- reasonForDetailedCheck = type.getId()+" is defined in different bundle";
+ assertSameEnoughToAllowReplacing(existingT, type, reasonForDetailedCheck);
}
- assertSameEnoughToAllowReplacing(existingT, type, reasonForDetailedCheck);
- }
- }
-
- log.debug("Inserting "+type+" into "+this);
- Map<String, RegisteredType> m = localRegisteredTypesAndContainingBundles.get(type.getId());
- if (m==null) {
- synchronized (localRegisteredTypesAndContainingBundles) {
- m = localRegisteredTypesAndContainingBundles.get(type.getId());
- if (m==null) {
- m = MutableMap.of();
- localRegisteredTypesAndContainingBundles.put(type.getId(), m);
- }
- }
- }
- synchronized (m) {
- m.put(type.getContainingBundle(), type);
- }
+
+ log.debug("Inserting "+type+" into "+this);
+ knownMatchingTypesByBundles.put(type.getContainingBundle(), type);
+ });
}
/**
@@ -509,46 +525,49 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
* @throws NoSuchElementException if not found */
@Beta // API stabilising
public void delete(VersionedName type) {
- synchronized (localRegisteredTypesAndContainingBundles) {
- if (localRegisteredTypesAndContainingBundles.remove(type.toString()) != null) {
- return;
- }
+ boolean changedLocally = Locks.withLock(localRegistryLock.writeLock(),
+ () -> (localRegisteredTypesAndContainingBundles.remove(type.toString()) != null));
+ if (changedLocally) {
+ return;
}
-
- // legacy deletion (may call back to us, but max once)
- mgmt.getCatalog().deleteCatalogItem(type.getSymbolicName(), type.getVersionString());
- // currently the above will succeed or throw; but if we delete that, we need to enable the code below
+ legacyDelete(type);
+ }
+
+ @SuppressWarnings("deprecation")
+ private void legacyDelete(VersionedName type) {
+ // when we delete this, we should simply do the following (as contract is to throw if can't delete)
// if (Strings.isBlank(type.getVersionString()) || BrooklynCatalog.DEFAULT_VERSION.equals(type.getVersionString())) {
// throw new IllegalStateException("Deleting items with unspecified version (argument DEFAULT_VERSION) not supported.");
// }
// throw new NoSuchElementException("No catalog item found with id "+type);
+
+ // NB the call below may call back to us, but max once)
+ mgmt.getCatalog().deleteCatalogItem(type.getSymbolicName(), type.getVersionString());
}
/** removes the given registered type in the noted bundle;
* if not known in that bundle tries deleting from legacy catalog.
* @throws NoSuchElementException if not found */
public void delete(RegisteredType type) {
- Map<String, RegisteredType> m = localRegisteredTypesAndContainingBundles.get(type.getId());
- if (m!=null) {
- RegisteredType removedItem = m.remove(type.getContainingBundle());
- if (m.isEmpty()) {
- synchronized (localRegisteredTypesAndContainingBundles) {
- m = localRegisteredTypesAndContainingBundles.get(type.getId());
- if (m!=null && m.isEmpty()) {
- localRegisteredTypesAndContainingBundles.remove(type.getId());
- } else {
- // either removed in parallel or no longer empty
- }
+ boolean changedLocally = Locks.withLock(localRegistryLock.writeLock(),
+ () -> {
+ Map<String, RegisteredType> m = localRegisteredTypesAndContainingBundles.get(type.getId());
+ if (m==null) return false;
+ RegisteredType removedItem = m.remove(type.getContainingBundle());
+ if (m.isEmpty()) {
+ localRegisteredTypesAndContainingBundles.remove(type.getId());
}
if (removedItem==null) {
throw new NoSuchElementException("Requested to delete "+type+" from "+type.getContainingBundle()+", "
+ "but that type was not known in that bundle, it is in "+m.keySet()+" instead");
}
- }
- } else {
- // try legacy delete
- delete(type.getVersionedName());
+ return true;
+ });
+ if (changedLocally) {
+ return;
}
+
+ legacyDelete(type.getVersionedName());
}
/** as {@link #delete(VersionedName)} */
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/54dcb0c6/utils/common/src/main/java/org/apache/brooklyn/util/osgi/VersionedName.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/osgi/VersionedName.java b/utils/common/src/main/java/org/apache/brooklyn/util/osgi/VersionedName.java
index 3b8bb0e..5114117 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/osgi/VersionedName.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/osgi/VersionedName.java
@@ -182,11 +182,14 @@ public class VersionedName implements Comparable<VersionedName> {
return VersionedNameComparator.INSTANCE.compare(this, other);
}
+ /** Comparator which puts a:3 < a:1 < b:2 < null */
public static class VersionedNameComparator implements Comparator<VersionedName> {
public static final VersionedNameComparator INSTANCE = new VersionedNameComparator();
@Override
public int compare(VersionedName o1, VersionedName o2) {
+ if (o1==null) { return o2==null ? 0 : 1; }
+ if (o2==null) { return -1; }
return ComparisonChain.start()
.compare(o1.getSymbolicName(), o2.getSymbolicName(), NaturalOrderComparator.INSTANCE)
.compare(o2.getOsgiVersionString(), o1.getOsgiVersionString(), VersionComparator.INSTANCE)
@@ -194,4 +197,17 @@ public class VersionedName implements Comparable<VersionedName> {
.result();
}
}
+
+ // RegisteredTypeNameThenWorstFirstComparator
+
+ /** Comparator which puts a:3 < a:1 < b:2 < null */
+ public static class VersionedNameStringComparator implements Comparator<String> {
+ public static final VersionedNameStringComparator INSTANCE = new VersionedNameStringComparator();
+
+ @Override
+ public int compare(String s1, String s2) {
+ return VersionedNameComparator.INSTANCE.compare(parseMaybe(s1, false).orNull(), parseMaybe(s2, false).orNull());
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/54dcb0c6/utils/common/src/test/java/org/apache/brooklyn/util/osgi/VersionedNameTest.java
----------------------------------------------------------------------
diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/osgi/VersionedNameTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/osgi/VersionedNameTest.java
index e3fe95c..6cc4e10 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/osgi/VersionedNameTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/osgi/VersionedNameTest.java
@@ -18,8 +18,12 @@ package org.apache.brooklyn.util.osgi;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
+import java.util.Comparator;
+
import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.util.javalang.coerce.TypeCoercerExtensible;
+import org.apache.brooklyn.util.osgi.VersionedName.VersionedNameComparator;
+import org.apache.brooklyn.util.osgi.VersionedName.VersionedNameStringComparator;
import org.osgi.framework.Version;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -59,5 +63,29 @@ public class VersionedNameTest {
assertFalse(VersionedName.parseMaybe("a.b:0.1.2:3.4.5", false).isPresent());
assertFalse(VersionedName.parseMaybe("", false).isPresent());
}
+
+ @Test
+ public void testOrder() {
+ assertOrder(VersionedNameComparator.INSTANCE,
+ VersionedName.fromString("a:3"), VersionedName.fromString("a:1"),
+ VersionedName.fromString("a:0"), VersionedName.fromString("a:1-SNAPSHOT"), VersionedName.fromString("a"),
+ VersionedName.fromString("b:2"), null);
+ }
+
+ @Test
+ public void testStringOrder() {
+ assertOrder(VersionedNameStringComparator.INSTANCE,
+ "a:3", "a:1", "a:0", "a:1-SNAPSHOT", "a",
+ "b:2", null);
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> void assertOrder(Comparator<T> comparator, T ...items) {
+ for (int i=0; i<items.length; i++) {
+ for (int j=0; j<items.length; j++) {
+ Assert.assertEquals(comparator.compare(items[i], items[j]), Integer.compare(i, j));
+ }
+ }
+ }
}
[7/9] brooklyn-server git commit: duplicate types in different
bundles should be returned by `getAll()`
Posted by al...@apache.org.
duplicate types in different bundles should be returned by `getAll()`
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/081212f9
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/081212f9
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/081212f9
Branch: refs/heads/master
Commit: 081212f9377eba37531166e8ef3ecda0c0a0e753
Parents: 856c1c9
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu Oct 26 01:23:34 2017 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu Oct 26 01:23:34 2017 +0100
----------------------------------------------------------------------
.../core/typereg/BasicBrooklynTypeRegistry.java | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/081212f9/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
index 663e6a5..46d3400 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
@@ -115,14 +115,17 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
@SuppressWarnings("deprecation")
@Override
public Iterable<RegisteredType> getMatching(Predicate<? super RegisteredType> filter) {
- Map<String,RegisteredType> result = MutableMap.of();
+ Set<RegisteredType> result = MutableSet.of();
+ // keep name record also so we can remove legacy items that are superseded
+ Set<String> typeNamesFound = MutableSet.of();
for (RegisteredType rt: getAllWithoutCatalog(filter)) {
- result.put(rt.getId(), rt);
+ result.add(rt);
+ typeNamesFound.add(rt.getId());
}
for (RegisteredType rt: Iterables.filter(
Iterables.transform(mgmt.getCatalog().getCatalogItemsLegacy(), RegisteredTypes.CI_TO_RT),
filter)) {
- if (!result.containsKey(rt.getId())) {
+ if (!typeNamesFound.contains(rt.getId())) {
// TODO ideally never come here, however
// legacy cataog currently still used for java-scanned annotations;
// hopefully that will be deprecated and removed in near future
@@ -131,10 +134,11 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
// make TypeRegistry instances instead of CatalogItem, esp if we had YOML to write that plan)
//log.warn("Item '"+rt.getId()+"' not in type registry; only found in legacy catalog");
- result.put(rt.getId(), rt);
+ typeNamesFound.add(rt.getId());
+ result.add(rt);
}
}
- return result.values();
+ return result;
}
@SuppressWarnings("deprecation")
[4/9] brooklyn-server git commit: fix inconsistency when type
definitions come from anonymous BOMs vs named-bundles
Posted by al...@apache.org.
fix inconsistency when type definitions come from anonymous BOMs vs named-bundles
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/7b45a567
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/7b45a567
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/7b45a567
Branch: refs/heads/master
Commit: 7b45a56704f24df72a45c0915ac5d2a5f9d41aae
Parents: 0801cb1
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Wed Oct 25 16:59:40 2017 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Wed Oct 25 16:59:40 2017 +0100
----------------------------------------------------------------------
.../brooklyn/core/typereg/BasicBrooklynTypeRegistry.java | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7b45a567/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
index a5e781b..663e6a5 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
@@ -404,11 +404,12 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
}
Set<String> oldContainingBundlesToRemove = MutableSet.of();
+ boolean newIsWrapperBundle = isWrapperBundle(type.getContainingBundle());
for (RegisteredType existingT: knownMatchingTypesByBundles.values()) {
String reasonForDetailedCheck = null;
boolean sameBundle = Objects.equals(existingT.getContainingBundle(), type.getContainingBundle());
boolean oldIsWrapperBundle = isWrapperBundle(existingT.getContainingBundle());
- if (sameBundle || oldIsWrapperBundle) {
+ if (sameBundle || (oldIsWrapperBundle && newIsWrapperBundle)) {
// allow replacement (different plan for same type) if either
// it's the same bundle or the old one was a wrapper, AND
// either we're forced or in snapshot-land
@@ -435,6 +436,10 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
} else {
reasonForDetailedCheck = "the type is not a SNAPSHOT and addition is not forced";
}
+ } else if (oldIsWrapperBundle) {
+ reasonForDetailedCheck = type.getId()+" is in a named bundle replacing an item from an anonymous bundle-wrapped BOM, so definitions must be the same (or else give it a different version)";
+ } else if (newIsWrapperBundle) {
+ reasonForDetailedCheck = type.getId()+" is in an anonymous bundle-wrapped BOM replacing an item from a named bundle, so definitions must be the same (or else give it a different version)";
} else {
reasonForDetailedCheck = type.getId()+" is defined in different bundle";
}
[9/9] brooklyn-server git commit: This closes #868
Posted by al...@apache.org.
This closes #868
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/e73ee291
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/e73ee291
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/e73ee291
Branch: refs/heads/master
Commit: e73ee291203aec7b9212731c9e2ee9c25b512069
Parents: 9045005 ed498fd
Author: Aled Sage <al...@gmail.com>
Authored: Fri Oct 27 12:25:54 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri Oct 27 12:25:54 2017 +0100
----------------------------------------------------------------------
.../CatalogOsgiVersionMoreEntityTest.java | 8 +-
.../catalog/internal/BasicBrooklynCatalog.java | 25 ++-
.../catalog/internal/CatalogBundleLoader.java | 9 +-
.../core/mgmt/ha/OsgiArchiveInstaller.java | 1 +
.../core/typereg/BasicBrooklynTypeRegistry.java | 221 ++++++++++++++-----
.../core/typereg/BasicRegisteredType.java | 4 +-
.../brooklyn/util/osgi/VersionedName.java | 16 ++
.../brooklyn/util/osgi/VersionedNameTest.java | 28 +++
8 files changed, 240 insertions(+), 72 deletions(-)
----------------------------------------------------------------------
[3/9] brooklyn-server git commit: weaken the "types being replaced
must come from the same bundle" to support anonymous bundles
Posted by al...@apache.org.
weaken the "types being replaced must come from the same bundle" to support anonymous bundles
this is when user uploads a catalog.bom without any bundle identification.
if they do it again, and the things are snapshot, they should be allowed to replace,
even though bundle names are different.
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/0801cb1e
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/0801cb1e
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/0801cb1e
Branch: refs/heads/master
Commit: 0801cb1e07bf6535a492dff783b8fc767de2ed15
Parents: 54dcb0c
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Wed Oct 25 16:27:46 2017 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Wed Oct 25 16:27:46 2017 +0100
----------------------------------------------------------------------
.../catalog/internal/BasicBrooklynCatalog.java | 7 +++-
.../core/typereg/BasicBrooklynTypeRegistry.java | 35 ++++++++++++++++++--
2 files changed, 38 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/0801cb1e/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
index 10880c0..74ee09e 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
@@ -1041,7 +1041,12 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
// (originally seen during a race where the empty-remover ran while we were installing)
throw new IllegalStateException("Loading from a bundle which is not installed");
}
- String wrapped = bb.get().getHeaders().get(BROOKLYN_WRAPPED_BOM_BUNDLE);
+ return isWrapperBundle(bb.get());
+ }
+
+ @Beta
+ public static boolean isWrapperBundle(Bundle b) {
+ String wrapped = b.getHeaders().get(BROOKLYN_WRAPPED_BOM_BUNDLE);
return wrapped!=null && wrapped.equalsIgnoreCase("true");
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/0801cb1e/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
index 7dc98fd..a5e781b 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
@@ -41,6 +41,8 @@ import org.apache.brooklyn.api.typereg.RegisteredTypeLoadingContext;
import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
import org.apache.brooklyn.core.catalog.internal.CatalogItemBuilder;
import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
+import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
+import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.collections.MutableSet;
@@ -52,6 +54,7 @@ import org.apache.brooklyn.util.osgi.VersionedName.VersionedNameStringComparator
import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
import org.apache.brooklyn.util.text.Identifiers;
import org.apache.brooklyn.util.text.Strings;
+import org.osgi.framework.Bundle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -400,10 +403,19 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
localRegisteredTypesAndContainingBundles.put(type.getId(), knownMatchingTypesByBundles);
}
+ Set<String> oldContainingBundlesToRemove = MutableSet.of();
for (RegisteredType existingT: knownMatchingTypesByBundles.values()) {
String reasonForDetailedCheck = null;
- if (Objects.equals(existingT.getContainingBundle(), type.getContainingBundle())) {
- // they are in the same bundle; is force replacement allowed?
+ boolean sameBundle = Objects.equals(existingT.getContainingBundle(), type.getContainingBundle());
+ boolean oldIsWrapperBundle = isWrapperBundle(existingT.getContainingBundle());
+ if (sameBundle || oldIsWrapperBundle) {
+ // allow replacement (different plan for same type) if either
+ // it's the same bundle or the old one was a wrapper, AND
+ // either we're forced or in snapshot-land
+ if (!sameBundle) {
+ // if old is wrapper bundle, we have to to remove the old record
+ oldContainingBundlesToRemove.add(existingT.getContainingBundle());
+ }
if (canForce) {
log.debug("Addition of "+type+" to replace "+existingT+" allowed because force is on");
continue;
@@ -429,11 +441,28 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
assertSameEnoughToAllowReplacing(existingT, type, reasonForDetailedCheck);
}
- log.debug("Inserting "+type+" into "+this);
+ log.debug("Inserting "+type+" into "+this+
+ (oldContainingBundlesToRemove.isEmpty() ? "" : " (removing entry from "+oldContainingBundlesToRemove+")"));
+ for (String oldContainingBundle: oldContainingBundlesToRemove) {
+ knownMatchingTypesByBundles.remove(oldContainingBundle);
+ }
knownMatchingTypesByBundles.put(type.getContainingBundle(), type);
});
}
+ private boolean isWrapperBundle(String bundleNameVersion) {
+ if (bundleNameVersion==null) return true;
+ Maybe<OsgiManager> osgi = ((ManagementContextInternal)mgmt).getOsgiManager();
+ // if not osgi, everything is treated as a wrapper bundle
+ if (osgi.isAbsent()) return true;
+ VersionedName vn = VersionedName.fromString(bundleNameVersion);
+ Maybe<Bundle> b = osgi.get().findBundle(new BasicOsgiBundleWithUrl(vn.getSymbolicName(), vn.getOsgiVersionString(), null));
+ // if bundle not found it is an error or a race; we don't fail, but we shouldn't treat it as a wrapper
+ if (b.isAbsent()) return false;
+
+ return BasicBrooklynCatalog.isWrapperBundle(b.get());
+ }
+
/**
* Allow replacing even of non-SNAPSHOT versions if plans are "similar enough";
* ie, forgiving some metadata changes.
[6/9] brooklyn-server git commit: fix discrepancy message
Posted by al...@apache.org.
fix discrepancy message
just compare names. the "kind" can switch from "unresolved" but the result won't be updated.
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/856c1c96
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/856c1c96
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/856c1c96
Branch: refs/heads/master
Commit: 856c1c96663f32e6b799f6b187ed3cfda511c10c
Parents: d179585
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Wed Oct 25 17:29:07 2017 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Wed Oct 25 17:29:07 2017 +0100
----------------------------------------------------------------------
.../brooklyn/core/catalog/internal/CatalogBundleLoader.java | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/856c1c96/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleLoader.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleLoader.java
index be9abba..c57808c 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleLoader.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleLoader.java
@@ -25,6 +25,7 @@ import java.net.URL;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
import org.apache.brooklyn.api.catalog.CatalogItem;
import org.apache.brooklyn.api.mgmt.ManagementContext;
@@ -103,11 +104,13 @@ public class CatalogBundleLoader {
this.managementContext.getCatalog().addTypesFromBundleBom(bomText, mb, force, result.mapOfNewToReplaced);
if (validate) {
Set<RegisteredType> matches = MutableSet.copyOf(this.managementContext.getTypeRegistry().getMatching(RegisteredTypePredicates.containingBundle(mb.getVersionedName())));
- if (!(matches.containsAll(result.mapOfNewToReplaced.keySet()) && result.mapOfNewToReplaced.keySet().containsAll(matches))) {
+ Set<String> resultNames = result.mapOfNewToReplaced.keySet().stream().map((type) -> type.getId()).collect(Collectors.toSet());
+ Set<String> matchesNames = matches.stream().map((type) -> type.getId()).collect(Collectors.toSet());
+ if (!(matchesNames.containsAll(resultNames) && resultNames.containsAll(matchesNames))) {
// sanity check
LOG.warn("Discrepancy in list of Brooklyn items found for "+mb.getVersionedName()+": "+
- "installer said "+result.mapOfNewToReplaced.keySet()+" ("+result.mapOfNewToReplaced.keySet().size()+") "+
- "but registry search found "+matches+" ("+matches.size()+")");
+ "installer gave "+result+" (of "+result.mapOfNewToReplaced.keySet().size()+" total installed), "+
+ "but registry search gave "+matches+" (from "+matches.size()+" total found for this bundle)");
}
Map<RegisteredType, Collection<Throwable>> validationErrors = this.managementContext.getCatalog().validateTypes( matches );
if (!validationErrors.isEmpty()) {