You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2016/11/10 14:34:18 UTC
[1/2] brooklyn-server git commit: Add ConfigParametersYamlTest cases
for top-level params
Repository: brooklyn-server
Updated Branches:
refs/heads/master a8d81ed58 -> 691283817
Add ConfigParametersYamlTest cases for top-level params
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/4f7dbabe
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/4f7dbabe
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/4f7dbabe
Branch: refs/heads/master
Commit: 4f7dbabe705516fc12797cc60e2fa35302dab638
Parents: 7d9fe81
Author: Aled Sage <al...@gmail.com>
Authored: Thu Nov 3 11:22:33 2016 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Thu Nov 3 11:22:33 2016 +0000
----------------------------------------------------------------------
.../camp/brooklyn/ConfigParametersYamlTest.java | 168 ++++++++++++++++++-
.../brooklyn/core/test/entity/TestEntity.java | 8 +-
.../core/test/entity/TestEntityImpl.java | 3 +
3 files changed, 169 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4f7dbabe/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
index c5f6652..47ba5ec 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
@@ -26,29 +26,31 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Iterables;
-
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.location.PortRange;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess;
import org.apache.brooklyn.entity.stock.BasicApplication;
+import org.apache.brooklyn.location.ssh.SshMachineLocation;
import org.apache.brooklyn.test.Asserts;
import org.apache.brooklyn.util.collections.MutableList;
import org.apache.brooklyn.util.core.internal.ssh.ExecCmdAsserts;
import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool;
import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool.ExecCmd;
import org.apache.brooklyn.util.time.Duration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
public class ConfigParametersYamlTest extends AbstractYamlTest {
@SuppressWarnings("unused")
@@ -61,6 +63,16 @@ public class ConfigParametersYamlTest extends AbstractYamlTest {
RecordingSshTool.clear();
}
+ @AfterMethod(alwaysRun=true)
+ @Override
+ public void tearDown() throws Exception {
+ try {
+ super.tearDown();
+ } finally {
+ RecordingSshTool.clear();
+ }
+ }
+
@Test
public void testConfigParametersListedInType() throws Exception {
addCatalogItems(
@@ -96,6 +108,80 @@ public class ConfigParametersYamlTest extends AbstractYamlTest {
assertEquals(entity.config().get(key), ImmutableMap.of("myDefaultKey", "myDefaultVal"));
}
+ /**
+ * See comment in testConfigParametersAtRootListedInTemplateSingleEntity for why we have two
+ * Note that (surprisingly!) it's very important that there are two entities listed under
+ * "services". If there is just one, then the BasicApplication created to wrap it will not
+ * have the key. Instead, the single child will have the key. This is because the top-level
+ * app is considered "uninteresting" as it is only there to wrap a non-app entity.
+ *
+ * @see {@link #testConfigParametersAtRootListedInTemplateSingleEntity()}
+ */
+ @Test
+ public void testConfigParametersAtRootListedInTemplateApp() throws Exception {
+
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " itemType: template",
+ " items:",
+ " - id: template-with-top-level-params",
+ " item:",
+ " brooklyn.parameters:",
+ " - name: test.parameter",
+ " description: myDescription",
+ " type: String",
+ " default: myDefaultParamVal",
+ " services:",
+ " - type: "+TestEntity.class.getName(),
+ " - type: "+TestEntity.class.getName()
+ );
+ String yaml = Joiner.on("\n").join(
+ "services:",
+ "- type: template-with-top-level-params");
+
+ Entity app = createStartWaitAndLogApplication(yaml);
+
+ ConfigKey<?> key = app.getEntityType().getConfigKey("test.parameter");
+ assertNotNull(key, "No key 'test.parameter'; keys="+app.getEntityType().getConfigKeys());
+ assertEquals(key.getDescription(), "myDescription");
+ assertEquals(key.getType(), String.class);
+ assertEquals(key.getDefaultValue(), "myDefaultParamVal");
+ }
+
+ /**
+ * See comment in {@link #testConfigParametersAtRootListedInTemplateApp()} for why the key
+ * is on the child entity rather than the top-level app!
+ */
+ @Test
+ public void testConfigParametersAtRootListedInTemplateSingleEntity() throws Exception {
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " itemType: template",
+ " items:",
+ " - id: template-with-top-level-params",
+ " item:",
+ " brooklyn.parameters:",
+ " - name: test.parameter",
+ " description: myDescription",
+ " type: String",
+ " default: myDefaultParamVal",
+ " services:",
+ " - type: "+TestEntity.class.getName()
+ );
+ String yaml = Joiner.on("\n").join(
+ "services:",
+ "- type: template-with-top-level-params");
+
+ Entity app = createStartWaitAndLogApplication(yaml);
+ TestEntity entity = (TestEntity) Iterables.getOnlyElement(app.getChildren());
+
+ ConfigKey<?> key = entity.getEntityType().getConfigKey("test.parameter");
+ assertNotNull(key, "No key 'test.parameter'; keys="+entity.getEntityType().getConfigKeys());
+ assertEquals(key.getDescription(), "myDescription");
+ assertEquals(key.getType(), String.class);
+ assertEquals(key.getDefaultValue(), "myDefaultParamVal");
+ }
+
@Test
public void testConfigParameterDefault() throws Exception {
addCatalogItems(
@@ -225,6 +311,70 @@ public class ConfigParametersYamlTest extends AbstractYamlTest {
assertEquals(entity.config().get(ConfigKeys.newStringConfigKey("my.sub.key")), "myDefaultVal");
}
+ @Test
+ public void testChildUsesDefaultsFromParent() throws Exception {
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " itemType: template",
+ " items:",
+ " - id: template-with-top-level-params",
+ " item:",
+ " brooklyn.parameters:",
+ " - name: test.parameter",
+ " description: myDescription",
+ " type: String",
+ " default: myDefaultParamVal",
+ " services:",
+ " - type: "+TestEntity.class.getName(),
+ " brooklyn.config:",
+ " " + TestEntity.ATTRIBUTE_AND_CONF_STRING.getName() + ": $brooklyn:config(\"test.parameter\")"
+ );
+ String yaml = Joiner.on("\n").join(
+ "services:",
+ "- type: template-with-top-level-params");
+
+ Entity app = createStartWaitAndLogApplication(yaml);
+ TestEntity entity = (TestEntity) Iterables.getOnlyElement(app.getChildren());
+ assertEquals(entity.sensors().get(TestEntity.ATTRIBUTE_AND_CONF_STRING), "myDefaultParamVal");
+ }
+
+ @Test
+ public void testChildSoftwareProcessUsesDefaultsFromParent() throws Exception {
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " itemType: template",
+ " items:",
+ " - id: template-with-top-level-params",
+ " item:",
+ " brooklyn.parameters:",
+ " - name: test.parameter",
+ " description: myDescription",
+ " type: String",
+ " default: myDefaultParamVal",
+ " services:",
+ " - type: "+VanillaSoftwareProcess.class.getName(),
+ " sshMonitoring.enabled: false",
+ " " + BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION.getName() + ": true",
+ " shell.env:",
+ " TEST: $brooklyn:config(\"test.parameter\")",
+ " launch.command: |",
+ " true",
+ " checkRunning.command: |",
+ " true"
+ );
+ String yaml = Joiner.on("\n").join(
+ "location:",
+ " localhost:",
+ " " + SshMachineLocation.SSH_TOOL_CLASS.getName() + ": " + RecordingSshTool.class.getName(),
+ "services:",
+ "- type: template-with-top-level-params");
+
+ createStartWaitAndLogApplication(yaml);
+
+ Map<?, ?> env = RecordingSshTool.getLastExecCmd().env;
+ assertEquals(env.get("TEST"), "myDefaultParamVal", "env="+env);
+ }
+
// TODO: fails; it presumably gets the config key defined in java, rather than the brooklyn.parameters key
// See https://issues.apache.org/jira/browse/BROOKLYN-328
@Test(groups={"WIP", "Broken"})
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4f7dbabe/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntity.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntity.java b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntity.java
index 71e84fe..0f2c493 100644
--- a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntity.java
+++ b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntity.java
@@ -41,6 +41,7 @@ import org.apache.brooklyn.core.entity.Attributes;
import org.apache.brooklyn.core.entity.EntityInternal;
import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
import org.apache.brooklyn.core.entity.trait.Startable;
+import org.apache.brooklyn.core.sensor.AttributeSensorAndConfigKey;
import org.apache.brooklyn.core.sensor.BasicNotificationSensor;
import org.apache.brooklyn.core.sensor.Sensors;
import org.apache.brooklyn.util.core.flags.SetFromFlag;
@@ -70,7 +71,12 @@ public interface TestEntity extends Entity, Startable, EntityLocal, EntityIntern
public static final SetConfigKey<Object> CONF_SET_OBJ_THING = new SetConfigKey<Object>(Object.class, "test.confSetObjThing", "Configuration key that's a set thing, of objects");
public static final BasicConfigKey<Object> CONF_OBJECT = new BasicConfigKey<Object>(Object.class, "test.confObject", "Configuration key that's an object");
public static final ConfigKey<EntitySpec<? extends Entity>> CHILD_SPEC = ConfigKeys.newConfigKey(new TypeToken<EntitySpec<? extends Entity>>() {}, "test.childSpec", "Spec to be used for creating children");
-
+
+ public static final AttributeSensorAndConfigKey<String, String> ATTRIBUTE_AND_CONF_STRING = ConfigKeys.newStringSensorAndConfigKey(
+ "test.attributeAndConfString",
+ "Attribute and config key",
+ "defaultval");
+
public static final AttributeSensor<Integer> SEQUENCE = Sensors.newIntegerSensor("test.sequence", "Test Sequence");
public static final AttributeSensor<String> NAME = Sensors.newStringSensor("test.name", "Test name");
public static final BasicNotificationSensor<Integer> MY_NOTIF = new BasicNotificationSensor<Integer>(Integer.class, "test.myNotif", "Test notification");
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4f7dbabe/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityImpl.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityImpl.java b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityImpl.java
index 77d4672..a17bce3 100644
--- a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityImpl.java
+++ b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestEntityImpl.java
@@ -32,6 +32,7 @@ import org.apache.brooklyn.api.location.Location;
import org.apache.brooklyn.core.entity.AbstractEntity;
import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic;
+import org.apache.brooklyn.core.feed.ConfigToAttributes;
import org.apache.brooklyn.util.collections.MutableMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -120,6 +121,8 @@ public class TestEntityImpl extends AbstractEntity implements TestEntity {
@Override
public void start(Collection<? extends Location> locs) {
+ ConfigToAttributes.apply(this);
+
LOG.trace("Starting {}", this);
callHistory.add("start");
ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING);
[2/2] brooklyn-server git commit: This closes #401
Posted by al...@apache.org.
This closes #401
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/69128381
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/69128381
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/69128381
Branch: refs/heads/master
Commit: 691283817f4410cdcfeab1f9f0d63a897ce59db7
Parents: a8d81ed 4f7dbab
Author: Aled Sage <al...@gmail.com>
Authored: Thu Nov 10 14:33:56 2016 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Thu Nov 10 14:33:56 2016 +0000
----------------------------------------------------------------------
.../camp/brooklyn/ConfigParametersYamlTest.java | 168 ++++++++++++++++++-
.../brooklyn/core/test/entity/TestEntity.java | 8 +-
.../core/test/entity/TestEntityImpl.java | 3 +
3 files changed, 169 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/69128381/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
----------------------------------------------------------------------