This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git

commit 23c33676f808fccc6e65259079a0a8cca9e9898a
Author: Alex Heneveld <[email protected]>
AuthorDate: Tue Oct 20 15:18:47 2020 +0100

    show errors when an unresolved item is attempted to be used
---
 .../java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java     | 8 ++++----
 .../brooklyn/core/catalog/internal/BasicBrooklynCatalog.java      | 8 ++++----
 .../apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java   | 4 ++--
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git 
a/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java 
b/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
index 1dbe39e..e77c415 100644
--- a/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
+++ b/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
@@ -149,7 +149,7 @@ public interface BrooklynCatalog {
     @Beta  // method may move elsewhere, or return type may change
     public void addTypesFromBundleBom(String yaml, @Nullable ManagedBundle 
bundle, boolean forceUpdate, Map<RegisteredType, RegisteredType> result);
 
-    /** As {@link #addTypesFromBundleBom(String, ManagedBundle, boolean, Map)} 
followed by {@link #validateType(RegisteredType, RegisteredTypeLoadingContext)}
+    /** As {@link #addTypesFromBundleBom(String, ManagedBundle, boolean, Map)} 
followed by {@link #validateType(RegisteredType, RegisteredTypeLoadingContext, 
boolean)}
      * e.g. for use in tests and ad hoc setup when there is just a YAML file.  
In OSGi mode this adds a bundle; otherwise it uses legacy catalog item addition 
mode.
      * <p>
      * Note that if addition or validation fails, this throws, unlike {@link 
#addTypesFromBundleBom(String, ManagedBundle, boolean, Map)},
@@ -162,8 +162,8 @@ public interface BrooklynCatalog {
     @Beta
     Collection<RegisteredType> addTypesAndValidateAllowInconsistent(String 
catalogYaml, @Nullable Map<RegisteredType, RegisteredType> result, boolean 
forceUpdate);
 
-    /** As {@link #validateType(RegisteredType, RegisteredTypeLoadingContext)} 
but taking a set of types, returning a map whose keys are
-     * those types where validation failed, mapped to the collection of errors 
validating that type. 
+    /** As {@link #validateType(RegisteredType, RegisteredTypeLoadingContext, 
boolean)} allowing unresolved, taking a set of types,
+     * and returning a map whose keys are those types where validation failed, 
mapped to the collection of errors validating that type.
      * An empty map result indicates no validation errors in the types passed 
in. 
      */
     @Beta  // method may move elsewhere
@@ -176,7 +176,7 @@ public interface BrooklynCatalog {
      * for the given registered type.
      */
     @Beta  // method may move elsewhere
-    Collection<Throwable> validateType(RegisteredType typeToValidate, 
@Nullable RegisteredTypeLoadingContext optionalConstraint);
+    Collection<Throwable> validateType(RegisteredType typeToValidate, 
@Nullable RegisteredTypeLoadingContext optionalConstraint, boolean 
allowUnresolved);
 
     /** As {@link #addItems(String, boolean, boolean)}
      *
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 5a1a9e2..2c0f55f 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
@@ -1660,7 +1660,7 @@ public class BasicBrooklynCatalog implements 
BrooklynCatalog {
         // (validation normally done by osgi load routines)
         Map<String,Collection<Throwable>> errors = MutableMap.of();
         for (CatalogItemDtoAbstract<?, ?> item: result) {
-            Collection<Throwable> errorsInItem = 
validateType(RegisteredTypes.of(item), null);
+            Collection<Throwable> errorsInItem = 
validateType(RegisteredTypes.of(item), null, true);
             if (!errorsInItem.isEmpty()) {
                 errors.put(item.getCatalogItemId(), errorsInItem);
             }
@@ -1710,7 +1710,7 @@ public class BasicBrooklynCatalog implements 
BrooklynCatalog {
             log.debug("Catalog load, starting validation cycle, 
"+typesRemainingToValidate.size()+" to validate");
             Map<RegisteredType,Collection<Throwable>> result = MutableMap.of();
             for (RegisteredType t: typesRemainingToValidate) {
-                Collection<Throwable> tr = validateType(t, null);
+                Collection<Throwable> tr = validateType(t, null, true);
                 if (!tr.isEmpty()) {
                     result.put(t, tr);
                 }
@@ -1727,10 +1727,10 @@ public class BasicBrooklynCatalog implements 
BrooklynCatalog {
     }
     
     @Override @Beta
-    public Collection<Throwable> validateType(RegisteredType typeToValidate, 
RegisteredTypeLoadingContext constraint) {
+    public Collection<Throwable> validateType(RegisteredType typeToValidate, 
RegisteredTypeLoadingContext constraint, boolean allowUnresolved) {
         ReferenceWithError<RegisteredType> result = 
validateResolve(typeToValidate, constraint);
         if (result.hasError()) {
-            if (RegisteredTypes.isTemplate(typeToValidate)) {
+            if (allowUnresolved && RegisteredTypes.isTemplate(typeToValidate)) 
{
                 // ignore for templates
                 return Collections.emptySet();
             }
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 916ba56..d9a21d6 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
@@ -252,13 +252,13 @@ public class BasicBrooklynTypeRegistry implements 
BrooklynTypeRegistry {
                 
             } else {
                 // try just-in-time validation
-                Collection<Throwable> validationErrors = 
mgmt.getCatalog().validateType(type, constraint);
+                Collection<Throwable> validationErrors = 
mgmt.getCatalog().validateType(type, constraint, false);
                 if (!validationErrors.isEmpty()) {
                     throw new ReferencedUnresolvedTypeException(type, true, 
Exceptions.create(validationErrors));
                 }
                 type = mgmt.getTypeRegistry().get(type.getSymbolicName(), 
type.getVersion());
                 if (type==null || 
type.getKind()==RegisteredTypeKind.UNRESOLVED) {
-                    // TODO show the resolution error
+                    // shouldn't come here
                     throw new ReferencedUnresolvedTypeException(type);
                 }
                 return createSpec(type, constraint, specSuperType);

Reply via email to