brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [11/18] brooklyn-server git commit: add config so app might not be destroyed on stop
Date Fri, 04 Mar 2016 16:15:56 GMT
add config so app might not be destroyed on stop


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

Branch: refs/heads/master
Commit: ba8a20d6ec8b055abc46f81550402e0d4a9b1d3a
Parents: 0194d59
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Wed Feb 24 14:59:04 2016 -0800
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Wed Feb 24 15:10:49 2016 -0800

----------------------------------------------------------------------
 .../apache/brooklyn/core/entity/AbstractApplication.java |  6 +++---
 .../brooklyn/core/entity/StartableApplication.java       |  7 +++++++
 .../apache/brooklyn/entity/stock/BasicStartableTest.java | 11 ++++++-----
 3 files changed, 16 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ba8a20d6/core/src/main/java/org/apache/brooklyn/core/entity/AbstractApplication.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractApplication.java b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractApplication.java
index 3fd4b05..18a79cd 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractApplication.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractApplication.java
@@ -215,7 +215,9 @@ public abstract class AbstractApplication extends AbstractEntity implements
Star
         ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL,
"Application stopped");
         setExpectedStateAndRecordLifecycleEvent(Lifecycle.STOPPED);
 
-        if (getParent()==null) {
+        logApplicationLifecycle("Stopped");
+        
+        if (getParent()==null && Boolean.TRUE.equals(getConfig(DESTROY_ON_STOP)))
{
             synchronized (this) {
                 //TODO review mgmt destroy lifecycle
                 //  we don't necessarily want to forget all about the app on stop, 
@@ -226,8 +228,6 @@ public abstract class AbstractApplication extends AbstractEntity implements
Star
                 getEntityManager().unmanage(this);
             }
         }
-
-        logApplicationLifecycle("Stopped");
     }
 
     protected void doStop() {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ba8a20d6/core/src/main/java/org/apache/brooklyn/core/entity/StartableApplication.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/StartableApplication.java
b/core/src/main/java/org/apache/brooklyn/core/entity/StartableApplication.java
index c0e27c0..cf806c3 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/StartableApplication.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/StartableApplication.java
@@ -19,7 +19,14 @@
 package org.apache.brooklyn.core.entity;
 
 import org.apache.brooklyn.api.entity.Application;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.core.entity.trait.Startable;
 
 public interface StartableApplication extends Application, Startable {
+    
+    ConfigKey<Boolean> DESTROY_ON_STOP = ConfigKeys.newBooleanConfigKey("application.stop.shouldDestroy",
+        "Whether the app should be removed from management after a successful stop (if it
is a root); "
+        + "true by default.", true);
+    
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ba8a20d6/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 3b847bf..49d3611 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
@@ -34,15 +34,13 @@ 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.factory.ApplicationBuilder;
+import org.apache.brooklyn.core.entity.StartableApplication;
 import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
-import org.apache.brooklyn.core.location.SimulatedLocation;
 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.entity.TestEntity;
-import org.apache.brooklyn.entity.stock.BasicEntity;
-import org.apache.brooklyn.entity.stock.BasicStartable;
 import org.apache.brooklyn.util.collections.MutableSet;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
@@ -68,7 +66,7 @@ public class BasicStartableTest {
         managementContext = LocalManagementContextForTests.newInstance();
         loc1 = managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
         loc2 = managementContext.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
-        app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
+        app = TestApplication.Factory.newManagedInstanceForTests(managementContext);
     }
     
     @AfterMethod(alwaysRun=true)
@@ -100,6 +98,7 @@ public class BasicStartableTest {
         final List<Object> contexts = Lists.newCopyOnWriteArrayList();
         
         LocationsFilter filter = new LocationsFilter() {
+            private static final long serialVersionUID = 7078046521812992013L;
             @Override public List<Location> filterForContext(List<Location> locations,
Object context) {
                 contexts.add(context);
                 assertEquals(locations, ImmutableList.of(loc1, loc2));
@@ -132,6 +131,7 @@ public class BasicStartableTest {
     public void testIgnoresUnstartableEntities() throws Exception {
         final AtomicReference<Exception> called = new AtomicReference<Exception>();
         LocationsFilter filter = new LocationsFilter() {
+            private static final long serialVersionUID = -5625121945234751178L;
             @Override public List<Location> filterForContext(List<Location> locations,
Object context) {
                 called.set(new Exception());
                 return locations;
@@ -156,6 +156,7 @@ public class BasicStartableTest {
                 .subscribe(startable, Attributes.SERVICE_STATE_ACTUAL, listener);
 
         app.start(ImmutableList.of(loc1));
+        app.config().set(StartableApplication.DESTROY_ON_STOP, false);
         app.stop();
 
         ArrayList<Lifecycle> expected = Lists.newArrayList(


Mime
View raw message