brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neykov <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #417: BROOKLYN-381: support nested DSL for $bro...
Date Fri, 11 Nov 2016 12:03:11 GMT
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/417#discussion_r87578674
  
    --- 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());
    --- End diff --
    
    Already available from `entity()`


---
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.
---

Mime
View raw message