[
https://issues.apache.org/jira/browse/BROOKLYN-381?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15656906#comment-15656906
]
ASF GitHub Bot commented on BROOKLYN-381:
-----------------------------------------
Github user neykov commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/417#discussion_r87578456
--- Diff:
camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/DslComponent.java
---
@@ -182,63 +257,112 @@ public Entity call() throws Exception {
throw new IllegalStateException("Unexpected scope
"+scope);
}
- Optional<Entity> result = Iterables.tryFind(entitiesToSearch,
EntityPredicates.configEqualTo(BrooklynCampConstants.PLAN_ID, componentId));
+ String desiredComponentId;
+ if (componentId == null) {
+ if (componentIdSupplier == null) {
+ throw new IllegalArgumentException("No component-id or
component-id supplier, when resolving entity in scope '" + scope + "' wrt " +
entity);
+ }
+
+ Maybe<Object> maybeComponentId =
Tasks.resolving(componentIdSupplier)
+ .as(Object.class)
+ .context(getExecutionContext())
+ .immediately(immediate)
+ .description("Resolving component-id from " +
componentIdSupplier)
+ .getMaybe();
+
+ if (immediate) {
+ if (maybeComponentId.isAbsent()) {
+ return
Maybe.absent(Maybe.getException(maybeComponentId));
+ }
+ }
+
+ // Support being passes an explicit entity via the DSL
+ if (maybeComponentId.get() instanceof Entity) {
+ if (Iterables.contains(entitiesToSearch,
maybeComponentId.get())) {
+ return Maybe.of((Entity)maybeComponentId.get());
+ } else {
+ throw new IllegalStateException("Resolved
component " + maybeComponentId.get() + " is not in scope '" + scope + "' wrt "
+ entity);
+ }
+ }
+
+ desiredComponentId =
TypeCoercions.coerce(maybeComponentId.get(), String.class);
+
+ if (Strings.isBlank(desiredComponentId)) {
+ throw new IllegalStateException("component-id blank,
from " + componentIdSupplier);
+ }
+
+ } else {
+ desiredComponentId = componentId;
+ }
+
+ Optional<Entity> result = Iterables.tryFind(entitiesToSearch,
EntityPredicates.configEqualTo(BrooklynCampConstants.PLAN_ID,
desiredComponentId));
if (result.isPresent()) {
return Maybe.of(result.get());
}
// TODO may want to block and repeat on new entities joining?
- throw new NoSuchElementException("No entity matching id " +
componentId+
+ throw new NoSuchElementException("No entity matching id " +
desiredComponentId+
(scope==Scope.GLOBAL ? "" : ", in scope "+scope+" wrt
"+entity+
(scopeComponent!=null ? " ("+scopeComponent+" from
"+entity()+")" : "")));
- }
+ }
+
+ private ExecutionContext getExecutionContext() {
+ EntityInternal contextEntity = (EntityInternal)
BrooklynTaskTags.getTargetOrContextEntity(Tasks.current());
+ ExecutionContext execContext =
+ (contextEntity != null) ?
contextEntity.getExecutionContext()
+ :
BasicExecutionContext.getCurrentExecutionContext();
--- End diff --
Should never be the case, better throw.
> Support nested DSL in $brooklyn:entity
> --------------------------------------
>
> Key: BROOKLYN-381
> URL: https://issues.apache.org/jira/browse/BROOKLYN-381
> Project: Brooklyn
> Issue Type: Improvement
> Affects Versions: 0.9.0
> Reporter: Aled Sage
>
> When using the yaml DSL to look up values on other entities, it would be
> useful to be able to make this more dynamic by getting the entity id from the
> DSL (e.g. from another attribute).
> For example, a slightly simplified example below - note the DSL for "url", to
> retrieve the URL from an entity whose id is set dynamically on the
> {{TestHttpCall}} entity:
> {noformat}
> services:
> - type: org.apache.brooklyn.entity.nosql.riak.RiakCluster
> id: target-app
> ...
> - type: loop-test-case
> name: "Value replicated on all Riak nodes"
> brooklyn.config:
> target: $brooklyn:component("target-app")
> testSpec:
> $brooklyn:entitySpec:
> type: test-http-status-200
> brooklyn.config:
> url:
> $brooklyn:entity(config("targetId")).attributeWhenReady("main.uri")
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)