brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [1/3] brooklyn-server git commit: Always add new parameters at start
Date Thu, 28 Jul 2016 17:25:26 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master e9d84bfcb -> a2148becf


Always add new parameters at start


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

Branch: refs/heads/master
Commit: f607990f48339283f9182feb9fd5e27cd3246299
Parents: a04bf4d
Author: Andrew Donald Kennedy <andrew.kennedy@cloudsoftcorp.com>
Authored: Tue Jul 26 21:15:34 2016 +0100
Committer: Andrew Donald Kennedy <andrew.kennedy@cloudsoftcorp.com>
Committed: Wed Jul 27 16:09:54 2016 +0100

----------------------------------------------------------------------
 .../internal/AbstractBrooklynObjectSpec.java    | 12 +++--
 .../catalog/SpecParameterParsingTest.java       |  4 +-
 .../catalog/SpecParameterUnwrappingTest.java    | 57 +++++++++++++++-----
 .../brooklyn/core/objs/BasicSpecParameter.java  |  5 +-
 4 files changed, 57 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f607990f/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java
b/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java
index 51eacee..dd65a44 100644
--- a/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java
+++ b/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java
@@ -155,10 +155,14 @@ public abstract class AbstractBrooklynObjectSpec<T,SpecT extends
AbstractBrookly
     @Beta
     public SpecT parametersAdd(List<? extends SpecParameter<?>> parameters) {
         // parameters follows immutable pattern, unlike the other fields
-        Set<SpecParameter<?>> params = MutableSet.<SpecParameter<?>>copyOf(this.parameters);
-        params.removeAll(parameters);
-        params.addAll(parameters);
-        this.parameters = ImmutableList.copyOf(params);
+        Set<SpecParameter<?>> params = MutableSet.<SpecParameter<?>>copyOf(parameters);
+        Set<SpecParameter<?>> current = MutableSet.<SpecParameter<?>>copyOf(this.parameters);
+        current.removeAll(params);
+
+        this.parameters = ImmutableList.<SpecParameter<?>>builder()
+                .addAll(params)
+                .addAll(current)
+                .build();
         return self();
     }
     /** replaces parameters with the given */

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f607990f/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterParsingTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterParsingTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterParsingTest.java
index e738b9b..63a16d3 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterParsingTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterParsingTest.java
@@ -69,7 +69,7 @@ public class SpecParameterParsingTest  extends AbstractYamlTest {
                 "      type: integer");
         EntitySpec<?> item = mgmt().getTypeRegistry().createSpec(mgmt().getTypeRegistry().get(itemId),
null, EntitySpec.class);
         List<SpecParameter<?>> inputs = item.getParameters();
-        assertEquals(inputs.size(), 3);
+        assertEquals(inputs.size(), 6);
         SpecParameter<?> firstInput = inputs.get(0);
         assertEquals(firstInput.getLabel(), "simple");
         assertEquals(firstInput.isPinned(), true);
@@ -107,7 +107,7 @@ public class SpecParameterParsingTest  extends AbstractYamlTest {
                 "      type: " + OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY);
         AbstractBrooklynObjectSpec<?,?> spec = createSpec(itemId);
         List<SpecParameter<?>> inputs = spec.getParameters();
-        assertEquals(inputs.size(), 1);
+        assertEquals(inputs.size(), 4);
         SpecParameter<?> firstInput = inputs.get(0);
         assertEquals(firstInput.getLabel(), "simple");
         assertTrue(firstInput.isPinned());

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f607990f/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterUnwrappingTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterUnwrappingTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterUnwrappingTest.java
index 77db2d5..3d46058 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterUnwrappingTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterUnwrappingTest.java
@@ -31,6 +31,7 @@ import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
 import com.google.common.base.Optional;
+import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
@@ -107,7 +108,7 @@ public class SpecParameterUnwrappingTest extends AbstractYamlTest {
         SpecParameter<String> SIMPLE_PARAM = new BasicSpecParameter<>("simple",
true, SIMPLE_CONFIG);
         CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, TEST_VERSION);
         AbstractBrooklynObjectSpec<?,?> spec = createSpec(item);
