You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by "Aled Sage (JIRA)" <ji...@apache.org> on 2017/03/23 11:35:41 UTC
[jira] [Commented] (BROOKLYN-458) Cluster can't use transformer to
get "host.name" sensor of "cluster.first.entity"
[ https://issues.apache.org/jira/browse/BROOKLYN-458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15938141#comment-15938141 ]
Aled Sage commented on BROOKLYN-458:
------------------------------------
Below is a workaround for this (which relies on the {{triggerSensors}} on the transformer to recalculate it, and uses an {{Aggregator}} to ensure we populate a triggerSensor when the child gets its {{host.name}} set:
{noformat}
brooklyn.catalog:
version: 0.2-SNAPSHOT
items:
- id: test-cluster
name: test-cluster
item:
type: org.apache.brooklyn.entity.group.DynamicCluster
memberSpec:
$brooklyn:entitySpec:
type: org.apache.brooklyn.entity.software.base.EmptySoftwareProcess
name: "Node"
brooklyn.enrichers:
- type: org.apache.brooklyn.enricher.stock.Aggregator
brooklyn.config:
enricher.aggregating.fromMembers: true
enricher.transformation.untyped: list
enricher.sourceSensor: $brooklyn:sensor("host.name")
enricher.targetSensor: $brooklyn:sensor("members.hostnames")
- type: org.apache.brooklyn.enricher.stock.Transformer
brooklyn.config:
enricher.triggerSensors:
- $brooklyn:sensor("cluster.first.entity")
- $brooklyn:sensor("members.hostnames")
enricher.targetSensor: $brooklyn:sensor("cluster_first_host")
enricher.targetValue:
$brooklyn:formatString:
- "%s"
- $brooklyn:entity($brooklyn:attributeWhenReady("cluster.first.entity")).attributeWhenReady("host.name")
{noformat}
> Cluster can't use transformer to get "host.name" sensor of "cluster.first.entity"
> ---------------------------------------------------------------------------------
>
> Key: BROOKLYN-458
> URL: https://issues.apache.org/jira/browse/BROOKLYN-458
> Project: Brooklyn
> Issue Type: Improvement
> Reporter: Aled Sage
>
> Mike shared the blueprint below (which I've turned into a unit test, against 0.11.0-SNAPSHOT):
> {noformat}
> @Test
> public void testClusterGetsAttributeOfChild() throws Exception {
> String yaml = Joiner.on("\n").join(
> "brooklyn.catalog:",
> " version: 0.2-SNAPSHOT",
> " items:",
> " - id: test-cluster",
> " name: test-cluster",
> " item:",
> " type: org.apache.brooklyn.entity.group.DynamicCluster",
> " memberSpec:",
> " $brooklyn:entitySpec:",
> " type: org.apache.brooklyn.entity.software.base.EmptySoftwareProcess",
> " name: \"Node\"",
> " brooklyn.enrichers:",
> " - type: org.apache.brooklyn.enricher.stock.Transformer",
> " brooklyn.config:",
> " enricher.sourceSensor: $brooklyn:sensor(\"cluster.first.entity\")",
> " enricher.targetSensor: $brooklyn:sensor(\"cluster_first_host\")",
> " enricher.targetValue:",
> " $brooklyn:formatString:",
> " - \"%s\"",
> " - $brooklyn:entity($brooklyn:attributeWhenReady(\"cluster.first.entity\")).attributeWhenReady(\"host.name\")");
> addCatalogItems(yaml);
>
> String appYaml = Joiner.on("\n").join(
> "location: localhost",
> "services:",
> "- type: test-cluster");
>
> Entity app = createAndStartApplication(appYaml);
> Entity cluster = Iterables.getOnlyElement(app.getChildren());
>
> EntityAsserts.assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, true);
> EntityAsserts.assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
> EntityAsserts.assertAttributeEventually(cluster, Sensors.newStringSensor("cluster_first_host"), StringPredicates.isNonBlank());
> }
> {noformat}
> It fails because sensor {{cluster_first_host}} is never set on the cluster entity. This is because the targetValue evaluation is triggered whenever the sourceSensor changes. However, when {{clsuter.first.entity}} is set, that entity does not yet have a {{host.name}}. Therefore the {{attributeWhenReady}} is not yet available. (Under-the-covers, it discovers this by using {{getImmediately}}, and thus returns immediately without blocking).
> Mike tried to work around this by setting the {{producer}} for the transformer enricher, but that led to him hitting https://issues.apache.org/jira/browse/BROOKLYN-457.
> This is not really a bug (but could probably do with improvements in our docs to explain it!).
> We'd like a way to elegantly write this blueprint though (hence marking this as an "improvement").
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)