brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [1/6] brooklyn-server git commit: DynamicGroup wraps entity filters in a same-app check
Date Mon, 31 Oct 2016 11:12:51 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master f4ebc2822 -> 9e4c225e8


DynamicGroup wraps entity filters in a same-app check


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/1be8303e
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/1be8303e
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/1be8303e

Branch: refs/heads/master
Commit: 1be8303e1a850b3268aa01030bd011f5afda0483
Parents: 23be8b2
Author: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Authored: Thu Oct 20 15:56:01 2016 +0100
Committer: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Committed: Thu Oct 27 11:25:03 2016 +0100

----------------------------------------------------------------------
 .../brooklyn/entity/group/DynamicGroup.java     |  2 ++
 .../brooklyn/entity/group/DynamicGroupImpl.java | 32 +++++++++++++-------
 2 files changed, 23 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1be8303e/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroup.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroup.java b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroup.java
index c06aa58..9ef1941 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroup.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroup.java
@@ -84,6 +84,8 @@ public interface DynamicGroup extends AbstractGroup {
      */
     <T> void addSubscription(Entity producer, Sensor<T> sensor);
 
+    /** @deprecated since 0.10.0 use <code>config().get(ENTITY_FILTER)</code>
instead. */
+    @Deprecated
     Predicate<? super Entity> entityFilter();
 
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1be8303e/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroupImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroupImpl.java b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroupImpl.java
index b8789bb..7572430 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroupImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroupImpl.java
@@ -18,8 +18,6 @@
  */
 package org.apache.brooklyn.entity.group;
 
-import groovy.lang.Closure;
-
 import java.util.Collection;
 import java.util.Map;
 
@@ -31,6 +29,7 @@ import org.apache.brooklyn.api.sensor.SensorEventListener;
 import org.apache.brooklyn.core.BrooklynLogging;
 import org.apache.brooklyn.core.BrooklynLogging.LoggingLevel;
 import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.entity.EntityPredicates;
 import org.apache.brooklyn.core.mgmt.internal.CollectionChangeListener;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.util.core.task.Tasks;
@@ -44,6 +43,8 @@ import com.google.common.base.Predicates;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
 
+import groovy.lang.Closure;
+
 public class DynamicGroupImpl extends AbstractGroupImpl implements DynamicGroup {
 
     private static final Logger log = LoggerFactory.getLogger(DynamicGroupImpl.class);
@@ -64,7 +65,7 @@ public class DynamicGroupImpl extends AbstractGroupImpl implements DynamicGroup
         super.init();
         sensors().set(RUNNING, true);
     }
-    
+
     @Override
     public void setEntityFilter(Predicate<? super Entity> filter) {
         // TODO Sould this be "evenIfOwned"?
@@ -80,12 +81,22 @@ public class DynamicGroupImpl extends AbstractGroupImpl implements DynamicGroup
 
     @Override
     public Predicate<? super Entity> entityFilter() {
+        return getEntityFilter();
+    }
+
+    /**
+     * @return
+     *      The filter configured in {@link #ENTITY_FILTER} ANDed with a check that the
+     *      entity has the same application ID.
+     */
+    protected Predicate<? super Entity> getEntityFilter() {
         Predicate<? super Entity> entityFilter = getConfig(ENTITY_FILTER);
         if (entityFilter == null) {
-            return Predicates.alwaysFalse();
-        } else {
-            return entityFilter;
+            entityFilter = Predicates.alwaysFalse();
         }
+        return Predicates.and(
+                EntityPredicates.applicationIdEqualTo(getApplicationId()),
+                entityFilter);
     }
 
     private boolean isRunning() {
@@ -198,10 +209,6 @@ public class DynamicGroupImpl extends AbstractGroupImpl implements DynamicGroup
                 if (log.isDebugEnabled()) log.debug("{} not scanning for children: stopped",
this);
                 return;
             }
-            if (getConfig(ENTITY_FILTER) == null) {
-                log.debug("{} not (yet) scanning for children: no filter defined", this,
this);
-                return;
-            }
             if (getApplication() == null) {
                 BrooklynLogging.log(log, BrooklynLogging.levelDependingIfReadOnly(this, LoggingLevel.WARN,
LoggingLevel.TRACE, LoggingLevel.TRACE),
                     "{} not (yet) scanning for children: no application defined", this);
@@ -211,7 +218,9 @@ public class DynamicGroupImpl extends AbstractGroupImpl implements DynamicGroup
             Collection<Entity> currentMembers = getMembers();
             Collection<Entity> toRemove = Sets.newLinkedHashSet(currentMembers);
 
-            for (Entity it : Iterables.filter(Entities.descendantsAndSelf(getApplication()),
entityFilter())) {
+            final Iterable<Entity> unfiltered = Entities.descendantsAndSelf(getApplication());
+            log.debug("{} filtering {} with {}", new Object[]{this, unfiltered, entityFilter()});
+            for (Entity it : Iterables.filter(unfiltered, entityFilter())) {
                 toRemove.remove(it);
                 if (!currentMembers.contains(it)) {
                     if (log.isDebugEnabled()) log.debug("{} rescan detected new item {}",
this, it);
@@ -228,4 +237,5 @@ public class DynamicGroupImpl extends AbstractGroupImpl implements DynamicGroup
                 log.debug("{} rescan complete, members now {}", this, getMembers());
         }
     }
+
 }


Mime
View raw message