You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ge...@apache.org on 2017/07/31 11:52:20 UTC
[1/2] brooklyn-server git commit: Support DSL in template options in
provisioning properties
Repository: brooklyn-server
Updated Branches:
refs/heads/master 840562651 -> 2bad5261a
Support DSL in template options in provisioning properties
At the moment it's not possible to specify DSL in template
options - for example you can't do
- type: some-type-publishing-subnet-id
id: ent1
- type: some-service
id: service
brooklyn.config:
provisioning.properties:
templateOptions:
subnetId: $brooklyn:entity("ent1").attributeWhenReady("subnet.id")
This adds support in TemplateOptionsOption for resolving the values supplied
for the options. This allows the approach in the blueprint above to be used.
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/676b50fe
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/676b50fe
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/676b50fe
Branch: refs/heads/master
Commit: 676b50fe0f6bf21f59fcbd185ee8e47a25cdd4e1
Parents: 8405626
Author: Geoff Macartney <ge...@cloudsoftcorp.com>
Authored: Thu Jul 27 17:08:29 2017 +0100
Committer: Geoff Macartney <ge...@cloudsoftcorp.com>
Committed: Mon Jul 31 12:46:09 2017 +0100
----------------------------------------------------------------------
...loudsCustomizerInstantiationYamlDslTest.java | 17 ++-
.../JcloudsTemplateOptionsYamlAwsTest.java | 129 +++++++++++++++++++
.../JcloudsTemplateOptionsYamlTest.java | 26 ++--
.../customize/TemplateOptionsOption.java | 30 ++++-
4 files changed, 180 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/676b50fe/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsCustomizerInstantiationYamlDslTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsCustomizerInstantiationYamlDslTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsCustomizerInstantiationYamlDslTest.java
index 1c6df9f..d3c9851 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsCustomizerInstantiationYamlDslTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsCustomizerInstantiationYamlDslTest.java
@@ -24,7 +24,10 @@ import static org.testng.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;
+import java.util.NoSuchElementException;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import org.apache.brooklyn.api.entity.Application;
import org.apache.brooklyn.api.entity.Entity;
@@ -48,6 +51,7 @@ import org.testng.annotations.Test;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
/**
@@ -141,6 +145,7 @@ public class JcloudsCustomizerInstantiationYamlDslTest extends AbstractJcloudsSt
assertEquals(expected.size(), 0);
}
+
public static class RecordingLocationCustomizer extends BasicJcloudsLocationCustomizer {
public static final List<CallParams> calls = Lists.newCopyOnWriteArrayList();
@@ -154,7 +159,17 @@ public class JcloudsCustomizerInstantiationYamlDslTest extends AbstractJcloudsSt
public void setEnabled(Boolean val) {
this.enabled = val;
}
-
+
+ public static TemplateOptions findTemplateOptionsInCustomizerArgs() {
+ for (CallParams call : calls) {
+ Optional<?> templateOptions = Iterables.tryFind(call.args, Predicates.instanceOf(TemplateOptions.class));
+ if (templateOptions.isPresent()) {
+ return (TemplateOptions) templateOptions.get();
+ }
+ }
+ throw new NoSuchElementException();
+ }
+
@Override
public void customize(JcloudsLocation location, ComputeService computeService, TemplateBuilder templateBuilder) {
if (Boolean.TRUE.equals(enabled)) {
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/676b50fe/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsTemplateOptionsYamlAwsTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsTemplateOptionsYamlAwsTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsTemplateOptionsYamlAwsTest.java
new file mode 100644
index 0000000..79f2e96
--- /dev/null
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsTemplateOptionsYamlAwsTest.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.camp.brooklyn;
+
+import static org.apache.brooklyn.camp.brooklyn.JcloudsCustomizerInstantiationYamlDslTest
+ .RecordingLocationCustomizer.findTemplateOptionsInCustomizerArgs;
+import static org.apache.brooklyn.test.LogWatcher.EventPredicates.containsMessage;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import org.apache.brooklyn.api.entity.Application;
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.camp.brooklyn.JcloudsCustomizerInstantiationYamlDslTest.RecordingLocationCustomizer;
+import org.apache.brooklyn.camp.brooklyn.spi.creation.CampTypePlanTransformer;
+import org.apache.brooklyn.core.entity.trait.Startable;
+import org.apache.brooklyn.core.typereg.RegisteredTypeLoadingContexts;
+import org.apache.brooklyn.entity.machine.MachineEntity;
+import org.apache.brooklyn.entity.stock.BasicEntity;
+import org.apache.brooklyn.location.jclouds.templates.customize.TemplateOptionsOption;
+import org.apache.brooklyn.test.LogWatcher;
+import org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions;
+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.base.Predicates;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * Tests that jcouds TemplateOptions are constructed properly from yaml blueprints.
+ */
+@Test
+public class JcloudsTemplateOptionsYamlAwsTest extends AbstractJcloudsStubYamlTest {
+
+ @BeforeMethod(alwaysRun=true)
+ @Override
+ public void setUp() throws Exception {
+ RecordingLocationCustomizer.clear();
+ super.setUp();
+ }
+
+ @AfterMethod(alwaysRun=true)
+ @Override
+ public void tearDown() throws Exception {
+ try {
+ super.tearDown();
+ } finally {
+ RecordingLocationCustomizer.clear();
+ }
+ }
+
+ @Override
+ protected String getLocationSpec() {
+ return "jclouds:aws-ec2:us-east-1";
+ }
+
+ @Test
+ public void testDslCanBeUsedInTemplateOptions() throws Exception {
+
+ String subnetValue = "subnet-123456";
+
+ String yaml = Joiner.on("\n").join(
+ "location: " + LOCATION_CATALOG_ID,
+ "services:",
+ " - type: " + BasicEntity.class.getName(),
+ " id: ent1",
+ " brooklyn.config:",
+ " subnet.value: " + subnetValue,
+ " - type: " + MachineEntity.class.getName(),
+ " brooklyn.config:",
+ " onbox.base.dir.skipResolution: true",
+ " sshMonitoring.enabled: false",
+ " metrics.usage.retrieve: false",
+ " enabled: true",
+ " provisioning.properties:",
+ " templateOptions:",
+ " subnetId: $brooklyn:entity(\"ent1\").config(\"subnet.value\")",
+ " customizer:",
+ " $brooklyn:object:",
+ " type: " + RecordingLocationCustomizer.class.getName(),
+ " object.fields:",
+ " enabled: $brooklyn:config(\"enabled\")");
+
+ final String ignoreOption = "Ignoring request to set template option";
+
+ final LogWatcher watcher = new LogWatcher(
+ ImmutableList.of(LoggerFactory.getLogger(TemplateOptionsOption.class).getName()),
+ ch.qos.logback.classic.Level.WARN,
+ Predicates.and(containsMessage(ignoreOption), containsMessage("subnetId")));
+
+ watcher.start();
+ try {
+ EntitySpec<?> spec = managementContext.getTypeRegistry().createSpecFromPlan(
+ CampTypePlanTransformer.FORMAT, yaml,
+ RegisteredTypeLoadingContexts.spec(Application.class), EntitySpec.class);
+ Entity app = managementContext.getEntityManager().createEntity(spec);
+
+ app.invoke(Startable.START, ImmutableMap.<String, Object>of()).get();
+
+ assertTrue(watcher.getEvents().isEmpty(), ignoreOption);
+
+ AWSEC2TemplateOptions options = (AWSEC2TemplateOptions) findTemplateOptionsInCustomizerArgs();
+ assertEquals(options.getSubnetId(), subnetValue);
+ } finally {
+ watcher.close();
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/676b50fe/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsTemplateOptionsYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsTemplateOptionsYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsTemplateOptionsYamlTest.java
index 943266b..7ec9c9f 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsTemplateOptionsYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsTemplateOptionsYamlTest.java
@@ -18,10 +18,10 @@
*/
package org.apache.brooklyn.camp.brooklyn;
+import static org.apache.brooklyn.camp.brooklyn.JcloudsCustomizerInstantiationYamlDslTest
+ .RecordingLocationCustomizer.findTemplateOptionsInCustomizerArgs;
import static org.testng.Assert.assertEquals;
-import java.util.NoSuchElementException;
-
import org.apache.brooklyn.api.entity.Application;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntitySpec;
@@ -30,7 +30,6 @@ import org.apache.brooklyn.camp.brooklyn.spi.creation.CampTypePlanTransformer;
import org.apache.brooklyn.core.entity.trait.Startable;
import org.apache.brooklyn.core.typereg.RegisteredTypeLoadingContexts;
import org.apache.brooklyn.entity.machine.MachineEntity;
-import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions;
import org.jclouds.googlecomputeengine.domain.Instance.ServiceAccount;
import org.testng.annotations.AfterMethod;
@@ -38,11 +37,8 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.google.common.base.Joiner;
-import com.google.common.base.Optional;
-import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Iterables;
/**
* Tests that jcouds TemplateOptions are constructed properly from yaml blueprints.
@@ -96,23 +92,17 @@ public class JcloudsTemplateOptionsYamlTest extends AbstractJcloudsStubYamlTest
" object.fields:",
" enabled: $brooklyn:config(\"enabled\")");
- EntitySpec<?> spec = managementContext.getTypeRegistry().createSpecFromPlan(CampTypePlanTransformer.FORMAT, yaml, RegisteredTypeLoadingContexts.spec(Application.class), EntitySpec.class);
+ EntitySpec<?> spec = managementContext.getTypeRegistry().createSpecFromPlan(
+ CampTypePlanTransformer.FORMAT, yaml,
+ RegisteredTypeLoadingContexts.spec(Application.class), EntitySpec.class);
Entity app = managementContext.getEntityManager().createEntity(spec);
app.invoke(Startable.START, ImmutableMap.<String, Object>of()).get();
- GoogleComputeEngineTemplateOptions options = (GoogleComputeEngineTemplateOptions) findTemplateOptionsInCustomizerArgs();
+ GoogleComputeEngineTemplateOptions options =
+ (GoogleComputeEngineTemplateOptions) findTemplateOptionsInCustomizerArgs();
assertEquals(options.serviceAccounts(), ImmutableList.of(
ServiceAccount.create("myemail", ImmutableList.of("myscope1", "myscope2"))));
}
-
- private TemplateOptions findTemplateOptionsInCustomizerArgs() {
- for (RecordingLocationCustomizer.CallParams call : RecordingLocationCustomizer.calls) {
- Optional<?> templateOptions = Iterables.tryFind(call.args, Predicates.instanceOf(TemplateOptions.class));
- if (templateOptions.isPresent()) {
- return (TemplateOptions) templateOptions.get();
- }
- }
- throw new NoSuchElementException();
- }
+
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/676b50fe/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/templates/customize/TemplateOptionsOption.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/templates/customize/TemplateOptionsOption.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/templates/customize/TemplateOptionsOption.java
index cd26535..c9b0e81 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/templates/customize/TemplateOptionsOption.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/templates/customize/TemplateOptionsOption.java
@@ -20,15 +20,25 @@
package org.apache.brooklyn.location.jclouds.templates.customize;
import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import org.apache.brooklyn.api.mgmt.ExecutionContext;
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.api.mgmt.Task;
+import org.apache.brooklyn.core.entity.EntityInternal;
+import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
+import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
import org.apache.brooklyn.util.core.config.ConfigBag;
import org.apache.brooklyn.util.core.flags.MethodCoercions;
+import org.apache.brooklyn.util.core.task.BasicExecutionContext;
+import org.apache.brooklyn.util.core.task.Tasks;
+import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.guava.Maybe;
import org.jclouds.compute.options.TemplateOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-class TemplateOptionsOption implements TemplateOptionCustomizer {
+public class TemplateOptionsOption implements TemplateOptionCustomizer {
private static final Logger LOG = LoggerFactory.getLogger(TemplateOptionsOption.class);
@Override
@@ -39,8 +49,22 @@ class TemplateOptionsOption implements TemplateOptionCustomizer {
Class<? extends TemplateOptions> clazz = options.getClass();
for (final Map.Entry<String, Object> option : optionsMap.entrySet()) {
- if (option.getValue() != null) {
- Maybe<?> result = MethodCoercions.tryFindAndInvokeBestMatchingMethod(options, option.getKey(), option.getValue());
+ Object optionValue = option.getValue();
+ if (optionValue != null) {
+
+ try {
+ final EntityInternal entity = (EntityInternal) BrooklynTaskTags.getTargetOrContextEntity(Tasks.current());
+ final ExecutionContext exec = (null != entity
+ ? entity.getExecutionContext()
+ : BasicExecutionContext.getCurrentExecutionContext());
+ if (exec != null) {
+ optionValue = Tasks.resolveDeepValue(optionValue, Object.class, exec);
+ }
+ } catch (ExecutionException | InterruptedException e) {
+ Exceptions.propagate(e);
+ }
+
+ Maybe<?> result = MethodCoercions.tryFindAndInvokeBestMatchingMethod(options, option.getKey(), optionValue);
if (result.isAbsent()) {
LOG.warn("Ignoring request to set template option {} because this is not supported by {}", new Object[]{option.getKey(), clazz.getCanonicalName()});
}
[2/2] brooklyn-server git commit: Closes #781
Posted by ge...@apache.org.
Closes #781
Support DSL in template options
At the moment it's not possible to specify DSL in template options - for example you can't do
- type: some-type-publishing-subnet-id
id: ent1
- type: some-service
id: service
brooklyn.config:
provisioning.properties:
templateOptions:
subnetId: $brooklyn:entity("ent1").attributeWhenReady("subnet.id")
see new test [here](https://github.com/geomacy/brooklyn-server/commit/d2f5bf9e0a5038208ff98aedb16795c217d01fc7#diff-99cb6184bb386646b61f6678346ec63bR75).
This adds support in `TemplateOptionsOption` for resolving the values supplied for the options. This allows the approach in the blueprint above to be used.
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/2bad5261
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/2bad5261
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/2bad5261
Branch: refs/heads/master
Commit: 2bad5261a33978826373373134a7be94e5cfecb6
Parents: 8405626 676b50f
Author: Geoff Macartney <ge...@cloudsoftcorp.com>
Authored: Mon Jul 31 12:52:04 2017 +0100
Committer: Geoff Macartney <ge...@cloudsoftcorp.com>
Committed: Mon Jul 31 12:52:04 2017 +0100
----------------------------------------------------------------------
...loudsCustomizerInstantiationYamlDslTest.java | 17 ++-
.../JcloudsTemplateOptionsYamlAwsTest.java | 129 +++++++++++++++++++
.../JcloudsTemplateOptionsYamlTest.java | 26 ++--
.../customize/TemplateOptionsOption.java | 30 ++++-
4 files changed, 180 insertions(+), 22 deletions(-)
----------------------------------------------------------------------