You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by alasdairhodge <gi...@git.apache.org> on 2017/03/08 13:38:17 UTC

[GitHub] brooklyn-server pull request #584: Generalised Entities.waitFor()

GitHub user alasdairhodge opened a pull request:

    https://github.com/apache/brooklyn-server/pull/584

    Generalised Entities.waitFor()

    Provides general-purpose blocking wait on any entity predicate. Example:
    ````
        Entities.waitFor(
            machineEntity,
            EntityPredicates.attributeEqualTo(MACHINE_STATE, MachineState.REBOOTING),
            Duration.FIVE_SECONDS);
    ````

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/alasdairhodge/brooklyn-server generalise-entities-wait

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/brooklyn-server/pull/584.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 #584
    
----
commit 24f4e0b1ac3ed2d463c51b5b2126f0726b44436a
Author: Alasdair Hodge <gi...@alasdairhodge.co.uk>
Date:   2017-03-08T13:21:20Z

    Add Functionals.isSatisfied(subject, predicate)

commit 71727885f174b17b27ef64d1090930084daf3430
Author: Alasdair Hodge <gi...@alasdairhodge.co.uk>
Date:   2017-03-08T13:21:37Z

    Add generalised Entities.waitFor(entity, condition, timeout)

----


---
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 #584: Generalised Entities.waitFor()

Posted by alasdairhodge <gi...@git.apache.org>.
Github user alasdairhodge commented on the issue:

    https://github.com/apache/brooklyn-server/pull/584
  
    Implemented custom service-up predicate with friendly `toString()`.


---
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 #584: Generalised Entities.waitFor()

Posted by geomacy <gi...@git.apache.org>.
Github user geomacy commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/584#discussion_r104918736
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/entity/Entities.java ---
    @@ -1237,25 +1239,32 @@ public static void warnOnIgnoringConfig(Entity entity, ConfigKey<?> key) {
                 log.warn("Ignoring "+key+" set on "+entity+" ("+entity.getConfig(key)+")");
         }
     
    -    /** Waits until {@link Startable#SERVICE_UP} returns true. */
    -    public static void waitForServiceUp(final Entity entity, Duration timeout) {
    -        String description = "Waiting for SERVICE_UP on "+entity;
    -        Tasks.setBlockingDetails(description);
    +    /** Waits until the passed entity satisfies the supplied predicate. */
    +    public static void waitFor(Entity entity, Predicate<Entity> condition, Duration timeout) {
             try {
    -            if (!Repeater.create(description).limitTimeTo(timeout)
    -                    .rethrowException().backoffTo(Duration.ONE_SECOND)
    -                    .until(new Callable<Boolean>() {
    -                        @Override
    -                        public Boolean call() {
    -                            return Boolean.TRUE.equals(entity.getAttribute(Startable.SERVICE_UP));
    -                        }})
    -                    .run()) {
    -                throw new IllegalStateException("Timeout waiting for SERVICE_UP from "+entity);
    +            String description = "Waiting for " + condition + " on " + entity;
    +            Tasks.setBlockingDetails(description);
    +
    +            Repeater repeater = Repeater.create(description)
    +                .until(isSatisfied(entity, condition))
    +                .limitTimeTo(timeout)
    +                .backoffTo(Duration.ONE_SECOND)
    +                .rethrowException();
    +
    +            if (!repeater.run()) {
    +                throw new IllegalStateException("Timeout waiting for " + condition + " on " + entity);
                 }
    +
             } finally {
                 Tasks.resetBlockingDetails();
             }
    -        log.debug("Detected SERVICE_UP for software {}", entity);
    +
    +        log.debug("Detected {} for {}", condition, entity);
    +    }
    +
    +    /** Waits until {@link Startable#SERVICE_UP} returns true. */
    +    public static void waitForServiceUp(final Entity entity, Duration timeout) {
    +        waitFor(entity, attributeEqualTo(Startable.SERVICE_UP, true), timeout);
    --- End diff --
    
    Might be nice to have a specific `serviceUp` predicate with a custom `toString` as the `toString` representation (for use on line 1262 above) for `attributeEqualTo` is a lot more verbose than just "SERVICE_UP".


---
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 #584: Generalised Entities.waitFor()

Posted by geomacy <gi...@git.apache.org>.
Github user geomacy commented on the issue:

    https://github.com/apache/brooklyn-server/pull/584
  
    LGTM, merging.


---
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 #584: Generalised Entities.waitFor()

Posted by alasdairhodge <gi...@git.apache.org>.
Github user alasdairhodge commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/584#discussion_r104919958
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/entity/Entities.java ---
    @@ -1237,25 +1239,32 @@ public static void warnOnIgnoringConfig(Entity entity, ConfigKey<?> key) {
                 log.warn("Ignoring "+key+" set on "+entity+" ("+entity.getConfig(key)+")");
         }
     
    -    /** Waits until {@link Startable#SERVICE_UP} returns true. */
    -    public static void waitForServiceUp(final Entity entity, Duration timeout) {
    -        String description = "Waiting for SERVICE_UP on "+entity;
    -        Tasks.setBlockingDetails(description);
    +    /** Waits until the passed entity satisfies the supplied predicate. */
    +    public static void waitFor(Entity entity, Predicate<Entity> condition, Duration timeout) {
             try {
    -            if (!Repeater.create(description).limitTimeTo(timeout)
    -                    .rethrowException().backoffTo(Duration.ONE_SECOND)
    -                    .until(new Callable<Boolean>() {
    -                        @Override
    -                        public Boolean call() {
    -                            return Boolean.TRUE.equals(entity.getAttribute(Startable.SERVICE_UP));
    -                        }})
    -                    .run()) {
    -                throw new IllegalStateException("Timeout waiting for SERVICE_UP from "+entity);
    +            String description = "Waiting for " + condition + " on " + entity;
    +            Tasks.setBlockingDetails(description);
    +
    +            Repeater repeater = Repeater.create(description)
    +                .until(isSatisfied(entity, condition))
    +                .limitTimeTo(timeout)
    +                .backoffTo(Duration.ONE_SECOND)
    +                .rethrowException();
    +
    +            if (!repeater.run()) {
    +                throw new IllegalStateException("Timeout waiting for " + condition + " on " + entity);
                 }
    +
             } finally {
                 Tasks.resetBlockingDetails();
             }
    -        log.debug("Detected SERVICE_UP for software {}", entity);
    +
    +        log.debug("Detected {} for {}", condition, entity);
    +    }
    +
    +    /** Waits until {@link Startable#SERVICE_UP} returns true. */
    +    public static void waitForServiceUp(final Entity entity, Duration timeout) {
    +        waitFor(entity, attributeEqualTo(Startable.SERVICE_UP, true), timeout);
    --- End diff --
    
    Excellent idea.


---
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 #584: Generalised Entities.waitFor()

Posted by alasdairhodge <gi...@git.apache.org>.
Github user alasdairhodge commented on the issue:

    https://github.com/apache/brooklyn-server/pull/584
  
    Thanks, @geomacy :o)


---
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 #584: Generalised Entities.waitFor()

Posted by alasdairhodge <gi...@git.apache.org>.
Github user alasdairhodge commented on the issue:

    https://github.com/apache/brooklyn-server/pull/584
  
    /cc @geomacy 


---
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 #584: Generalised Entities.waitFor()

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/brooklyn-server/pull/584


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