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 2017/09/19 22:24:39 UTC

[GitHub] brooklyn-server pull request #833: Fix PeriodicEffectorPolicy

GitHub user aledsage opened a pull request:

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

    Fix PeriodicEffectorPolicy

    The `PeriodicEffectorPolicy` rebind test(s) were failing non-deterministically in the jenkins master build, and same for me locally.
    
    This PR makes a bunch of changes to fix those, along with various other improvements to the policy implementations. The config / documented behaviour of the policies should be unaffected by these changes.

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

    $ git pull https://github.com/aledsage/brooklyn-server fix-PeriodicEffectorPolicy

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

    https://github.com/apache/brooklyn-server/pull/833.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 #833
    
----
commit 5ed11a8f44938da27e6964eeecad3e09e25b5b78
Author: Aled Sage <al...@gmail.com>
Date:   2017-09-19T22:16:07Z

    Fix PeriodicEffectorPolicy

----


---

[GitHub] brooklyn-server pull request #833: Fix PeriodicEffectorPolicy

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

    https://github.com/apache/brooklyn-server/pull/833#discussion_r139935476
  
    --- Diff: policy/src/main/java/org/apache/brooklyn/policy/action/AbstractScheduledEffectorPolicy.java ---
    @@ -233,8 +269,8 @@ public synchronized void run() {
                 Object result = entity.invoke(effector, resolved).getUnchecked();
                 LOG.debug("{}: Effector {} returned {}", new Object[] { this, effector.getName(), result });
             } catch (RuntimeInterruptedException rie) {
    -            Thread.interrupted();
    -            // TODO sometimes this seems to hang the executor?
    +            // Gracefully stop
    +            Thread.currentThread().interrupt();
    --- End diff --
    
    Thanks, I couldn't remember the right way to handle this.


---

[GitHub] brooklyn-server pull request #833: Fix PeriodicEffectorPolicy

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

    https://github.com/apache/brooklyn-server/pull/833#discussion_r139935880
  
    --- Diff: policy/src/test/java/org/apache/brooklyn/policy/action/AbstractEffectorPolicyTest.java ---
    @@ -0,0 +1,81 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.brooklyn.policy.action;
    +
    +import static org.testng.Assert.assertEquals;
    +import static org.testng.Assert.assertTrue;
    +
    +import java.util.List;
    +
    +import org.apache.brooklyn.api.objs.Configurable;
    +import org.apache.brooklyn.api.sensor.AttributeSensor;
    +import org.apache.brooklyn.config.ConfigKey;
    +import org.apache.brooklyn.core.sensor.Sensors;
    +import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
    +import org.apache.brooklyn.core.test.entity.TestEntity;
    +import org.apache.brooklyn.test.Asserts;
    +import org.apache.brooklyn.util.time.Duration;
    +
    +import com.google.common.base.Predicates;
    +import com.google.common.collect.ImmutableMap;
    +import com.google.common.collect.Iterables;
    +
    +public class AbstractEffectorPolicyTest extends BrooklynAppUnitTestSupport {
    --- End diff --
    
    I think this looks better, I should probably have done the same and lifted shared parts up out of the tests.


---

[GitHub] brooklyn-server pull request #833: Fix PeriodicEffectorPolicy

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

    https://github.com/apache/brooklyn-server/pull/833#discussion_r139935683
  
    --- Diff: policy/src/main/java/org/apache/brooklyn/policy/action/AbstractScheduledEffectorPolicy.java ---
    @@ -101,15 +102,15 @@
     
         public static final ConfigKey<Boolean> RUNNING = ConfigKeys.builder(Boolean.class)
                 .name("running")
    -            .description("Set if the executor has started")
    +            .description("[INTERNAL] Set if the executor has started")
                 .defaultValue(Boolean.FALSE)
                 .reconfigurable(true)
                 .build();
     
         public static final ConfigKey<List<Long>> SCHEDULED = ConfigKeys.builder(new TypeToken<List<Long>>() { })
                 .name("scheduled")
                 .description("List of all scheduled execution start times")
    -            .defaultValue(Lists.newCopyOnWriteArrayList())
    +            .defaultValue(ImmutableList.of())
    --- End diff --
    
    We can use the non-COW version because you just re-set the config with a mutated copy, right?


---

[GitHub] brooklyn-server pull request #833: Fix PeriodicEffectorPolicy

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

    https://github.com/apache/brooklyn-server/pull/833#discussion_r139935768
  
    --- Diff: policy/src/main/java/org/apache/brooklyn/policy/action/AbstractScheduledEffectorPolicy.java ---
    @@ -210,16 +227,35 @@ protected Duration getWaitUntil(String time) {
             }
         }
     
    +    protected Date parseTime(String time) throws ParseException {
    +        boolean formatted = time.contains(":"); // FIXME deprecated TimeDuration coercion
    +        if (formatted) {
    +            synchronized (FORMATTER) {
    +                // DateFormat is not thread-safe; docs say to use one-per-thread, or to synchronize externally
    +                return FORMATTER.parse(time);
    --- End diff --
    
    Good catch


---

[GitHub] brooklyn-server pull request #833: Fix PeriodicEffectorPolicy

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

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


---

[GitHub] brooklyn-server pull request #833: Fix PeriodicEffectorPolicy

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

    https://github.com/apache/brooklyn-server/pull/833#discussion_r139935372
  
    --- Diff: policy/src/main/java/org/apache/brooklyn/policy/action/ScheduledEffectorPolicy.java ---
    @@ -59,8 +60,8 @@ public ScheduledEffectorPolicy() {
         public void setEntity(final EntityLocal entity) {
             super.setEntity(entity);
     
    -        subscriptions().subscribe(entity, INVOKE_IMMEDIATELY, this);
    -        subscriptions().subscribe(entity, INVOKE_AT, this);
    +        subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), entity, INVOKE_IMMEDIATELY, this);
    --- End diff --
    
    This makes sense, good idea


---

[GitHub] brooklyn-server pull request #833: Fix PeriodicEffectorPolicy

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

    https://github.com/apache/brooklyn-server/pull/833#discussion_r139937923
  
    --- Diff: policy/src/main/java/org/apache/brooklyn/policy/action/AbstractScheduledEffectorPolicy.java ---
    @@ -101,15 +102,15 @@
     
         public static final ConfigKey<Boolean> RUNNING = ConfigKeys.builder(Boolean.class)
                 .name("running")
    -            .description("Set if the executor has started")
    +            .description("[INTERNAL] Set if the executor has started")
                 .defaultValue(Boolean.FALSE)
                 .reconfigurable(true)
                 .build();
     
         public static final ConfigKey<List<Long>> SCHEDULED = ConfigKeys.builder(new TypeToken<List<Long>>() { })
                 .name("scheduled")
                 .description("List of all scheduled execution start times")
    -            .defaultValue(Lists.newCopyOnWriteArrayList())
    +            .defaultValue(ImmutableList.of())
    --- End diff --
    
    If you set the defaultValue to something mutable, then if two different policy instances retrieve and modify it, they'll see each other's changes!
    
    And yes, because we're modifying a copy we can use the non-COW version.


---