brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drigod...@apache.org
Subject [4/5] brooklyn-server git commit: add more places where unresolved templates can be used
Date Mon, 21 Aug 2017 18:33:00 GMT
add more places where unresolved templates can be used

not sure any of them are needed, most things should go through BBTR.createSpec;
but try more broadly, and log warnings if appropriate


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

Branch: refs/heads/master
Commit: 49cf9c166ecfdcf85a531ee83c6dde01845d86c0
Parents: ae0fd54
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Wed Aug 16 17:16:13 2017 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Wed Aug 16 17:27:25 2017 +0100

----------------------------------------------------------------------
 .../spi/creation/CampTypePlanTransformer.java   | 25 +++++++---
 .../typereg/AbstractTypePlanTransformer.java    | 19 ++++++-
 .../core/typereg/BasicBrooklynTypeRegistry.java | 52 +++++++++++++-------
 .../brooklyn/core/typereg/RegisteredTypes.java  | 16 +++++-
 4 files changed, 86 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/49cf9c16/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampTypePlanTransformer.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampTypePlanTransformer.java
b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampTypePlanTransformer.java
index 0901632..eaa68b8 100644
--- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampTypePlanTransformer.java
+++ b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampTypePlanTransformer.java
@@ -48,16 +48,29 @@ public class CampTypePlanTransformer extends AbstractTypePlanTransformer
{
 
     @Override
     protected double scoreForNullFormat(Object planData, RegisteredType type, RegisteredTypeLoadingContext
context) {
-        if (type!=null && type.getKind()!=RegisteredTypeKind.SPEC) return 0;
+        double weight;
+        if (type!=null) {
+            if (type.getKind()==RegisteredTypeKind.SPEC) {
+                weight = 1.0;
+            } else if (type.getKind()==RegisteredTypeKind.UNRESOLVED) {
+                // might be a template
+                weight = 0.4;
+            } else {
+                return 0;
+            }
+        } else {
+            // have a plan but no type, weaken slightly
+            weight = 0.8;
+        }
         
         Maybe<Map<?,?>> plan = RegisteredTypes.getAsYamlMap(planData);
         if (plan.isAbsent()) return 0;
-        if (plan.get().containsKey("services")) return 0.8;
-        if (plan.get().containsKey("type")) return 0.4;
+        if (plan.get().containsKey("services")) return weight*0.8;
+        if (plan.get().containsKey("type")) return weight*0.4;
         // TODO these should become legacy
-        if (plan.get().containsKey("brooklyn.locations")) return 0.7;
-        if (plan.get().containsKey("brooklyn.policies")) return 0.7;
-        if (plan.get().containsKey("brooklyn.enrichers")) return 0.7;
+        if (plan.get().containsKey("brooklyn.locations")) return weight*0.7;
+        if (plan.get().containsKey("brooklyn.policies")) return weight*0.7;
+        if (plan.get().containsKey("brooklyn.enrichers")) return weight*0.7;
         return 0;
     }
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/49cf9c16/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 d0970c8..52ee199 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
@@ -112,8 +112,23 @@ public abstract class AbstractTypePlanTransformer implements BrooklynTypePlanTra
                         return createBean(type, context);
                     } catch (Exception e) { throw Exceptions.propagate(e); }
                 }
