brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [05/18] brooklyn-server git commit: fix issue where app can show STOPPED immediately after creation
Date Fri, 04 Mar 2016 16:15:50 GMT
fix issue where app can show STOPPED immediately after creation


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

Branch: refs/heads/master
Commit: c565d008b01296b81da4c0036ff9c55ddbfff7a2
Parents: a74b8d2
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Wed Feb 24 10:36:55 2016 -0800
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Wed Feb 24 10:36:55 2016 -0800

----------------------------------------------------------------------
 .../core/mgmt/internal/EffectorUtils.java       |  2 +-
 .../entity/lifecycle/ServiceStateLogicTest.java | 16 +++++++---------
 .../rest/resources/ApplicationResource.java     | 20 ++++++++++++++++++++
 3 files changed, 28 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c565d008/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EffectorUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EffectorUtils.java
b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EffectorUtils.java
index b933cf4..7263f3b 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EffectorUtils.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EffectorUtils.java
@@ -267,7 +267,7 @@ public class EffectorUtils {
         private static final long serialVersionUID = 6146890711493851848L;
         private String entityId;
         private String effectorName;
-        public EffectorCallPropagatedRuntimeException(Entity entity, Effector<?> effector,
Throwable throwable) {
+        EffectorCallPropagatedRuntimeException(Entity entity, Effector<?> effector,
Throwable throwable) {
             super(makeMessage(entity, effector), throwable);
             this.entityId = entity.getId();
             this.effectorName = effector.getName();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c565d008/core/src/test/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogicTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogicTest.java
b/core/src/test/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogicTest.java
index ddb4d53..0932fce 100644
--- a/core/src/test/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogicTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogicTest.java
@@ -26,9 +26,8 @@ import org.apache.brooklyn.api.sensor.Enricher;
 import org.apache.brooklyn.core.entity.Attributes;
 import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityAdjuncts;
+import org.apache.brooklyn.core.entity.EntityAsserts;
 import org.apache.brooklyn.core.entity.EntityInternal;
-import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
-import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic;
 import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ComputeServiceIndicatorsFromChildrenAndMembers;
 import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ServiceNotUpLogic;
 import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ServiceProblemsLogic;
@@ -37,7 +36,6 @@ import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.core.test.entity.TestEntityImpl.TestEntityWithoutEnrichers;
 import org.apache.brooklyn.entity.group.DynamicCluster;
-import org.apache.brooklyn.test.EntityTestUtils;
 import org.apache.brooklyn.util.collections.QuorumCheck.QuorumChecks;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.time.Duration;
@@ -267,25 +265,25 @@ public class ServiceStateLogicTest extends BrooklynAppUnitTestSupport
{
                 .configure(DynamicCluster.INITIAL_SIZE, 1));
 
         cluster.start(ImmutableList.of(app.newSimulatedLocation()));
-        EntityTestUtils.assertGroupSizeEqualsEventually(cluster, 1);
+        EntityAsserts.assertGroupSizeEqualsEventually(cluster, 1);
 
         //manually set state to healthy as enrichers are disabled
         EntityInternal child = (EntityInternal) cluster.getMembers().iterator().next();
         child.sensors().set(Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
         child.sensors().set(Attributes.SERVICE_UP, Boolean.TRUE);
 
-        EntityTestUtils.assertAttributeEqualsEventually(cluster, Attributes.SERVICE_STATE_ACTUAL,
Lifecycle.RUNNING);
+        EntityAsserts.assertAttributeEqualsEventually(cluster, Attributes.SERVICE_STATE_ACTUAL,
Lifecycle.RUNNING);
 
         //set untyped service state, the quorum check should be able to handle coercion
         AttributeSensor<Object> stateSensor = Sensors.newSensor(Object.class, Attributes.SERVICE_STATE_ACTUAL.getName());
         child.sensors().set(stateSensor, "running");
 
-        EntityTestUtils.assertAttributeEqualsContinually(cluster, Attributes.SERVICE_STATE_ACTUAL,
Lifecycle.RUNNING);
+        EntityAsserts.assertAttributeEqualsContinually(cluster, Attributes.SERVICE_STATE_ACTUAL,
Lifecycle.RUNNING);
     }
 
     private static <T> void assertAttributeEqualsEventually(Entity x, AttributeSensor<T>
sensor, T value) {
         try {
-            EntityTestUtils.assertAttributeEqualsEventually(ImmutableMap.of("timeout", Duration.seconds(3)),
x, sensor, value);
+            EntityAsserts.assertAttributeEqualsEventually(ImmutableMap.of("timeout", Duration.seconds(3)),
x, sensor, value);
         } catch (Throwable e) {
             log.warn("Expected "+x+" eventually to have "+sensor+" = "+value+"; instead:");
             Entities.dumpInfo(x);
@@ -294,7 +292,7 @@ public class ServiceStateLogicTest extends BrooklynAppUnitTestSupport
{
     }
     private static <T> void assertAttributeEqualsContinually(Entity x, AttributeSensor<T>
sensor, T value) {
         try {
-            EntityTestUtils.assertAttributeEqualsContinually(ImmutableMap.of("timeout", Duration.millis(25)),
x, sensor, value);
+            EntityAsserts.assertAttributeEqualsContinually(ImmutableMap.of("timeout", Duration.millis(25)),
x, sensor, value);
         } catch (Throwable e) {
             log.warn("Expected "+x+" continually to have "+sensor+" = "+value+"; instead:");
             Entities.dumpInfo(x);
@@ -303,7 +301,7 @@ public class ServiceStateLogicTest extends BrooklynAppUnitTestSupport
{
     }
     private static <T> void assertAttributeEquals(Entity x, AttributeSensor<T>
sensor, T value) {
         try {
-            EntityTestUtils.assertAttributeEquals(x, sensor, value);
+            EntityAsserts.assertAttributeEquals(x, sensor, value);
         } catch (Throwable e) {
             log.warn("Expected "+x+" to have "+sensor+" = "+value+"; instead:");
             Entities.dumpInfo(x);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c565d008/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ApplicationResource.java
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ApplicationResource.java
index f24dcf9..e3c23f0 100644
--- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ApplicationResource.java
+++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ApplicationResource.java
@@ -31,6 +31,7 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Callable;
 
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
@@ -81,7 +82,9 @@ import org.apache.brooklyn.util.exceptions.UserFacingException;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.javalang.JavaClassNames;
 import org.apache.brooklyn.util.net.Urls;
+import org.apache.brooklyn.util.repeat.Repeater;
 import org.apache.brooklyn.util.text.Strings;
+import org.apache.brooklyn.util.time.Duration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -229,6 +232,7 @@ public class ApplicationResource extends AbstractBrooklynRestResource
implements
         List<Location> locations = brooklyn().getLocations(applicationSpec);
         Application app = brooklyn().create(applicationSpec);
         Task<?> t = brooklyn().start(app, locations);
+        waitForStart(app, Duration.millis(100));
         TaskSummary ts = TaskTransformer.fromTask(ui.getBaseUriBuilder()).apply(t);
         URI ref = serviceAbsoluteUriBuilder(uriInfo.getBaseUriBuilder(), ApplicationApi.class,
"get")
                 .build(app.getApplicationId());
@@ -290,6 +294,7 @@ public class ApplicationResource extends AbstractBrooklynRestResource
implements
         try {
             Application app = EntityManagementUtils.createUnstarted(mgmt(), spec);
             CreationResult<Application,Void> result = EntityManagementUtils.start(app);
+            waitForStart(app, Duration.millis(100));
 
             boolean isEntitled = Entitlements.isEntitled(
                     mgmt().getEntitlementManager(),
@@ -315,6 +320,21 @@ public class ApplicationResource extends AbstractBrooklynRestResource
implements
         }
     }
 
+    private void waitForStart(final Application app, Duration timeout) {
+        // without this UI shows "stopped" sometimes esp if brooklyn has just started,
+        // because app goes to stopped state if it sees unstarted children,
+        // and that gets returned too quickly, before the start has taken effect
+        Repeater.create("wait a bit for app start").every(Duration.millis(10)).limitTimeTo(timeout).until(
+            new Callable<Boolean>() {
+                @Override
+                public Boolean call() throws Exception {
+                    Lifecycle state = app.getAttribute(Attributes.SERVICE_STATE_ACTUAL);
+                    if (state==Lifecycle.CREATED || state==Lifecycle.STOPPED) return false;
+                    return true;
+                }
+            }).run();
+    }
+
     @Override
     public Response createPoly(byte[] inputToAutodetectType) {
         log.debug("Creating app from autodetecting input");


Mime
View raw message