brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From geom...@apache.org
Subject [37/39] brooklyn-server git commit: fix broken tests by reverting the increased flexibility to the java catalog spec transformer
Date Wed, 19 Jul 2017 16:26:07 GMT
fix broken tests by reverting the increased flexibility to the java catalog spec transformer

andre-enable camp items in rebind-osgi tests a different way


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

Branch: refs/heads/master
Commit: c7034e60367b95945351558b4267c085e5b52909
Parents: c2d9bff
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Tue Jul 18 13:42:32 2017 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Tue Jul 18 13:42:32 2017 +0100

----------------------------------------------------------------------
 .../brooklyn/catalog/CatalogYamlRebindTest.java | 24 ++++++++----------
 .../internal/JavaCatalogToSpecTransformer.java  | 26 --------------------
 .../core/typereg/TypePlanTransformers.java      |  1 +
 .../apache/brooklyn/util/core/task/Tasks.java   |  8 +++++-
 4 files changed, 18 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c7034e60/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlRebindTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlRebindTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlRebindTest.java
index 0aa01be..66e5663 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlRebindTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlRebindTest.java
@@ -87,28 +87,24 @@ public class CatalogYamlRebindTest extends AbstractYamlRebindTest {
     
     enum OsgiMode {
         NONE,
-        // we don't test OSGi with this because CAMP isn't available 
-        // (and the library bundles assume CAMP in their catalog.bom)
-        // OSGi rebind isn't the focus of the tests which use this parameter
-        // so it's okay, though a bit ugly
-//        NORMAL,
+        NORMAL
     }
 
     boolean useOsgi = false;
-    private Boolean defaultEnablementOfFeatureAutoFixatalogRefOnRebind;
+    private Boolean defaultEnablementOfFeatureAutoFixCatalogRefOnRebind;
     
     @BeforeMethod(alwaysRun=true)
     @Override
     public void setUp() throws Exception {
-        defaultEnablementOfFeatureAutoFixatalogRefOnRebind = BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_AUTO_FIX_CATALOG_REF_ON_REBIND);
+        defaultEnablementOfFeatureAutoFixCatalogRefOnRebind = BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_AUTO_FIX_CATALOG_REF_ON_REBIND);
         super.setUp();
     }
     
     @AfterMethod(alwaysRun=true)
     @Override
     public void tearDown() throws Exception {
-        if (defaultEnablementOfFeatureAutoFixatalogRefOnRebind != null) {
-            BrooklynFeatureEnablement.setEnablement(BrooklynFeatureEnablement.FEATURE_AUTO_FIX_CATALOG_REF_ON_REBIND,
defaultEnablementOfFeatureAutoFixatalogRefOnRebind);
+        if (defaultEnablementOfFeatureAutoFixCatalogRefOnRebind != null) {
+            BrooklynFeatureEnablement.setEnablement(BrooklynFeatureEnablement.FEATURE_AUTO_FIX_CATALOG_REF_ON_REBIND,
defaultEnablementOfFeatureAutoFixCatalogRefOnRebind);
         }
         super.tearDown();
     }
@@ -368,8 +364,10 @@ public class CatalogYamlRebindTest extends AbstractYamlRebindTest {
         Entities.destroyAll(origManagementContext);
         try {
             useOsgi = true;
-            origManagementContext = createOrigManagementContext();
-            origApp = createApp();
+            tearDown();
+            setUp();
+        } catch (Exception e) {
+            throw Exceptions.propagate(e);
         } finally {
             useOsgi = false;
         }
@@ -380,10 +378,8 @@ public class CatalogYamlRebindTest extends AbstractYamlRebindTest {
         doTestLongReferenceSequence();
     }
     
-    @Test(groups="Broken")
+    @Test
     public void testLongReferenceSequenceWithOsgi() throws Exception {
-        // won't work in OSGi mode because we need CAMP to resolve type "a0"
-        // (poor man's resolver only resolves Java classes)
         recreateOrigManagementContextWithOsgi();
         doTestLongReferenceSequence();
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c7034e60/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java
b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java
index 83dabc4..9d95542 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java
@@ -18,7 +18,6 @@
  */
 package org.apache.brooklyn.core.catalog.internal;
 
-import java.util.Map;
 import java.util.Set;
 
 import org.apache.brooklyn.api.catalog.CatalogItem;
@@ -38,13 +37,9 @@ import org.apache.brooklyn.core.objs.BasicSpecParameter;
 import org.apache.brooklyn.core.plan.PlanToSpecTransformer;
 import org.apache.brooklyn.core.typereg.UnsupportedTypePlanException;
 import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.apache.brooklyn.util.text.Strings;
-import org.apache.brooklyn.util.yaml.Yamls;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.collect.Iterables;
-
 /**
  * Instantiates classes from a registered type which simply
  * defines the java class name and OSGi bundles to use.
@@ -82,28 +77,7 @@ public class JavaCatalogToSpecTransformer implements PlanToSpecTransformer
{
             CatalogItem<T, SpecT> item, Set<String> encounteredTypes) throws
UnsupportedTypePlanException {
         @SuppressWarnings("deprecation")
         String javaType = item.getJavaType();
-        boolean poorMansCamp = false;
-        if (javaType == null) {
-            if (Strings.isNonBlank( item.getPlanYaml() )) {
-                try {
-                    Map<?,?> parsed = (Map<?,?>) Iterables.getOnlyElement( Yamls.parseAll(item.getPlanYaml())
);
-                    if ("type".equals(Iterables.getOnlyElement(parsed.keySet()))) {
-                        javaType = (String) Iterables.getOnlyElement(parsed.values());
-                        poorMansCamp = true;
-                    }
-                } catch (Exception e) {
-                    throw new UnsupportedTypePlanException(getClass().getName() + " parses
only old-style catalog items containing only 'type: JavaClass' in YAML (or javaType in DTO)",
e);
-                }
-            }
-        }
         if (javaType != null) {
-            // TODO "JavaType" should never be used any more; but we do want to support a
poor-man's camp
-            // for tests that expect CAMP in core where CAMP module isn't available
-            if (poorMansCamp) {
-                // cannot warn here as -- however all CatalogToSpec transformers including
this will be removed;
-                // in favour of TypePlanTransformer instances
-                log.trace("Deprecated functionality (since 0.9.0). Using old-style java type
attribute for " + item);
-            }
             Class<?> type;
             try {
                 // java types were deprecated before we added osgi support so this isn't
necessary,

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c7034e60/core/src/main/java/org/apache/brooklyn/core/typereg/TypePlanTransformers.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/TypePlanTransformers.java
b/core/src/main/java/org/apache/brooklyn/core/typereg/TypePlanTransformers.java
index ba81e07..cc4845c 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/TypePlanTransformers.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/TypePlanTransformers.java
@@ -125,6 +125,7 @@ public class TypePlanTransformers {
                     (Strings.isNonBlank(e.getMessage()) ? " ("+e.getMessage()+")" : ""));
             } catch (Throwable e) {
                 Exceptions.propagateIfFatal(e);
+                log.debug("Transformer for "+t.getFormatCode()+" gave an error creating this
plan (retrying with others): "+e, e);
                 failuresFromTransformers.add(new PropagatedRuntimeException(
                     (type.getSymbolicName()!=null ? "Error in definition of "+type.getId()
: 
                         "Transformer for "+t.getFormatCode()+" gave an error creating this
plan") + ": "+

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c7034e60/core/src/main/java/org/apache/brooklyn/util/core/task/Tasks.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/task/Tasks.java b/core/src/main/java/org/apache/brooklyn/util/core/task/Tasks.java
index 09116af..ac07c35 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/task/Tasks.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/task/Tasks.java
@@ -33,13 +33,14 @@ import org.apache.brooklyn.api.mgmt.Task;
 import org.apache.brooklyn.api.mgmt.TaskAdaptable;
 import org.apache.brooklyn.api.mgmt.TaskFactory;
 import org.apache.brooklyn.api.mgmt.TaskQueueingContext;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.util.core.config.ConfigBag;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.exceptions.ReferenceWithError;
 import org.apache.brooklyn.util.repeat.Repeater;
 import org.apache.brooklyn.util.time.CountdownTimer;
 import org.apache.brooklyn.util.time.Duration;
 import org.apache.brooklyn.util.time.Time;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -133,6 +134,11 @@ public class Tasks {
     public static ValueResolver.ResolverBuilderPretype resolving(Object v) {
         return new ValueResolver.ResolverBuilderPretype(v);
     }
+    
+    @SuppressWarnings("unchecked")
+    public static <T> ValueResolver<T> resolving(ConfigBag config, ConfigKey<T>
key) {
+        return new ValueResolver.ResolverBuilderPretype(config.getStringKey(key.getName())).as((Class<T>)key.getType());
+    }
 
     /** @see #resolveValue(Object, Class, ExecutionContext, String) */
     public static <T> T resolveValue(Object v, Class<T> type, @Nullable ExecutionContext
exec) throws ExecutionException, InterruptedException {


Mime
View raw message