You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by aledsage <gi...@git.apache.org> on 2016/11/08 16:01:43 UTC
[GitHub] brooklyn-server pull request #417: BROOKLYN-381: support nested DSL for $bro...
GitHub user aledsage opened a pull request:
https://github.com/apache/brooklyn-server/pull/417
BROOKLYN-381: support nested DSL for $brooklyn:entity()
Note this builds on https://github.com/apache/brooklyn-server/pull/416; please review + merge that PR first. I'll then rebase so the initial commits disappear.
@googlielmo you'll be interested in this.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/aledsage/brooklyn-server feature/dsl-entity-nested-dsl
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/brooklyn-server/pull/417.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #417
----
----
---
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.
---
[GitHub] brooklyn-server pull request #417: BROOKLYN-381: support nested DSL for $bro...
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/417#discussion_r87578030
--- 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)
--- End diff --
For the `false` case would make more sense to skip `if (timeout == null) timeout = ValueResolver.NON_BLOCKING_WAIT;` in the method.
---
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.
---
[GitHub] brooklyn-server issue #417: BROOKLYN-381: support nested DSL for $brooklyn:e...
Posted by googlielmo <gi...@git.apache.org>.
Github user googlielmo commented on the issue:
https://github.com/apache/brooklyn-server/pull/417
Paired with @aledsage when doing this. LGTM.
---
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.
---
[GitHub] brooklyn-server pull request #417: BROOKLYN-381: support nested DSL for $bro...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/brooklyn-server/pull/417
---
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.
---
[GitHub] brooklyn-server pull request #417: BROOKLYN-381: support nested DSL for $bro...
Posted by neykov <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] brooklyn-server pull request #417: BROOKLYN-381: support nested DSL for $bro...
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/417#discussion_r87578200
--- 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
--- End diff --
typo `passes`
---
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.
---
[GitHub] brooklyn-server issue #417: BROOKLYN-381: support nested DSL for $brooklyn:e...
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on the issue:
https://github.com/apache/brooklyn-server/pull/417
LGTM, minor comments only.
---
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.
---
[GitHub] brooklyn-server issue #417: BROOKLYN-381: support nested DSL for $brooklyn:e...
Posted by tbouron <gi...@git.apache.org>.
Github user tbouron commented on the issue:
https://github.com/apache/brooklyn-server/pull/417
I'm not really familiar with the code but LGTM. Unit test pass and I tested it with https://github.com/brooklyncentral/brooklyn-riak-cluster/pull/1
---
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.
---
[GitHub] brooklyn-server pull request #417: BROOKLYN-381: support nested DSL for $bro...
Posted by neykov <gi...@git.apache.org>.
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.
---
[GitHub] brooklyn-server issue #417: BROOKLYN-381: support nested DSL for $brooklyn:e...
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the issue:
https://github.com/apache/brooklyn-server/pull/417
@neykov sorry, I missed your comments before merging! I'll look through those, and address them in a subsequent pull request.
---
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.
---
[GitHub] brooklyn-server pull request #417: BROOKLYN-381: support nested DSL for $bro...
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/417#discussion_r87578148
--- 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)
--- End diff --
If not `immediate` should it block indefinitely? Sounds like it.
---
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.
---
[GitHub] brooklyn-server pull request #417: BROOKLYN-381: support nested DSL for $bro...
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/417#discussion_r87578994
--- 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)
--- End diff --
I see now you already changed the implementation.
---
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.
---
[GitHub] brooklyn-server issue #417: BROOKLYN-381: support nested DSL for $brooklyn:e...
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the issue:
https://github.com/apache/brooklyn-server/pull/417
Thanks @tbouron @googlielmo - merging now.
---
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.
---