-                @Override protected Object visitUnresolved() { 
-                    throw new IllegalStateException(type+" is not yet resolved");
+                @Override protected Object visitUnresolved() {
+                    try {
+                        // don't think there are valid times when this comes here?
+                        // currently should only used for "templates" which are always for
specs,
+                        // but callers of that shouldn't be talking to type plan transformers,
+                        // they should be calling to main BBTR methods.
+                        // do it and alert just in case however.
+                        // TODO remove if we don't see any warnings (or when we sort out
semantics for template v app v allowed-unresolved better)
+                        log.debug("Request for "+this+" to validate UNRESOLVED kind "+type+";
trying as spec");
+                        Object result = visitSpec();
+                        log.warn("Request to use "+this+" from UNRESOLVED state succeeded
treating is as a spec");
+                        log.debug("Trace for request to use "+this+" in UNRESOLVED state
succeeding", new Throwable("Location of request to use "+this+" in UNRESOLVED state"));
+                        return result;
+                    } catch (Exception e) {
+                        Exceptions.propagateIfFatal(e);
+                        throw new IllegalStateException(type+" is in registry but its definition
cannot be resolved", e);
+                    }
                 }
             }.visit(type.getKind()), type, context).get();
         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/49cf9c16/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 aae9297..1ff5bd4 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
@@ -179,24 +179,24 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry
{
     @Override
     public <SpecT extends AbstractBrooklynObjectSpec<?,?>> SpecT createSpec(RegisteredType
type, @Nullable RegisteredTypeLoadingContext constraint, Class<SpecT> specSuperType)
{
         Preconditions.checkNotNull(type, "type");
-        if (type.getKind()!=RegisteredTypeKind.SPEC) { 
-            if (type.getKind()==RegisteredTypeKind.UNRESOLVED) {
-                // try just-in-time validation
-                Collection<Throwable> validationErrors = mgmt.getCatalog().validateType(type);
-                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) {
-                    throw new ReferencedUnresolvedTypeException(type);
-                }
-                return createSpec(type, constraint, specSuperType);
-                
-            } else {
-                throw new UnsupportedTypePlanException("Cannot create spec from type "+type+"
(kind "+type.getKind()+")");
+        if (type.getKind()==RegisteredTypeKind.SPEC) {
+            return createSpec(type, type.getPlan(), type.getSymbolicName(), type.getVersion(),
type.getSuperTypes(), constraint, specSuperType);
+            
+        } else if (type.getKind()==RegisteredTypeKind.UNRESOLVED) {
+            // try just-in-time validation
+            Collection<Throwable> validationErrors = mgmt.getCatalog().validateType(type);
+            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) {
+                throw new ReferencedUnresolvedTypeException(type);
             }
+            return createSpec(type, constraint, specSuperType);
+            
+        } else {
+            throw new UnsupportedTypePlanException("Cannot create spec from type "+type+"
(kind "+type.getKind()+")");
         }
-        return createSpec(type, type.getPlan(), type.getSymbolicName(), type.getVersion(),
type.getSuperTypes(), constraint, specSuperType);
     }
     
     @SuppressWarnings({ "deprecation", "unchecked", "rawtypes" })
@@ -305,7 +305,25 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry
{
             @Override protected T visitBean() { return createBean(type, constraint, optionalResultSuperType);
}
             @SuppressWarnings({ "unchecked", "rawtypes" })
             @Override protected T visitSpec() { return (T) createSpec(type, constraint, (Class)optionalResultSuperType);
}
-            @Override protected T visitUnresolved() { throw new IllegalArgumentException("Kind-agnostic
create method can only be used when the registered type declares its kind, which "+type+"
does not"); }
+            @Override protected T visitUnresolved() {
+                try {
+                    // don't think there are valid times when this comes here?
+                    // currently should only used for "templates" which are always for specs,
+                    // but callers of that shouldn't be talking to type plan transformers,
+                    // they should be calling to main BBTR methods.
+                    // do it and alert just in case however.
+                    // TODO remove if we don't see any warnings (or when we sort out semantics
for template v app v allowed-unresolved better)
+                    log.debug("Request for "+this+" to create UNRESOLVED kind "+type+"; trying
as spec");
+                    T result = visitSpec();
+                    log.warn("Request to use "+this+" from UNRESOLVED state succeeded treating
is as a spec");
+                    log.debug("Trace for request to use "+this+" in UNRESOLVED state succeeding",
new Throwable("Location of request to use "+this+" in UNRESOLVED state"));
+                    return result;
+                } catch (Exception e) {
+                    Exceptions.propagateIfFatal(e);
+                    throw new IllegalArgumentException("Kind-agnostic create method only
intended for used when the registered type declares its kind, which "+type+" does not, "
+                        + "and failed treating it as a spec: "+e, e);
+                }
+            }
         }.visit(type.getKind());
     }
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/49cf9c16/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 360df02..6ec5983 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
@@ -518,7 +518,21 @@ public class RegisteredTypes {
                 return tryValidateBean(object, type, context);
             }
             
-            protected Maybe<T> visitUnresolved() { 
+            protected Maybe<T> visitUnresolved() {
+                // don't think there are valid times when this comes here?
+                // currently should only used for "templates" which are always for specs,
+                // but callers of that shouldn't be talking to type plan transformers,
+                // they should be calling to main BBTR methods.
+                // do it and alert just in case however.
+                // TODO remove if we don't see any warnings (or when we sort out semantics
for template v app v allowed-unresolved better)
+                log.debug("Request for "+this+" to validate UNRESOLVED kind "+type+"; trying
as spec");
+                Maybe<T> result = visitSpec();
+                if (result.isPresent()) {
+                    log.warn("Request to use "+this+" from UNRESOLVED state succeeded treating
is as a spec");
+                    log.debug("Trace for request to use "+this+" in UNRESOLVED state succeeding",
new Throwable("Location of request to use "+this+" in UNRESOLVED state"));
+                    return result;
+                }
+                
                 return Maybe.absent(object+" is not yet resolved");
             }
         }.visit(kind);


Mime
View raw message