[ https://issues.apache.org/jira/browse/BROOKLYN-565?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16264592#comment-16264592 ]
Aled Sage commented on BROOKLYN-565: ------------------------------------ My attempted fix was to do a deep inspection of the {{$brooklyn:object}} to see if it contained any dsl (i.e. any {{DeferredSupplier}}s. If it did, then don't construct the object immediately and instead return a deferred {{DslObject}}. Unfortunately that broke the test {{EnrichersYamlTest.testWithTransformerValueFunctionUsingDsl}}, which demonstrates a pattern used in some blueprints out in the wild. For example, something like: {noformat} brooklyn.enrichers: - type: org.apache.brooklyn.enricher.stock.Transformer brooklyn.config: enricher.sourceSensor: $brooklyn:sensor("service.status") enricher.targetSensor: $brooklyn:sensor("master.registrationDetails") enricher.transformation: $brooklyn:object: type: com.google.common.base.Functions factoryMethod.name: forMap factoryMethod.args: - "MASTER": $brooklyn:attributeWhenReady("registrationDetails") - "not master" {noformat} Therefore reverting the fix. > brooklyn:object with nested DSL inside list is not resolved > ----------------------------------------------------------- > > Key: BROOKLYN-565 > URL: https://issues.apache.org/jira/browse/BROOKLYN-565 > Project: Brooklyn > Issue Type: Bug > Reporter: Aled Sage > > When using {{$brooklyn:object}} with a nested DSL expression that is > contained within a list, it does not resolve the nested DSL expression. > This is because it thinks that deferred-evaluation is not necessary. It > constructs the object immediately - we end up with a DSL object in the list > rather than the resolved value. > The workaround is to include {{deferred: true}} inside the brooklyn object. > The problem does not happen if there are any other top-level values in > {{brooklyn.fields}} that are DSL expressions (it realises then that it must > defer the evaluation). > This is demonstrated by adding the following tests to {{ObjectsYamlTest}}: > {noformat} > @Test > public void testFieldOfTypeListAsDeferredSuppliersExplicitlyDeferred() > throws Exception { > // Using explicit `deferred: true` > Entity testEntity = setupAndCheckTestEntityInBasicYamlWith( > " brooklyn.config:", > " mystring: myval", > " myint: 123", > " test.confObject:", > " $brooklyn:object:", > " type: "+ObjectsYamlTest.class.getName()+"$TestObject", > " deferred: true", > " object.fields:", > " list: ", > " - $brooklyn:config(\"mystring\")"); > TestObject testObject = (TestObject) > testEntity.getConfig(TestEntity.CONF_OBJECT); > Assert.assertEquals(testObject.getList(), ImmutableList.of("myval")); > } > > // Fails if don't include `deferred: true` > // see {@link #testFieldOfTypeListAsDeferredSuppliersExplicitlyDeferred()} > @Test(groups="Broken") > public void testFieldOfTypeListAsDeferredSuppliers() throws Exception { > // should defer evaluation automatically, and resolve config > Entity testEntity = setupAndCheckTestEntityInBasicYamlWith( > " brooklyn.config:", > " mystring: myval", > " myint: 123", > " test.confObject:", > " $brooklyn:object:", > " type: "+ObjectsYamlTest.class.getName()+"$TestObject", > " object.fields:", > " list: ", > " - $brooklyn:config(\"mystring\")"); > TestObject testObject = (TestObject) > testEntity.getConfig(TestEntity.CONF_OBJECT); > Assert.assertEquals(testObject.getList(), ImmutableList.of("myval")); > } > {noformat} -- This message was sent by Atlassian JIRA (v6.4.14#64029)