brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [2/6] brooklyn-server git commit: BasicStartable is on fire if any of its children are on fire
Date Mon, 31 Oct 2016 11:12:52 GMT
BasicStartable is on fire if any of its children are on fire

And follow the same pattern as DynamicCluster for setting expected
state when starting and stopping.

Fixes https://issues.apache.org/jira/browse/BROOKLYN-372.


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

Branch: refs/heads/master
Commit: 035664df997bef70e222ed275b88c6da6f4f062f
Parents: 1be8303
Author: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Authored: Thu Oct 20 16:40:48 2016 +0100
Committer: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Committed: Fri Oct 28 14:35:11 2016 +0100

----------------------------------------------------------------------
 .../entity/stock/BasicStartableImpl.java        | 15 ++++-
 .../entity/stock/BasicStartableTest.java        | 61 +++++++++-----------
 2 files changed, 38 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/035664df/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartableImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartableImpl.java b/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartableImpl.java
index 6ca6190..2ffba5d 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartableImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/stock/BasicStartableImpl.java
@@ -38,9 +38,11 @@ import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityPredicates;
 import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
 import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic;
+import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ServiceProblemsLogic;
 import org.apache.brooklyn.core.entity.trait.Startable;
 import org.apache.brooklyn.core.entity.trait.StartableMethods;
 import org.apache.brooklyn.core.location.Locations;
+import org.apache.brooklyn.util.collections.QuorumCheck;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 
 public class BasicStartableImpl extends AbstractEntity implements BasicStartable {
@@ -80,10 +82,8 @@ public class BasicStartableImpl extends AbstractEntity implements BasicStartable
                 }
             }
             sensors().set(Attributes.SERVICE_UP, true);
+        } finally {
             ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING);
-        } catch (Throwable t) {
-            ServiceStateLogic.setExpectedState(this, Lifecycle.ON_FIRE);
-            throw Exceptions.propagate(t);
         }
     }
 
@@ -105,6 +105,15 @@ public class BasicStartableImpl extends AbstractEntity implements BasicStartable
         StartableMethods.restart(this);
     }
 
