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.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---