You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by geomacy <gi...@git.apache.org> on 2017/07/27 17:57:03 UTC
[GitHub] brooklyn-server pull request #781: Support DSL in template options
GitHub user geomacy opened a pull request:
https://github.com/apache/brooklyn-server/pull/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 evaluating options that are tasks (I would have used more explicit DSL related classes but for a circular dependency that would create between `camp-brooklyn` and `brooklyn-locations-jclouds`. This allows the approach in the blueprint above to be used.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/geomacy/brooklyn-server support-dsl-in-template-options
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/brooklyn-server/pull/781.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #781
----
commit d2f5bf9e0a5038208ff98aedb16795c217d01fc7
Author: Geoff Macartney <ge...@cloudsoftcorp.com>
Date: 2017-07-27T16:08:29Z
Add test for DSL in template options.
commit 660a784adfebf20a1058c57e4e56458716102727
Author: Geoff Macartney <ge...@cloudsoftcorp.com>
Date: 2017-07-27T16:08:55Z
Support DSL in template options in provisioning properties
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] brooklyn-server pull request #781: Support DSL in template options
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/781#discussion_r129914806
--- Diff: locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/templates/customize/TemplateOptionsOption.java ---
@@ -39,8 +45,17 @@ public void apply(TemplateOptions options, ConfigBag config, Object v) {
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) {
+
+ if (optionValue instanceof TaskFactory<?>) {
+ final TaskAdaptable<?> taskA = ((TaskFactory<?>) optionValue).newTask();
+ optionValue = getValueFromTask(taskA.asTask());
+ } else if (optionValue instanceof TaskAdaptable<?>) {
+ optionValue = getValueFromTask(((TaskAdaptable<?>) optionValue).asTask());
+ }
+
+ Maybe<?> result = MethodCoercions.tryFindAndInvokeBestMatchingMethod(options, option.getKey(), optionValue);
--- End diff --
Can you use `ValueResolver` instead? For example:
`Tasks.resolveDeepValue(value, Object.class, mgmt.getServerExecutionContext());` (or alternatively the context entity's execution context).
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] brooklyn-server pull request #781: Support DSL in template options
Posted by geomacy <gi...@git.apache.org>.
Github user geomacy commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/781#discussion_r130073414
--- Diff: locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/templates/customize/TemplateOptionsOption.java ---
@@ -39,8 +45,17 @@ public void apply(TemplateOptions options, ConfigBag config, Object v) {
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) {
+
+ if (optionValue instanceof TaskFactory<?>) {
+ final TaskAdaptable<?> taskA = ((TaskFactory<?>) optionValue).newTask();
+ optionValue = getValueFromTask(taskA.asTask());
+ } else if (optionValue instanceof TaskAdaptable<?>) {
+ optionValue = getValueFromTask(((TaskAdaptable<?>) optionValue).asTask());
+ }
+
+ Maybe<?> result = MethodCoercions.tryFindAndInvokeBestMatchingMethod(options, option.getKey(), optionValue);
--- End diff --
ok that's a new commit added now with the `null` replaced with the `getTargetOrContextEntity` context
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] brooklyn-server pull request #781: Support DSL in template options
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/781#discussion_r130329597
--- Diff: locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/templates/customize/TemplateOptionsOption.java ---
@@ -39,8 +49,22 @@ public void apply(TemplateOptions options, ConfigBag config, Object v) {
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) {
--- End diff --
I wonder if there is some way we could log.warn if `exec != null` and if the value is a deferred supplier. But not sure how easy it is to do for the latter (looking at `ValueResolver`, it handles `v instanceof ImmediateSupplier || v instanceof DeferredSupplier || v instanceof TaskFactory || v instanceof TaskAdaptable || v instanceof Task || v instanceof Future`, but it also recursively looks inside iterables and maps.
Therefore maybe just ignore this comment :-(
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] brooklyn-server issue #781: Support DSL in template options
Posted by geomacy <gi...@git.apache.org>.
Github user geomacy commented on the issue:
https://github.com/apache/brooklyn-server/pull/781
Retest this please.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] brooklyn-server pull request #781: Support DSL in template options
Posted by geomacy <gi...@git.apache.org>.
Github user geomacy commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/781#discussion_r129961765
--- Diff: locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/templates/customize/TemplateOptionsOption.java ---
@@ -39,8 +45,17 @@ public void apply(TemplateOptions options, ConfigBag config, Object v) {
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) {
+
+ if (optionValue instanceof TaskFactory<?>) {
+ final TaskAdaptable<?> taskA = ((TaskFactory<?>) optionValue).newTask();
+ optionValue = getValueFromTask(taskA.asTask());
+ } else if (optionValue instanceof TaskAdaptable<?>) {
+ optionValue = getValueFromTask(((TaskAdaptable<?>) optionValue).asTask());
+ }
+
+ Maybe<?> result = MethodCoercions.tryFindAndInvokeBestMatchingMethod(options, option.getKey(), optionValue);
--- End diff --
Ah! Don't know why I didn't think of that. Nicer. I think I can pass null as the context and it will use the current exectution context?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] brooklyn-server pull request #781: Support DSL in template options
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/brooklyn-server/pull/781
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] brooklyn-server issue #781: Support DSL in template options
Posted by geomacy <gi...@git.apache.org>.
Github user geomacy commented on the issue:
https://github.com/apache/brooklyn-server/pull/781
Thanks @aledsage, have updated message per your first comment. Will squash and merge.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] brooklyn-server issue #781: Support DSL in template options
Posted by geomacy <gi...@git.apache.org>.
Github user geomacy commented on the issue:
https://github.com/apache/brooklyn-server/pull/781
Build failure is Jenkins related, I think.
# There is insufficient memory for the Java Runtime Environment to continue.
# Cannot create GC thread. Out of system resources.
Retest this please
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] brooklyn-server pull request #781: Support DSL in template options
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/781#discussion_r130041426
--- Diff: locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/templates/customize/TemplateOptionsOption.java ---
@@ -39,8 +45,17 @@ public void apply(TemplateOptions options, ConfigBag config, Object v) {
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) {
+
+ if (optionValue instanceof TaskFactory<?>) {
+ final TaskAdaptable<?> taskA = ((TaskFactory<?>) optionValue).newTask();
+ optionValue = getValueFromTask(taskA.asTask());
+ } else if (optionValue instanceof TaskAdaptable<?>) {
+ optionValue = getValueFromTask(((TaskAdaptable<?>) optionValue).asTask());
+ }
+
+ Maybe<?> result = MethodCoercions.tryFindAndInvokeBestMatchingMethod(options, option.getKey(), optionValue);
--- End diff --
Don't think you can use `null` here. Seems the thread context is something used around immediate values only. cc @ahgittin.
Looking at the code the canonical usage is with: `((EntityInternal)BrooklynTaskTags.getTargetOrContextEntity(Tasks.current())).getExecutionContext()`.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] brooklyn-server pull request #781: Support DSL in template options
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/781#discussion_r130314354
--- Diff: camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsTemplateOptionsYamlAwsTest.java ---
@@ -0,0 +1,127 @@
+/*
+ * 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.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.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 subnetId because this is not supported";
--- End diff --
Minor point: given this is asserting the absence of the log message, I'd shorten the message we're looking to be more minimal.
With this code, there is too much potential for future false-negatives (e.g. if someone changes the log message to put subnetId in quotes, then this test would always pass, even if the underlying code was broken.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---