brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [7/8] brooklyn-server git commit: Tidy up calls to entity.getManagementSupport()
Date Mon, 30 May 2016 14:24:41 GMT
Tidy up calls to entity.getManagementSupport()


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

Branch: refs/heads/master
Commit: 5477a4b894d792774c9a17b082d03350bc8e2a30
Parents: 4af7f34
Author: Aled Sage <aled.sage@gmail.com>
Authored: Fri May 27 21:32:25 2016 +0100
Committer: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Committed: Mon May 30 17:21:21 2016 +0300

----------------------------------------------------------------------
 .../brooklyn/core/entity/AbstractEntity.java      |  5 +++--
 .../org/apache/brooklyn/core/entity/Entities.java |  6 +++---
 .../brooklyn/core/entity/EntityInternal.java      | 11 +++++++++++
 .../mgmt/internal/AbstractManagementContext.java  |  2 +-
 .../brooklyn/core/objs/AbstractEntityAdjunct.java |  4 ++--
 .../org/apache/brooklyn/feed/shell/ShellFeed.java |  2 +-
 .../brooklyn/util/core/task/DynamicTasks.java     |  2 +-
 .../brooklyn/core/effector/EffectorBasicTest.java | 18 +++++++++++++++---
 .../ha/HighAvailabilityManagerInMemoryTest.java   | 14 +++++++-------
 .../core/mgmt/rebind/RebindEntityTest.java        |  2 +-
 .../brooklyn/policy/ha/ServiceReplacer.java       |  2 +-
 .../brooklyn/entity/chef/ChefAttributeFeed.java   |  4 ++--
 .../windows/WindowsPerformanceCounterFeed.java    |  2 +-
 13 files changed, 49 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5477a4b8/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
index 62a4bf8..6440583 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
@@ -1443,7 +1443,7 @@ public abstract class AbstractEntity extends AbstractBrooklynObject
implements E
      */
     @Beta
     // TODO revert to private when config() is reverted to return SensorSupportInternal