-        assertEquals(ImmutableSet.copyOf(spec.getParameters()), ImmutableList.of(SIMPLE_PARAM));
+        assertTrue(Iterables.tryFind(spec.getParameters(), Predicates.<SpecParameter<?>>equalTo(SIMPLE_PARAM)).isPresent());
     }
 
     @Test(dataProvider = "brooklynTypes")
@@ -141,7 +142,7 @@ public class SpecParameterUnwrappingTest extends AbstractYamlTest {
         CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, TEST_VERSION);
         AbstractBrooklynObjectSpec<?,?> spec = createSpec(item);
         List<SpecParameter<?>> params = spec.getParameters();
-        assertEquals(params.size(), 1);
+        assertEquals(params.size(), 4);
         assertTrue(Iterables.tryFind(params, nameEqualTo("simple")).isPresent());
     }
 
@@ -164,7 +165,17 @@ public class SpecParameterUnwrappingTest extends AbstractYamlTest {
         CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, TEST_VERSION);
         AbstractBrooklynObjectSpec<?,?> spec = createSpec(item);
         List<SpecParameter<?>> params = spec.getParameters();
-        assertEquals(params.size(), 1);
+        switch (type.getSimpleName()) {
+            case "ConfigEntityForTest":
+                assertEquals(params.size(), 3);
+                break;
+            case "ConfigPolicyForTest":
+                assertEquals(params.size(), 2);
+                break;
+            case "ConfigLocationForTest":
+                assertEquals(params.size(), 7);
+                break;
+        }
         assertTrue(Iterables.tryFind(params, nameEqualTo("simple")).isPresent());
         assertTrue(Iterables.tryFind(params, labelEqualTo("simple")).isPresent());
     }
@@ -190,7 +201,17 @@ public class SpecParameterUnwrappingTest extends AbstractYamlTest {
         CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, TEST_VERSION);
         AbstractBrooklynObjectSpec<?,?> spec = createSpec(item);
         List<SpecParameter<?>> params = spec.getParameters();
-        assertEquals(params.size(), 2);
+        switch (type.getSimpleName()) {
+            case "ConfigEntityForTest":
+                assertEquals(params.size(), 4);
+                break;
+            case "ConfigPolicyForTest":
+                assertEquals(params.size(), 3);
+                break;
+            case "ConfigLocationForTest":
+                assertEquals(params.size(), 8);
+                break;
+        }
         assertTrue(Iterables.tryFind(params, nameEqualTo("simple")).isPresent());
         assertTrue(Iterables.tryFind(params, nameEqualTo("override")).isPresent());
     }
@@ -217,7 +238,17 @@ public class SpecParameterUnwrappingTest extends AbstractYamlTest {
         CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, TEST_VERSION);
         AbstractBrooklynObjectSpec<?,?> spec = createSpec(item);
         List<SpecParameter<?>> params = spec.getParameters();
-        assertEquals(params.size(), 1);
+        switch (type.getSimpleName()) {
+            case "ConfigEntityForTest":
+                assertEquals(params.size(), 4);
+                break;
+            case "ConfigPolicyForTest":
+                assertEquals(params.size(), 3);
+                break;
+            case "ConfigLocationForTest":
+                assertEquals(params.size(), 8);
+                break;
+        }
         assertTrue(Iterables.tryFind(params, nameEqualTo("simple")).isPresent());
         assertTrue(Iterables.tryFind(params, labelEqualTo("override")).isPresent());
     }
@@ -271,7 +302,7 @@ public class SpecParameterUnwrappingTest extends AbstractYamlTest {
         CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, TEST_VERSION);
         AbstractBrooklynObjectSpec<?,?> spec = createSpec(item);
         List<SpecParameter<?>> params = spec.getParameters();
-        assertEquals(params.size(), 1);
+        assertEquals(params.size(), 3);
         assertTrue(Iterables.tryFind(params, nameEqualTo("simple")).isPresent());
         Optional<ConfigKey<?>> config = Iterables.tryFind(spec.getConfig().keySet(),
ConfigPredicates.nameEqualTo("simple"));
         assertTrue(config.isPresent());
@@ -326,7 +357,7 @@ public class SpecParameterUnwrappingTest extends AbstractYamlTest {
         EntitySpec<?> parentSpec = (EntitySpec<?>) catalog.createSpec((CatalogItem)item);
         EntitySpec<?> spec = parentSpec.getChildren().get(0);
         List<SpecParameter<?>> params = spec.getParameters();
-        assertEquals(params.size(), 1);
+        assertEquals(params.size(), 3);
         assertTrue(Iterables.tryFind(params, nameEqualTo("simple")).isPresent());
         assertTrue(Iterables.tryFind(params, labelEqualTo("simple")).isPresent());
     }