+    @Override
+    protected void initEnrichers() {
+        super.initEnrichers();
+        enrichers().add(ServiceStateLogic.newEnricherFromChildrenUp()
+                .checkChildrenOnly()
+                .requireUpChildren(QuorumCheck.QuorumChecks.all())
+                .suppressDuplicates(true));
+    }
+
     // TODO make public in StartableMethods
     private static Iterable<Entity> filterStartableManagedEntities(Iterable<Entity>
contenders) {
         return Iterables.filter(contenders, Predicates.and(Predicates.instanceOf(Startable.class),
EntityPredicates.isManaged()));

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/035664df/core/src/test/java/org/apache/brooklyn/entity/stock/BasicStartableTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/stock/BasicStartableTest.java b/core/src/test/java/org/apache/brooklyn/entity/stock/BasicStartableTest.java
index d943468..9977956 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/stock/BasicStartableTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/stock/BasicStartableTest.java
@@ -27,23 +27,18 @@ import java.util.concurrent.atomic.AtomicReference;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.location.LocationSpec;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.core.entity.Attributes;
-import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityAsserts;
 import org.apache.brooklyn.core.entity.RecordingSensorEventListener;
 import org.apache.brooklyn.core.entity.StartableApplication;
 import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
 import org.apache.brooklyn.core.location.Locations.LocationsFilter;
 import org.apache.brooklyn.core.location.SimulatedLocation;
-import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
-import org.apache.brooklyn.core.test.entity.TestApplication;
+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.collections.MutableList;
 import org.apache.brooklyn.util.collections.MutableSet;
-import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
@@ -54,42 +49,38 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 
-public class BasicStartableTest {
+public class BasicStartableTest extends BrooklynAppUnitTestSupport {
 
-    private ManagementContext managementContext;
     private SimulatedLocation loc1;
     private SimulatedLocation loc2;
-    private TestApplication app;
-    private BasicStartable startable;
-    private TestEntity entity;
-    private TestEntity entity2;
-    
+
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        managementContext = LocalManagementContextForTests.newInstance();
-        loc1 = managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
-        loc2 = managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
-        app = TestApplication.Factory.newManagedInstanceForTests(managementContext);
-    }
-    
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (managementContext != null) Entities.destroyAll(managementContext);
+        super.setUp();
+        loc1 = app.newSimulatedLocation();
+        loc2 = app.newSimulatedLocation();
     }
-    
+
     @Test
     public void testSetsLocations() throws Exception {
-        startable = app.addChild(EntitySpec.create(BasicStartable.class));
+        BasicStartable startable = app.addChild(EntitySpec.create(BasicStartable.class));
         app.start(ImmutableList.of(loc1, loc2));
-        
         assertEqualsIgnoringOrder(startable.getLocations(), ImmutableSet.of(loc1, loc2));
     }
-    
+
+    @Test
+    public void testStartsWhenNoStartableChildren() {
+        BasicStartable startable = app.createAndManageChild(EntitySpec.create(BasicStartable.class)
+                .child(EntitySpec.create(BasicEntity.class)));
+        app.start(ImmutableList.of(app.newSimulatedLocation()));
+        EntityAsserts.assertAttributeEquals(startable, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
+    }
+
     @Test
     public void testDefaultIsAllLocations() throws Exception {
-        startable = app.addChild(EntitySpec.create(BasicStartable.class));
-        entity = startable.addChild(EntitySpec.create(TestEntity.class));
-        entity2 = startable.addChild(EntitySpec.create(TestEntity.class));
+        BasicStartable startable = app.addChild(EntitySpec.create(BasicStartable.class));
+        TestEntity entity = startable.addChild(EntitySpec.create(TestEntity.class));
+        TestEntity entity2 = startable.addChild(EntitySpec.create(TestEntity.class));
         app.start(ImmutableList.of(loc1, loc2));
         
         assertEqualsIgnoringOrder(entity.getLocations(), ImmutableSet.of(loc1, loc2));
@@ -119,10 +110,10 @@ public class BasicStartableTest {
                 }
             }
         };
-        startable = app.addChild(EntitySpec.create(BasicStartable.class)
+        BasicStartable startable = app.addChild(EntitySpec.create(BasicStartable.class)
                 .configure(BasicStartable.LOCATIONS_FILTER, filter));
-        entity = startable.addChild(EntitySpec.create(TestEntity.class).displayName("1"));
-        entity2 = startable.addChild(EntitySpec.create(TestEntity.class).displayName("2"));
+        TestEntity entity = startable.addChild(EntitySpec.create(TestEntity.class).displayName("1"));
+        TestEntity entity2 = startable.addChild(EntitySpec.create(TestEntity.class).displayName("2"));
         app.start(ImmutableList.of(loc1, loc2));
         
         assertEqualsIgnoringOrder(entity.getLocations(), ImmutableSet.of(loc1));
@@ -140,7 +131,7 @@ public class BasicStartableTest {
                 return locations;
             }
         };
-        startable = app.addChild(EntitySpec.create(BasicStartable.class)
+        BasicStartable startable = app.addChild(EntitySpec.create(BasicStartable.class)
                 .configure(BasicStartable.LOCATIONS_FILTER, filter));
         BasicEntity entity = startable.addChild(EntitySpec.create(BasicEntity.class));
         app.start(ImmutableList.of(loc1, loc2));
@@ -157,11 +148,11 @@ public class BasicStartableTest {
     //        at org.apache.brooklyn.entity.stock.BasicStartableTest.testTransitionsThroughLifecycles(BasicStartableTest.java:170)
     @Test(groups={"Broken"})
     public void testTransitionsThroughLifecycles() throws Exception {
-        startable = app.addChild(EntitySpec.create(BasicStartable.class));
+        BasicStartable startable = app.addChild(EntitySpec.create(BasicStartable.class));
         EntityAsserts.assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL,
Lifecycle.STOPPED);
         
         final RecordingSensorEventListener<Lifecycle> listener = new RecordingSensorEventListener<Lifecycle>(true);
-        managementContext.getSubscriptionContext(startable)
+        mgmt.getSubscriptionContext(startable)
                 .subscribe(startable, Attributes.SERVICE_STATE_ACTUAL, listener);
 
         app.start(ImmutableList.of(loc1));


Mime
View raw message