-    public class BasicSubscriptionSupport implements SubscriptionSupportInternal {
+    public class BasicSubscriptionSupport implements EntitySubscriptionSupportInternal {
         
         @Override
         public <T> SubscriptionHandle subscribe(Entity producer, Sensor<T> sensor,
SensorEventListener<? super T> listener) {
@@ -1501,7 +1501,8 @@ public abstract class AbstractEntity extends AbstractBrooklynObject
implements E
             getSubscriptionTracker().unsubscribeAll();
         }
         
-        protected SubscriptionContext getSubscriptionContext() {
+        @Override
+        public SubscriptionContext getSubscriptionContext() {
             // Rely on synchronization in EntityManagementSupport; synchronizing on AbstractEntity.this
             // is dangerous because user's entity code might synchronize on that and call
getAttribute.
             // Given that getSubscriptionContext is called by AttributeMap.update (via emitInternal),

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5477a4b8/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java b/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
index 9c8ebc8..ca7f2a8 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
@@ -220,7 +220,7 @@ public class Entities {
 
         // we pass to callingEntity for consistency above, but in exec-context it should
be re-dispatched to targetEntity
         // reassign t as the return value may be a wrapper, if it is switching execution
contexts; see submitInternal's javadoc
-        t = ((EntityInternal)callingEntity).getManagementSupport().getExecutionContext().submit(
+        t = ((EntityInternal)callingEntity).getExecutionContext().submit(
                 MutableMap.of("tag", BrooklynTaskTags.tagForCallerEntity(callingEntity)),
t);
 
         if (DynamicTasks.getTaskQueuingContext()!=null) {
@@ -1103,7 +1103,7 @@ public class Entities {
         // TODO it is messy to have to do this, but not sure there is a cleaner way :(
         final Semaphore s = new Semaphore(0);
         final AtomicReference<T> result = new AtomicReference<T>();
-        final ExecutionContext executionContext = ((EntityInternal)entity).getManagementSupport().getExecutionContext();
+        final ExecutionContext executionContext = ((EntityInternal)entity).getExecutionContext();
         executionContext.execute(new Runnable() {
             // TODO could give this task a name, like "create task from factory"
             @Override
@@ -1128,7 +1128,7 @@ public class Entities {
      * @return the task passed in, for fluency
      */
     public static <T extends TaskAdaptable<?>> T submit(final Entity entity,
final T task) {
-        final ExecutionContext executionContext = ((EntityInternal)entity).getManagementSupport().getExecutionContext();
+        final ExecutionContext executionContext = ((EntityInternal)entity).getExecutionContext();
         executionContext.submit(task.asTask());
         return task;
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5477a4b8/core/src/main/java/org/apache/brooklyn/core/entity/EntityInternal.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/EntityInternal.java b/core/src/main/java/org/apache/brooklyn/core/entity/EntityInternal.java
index 3602bee..51ac9eb 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/EntityInternal.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/EntityInternal.java
@@ -30,15 +30,18 @@ import org.apache.brooklyn.api.entity.Group;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.mgmt.ExecutionContext;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.api.mgmt.SubscriptionContext;
 import org.apache.brooklyn.api.mgmt.rebind.RebindSupport;
 import org.apache.brooklyn.api.mgmt.rebind.Rebindable;
 import org.apache.brooklyn.api.mgmt.rebind.mementos.EntityMemento;
+import org.apache.brooklyn.api.objs.BrooklynObject;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
 import org.apache.brooklyn.api.sensor.Feed;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.entity.internal.EntityConfigMap;
 import org.apache.brooklyn.core.mgmt.internal.EntityManagementSupport;
 import org.apache.brooklyn.core.objs.BrooklynObjectInternal;
+import org.apache.brooklyn.core.objs.BrooklynObjectInternal.SubscriptionSupportInternal;
 import org.apache.brooklyn.util.core.config.ConfigBag;
 
 import com.google.common.annotations.Beta;
@@ -187,6 +190,9 @@ public interface EntityInternal extends BrooklynObjectInternal, EntityLocal,
Reb
     void requestPersist();
     
     @Override
+    EntitySubscriptionSupportInternal subscriptions();
+
+    @Override
     SensorSupportInternal sensors();
 
     @Override
@@ -196,6 +202,11 @@ public interface EntityInternal extends BrooklynObjectInternal, EntityLocal,
Reb
     EnricherSupportInternal enrichers();
 
     @Beta
+    public interface EntitySubscriptionSupportInternal extends BrooklynObjectInternal.SubscriptionSupportInternal
{
+        public SubscriptionContext getSubscriptionContext();
+    }
+    
+    @Beta
     public interface SensorSupportInternal extends Entity.SensorSupport {
         /**
          * 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5477a4b8/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
index da9fcae..75af42c 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
@@ -254,7 +254,7 @@ public abstract class AbstractManagementContext implements ManagementContextInte
             );
             return new BasicExecutionContext(MutableMap.of("tags", tags), getExecutionManager());
         } else {
-            return ((EntityInternal)e).getManagementSupport().getExecutionContext();
+            return ((EntityInternal)e).getExecutionContext();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5477a4b8/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
index d3bd9a8..5f5d030 100644
--- a/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
+++ b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
@@ -253,7 +253,7 @@ public abstract class AbstractEntityAdjunct extends AbstractBrooklynObject
imple
             synchronized (AbstractEntityAdjunct.this) {
                 if (_subscriptionTracker!=null) return _subscriptionTracker;
                 if (entity==null) return null;
-                _subscriptionTracker = new SubscriptionTracker(((EntityInternal)entity).getManagementSupport().getSubscriptionContext());
+                _subscriptionTracker = new SubscriptionTracker(((EntityInternal)entity).subscriptions().getSubscriptionContext());
                 return _subscriptionTracker;
             }
         }
@@ -452,7 +452,7 @@ public abstract class AbstractEntityAdjunct extends AbstractBrooklynObject
imple
     protected synchronized SubscriptionTracker getSubscriptionTracker() {
         if (_subscriptionTracker!=null) return _subscriptionTracker;
         if (entity==null) return null;
-        _subscriptionTracker = new SubscriptionTracker(((EntityInternal)entity).getManagementSupport().getSubscriptionContext());
+        _subscriptionTracker = new SubscriptionTracker(((EntityInternal)entity).subscriptions().getSubscriptionContext());
         return _subscriptionTracker;
     }
     

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5477a4b8/core/src/main/java/org/apache/brooklyn/feed/shell/ShellFeed.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/feed/shell/ShellFeed.java b/core/src/main/java/org/apache/brooklyn/feed/shell/ShellFeed.java
index caeb21a..afbdcf7 100644
--- a/core/src/main/java/org/apache/brooklyn/feed/shell/ShellFeed.java
+++ b/core/src/main/java/org/apache/brooklyn/feed/shell/ShellFeed.java
@@ -228,7 +228,7 @@ public class ShellFeed extends AbstractFeed {
 
             final ProcessTaskFactory<?> taskFactory = newTaskFactory(pollInfo.command,
pollInfo.env, pollInfo.dir, 
                     pollInfo.input, pollInfo.context, pollInfo.timeout);
-            final ExecutionContext executionContext = ((EntityInternal) entity).getManagementSupport().getExecutionContext();
+            final ExecutionContext executionContext = ((EntityInternal) entity).getExecutionContext();
 
             getPoller().scheduleAtFixedRate(
                     new Callable<SshPollValue>() {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5477a4b8/core/src/main/java/org/apache/brooklyn/util/core/task/DynamicTasks.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/task/DynamicTasks.java b/core/src/main/java/org/apache/brooklyn/util/core/task/DynamicTasks.java
index 5574709..de384fc 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/task/DynamicTasks.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/task/DynamicTasks.java
@@ -104,7 +104,7 @@ public class DynamicTasks {
         }
         /** as {@link #executionContext(ExecutionContext)} but inferring from the entity
*/
         public TaskQueueingResult<T> executionContext(Entity entity) {
-            this.execContext = ((EntityInternal)entity).getManagementSupport().getExecutionContext();
+            this.execContext = ((EntityInternal)entity).getExecutionContext();
             return this;
         }
         private boolean orSubmitInternal() {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5477a4b8/core/src/test/java/org/apache/brooklyn/core/effector/EffectorBasicTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/effector/EffectorBasicTest.java b/core/src/test/java/org/apache/brooklyn/core/effector/EffectorBasicTest.java
index 8af533f..55a5d22 100644
--- a/core/src/test/java/org/apache/brooklyn/core/effector/EffectorBasicTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/effector/EffectorBasicTest.java
@@ -114,11 +114,23 @@ public class EffectorBasicTest extends BrooklynAppUnitTestSupport {
         }
     }
 
-    @Test(expectedExceptions=IllegalStateException.class, expectedExceptionsMessageRegExp=".*no
longer managed.*")
-    public void testInvokeEffectorListWithEmptyUsingUnmanagedContext() throws Exception{
+    @Test
+    public void testInvokeEffectorListWithEmptyUsingUnmanagedContext() throws Exception {
+        // Previously this threw the IllegalStateException directly, because DynamicTasks
called
+        // ((EntityInternal)entity).getManagementSupport().getExecutionContext();
+        // (so it successfully called getManagementSupport, and then hit the exception.
+        // Now it calls ((EntityInternal)entity).getExecutionContext(), so the exception
happens in
+        // the entity-proxy and is thus wrapped.
         TestEntity entity = app.addChild(EntitySpec.create(TestEntity.class));
         Entities.unmanage(entity);
-        Entities.invokeEffectorList(entity, ImmutableList.<StartableApplication>of(),
Startable.STOP).get(Duration.THIRTY_SECONDS);
+        try {
+            Entities.invokeEffectorList(entity, ImmutableList.<StartableApplication>of(),
Startable.STOP).get(Duration.THIRTY_SECONDS);
+            Asserts.shouldHaveFailedPreviously();
+        } catch (Exception e) {
+            IllegalStateException e2 = Exceptions.getFirstThrowableOfType(e, IllegalStateException.class);
+            if (e2 == null) throw e;
+            Asserts.expectedFailureContains(e2, "no longer managed");
+        }
     }
 
     // check various failure situations

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5477a4b8/core/src/test/java/org/apache/brooklyn/core/mgmt/ha/HighAvailabilityManagerInMemoryTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/ha/HighAvailabilityManagerInMemoryTest.java
b/core/src/test/java/org/apache/brooklyn/core/mgmt/ha/HighAvailabilityManagerInMemoryTest.java
index 84f076f..21f61d3 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/ha/HighAvailabilityManagerInMemoryTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/ha/HighAvailabilityManagerInMemoryTest.java
@@ -79,8 +79,8 @@ public class HighAvailabilityManagerInMemoryTest extends HighAvailabilityManager
         Collection<Location> lm = managementContext.getLocationManager().getLocations();
         log.info("Locs managed are: "+lm);
         log.info("            objs: "+identities(lm));
-        Assert.assertNotNull(entity.getManagementSupport().getManagementContext());
-        Assert.assertNotNull( ((EntityInternal)app.getChildren().iterator().next()).getManagementSupport().getManagementContext());
+        Assert.assertNotNull(entity.getManagementContext());
+        Assert.assertNotNull( ((EntityInternal)app.getChildren().iterator().next()).getManagementContext());
         Assert.assertTrue( ((EntityInternal)app.getChildren().iterator().next()).getManagementSupport().isDeployed());
         checkEntitiesHealthy(app, entity);
         
@@ -118,13 +118,13 @@ public class HighAvailabilityManagerInMemoryTest extends HighAvailabilityManager
     }
 
     private void checkEntitiesHealthy(TestApplication app, TestEntity entity) {
-        Assert.assertNotNull(app.getManagementSupport().getManagementContext());
-        Assert.assertTrue( app.getManagementSupport().getManagementContext().isRunning()
);
+        Assert.assertNotNull(app.getManagementContext());
+        Assert.assertTrue( app.getManagementContext().isRunning() );
         
-        Assert.assertNotNull(entity.getManagementSupport().getManagementContext());
-        Assert.assertNotNull( ((EntityInternal)app.getChildren().iterator().next()).getManagementSupport().getManagementContext()
);
+        Assert.assertNotNull(entity.getManagementContext());
+        Assert.assertNotNull( ((EntityInternal)app.getChildren().iterator().next()).getManagementContext()
);
         Assert.assertTrue( ((EntityInternal)app.getChildren().iterator().next()).getManagementSupport().isDeployed());
-        Assert.assertTrue( ((EntityInternal)app.getChildren().iterator().next()).getManagementSupport().getManagementContext()
instanceof LocalManagementContext );
+        Assert.assertTrue( ((EntityInternal)app.getChildren().iterator().next()).getManagementContext()
instanceof LocalManagementContext );
     }
 
     @Test(groups="Integration", invocationCount=50)

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5477a4b8/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java
index 12411ac..2bcebf4 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindEntityTest.java
@@ -896,7 +896,7 @@ public class RebindEntityTest extends RebindTestFixtureWithApp {
 
         private void onReconstruct() {
             if (getConfig(SUBSCRIBE) != null) {
-                getManagementSupport().getSubscriptionContext().subscribe(null, getConfig(SUBSCRIBE),
new SensorEventListener<Object>() {
+                subscriptions().getSubscriptionContext().subscribe(null, getConfig(SUBSCRIBE),
new SensorEventListener<Object>() {
                         @Override public void onEvent(SensorEvent<Object> event) {
                             events.add(event.getValue());
                         }});

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5477a4b8/policy/src/main/java/org/apache/brooklyn/policy/ha/ServiceReplacer.java
----------------------------------------------------------------------
diff --git a/policy/src/main/java/org/apache/brooklyn/policy/ha/ServiceReplacer.java b/policy/src/main/java/org/apache/brooklyn/policy/ha/ServiceReplacer.java
index ade0899..9d71b78 100644
--- a/policy/src/main/java/org/apache/brooklyn/policy/ha/ServiceReplacer.java
+++ b/policy/src/main/java/org/apache/brooklyn/policy/ha/ServiceReplacer.java
@@ -160,7 +160,7 @@ public class ServiceReplacer extends AbstractPolicy {
         }
         
         LOG.warn("ServiceReplacer acting on failure detected at "+failedEntity+" ("+reason+",
child of "+entity+")");
-        ((EntityInternal)entity).getManagementSupport().getExecutionContext().submit(MutableMap.of(),
new Runnable() {
+        ((EntityInternal)entity).getExecutionContext().submit(MutableMap.of(), new Runnable()
{
 
             @Override
             public void run() {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5477a4b8/software/base/src/main/java/org/apache/brooklyn/entity/chef/ChefAttributeFeed.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/chef/ChefAttributeFeed.java
b/software/base/src/main/java/org/apache/brooklyn/entity/chef/ChefAttributeFeed.java
index d26faa5..14038b0 100644
--- a/software/base/src/main/java/org/apache/brooklyn/entity/chef/ChefAttributeFeed.java
+++ b/software/base/src/main/java/org/apache/brooklyn/entity/chef/ChefAttributeFeed.java
@@ -223,7 +223,7 @@ public class ChefAttributeFeed extends AbstractFeed {
         final Callable<SshPollValue> getAttributesFromKnife = new Callable<SshPollValue>()
{
             public SshPollValue call() throws Exception {
                 ProcessTaskWrapper<String> taskWrapper = knifeTaskFactory.newTask();
-                final ExecutionContext executionContext = ((EntityInternal) entity).getManagementSupport().getExecutionContext();
+                final ExecutionContext executionContext = ((EntityInternal) entity).getExecutionContext();
                 log.debug("START: Running knife to query attributes of Chef node {}", nodeName);
                 executionContext.submit(taskWrapper);
                 taskWrapper.block();
@@ -278,7 +278,7 @@ public class ChefAttributeFeed extends AbstractFeed {
 
         @Override
         public T call() throws Exception {
-            final ExecutionContext executionContext = ((EntityInternal) entity).getManagementSupport().getExecutionContext();
+            final ExecutionContext executionContext = ((EntityInternal) entity).getExecutionContext();
             return executionContext.submit(Maps.newHashMap(), job).get();
         }
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5477a4b8/software/winrm/src/main/java/org/apache/brooklyn/feed/windows/WindowsPerformanceCounterFeed.java
----------------------------------------------------------------------
diff --git a/software/winrm/src/main/java/org/apache/brooklyn/feed/windows/WindowsPerformanceCounterFeed.java
b/software/winrm/src/main/java/org/apache/brooklyn/feed/windows/WindowsPerformanceCounterFeed.java
index 0677e97..329a652 100644
--- a/software/winrm/src/main/java/org/apache/brooklyn/feed/windows/WindowsPerformanceCounterFeed.java
+++ b/software/winrm/src/main/java/org/apache/brooklyn/feed/windows/WindowsPerformanceCounterFeed.java
@@ -258,7 +258,7 @@ public class WindowsPerformanceCounterFeed extends AbstractFeed {
 
         @Override
         public T call() throws Exception {
-            ExecutionContext executionContext = ((EntityInternal) entity).getManagementSupport().getExecutionContext();
+            ExecutionContext executionContext = ((EntityInternal) entity).getExecutionContext();
             return executionContext.submit(Maps.newHashMap(), job).get();
         }
     }


Mime
View raw message