brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [07/12] incubator-brooklyn git commit: clean-up of type registry work following PR comments; all addressed apart from weird validate semantics
Date Mon, 21 Dec 2015 12:10:57 GMT
clean-up of type registry work following PR comments; all addressed apart from weird validate
semantics


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/48bb7985
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/48bb7985
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/48bb7985

Branch: refs/heads/master
Commit: 48bb79857ce0f841017d5d4721bfd510e902d7f1
Parents: 420ea30
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Thu Dec 10 14:17:31 2015 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Thu Dec 17 13:22:51 2015 +0000

----------------------------------------------------------------------
 .../api/typereg/BrooklynTypeRegistry.java       |  2 +-
 .../core/catalog/internal/CatalogUtils.java     |  8 ++--
 .../core/location/BasicLocationRegistry.java    |  2 +-
 .../typereg/AbstractTypePlanTransformer.java    |  2 +-
 .../core/typereg/BasicBrooklynTypeRegistry.java | 26 ++++++++-----
 .../core/typereg/RegisteredTypePredicates.java  | 22 +++++------
 .../brooklyn/core/typereg/RegisteredTypes.java  | 40 ++++++++++++--------
 .../typereg/BasicBrooklynTypeRegistryTest.java  | 18 ++++-----
 .../BrooklynEntityDecorationResolver.java       |  7 ++--
 .../catalog/CatalogYamlLocationTest.java        |  4 +-
 .../catalog/CatalogYamlVersioningTest.java      | 14 +++----
 .../brooklyn/test/lite/CampYamlLiteTest.java    |  4 +-
 .../rest/resources/ApplicationResource.java     |  2 +-
 .../rest/resources/CatalogResource.java         |  4 +-
 14 files changed, 88 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/48bb7985/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java b/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java
index eb59d27..17a7fb3 100644
--- a/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java
+++ b/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java
@@ -42,7 +42,7 @@ public interface BrooklynTypeRegistry {
     }
     
     Iterable<RegisteredType> getAll();