@@ -347,7 +378,7 @@ public class SpecParameterUnwrappingTest extends AbstractYamlTest {
                 "services:",
                 "- type: " + ver(SYMBOLIC_NAME));
         List<SpecParameter<?>> params = spec.getParameters();
-        assertEquals(params.size(), 1);
+        assertEquals(params.size(), 4);
         assertTrue(Iterables.tryFind(params, nameEqualTo("simple")).isPresent());
         assertTrue(Iterables.tryFind(params, labelEqualTo("simple")).isPresent());
     }
@@ -369,7 +400,7 @@ public class SpecParameterUnwrappingTest extends AbstractYamlTest {
                 "services:",
                 "- type: " + ver(SYMBOLIC_NAME));
         List<SpecParameter<?>> params = spec.getParameters();
-        assertEquals(params.size(), 1);
+        assertEquals(params.size(), 4);
         assertTrue(Iterables.tryFind(params, nameEqualTo("simple")).isPresent());
         assertTrue(Iterables.tryFind(params, labelEqualTo("simple")).isPresent());
     }
@@ -391,7 +422,7 @@ public class SpecParameterUnwrappingTest extends AbstractYamlTest {
                 "services:",
                 "- type: " + ver(SYMBOLIC_NAME));
         List<SpecParameter<?>> params = spec.getParameters();
-        assertEquals(params.size(), 1);
+        assertEquals(params.size(), 4);
         assertTrue(Iterables.tryFind(params, nameEqualTo("simple")).isPresent());
         assertTrue(Iterables.tryFind(params, labelEqualTo("simple")).isPresent());
     }
@@ -506,7 +537,7 @@ public class SpecParameterUnwrappingTest extends AbstractYamlTest {
         CatalogItem<?, ?> item = catalog.getCatalogItem(ConfigEntityForTest.class.getSimpleName()
+ "WithParams", TEST_VERSION);
         AbstractBrooklynObjectSpec<?,?> spec = createSpec(item);
         List<SpecParameter<?>> params = spec.getParameters();
-        assertEquals(params.size(), 1);
+        assertEquals(params.size(), 3);
         assertTrue(Iterables.tryFind(params, nameEqualTo("num")).isPresent());
 
         Application app = (Application) createAndStartApplication(
@@ -537,7 +568,7 @@ public class SpecParameterUnwrappingTest extends AbstractYamlTest {
                 "services:",
                 "- type: " + BasicApplication.class.getName());
         List<SpecParameter<?>> inputs = spec.getParameters();
-        assertEquals(inputs.size(), 1);
+        assertEquals(inputs.size(), 4);
         SpecParameter<?> firstInput = inputs.get(0);
         assertEquals(firstInput.getLabel(), "simple");
     }
@@ -550,7 +581,7 @@ public class SpecParameterUnwrappingTest extends AbstractYamlTest {
                 "  brooklyn.parameters:",
                 "  - simple");
         List<SpecParameter<?>> inputs = spec.getParameters();
-        assertEquals(inputs.size(), 1);
+        assertEquals(inputs.size(), 4);
         SpecParameter<?> firstInput = inputs.get(0);
         assertEquals(firstInput.getLabel(), "simple");
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f607990f/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java b/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
index 3ec9469..e525fc6 100644
--- a/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
+++ b/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
@@ -390,10 +390,11 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
      * @see EntitySpec#parameters(List)
      */
     public static void addParameters(AbstractBrooklynObjectSpec<?, ?> spec, List<?
extends SpecParameter<?>> explicitParams, BrooklynClassLoadingContext loader) {
+        if (spec.getParameters().isEmpty()) {
+            spec.parametersAdd(BasicSpecParameter.fromSpec(loader.getManagementContext(),
spec));
+        }
         if (explicitParams.size() > 0) {
             spec.parametersAdd(explicitParams);
-        } else {
-            spec.parametersAdd(BasicSpecParameter.fromSpec(loader.getManagementContext(),
spec));
         }
     }
 


Mime
View raw message