-    Iterable<RegisteredType> getAll(Predicate<? super RegisteredType> filter);
+    Iterable<RegisteredType> getMatching(Predicate<? super RegisteredType> filter);
 
     /** @return The item matching the given given 
      * {@link RegisteredType#getSymbolicName() symbolicName} 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/48bb7985/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 078e1d7..fbf34f7 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
@@ -86,12 +86,12 @@ public class CatalogUtils {
         ManagementContext mgmt = ((EntityInternal)entity).getManagementContext();
         String catId = entity.getCatalogItemId();
         if (Strings.isBlank(catId)) return JavaBrooklynClassLoadingContext.create(mgmt);
-        RegisteredType cat = RegisteredTypes.validate(mgmt.getTypeRegistry().get(catId),
RegisteredTypeLoadingContexts.spec(Entity.class)).get();
-        if (cat==null) {
+        Maybe<RegisteredType> cat = RegisteredTypes.tryValidate(mgmt.getTypeRegistry().get(catId),
RegisteredTypeLoadingContexts.spec(Entity.class));
+        if (cat.get()==null) {
             log.warn("Cannot load "+catId+" to get classloader for "+entity+"; will try with
standard loader, but might fail subsequently");
             return JavaBrooklynClassLoadingContext.create(mgmt);
         }
-        return newClassLoadingContext(mgmt, cat);
+        return newClassLoadingContext(mgmt, cat.get());
     }
 
     public static BrooklynClassLoadingContext newClassLoadingContext(@Nullable ManagementContext
mgmt, String catalogItemId, Collection<? extends OsgiBundleWithUrl> libraries) {
@@ -268,7 +268,7 @@ public class CatalogUtils {
     }
 
     public static boolean isBestVersion(ManagementContext mgmt, CatalogItem<?,?> item)
{
-        RegisteredType best = RegisteredTypes.getBestVersion(mgmt.getTypeRegistry().getAll(
+        RegisteredType best = RegisteredTypes.getBestVersion(mgmt.getTypeRegistry().getMatching(
             RegisteredTypePredicates.symbolicName(item.getSymbolicName())));
         if (best==null) return false;
         return (best.getVersion().equals(item.getVersion()));

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/48bb7985/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
b/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
index 202ecf4..b8452f3 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
@@ -288,7 +288,7 @@ public class BasicLocationRegistry implements LocationRegistry {
                 definedLocations.putAll(oldDefined);
             }
             
-            for (RegisteredType item: mgmt.getTypeRegistry().getAll(RegisteredTypePredicates.IS_LOCATION))
{
+            for (RegisteredType item: mgmt.getTypeRegistry().getMatching(RegisteredTypePredicates.IS_LOCATION))
{
                 updateDefinedLocation(item);
                 count++;
             }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/48bb7985/core/src/main/java/org/apache/brooklyn/core/typereg/AbstractTypePlanTransformer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/AbstractTypePlanTransformer.java
b/core/src/main/java/org/apache/brooklyn/core/typereg/AbstractTypePlanTransformer.java
index 283b7da..7b91529 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/AbstractTypePlanTransformer.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/AbstractTypePlanTransformer.java
@@ -128,7 +128,7 @@ public abstract class AbstractTypePlanTransformer implements BrooklynTypePlanTra
     protected <T> T validate(T createdObject, RegisteredType type, RegisteredTypeLoadingContext
constraint) {
         if (createdObject==null) return null;
         try {
-            return RegisteredTypes.validate(createdObject, type, constraint).get();
+            return RegisteredTypes.tryValidate(createdObject, type, constraint).get();
         } catch (Exception e) {
             Exceptions.propagateIfFatal(e);
             throw new IllegalStateException("Created incompatible object: "+Exceptions.collapseText(e),
e);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/48bb7985/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 a642861..496c028 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
@@ -62,7 +62,7 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry {
     }
     
     public Iterable<RegisteredType> getAll() {
-        return getAll(Predicates.alwaysTrue());
+        return getMatching(Predicates.alwaysTrue());
     }
     
     private Iterable<RegisteredType> getAllWithoutCatalog(Predicate<? super RegisteredType>
filter) {
@@ -74,12 +74,12 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry
{
     private RegisteredType getExactWithoutLegacyCatalog(String symbolicName, String version,
RegisteredTypeLoadingContext constraint) {
         // TODO look in any nested/private registries
         RegisteredType item = localRegisteredTypes.get(symbolicName+":"+version);
-        return RegisteredTypes.validate(item, constraint).orNull();
+        return RegisteredTypes.tryValidate(item, constraint).orNull();
     }
 
     @SuppressWarnings("deprecation")
     @Override
-    public Iterable<RegisteredType> getAll(Predicate<? super RegisteredType>
filter) {
+    public Iterable<RegisteredType> getMatching(Predicate<? super RegisteredType>
filter) {
         return Iterables.filter(Iterables.concat(
                 getAllWithoutCatalog(filter),
                 Iterables.transform(mgmt.getCatalog().getCatalogItems(), RegisteredTypes.CI_TO_RT)),

@@ -95,16 +95,20 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry
{
 
         RegisteredType type;
         if (!BrooklynCatalog.DEFAULT_VERSION.equals(version)) {
+            // normal code path when version is supplied
+            
             type = getExactWithoutLegacyCatalog(symbolicNameOrAliasIfNoVersion, version,
context);
             if (type!=null) return Maybe.of(type);
         }
-        
+
         if (BrooklynCatalog.DEFAULT_VERSION.equals(version)) {
-            Iterable<RegisteredType> types = getAll(Predicates.and(RegisteredTypePredicates.symbolicName(symbolicNameOrAliasIfNoVersion),

+            // alternate code path, if version blank or default
+            
+            Iterable<RegisteredType> types = getMatching(Predicates.and(RegisteredTypePredicates.symbolicName(symbolicNameOrAliasIfNoVersion),

                 RegisteredTypePredicates.satisfies(context)));
             if (Iterables.isEmpty(types)) {
                 // look for alias if no exact symbolic name match AND no version is specified
-                types = getAll(Predicates.and(RegisteredTypePredicates.alias(symbolicNameOrAliasIfNoVersion),

+                types = getMatching(Predicates.and(RegisteredTypePredicates.alias(symbolicNameOrAliasIfNoVersion),

                     RegisteredTypePredicates.satisfies(context) ) );
                 // if there are multiple symbolic names then throw?
                 Set<String> uniqueSymbolicNames = MutableSet.of();
@@ -112,8 +116,10 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry
{
                     uniqueSymbolicNames.add(t.getSymbolicName());
                 }
                 if (uniqueSymbolicNames.size()>1) {
-                    log.warn("Multiple matches found for alias '"+symbolicNameOrAliasIfNoVersion+"':
"+uniqueSymbolicNames+"; "
-                        + "picking highest version across different symbolic names. Use symbolic_name:version
syntax to prevent this lookup.");
+                    String message = "Multiple matches found for alias '"+symbolicNameOrAliasIfNoVersion+"':
"+uniqueSymbolicNames+"; "
+                        + "refusing to select any.";
+                    log.warn(message);
+                    return Maybe.absent(message);
                 }
             }
             if (!Iterables.isEmpty(types)) {
@@ -122,7 +128,7 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry
{
             }
         }
         
-        // fallback to catalog
+        // missing case is to look for exact version in legacy catalog
         CatalogItem<?, ?> item = mgmt.getCatalog().getCatalogItem(symbolicNameOrAliasIfNoVersion,
version);
         if (item!=null) 
             return Maybe.of( RegisteredTypes.CI_TO_RT.apply( item ) );
@@ -275,7 +281,7 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry
{
         if (!type.getId().equals(type.getSymbolicName()+":"+type.getVersion()))
             Asserts.fail("Registered type "+type+" has ID / symname mismatch");
         
-        RegisteredType oldType = localRegisteredTypes.get(type.getId());
+        RegisteredType oldType = mgmt.getTypeRegistry().get(type.getId());
         if (oldType==null || canForce) {
             log.debug("Inserting "+type+" into "+this);
             localRegisteredTypes.put(type.getId(), type);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/48bb7985/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypePredicates.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypePredicates.java
b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypePredicates.java
index bf6fb6f..2c02874 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypePredicates.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypePredicates.java
@@ -117,13 +117,13 @@ public class RegisteredTypePredicates {
         return version(Predicates.equalTo(name));
     }
     public static Predicate<RegisteredType> version(final Predicate<? super String>
filter) {
-        return new versionMatches(filter);
+        return new VersionMatches(filter);
     }
     
-    private static class versionMatches implements Predicate<RegisteredType> {
+    private static class VersionMatches implements Predicate<RegisteredType> {
         private final Predicate<? super String> filter;
         
-        public versionMatches(Predicate<? super String> filter) {
+        public VersionMatches(Predicate<? super String> filter) {
             this.filter = filter;
         }
         @Override
@@ -135,14 +135,14 @@ public class RegisteredTypePredicates {
     public static Predicate<RegisteredType> alias(final String alias) {
         return aliases(CollectionFunctionals.any(Predicates.equalTo(alias)));
     }
-    public static Predicate<RegisteredType> aliases(final Predicate<Iterable<String>>
filter) {
+    public static Predicate<RegisteredType> aliases(final Predicate<? super Iterable<String>>
filter) {
         return new AliasesMatch(filter);
     }
     
     private static class AliasesMatch implements Predicate<RegisteredType> {
-        private final Predicate<Iterable<String>> filter;
+        private final Predicate<? super Iterable<String>> filter;
         
-        public AliasesMatch(Predicate<Iterable<String>> filter) {
+        public AliasesMatch(Predicate<? super Iterable<String>> filter) {
             this.filter = filter;
         }
         @Override
@@ -154,14 +154,14 @@ public class RegisteredTypePredicates {
     public static Predicate<RegisteredType> tag(final Object tag) {
         return tags(CollectionFunctionals.any(Predicates.equalTo(tag)));
     }
-    public static Predicate<RegisteredType> tags(final Predicate<Iterable<Object>>
filter) {
+    public static Predicate<RegisteredType> tags(final Predicate<? super Iterable<Object>>
filter) {
         return new TagsMatch(filter);
     }
     
     private static class TagsMatch implements Predicate<RegisteredType> {
-        private final Predicate<Iterable<Object>> filter;
+        private final Predicate<? super Iterable<Object>> filter;
         
-        public TagsMatch(Predicate<Iterable<Object>> filter) {
+        public TagsMatch(Predicate<? super Iterable<Object>> filter) {
             this.filter = filter;
         }
         @Override
@@ -232,7 +232,7 @@ public class RegisteredTypePredicates {
     }
     public static boolean isBestVersion(ManagementContext mgmt, RegisteredType item) {
         if (item==null) return false;
-        Iterable<RegisteredType> matches = mgmt.getTypeRegistry().getAll(
+        Iterable<RegisteredType> matches = mgmt.getTypeRegistry().getMatching(
             RegisteredTypePredicates.symbolicName(item.getSymbolicName()) );
         if (!matches.iterator().hasNext()) return false;
         RegisteredType best = RegisteredTypes.getBestVersion(matches);
@@ -250,7 +250,7 @@ public class RegisteredTypePredicates {
         }
         @Override
         public boolean apply(@Nullable RegisteredType item) {
-            return RegisteredTypes.validate(item, context).isPresent();
+            return RegisteredTypes.tryValidate(item, context).isPresent();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/48bb7985/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java
index 3a89e60..2f792f0 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java
@@ -19,12 +19,12 @@
 package org.apache.brooklyn.core.typereg;
 
 import java.lang.reflect.Method;
-import java.util.Collections;
 import java.util.Comparator;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
+import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import org.apache.brooklyn.api.catalog.CatalogItem;
@@ -40,7 +40,6 @@ import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
 import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.core.objs.BrooklynObjectInternal;
 import org.apache.brooklyn.core.typereg.JavaClassNameTypePlanTransformer.JavaClassNameTypeImplementationPlan;
-import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.text.NaturalOrderComparator;
@@ -52,6 +51,7 @@ import com.google.common.base.Function;
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
 import com.google.common.collect.ComparisonChain;
+import com.google.common.collect.Ordering;
 import com.google.common.reflect.TypeToken;
 
 /**
@@ -96,7 +96,6 @@ public class RegisteredTypes {
         type.description = item.getDescription();
         type.iconUrl = item.getIconUrl();
         
-        if (item.getLibraries()!=null) type.bundles.addAll(item.getLibraries());
         type.disabled = item.isDisabled();
         type.deprecated = item.isDeprecated();
         if (item.getLibraries()!=null) type.bundles.addAll(item.getLibraries());
@@ -284,7 +283,13 @@ public class RegisteredTypes {
         return false;
     }
 
-    public static Maybe<RegisteredType> validate(RegisteredType item, final RegisteredTypeLoadingContext
constraint) {
+    /** Validates that the given type matches the context (if supplied);
+     * returns a Maybe(null) if the type is null. */
+    public static Maybe<RegisteredType> tryValidate(RegisteredType item, final RegisteredTypeLoadingContext
constraint) {
+        // kept as a Maybe in case someone wants a wrapper around item validity;
+        // unclear what the contract should be, as this can return Maybe.Present(null)
+        // which is suprising, but it is more natural to callers otherwise they'll likely
do a separate null check on the item
+        // (often handling null different to errors) so the Maybe.get() is redundant as they
have an object for the input anyway.
         if (item==null || constraint==null) return Maybe.of(item);
         if (constraint.getExpectedKind()!=null && !constraint.getExpectedKind().equals(item.getKind()))
             return Maybe.absent(item+" is not the expected kind "+constraint.getExpectedKind());
@@ -312,7 +317,7 @@ public class RegisteredTypes {
 
     public static RegisteredType getBestVersion(Iterable<RegisteredType> types) {
         if (types==null || !types.iterator().hasNext()) return null;
-        return Collections.max(MutableList.copyOf(types), RegisteredTypeComparator.INSTANCE);
+        return Ordering.from(RegisteredTypeComparator.INSTANCE).max(types);
     }
     
     public static class RegisteredTypeComparator implements Comparator<RegisteredType>
{
@@ -329,8 +334,13 @@ public class RegisteredTypes {
         }
     }
 
-    public static <T> Maybe<T> validate(final T object, final RegisteredType
type, final RegisteredTypeLoadingContext constraint) {
-        RegisteredTypeKind kind = type!=null ? type.getKind() : constraint!=null ? constraint.getExpectedKind()
: null;
+    /** validates that the given object (required) satisfies the constraints implied by the
given
+     * type and context object, using {@link Maybe} as the result set absent containing the
error(s)
+     * if not satisfied */
+    public static <T> Maybe<T> tryValidate(@Nonnull final T object, @Nullable
final RegisteredType type, @Nullable final RegisteredTypeLoadingContext context) {
+        if (object==null) return Maybe.absent("object is null");
+        
+        RegisteredTypeKind kind = type!=null ? type.getKind() : context!=null ? context.getExpectedKind()
: null;
         if (kind==null) {
             if (object instanceof AbstractBrooklynObjectSpec) kind=RegisteredTypeKind.SPEC;
             else kind=RegisteredTypeKind.BEAN;
@@ -338,17 +348,17 @@ public class RegisteredTypes {
         return new RegisteredTypeKindVisitor<Maybe<T>>() {
             @Override
             protected Maybe<T> visitSpec() {
-                return validateSpec(object, type, constraint);
+                return validateSpec(object, type, context);
             }
 
             @Override
             protected Maybe<T> visitBean() {
-                return validateBean(object, type, constraint);
+                return validateBean(object, type, context);
             }
         }.visit(kind);
     }
 
-    private static <T> Maybe<T> validateBean(T object, RegisteredType type, final
RegisteredTypeLoadingContext constraint) {
+    private static <T> Maybe<T> validateBean(T object, RegisteredType type, final
RegisteredTypeLoadingContext context) {
         if (object==null) return Maybe.absent("object is null");
         
         if (type!=null) {
@@ -358,11 +368,11 @@ public class RegisteredTypes {
                 return Maybe.absent(object+" does not have all the java supertypes of "+type);
         }
 
-        if (constraint!=null) {
-            if (constraint.getExpectedKind()!=RegisteredTypeKind.BEAN)
-                return Maybe.absent("Validating a bean when constraint expected "+constraint.getExpectedKind());
-            if (constraint.getExpectedJavaSuperType()!=null && !constraint.getExpectedJavaSuperType().isInstance(object))
-                return Maybe.absent(object+" is not of the expected java supertype "+constraint.getExpectedJavaSuperType());
+        if (context!=null) {
+            if (context.getExpectedKind()!=RegisteredTypeKind.BEAN)
+                return Maybe.absent("Validating a bean when constraint expected "+context.getExpectedKind());
+            if (context.getExpectedJavaSuperType()!=null && !context.getExpectedJavaSuperType().isInstance(object))
+                return Maybe.absent(object+" is not of the expected java supertype "+context.getExpectedJavaSuperType());
         }
         
         return Maybe.of(object);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/48bb7985/core/src/test/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistryTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistryTest.java
b/core/src/test/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistryTest.java
index a62ab7e..6f2f573 100644
--- a/core/src/test/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistryTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistryTest.java
@@ -56,7 +56,7 @@ public class BasicBrooklynTypeRegistryTest extends BrooklynMgmtUnitTestSupport
{
         Assert.assertEquals( registry().get(SAMPLE_TYPE.getSymbolicName(), SAMPLE_TYPE.getVersion()),
SAMPLE_TYPE );
         Assert.assertEquals( registry().get(SAMPLE_TYPE.getId()), SAMPLE_TYPE );
         
-        Assert.assertTrue( Iterables.contains(registry().getAll(
+        Assert.assertTrue( Iterables.contains(registry().getMatching(
             RegisteredTypePredicates.symbolicName(SAMPLE_TYPE.getSymbolicName())), SAMPLE_TYPE)
);
     }
 
@@ -78,7 +78,7 @@ public class BasicBrooklynTypeRegistryTest extends BrooklynMgmtUnitTestSupport
{
         }
         
         // only one entry
-        Assert.assertEquals( Iterables.size(registry().getAll(
+        Assert.assertEquals( Iterables.size(registry().getMatching(
             RegisteredTypePredicates.symbolicName(SAMPLE_TYPE.getSymbolicName()))), 1);
         // unversioned request returns sample
         Assert.assertEquals( registry().get(SAMPLE_TYPE.getSymbolicName()), SAMPLE_TYPE );
@@ -95,7 +95,7 @@ public class BasicBrooklynTypeRegistryTest extends BrooklynMgmtUnitTestSupport
{
         Assert.assertEquals( registry().get(SAMPLE_TYPE2.getId()), SAMPLE_TYPE2 );
         Assert.assertNotEquals( registry().get(SAMPLE_TYPE2.getId()), SAMPLE_TYPE );
         
-        Assert.assertEquals( Iterables.size(registry().getAll(
+        Assert.assertEquals( Iterables.size(registry().getMatching(
             RegisteredTypePredicates.symbolicName(SAMPLE_TYPE.getSymbolicName()))), 2);
         
         // unversioned request returns latest
@@ -106,11 +106,11 @@ public class BasicBrooklynTypeRegistryTest extends BrooklynMgmtUnitTestSupport
{
     public void testGetWithFilter() {
         add(SAMPLE_TYPE);
         
-        Assert.assertEquals( Iterables.size(registry().getAll(Predicates.and(
+        Assert.assertEquals( Iterables.size(registry().getMatching(Predicates.and(
             RegisteredTypePredicates.symbolicName(SAMPLE_TYPE.getSymbolicName()),
             RegisteredTypePredicates.subtypeOf(String.class)
             ))), 1 );
-        Assert.assertTrue( Iterables.isEmpty(registry().getAll(Predicates.and(
+        Assert.assertTrue( Iterables.isEmpty(registry().getMatching(Predicates.and(
                 RegisteredTypePredicates.symbolicName(SAMPLE_TYPE.getSymbolicName()),
                 RegisteredTypePredicates.subtypeOf(Integer.class)
             ))) );
@@ -136,7 +136,7 @@ public class BasicBrooklynTypeRegistryTest extends BrooklynMgmtUnitTestSupport
{
         add(sampleType15WithAliases);
         Assert.assertEquals(sampleType15WithAliases.getAliases(), MutableSet.of("my_a", "the_a"));
         
-        Assert.assertEquals( Iterables.size(registry().getAll(
+        Assert.assertEquals( Iterables.size(registry().getMatching(
             RegisteredTypePredicates.symbolicName(SAMPLE_TYPE.getSymbolicName()))), 3);
         
         Assert.assertEquals( registry().get("my_a"), sampleType15WithAliases );
@@ -147,7 +147,7 @@ public class BasicBrooklynTypeRegistryTest extends BrooklynMgmtUnitTestSupport
{
         Assert.assertEquals( registry().get(sampleType15WithAliases.getSymbolicName()), SAMPLE_TYPE2
);
         
         // and filters work
-        Assert.assertEquals( registry().getAll(RegisteredTypePredicates.alias("the_a")),
+        Assert.assertEquals( registry().getMatching(RegisteredTypePredicates.alias("the_a")),
             MutableList.of(sampleType15WithAliases) );
         Assert.assertEquals( registry().get("my_a",  
             RegisteredTypeLoadingContexts.bean(String.class)), sampleType15WithAliases );
@@ -166,13 +166,13 @@ public class BasicBrooklynTypeRegistryTest extends BrooklynMgmtUnitTestSupport
{
         add(sampleType15WithTags);
         Assert.assertEquals(sampleType15WithTags.getTags(), MutableSet.of("my_a", "the_a"));
         
-        Assert.assertEquals( Iterables.size(registry().getAll(
+        Assert.assertEquals( Iterables.size(registry().getMatching(
             RegisteredTypePredicates.symbolicName(SAMPLE_TYPE.getSymbolicName()))), 3);
         
         Assert.assertEquals( registry().get(sampleType15WithTags.getId()), sampleType15WithTags
);
         
         // and filters work
-        Assert.assertEquals( registry().getAll(RegisteredTypePredicates.tag("the_a")),
+        Assert.assertEquals( registry().getMatching(RegisteredTypePredicates.tag("the_a")),
             MutableList.of(sampleType15WithTags) );
         
         // but can't lookup by tag as a get

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/48bb7985/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java
b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java
index acde8ec..e4f500d 100644
--- a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java
+++ b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java
@@ -37,6 +37,7 @@ import org.apache.brooklyn.core.typereg.RegisteredTypeLoadingContexts;
 import org.apache.brooklyn.core.typereg.RegisteredTypes;
 import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.core.config.ConfigBag;
+import org.apache.brooklyn.util.guava.Maybe;
 
 import com.google.common.annotations.Beta;
 import com.google.common.collect.ImmutableList;
@@ -115,10 +116,10 @@ public abstract class BrooklynEntityDecorationResolver<DT> {
             String policyType = decoLoader.getTypeName().get();
             ManagementContext mgmt = instantiator.loader.getManagementContext();
             
-            RegisteredType item = RegisteredTypes.validate(mgmt.getTypeRegistry().get(policyType),
RegisteredTypeLoadingContexts.spec(Policy.class)).get();
+            Maybe<RegisteredType> item = RegisteredTypes.tryValidate(mgmt.getTypeRegistry().get(policyType),
RegisteredTypeLoadingContexts.spec(Policy.class));
             PolicySpec<?> spec;
-            if (item!=null) {
-                spec = mgmt.getTypeRegistry().createSpec(item, null, PolicySpec.class);
+            if (item.get()!=null) {
+                spec = mgmt.getTypeRegistry().createSpec(item.get(), null, PolicySpec.class);
             } else {
                 Class<? extends Policy> type = decoLoader.getType(Policy.class);
                 spec = PolicySpec.create(type)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/48bb7985/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
index 291a06a..47925e5 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
@@ -53,7 +53,7 @@ public class CatalogYamlLocationTest extends AbstractYamlTest {
 
     @AfterMethod
     public void tearDown() {
-        for (RegisteredType ci : mgmt().getTypeRegistry().getAll(RegisteredTypePredicates.IS_LOCATION))
{
+        for (RegisteredType ci : mgmt().getTypeRegistry().getMatching(RegisteredTypePredicates.IS_LOCATION))
{
             mgmt().getCatalog().deleteCatalogItem(ci.getSymbolicName(), ci.getVersion());
         }
     }
@@ -246,7 +246,7 @@ public class CatalogYamlLocationTest extends AbstractYamlTest {
     }
 
     private int countCatalogLocations() {
-        return Iterables.size(mgmt().getTypeRegistry().getAll(RegisteredTypePredicates.IS_LOCATION));
+        return Iterables.size(mgmt().getTypeRegistry().getMatching(RegisteredTypePredicates.IS_LOCATION));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/48bb7985/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlVersioningTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlVersioningTest.java
b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlVersioningTest.java
index f92f3a4..440c114 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlVersioningTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlVersioningTest.java
@@ -121,11 +121,11 @@ public class CatalogYamlVersioningTest extends AbstractYamlTest {
         addCatalogEntity(symbolicName, version);
         
         Iterable<RegisteredType> matches;
-        matches = types.getAll(RegisteredTypePredicates.symbolicName(Predicates.equalTo(symbolicName)));
+        matches = types.getMatching(RegisteredTypePredicates.symbolicName(Predicates.equalTo(symbolicName)));
         assertTrue(matches.iterator().hasNext());
         
         mgmt().getCatalog().deleteCatalogItem(symbolicName, version);
-        matches = types.getAll(RegisteredTypePredicates.symbolicName(Predicates.equalTo(symbolicName)));
+        matches = types.getMatching(RegisteredTypePredicates.symbolicName(Predicates.equalTo(symbolicName)));
         assertFalse(matches.iterator().hasNext());
     }
     
@@ -135,11 +135,11 @@ public class CatalogYamlVersioningTest extends AbstractYamlTest {
         addCatalogEntity(symbolicName, null);
 
         Iterable<RegisteredType> matches;
-        matches = types.getAll(RegisteredTypePredicates.symbolicName(Predicates.equalTo(symbolicName)));
+        matches = types.getMatching(RegisteredTypePredicates.symbolicName(Predicates.equalTo(symbolicName)));
         assertTrue(matches.iterator().hasNext());
         
         mgmt().getCatalog().deleteCatalogItem(symbolicName, BasicBrooklynCatalog.NO_VERSION);
-        matches = types.getAll(RegisteredTypePredicates.symbolicName(Predicates.equalTo(symbolicName)));
+        matches = types.getMatching(RegisteredTypePredicates.symbolicName(Predicates.equalTo(symbolicName)));
         assertFalse(matches.iterator().hasNext());
     }
     
@@ -150,7 +150,7 @@ public class CatalogYamlVersioningTest extends AbstractYamlTest {
         String v2 = "0.2.0-SNAPSHOT";
         addCatalogEntity(symbolicName, v1);
         addCatalogEntity(symbolicName, v2);
-        Iterable<RegisteredType> items = types.getAll(RegisteredTypePredicates.symbolicName(Predicates.equalTo(symbolicName)));
+        Iterable<RegisteredType> items = types.getMatching(RegisteredTypePredicates.symbolicName(Predicates.equalTo(symbolicName)));
         assertEquals(Iterables.size(items), 2);
     }
     
@@ -212,7 +212,7 @@ public class CatalogYamlVersioningTest extends AbstractYamlTest {
                 "      type: referrent\n" +
                 "      version: 1.1"));
         
-        Iterable<RegisteredType> items = types.getAll(RegisteredTypePredicates.symbolicName(Predicates.equalTo("referrer")));
+        Iterable<RegisteredType> items = types.getMatching(RegisteredTypePredicates.symbolicName(Predicates.equalTo("referrer")));
         Assert.assertEquals(Iterables.size(items), 1, "Wrong number of: "+items);
         RegisteredType item = Iterables.getOnlyElement(items);
         Assert.assertEquals(item.getVersion(), "1.0");
@@ -239,7 +239,7 @@ public class CatalogYamlVersioningTest extends AbstractYamlTest {
     }
     
     private void assertSingleCatalogItem(String symbolicName, String version) {
-        Iterable<RegisteredType> items = types.getAll(RegisteredTypePredicates.symbolicName(Predicates.equalTo(symbolicName)));
+        Iterable<RegisteredType> items = types.getMatching(RegisteredTypePredicates.symbolicName(Predicates.equalTo(symbolicName)));
         RegisteredType item = Iterables.getOnlyElement(items);
         assertEquals(item.getSymbolicName(), symbolicName);
         assertEquals(item.getVersion(), version);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/48bb7985/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
index 57adfeb..9cd6bc5 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
@@ -230,11 +230,13 @@ public class CampYamlLiteTest {
     }
 
     private void assertMgmtHasSampleMyCatalogApp(String symbolicName, String bundleUrl) {
-        RegisteredType item = RegisteredTypes.validate(mgmt.getTypeRegistry().get(symbolicName),
RegisteredTypeLoadingContexts.spec(Entity.class)).get();
+        RegisteredType item = mgmt.getTypeRegistry().get(symbolicName);
         assertNotNull(item, "failed to load item with id=" + symbolicName + " from catalog.
Entries were: " +
                 Joiner.on(",").join(mgmt.getTypeRegistry().getAll()));
         assertEquals(item.getSymbolicName(), symbolicName);
 
+        RegisteredTypes.tryValidate(item, RegisteredTypeLoadingContexts.spec(Entity.class)).get();
+        
         // stored as yaml, not java
         String planYaml = RegisteredTypes.getImplementationDataStringForSpec(item);
         assertNotNull(planYaml);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/48bb7985/usage/rest-server/src/main/java/org/apache/brooklyn/rest/resources/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/resources/ApplicationResource.java
b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/resources/ApplicationResource.java
index 89f253a..83c6423 100644
--- a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/resources/ApplicationResource.java
+++ b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/resources/ApplicationResource.java
@@ -402,7 +402,7 @@ public class ApplicationResource extends AbstractBrooklynRestResource
implements
     }
 
     private void checkSpecTypeIsValid(String type, Class<? extends BrooklynObject>
subType) {
-        if (RegisteredTypes.validate(mgmt().getTypeRegistry().get(type), RegisteredTypeLoadingContexts.spec(subType))
== null) {
+        if (RegisteredTypes.tryValidate(mgmt().getTypeRegistry().get(type), RegisteredTypeLoadingContexts.spec(subType))
== null) {
             try {
                 brooklyn().getCatalogClassLoader().loadClass(type);
             } catch (ClassNotFoundException e) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/48bb7985/usage/rest-server/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
index 03b05f9..0993f16 100644
--- a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
+++ b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
@@ -149,10 +149,12 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
                 Entitlements.getEntitlementContext().user());
         }
         try {
-            RegisteredType item = RegisteredTypes.validate(mgmt().getTypeRegistry().get(entityId),
RegisteredTypeLoadingContexts.spec(Entity.class)).get();
+            RegisteredType item = mgmt().getTypeRegistry().get(entityId);
             if (item==null) {
                 throw WebResourceUtils.notFound("Entity with id '%s' not found", entityId);
             }
+            RegisteredTypes.tryValidate(item, RegisteredTypeLoadingContexts.spec(Entity.class));
+            
             brooklyn().getCatalog().deleteCatalogItem(item.getSymbolicName(), item.getVersion());
         } catch (NoSuchElementException e) {
             throw WebResourceUtils.notFound("Entity with id '%s' not found", entityId);


Mime
View raw message