You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2014/10/07 10:38:21 UTC
[1/9] git commit: set transitioning fields on cluster when resizing
to or from 0, and better comments on failures
Repository: incubator-brooklyn
Updated Branches:
refs/heads/master 67ad4f4f4 -> 9a87012e1
set transitioning fields on cluster when resizing to or from 0, and better comments on failures
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/af07b5f6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/af07b5f6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/af07b5f6
Branch: refs/heads/master
Commit: af07b5f607995ca6a518da0a6f5c243b9992ed97
Parents: afc7dae
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Oct 3 16:13:15 2014 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Oct 3 16:56:03 2014 +0100
----------------------------------------------------------------------
.../entity/group/DynamicClusterImpl.java | 30 +++++++++++++++++---
.../entity/group/DynamicClusterTest.java | 10 +++++--
2 files changed, 33 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/af07b5f6/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java b/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java
index 3c1bc82..c5b4957 100644
--- a/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java
+++ b/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java
@@ -37,12 +37,14 @@ import org.slf4j.LoggerFactory;
import brooklyn.config.render.RendererHints;
import brooklyn.entity.Entity;
import brooklyn.entity.basic.AbstractGroupImpl;
+import brooklyn.entity.basic.Attributes;
import brooklyn.entity.basic.DelegateEntity;
import brooklyn.entity.basic.Entities;
import brooklyn.entity.basic.EntityFactory;
import brooklyn.entity.basic.EntityFactoryForLocation;
import brooklyn.entity.basic.EntityLocal;
import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.basic.Lifecycle.Transition;
import brooklyn.entity.basic.QuorumCheck.QuorumChecks;
import brooklyn.entity.basic.ServiceStateLogic;
import brooklyn.entity.basic.ServiceStateLogic.ServiceProblemsLogic;
@@ -414,18 +416,38 @@ public class DynamicClusterImpl extends AbstractGroupImpl implements DynamicClus
@Override
public Integer resize(Integer desiredSize) {
synchronized (mutex) {
- int currentSize = getCurrentSize();
- int delta = desiredSize - currentSize;
+ Transition originalExpected = getAttribute(Attributes.SERVICE_STATE_EXPECTED);
+
+ int originalSize = getCurrentSize();
+ if (originalSize==0) {
+ ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING);
+ }
+ int delta = desiredSize - originalSize;
+ if (desiredSize==0) {
+ ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPING);
+ }
if (delta != 0) {
- LOG.info("Resize {} from {} to {}", new Object[] {this, currentSize, desiredSize});
+ LOG.info("Resize {} from {} to {}", new Object[] {this, originalSize, desiredSize});
} else {
- if (LOG.isDebugEnabled()) LOG.debug("Resize no-op {} from {} to {}", new Object[] {this, currentSize, desiredSize});
+ if (LOG.isDebugEnabled()) LOG.debug("Resize no-op {} from {} to {}", new Object[] {this, originalSize, desiredSize});
}
resizeByDelta(delta);
+
+ restoreStateAfterResize(originalExpected, originalSize, desiredSize);
}
return getCurrentSize();
}
+ // TODO this logic maybe belongs in abstract group? fixes test in
+ // see test in DynamicClusterTest.testResizeFromZeroToOneDoesNotGoThroughFailing
+ protected void restoreStateAfterResize(Transition originalExpected, int originalSize, Integer desiredSize) {
+ if (originalExpected!=null) {
+ ServiceStateLogic.setExpectedState(this, originalExpected.getState());
+ } else {
+ ServiceStateLogic.setExpectedState(this, desiredSize==0 ? Lifecycle.STOPPED : Lifecycle.RUNNING);
+ }
+ }
+
/**
* {@inheritDoc}
*
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/af07b5f6/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java b/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
index 8f01fb4..a7166ab 100644
--- a/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
+++ b/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
@@ -49,9 +49,7 @@ import brooklyn.entity.basic.Attributes;
import brooklyn.entity.basic.BrooklynTaskTags;
import brooklyn.entity.basic.Entities;
import brooklyn.entity.basic.EntityFactory;
-import brooklyn.entity.basic.QuorumCheck;
import brooklyn.entity.basic.EntitySubscriptionTest.RecordingSensorEventListener;
-import brooklyn.entity.basic.ServiceStateLogic.ComputeServiceIndicatorsFromChildrenAndMembers;
import brooklyn.entity.basic.Lifecycle;
import brooklyn.entity.proxying.EntitySpec;
import brooklyn.entity.trait.Changeable;
@@ -184,8 +182,14 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport {
assertEquals(entity.getApplication(), app);
}
+ /** two "errors" which could cause this:
+ * <li> TestEntity set expected RUNNING before setting SERVICE_UP, means it goes on fire briefly, so parent might also;
+ * <li> DynamicCluster could see service up false when expected running because it was resizing to/from 0
+ * (so there may be a moment when UP_QUORUM_CHECK fails as >=1 child, but 0 up, because all children are transitioning;
+ * this is fixed with logic in {@link DynamicClusterImpl#restoreStateAfterResize(brooklyn.entity.basic.Lifecycle.Transition, int, Integer)}.
+ */
@Test
- public void resizeFromZeroToOneDoesNotGoThroughFailing() throws Exception {
+ public void testResizeFromZeroToOneDoesNotGoThroughFailing() throws Exception {
final DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
.configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntity.class))
.configure(DynamicCluster.INITIAL_SIZE, 1));
[7/9] git commit: better log for service state logic
Posted by al...@apache.org.
better log for service state logic
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/527604ed
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/527604ed
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/527604ed
Branch: refs/heads/master
Commit: 527604ed2af7482191639f6d4cdcd3d401e154d4
Parents: 55d96f1
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Sat Oct 4 01:31:01 2014 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Sat Oct 4 01:31:01 2014 +0100
----------------------------------------------------------------------
.../main/java/brooklyn/entity/basic/ServiceStateLogic.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/527604ed/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java b/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
index 8b0185d..abe5d94 100644
--- a/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
+++ b/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
@@ -252,7 +252,8 @@ public class ServiceStateLogic {
if (Boolean.TRUE.equals(serviceUp) && (problems==null || problems.isEmpty())) {
return Lifecycle.RUNNING;
} else {
- log.warn("Setting "+entity+" "+Lifecycle.ON_FIRE+" due to problems when expected running, up="+serviceUp+", problems: "+problems);
+ log.warn("Setting "+entity+" "+Lifecycle.ON_FIRE+" due to problems when expected running, up="+serviceUp+", "+
+ (problems==null || problems.isEmpty() ? "not-up-indicators: "+entity.getAttribute(SERVICE_NOT_UP_INDICATORS) : "problems: "+problems));
return Lifecycle.ON_FIRE;
}
}
@@ -485,10 +486,11 @@ public class ServiceStateLogic {
protected void updateMapSensor(AttributeSensor<Map<String, Object>> sensor, Object value) {
if (log.isTraceEnabled()) log.trace("{} updating map sensor {} with {}", new Object[] { this, sensor, value });
- if (value!=null)
+ if (value!=null) {
updateMapSensorEntry(entity, sensor, getKeyForMapSensor(), value);
- else
+ } else {
clearMapSensorEntry(entity, sensor, getKeyForMapSensor());
+ }
}
/** not used; see specific `computeXxx` methods, invoked by overridden onUpdated */
[8/9] git commit: back out logic where DynamicCluster tried to be
smart about setting transitions starting/stopping when resizing from/to size
0;
now it does not. 0 is not a valid size for a running cluster. makes sense as a
default. notes for how to do
Posted by al...@apache.org.
back out logic where DynamicCluster tried to be smart about setting transitions starting/stopping when resizing from/to size 0;
now it does not. 0 is not a valid size for a running cluster. makes sense as a default. notes for how to do something different here.
also minor tidies to ServerPool which was sensitive to this behaviour.
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/ea10fef2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/ea10fef2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/ea10fef2
Branch: refs/heads/master
Commit: ea10fef26853efcede2376a41e172e32d5e7889f
Parents: 527604e
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Sat Oct 4 01:42:50 2014 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Sat Oct 4 01:42:50 2014 +0100
----------------------------------------------------------------------
.../entity/group/DynamicClusterImpl.java | 22 --------------------
.../entity/group/DynamicClusterTest.java | 11 +++++-----
.../brooklyn/entity/pool/ServerPoolImpl.java | 2 +-
.../brooklyn/entity/pool/ServerPoolTest.java | 3 +--
4 files changed, 8 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ea10fef2/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java b/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java
index c5b4957..75bdc19 100644
--- a/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java
+++ b/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java
@@ -37,14 +37,12 @@ import org.slf4j.LoggerFactory;
import brooklyn.config.render.RendererHints;
import brooklyn.entity.Entity;
import brooklyn.entity.basic.AbstractGroupImpl;
-import brooklyn.entity.basic.Attributes;
import brooklyn.entity.basic.DelegateEntity;
import brooklyn.entity.basic.Entities;
import brooklyn.entity.basic.EntityFactory;
import brooklyn.entity.basic.EntityFactoryForLocation;
import brooklyn.entity.basic.EntityLocal;
import brooklyn.entity.basic.Lifecycle;
-import brooklyn.entity.basic.Lifecycle.Transition;
import brooklyn.entity.basic.QuorumCheck.QuorumChecks;
import brooklyn.entity.basic.ServiceStateLogic;
import brooklyn.entity.basic.ServiceStateLogic.ServiceProblemsLogic;
@@ -416,38 +414,18 @@ public class DynamicClusterImpl extends AbstractGroupImpl implements DynamicClus
@Override
public Integer resize(Integer desiredSize) {
synchronized (mutex) {
- Transition originalExpected = getAttribute(Attributes.SERVICE_STATE_EXPECTED);
-
int originalSize = getCurrentSize();
- if (originalSize==0) {
- ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING);
- }
int delta = desiredSize - originalSize;
- if (desiredSize==0) {
- ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPING);
- }
if (delta != 0) {
LOG.info("Resize {} from {} to {}", new Object[] {this, originalSize, desiredSize});
} else {
if (LOG.isDebugEnabled()) LOG.debug("Resize no-op {} from {} to {}", new Object[] {this, originalSize, desiredSize});
}
resizeByDelta(delta);
-
- restoreStateAfterResize(originalExpected, originalSize, desiredSize);
}
return getCurrentSize();
}
- // TODO this logic maybe belongs in abstract group? fixes test in
- // see test in DynamicClusterTest.testResizeFromZeroToOneDoesNotGoThroughFailing
- protected void restoreStateAfterResize(Transition originalExpected, int originalSize, Integer desiredSize) {
- if (originalExpected!=null) {
- ServiceStateLogic.setExpectedState(this, originalExpected.getState());
- } else {
- ServiceStateLogic.setExpectedState(this, desiredSize==0 ? Lifecycle.STOPPED : Lifecycle.RUNNING);
- }
- }
-
/**
* {@inheritDoc}
*
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ea10fef2/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java b/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
index a7166ab..ad5394a 100644
--- a/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
+++ b/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
@@ -51,6 +51,7 @@ import brooklyn.entity.basic.Entities;
import brooklyn.entity.basic.EntityFactory;
import brooklyn.entity.basic.EntitySubscriptionTest.RecordingSensorEventListener;
import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.basic.ServiceStateLogic;
import brooklyn.entity.proxying.EntitySpec;
import brooklyn.entity.trait.Changeable;
import brooklyn.entity.trait.FailingEntity;
@@ -182,11 +183,11 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport {
assertEquals(entity.getApplication(), app);
}
- /** two "errors" which could cause this:
- * <li> TestEntity set expected RUNNING before setting SERVICE_UP, means it goes on fire briefly, so parent might also;
- * <li> DynamicCluster could see service up false when expected running because it was resizing to/from 0
- * (so there may be a moment when UP_QUORUM_CHECK fails as >=1 child, but 0 up, because all children are transitioning;
- * this is fixed with logic in {@link DynamicClusterImpl#restoreStateAfterResize(brooklyn.entity.basic.Lifecycle.Transition, int, Integer)}.
+ /** This can be sensitive to order, e.g. if TestEntity set expected RUNNING before setting SERVICE_UP,
+ * there would be a point when TestEntity is ON_FIRE.
+ * <p>
+ * There can also be issues if a cluster is resizing from/to 0 while in a RUNNING state.
+ * To correct that, use {@link ServiceStateLogic#newEnricherFromChildrenUp()}.
*/
@Test
public void testResizeFromZeroToOneDoesNotGoThroughFailing() throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ea10fef2/software/base/src/main/java/brooklyn/entity/pool/ServerPoolImpl.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/pool/ServerPoolImpl.java b/software/base/src/main/java/brooklyn/entity/pool/ServerPoolImpl.java
index ddc9add..7e13591 100644
--- a/software/base/src/main/java/brooklyn/entity/pool/ServerPoolImpl.java
+++ b/software/base/src/main/java/brooklyn/entity/pool/ServerPoolImpl.java
@@ -297,7 +297,7 @@ public class ServerPoolImpl extends DynamicClusterImpl implements ServerPool {
}
if (delta < removable) {
- LOG.info("Too few removable machines in {} to shrink by delta {}. Altered delta to {}",
+ LOG.warn("Too few removable machines in {} to shrink by delta {}. Altered delta to {}",
new Object[]{this, delta, removable});
delta = removable;
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ea10fef2/software/base/src/test/java/brooklyn/entity/pool/ServerPoolTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/brooklyn/entity/pool/ServerPoolTest.java b/software/base/src/test/java/brooklyn/entity/pool/ServerPoolTest.java
index 584fbfe..1eb222b 100644
--- a/software/base/src/test/java/brooklyn/entity/pool/ServerPoolTest.java
+++ b/software/base/src/test/java/brooklyn/entity/pool/ServerPoolTest.java
@@ -119,11 +119,10 @@ public class ServerPoolTest extends AbstractServerPoolTest {
assertAvailableCountEquals(1);
assertClaimedCountEquals(getInitialPoolSize() - 1);
- LOG.info("Test attempting to resize to 0 members. Should only drop one machine.");
+ LOG.info("Test attempting to resize to 0 members. Should only drop the one available machine.");
pool.resize(0);
assertAvailableCountEventuallyEquals(0);
-
assertEquals(Iterables.size(pool.getMembers()), getInitialPoolSize() - 1);
assertAvailableCountEquals(0);
assertClaimedCountEquals(getInitialPoolSize() - 1);
[9/9] git commit: This closes #213
Posted by al...@apache.org.
This closes #213
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/9a87012e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/9a87012e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/9a87012e
Branch: refs/heads/master
Commit: 9a87012e1ec73e79a2f432e7cdde39a844f9e557
Parents: 67ad4f4 ea10fef
Author: Aled Sage <al...@gmail.com>
Authored: Tue Oct 7 09:37:10 2014 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Oct 7 09:37:10 2014 +0100
----------------------------------------------------------------------
.../entity/basic/ServiceStateLogic.java | 31 +++++++++++--
.../entity/group/DynamicClusterImpl.java | 8 ++--
.../entity/group/DynamicClusterTest.java | 27 ++++++++++-
.../BrooklynMementoPersisterFileBasedTest.java | 2 +-
.../internal/EntityExecutionManagerTest.java | 49 ++++++++++----------
.../brooklyn/test/entity/TestEntityImpl.java | 4 +-
.../brooklyn/policy/ha/ServiceReplacer.java | 2 +-
.../brooklyn/policy/ha/ServiceReplacerTest.java | 18 ++++++-
.../brooklyn/entity/pool/ServerPoolImpl.java | 2 +-
.../brooklyn/entity/pool/ServerPoolTest.java | 3 +-
10 files changed, 104 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9a87012e/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java
----------------------------------------------------------------------
[6/9] git commit: add repeat-untils for some brooklyn-GC-related
tests (maybe there is a 1ms window between tasks finishing and that fact
propagating thus the tasks being cleanable...)
Posted by al...@apache.org.
add repeat-untils for some brooklyn-GC-related tests (maybe there is a 1ms window between tasks finishing and that fact propagating thus the tasks being cleanable...)
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/55d96f1f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/55d96f1f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/55d96f1f
Branch: refs/heads/master
Commit: 55d96f1fcdffd68fa2a7ca57b60384012c6195d4
Parents: af07b5f
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Oct 3 16:45:50 2014 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Oct 3 16:58:07 2014 +0100
----------------------------------------------------------------------
.../internal/EntityExecutionManagerTest.java | 49 ++++++++++----------
1 file changed, 25 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/55d96f1f/core/src/test/java/brooklyn/management/internal/EntityExecutionManagerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/management/internal/EntityExecutionManagerTest.java b/core/src/test/java/brooklyn/management/internal/EntityExecutionManagerTest.java
index d8a0a53..4d794d0 100644
--- a/core/src/test/java/brooklyn/management/internal/EntityExecutionManagerTest.java
+++ b/core/src/test/java/brooklyn/management/internal/EntityExecutionManagerTest.java
@@ -27,6 +27,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.Callable;
import java.util.concurrent.Semaphore;
import org.slf4j.Logger;
@@ -53,6 +54,7 @@ import brooklyn.test.entity.TestApplication;
import brooklyn.test.entity.TestEntity;
import brooklyn.util.collections.MutableMap;
import brooklyn.util.javalang.JavaClassNames;
+import brooklyn.util.repeat.Repeater;
import brooklyn.util.task.BasicExecutionManager;
import brooklyn.util.task.ExecutionListener;
import brooklyn.util.task.TaskBuilder;
@@ -131,9 +133,19 @@ public class EntityExecutionManagerTest {
return Tasks.builder().name(name).dynamic(false).body(Callables.returning(null));
}
- protected static void assertTaskCountForEntity(Entity entity, int expectedCount) {
- Collection<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(((EntityInternal)entity).getManagementContext().getExecutionManager(), entity);
- Assert.assertEquals(tasks.size(), expectedCount, "Tasks were "+tasks);
+ protected void assertTaskCountForEntitySoon(final Entity entity, final int expectedCount) {
+ // Dead task (and initialization task) should have been GC'd on completion.
+ // However, the GC'ing happens in a listener, executed in a different thread - the task.get()
+ // doesn't block for it. Therefore can't always guarantee it will be GC'ed by now.
+ Repeater.create().backoff(Duration.millis(10), 2, Duration.millis(500)).limitTimeTo(Duration.TEN_SECONDS).until(new Callable<Boolean>() {
+ @Override
+ public Boolean call() throws Exception {
+ forceGc();
+ Collection<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(((EntityInternal)entity).getManagementContext().getExecutionManager(), entity);
+ Assert.assertEquals(tasks.size(), expectedCount, "Tasks were "+tasks);
+ return true;
+ }
+ }).run();
}
@Test
@@ -144,14 +156,9 @@ public class EntityExecutionManagerTest {
final Task<?> task = runEmptyTaskWithNameAndTags(e, "should-be-kept", ManagementContextInternal.NON_TRANSIENT_TASK_TAG);
runEmptyTaskWithNameAndTags(e, "should-be-gcd", ManagementContextInternal.TRANSIENT_TASK_TAG);
- // Dead task (and initialization task) should have been GC'd on completion.
- // However, the GC'ing happens in a listener, executed in a different thread - the task.get()
- // doesn't block for it. Therefore can't guarantee it will be GC'ed by now.
- Asserts.succeedsEventually(new Runnable() {
- public void run() {
- Collection<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(app.getManagementContext().getExecutionManager(), e);
- assertEquals(tasks, ImmutableList.of(task), "Mismatched tasks, got: "+tasks);
- }});
+ assertTaskCountForEntitySoon(e, 1);
+ Collection<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(app.getManagementContext().getExecutionManager(), e);
+ assertEquals(tasks, ImmutableList.of(task), "Mismatched tasks, got: "+tasks);
}
@Test
@@ -165,8 +172,7 @@ public class EntityExecutionManagerTest {
for (int count=0; count<5; count++)
runEmptyTaskWithNameAndTags(e, "task"+count, ManagementContextInternal.NON_TRANSIENT_TASK_TAG, "boring-tag");
- forceGc();
- assertTaskCountForEntity(e, 2);
+ assertTaskCountForEntitySoon(e, 2);
}
@Test
@@ -182,9 +188,8 @@ public class EntityExecutionManagerTest {
for (int count=0; count<5; count++)
runEmptyTaskWithNameAndTags(app, "task-app-"+count, ManagementContextInternal.NON_TRANSIENT_TASK_TAG, "boring-tag");
- forceGc();
- assertTaskCountForEntity(app, 2);
- assertTaskCountForEntity(e, 2);
+ assertTaskCountForEntitySoon(app, 2);
+ assertTaskCountForEntitySoon(e, 2);
}
@Test
@@ -219,15 +224,13 @@ public class EntityExecutionManagerTest {
runEmptyTaskWithNameAndTags(app, "task-"+(count++), ManagementContextInternal.NON_TRANSIENT_TASK_TAG, "another-tag-app", "another-tag");
runEmptyTaskWithNameAndTags(app, "task-"+(count++), ManagementContextInternal.NON_TRANSIENT_TASK_TAG, "another-tag-app", "another-tag");
- forceGc();
- assertTaskCountForEntity(e, 6);
- assertTaskCountForEntity(app, 3);
+ assertTaskCountForEntitySoon(e, 6);
+ assertTaskCountForEntitySoon(app, 3);
// now with a lowered limit, we should remove one more e
((BrooklynProperties)app.getManagementContext().getConfig()).put(
BrooklynGarbageCollector.MAX_TASKS_PER_ENTITY, 5);
- forceGc();
- assertTaskCountForEntity(e, 5);
+ assertTaskCountForEntitySoon(e, 5);
}
@Test
@@ -244,11 +247,9 @@ public class EntityExecutionManagerTest {
((EntityInternal)e).getExecutionContext().submit(tb.build()).getUnchecked();
}
- forceGc();
-
// might need an eventually here, if the internal job completion and GC is done in the background
// (if there are no test failures for a few months, since Sept 2014, then we can remove this comment)
- assertTaskCountForEntity(e, 2);
+ assertTaskCountForEntitySoon(e, 2);
}
@Test
[4/9] git commit: better logging and tighter assertions to debug
jenkins-failing ServiceReplacerTest,
and extracted unit test isolating the problem
Posted by al...@apache.org.
better logging and tighter assertions to debug jenkins-failing ServiceReplacerTest, and extracted unit test isolating the problem
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/1284f911
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/1284f911
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/1284f911
Branch: refs/heads/master
Commit: 1284f91157947434fb08bd63030f6f082dc0e8e3
Parents: a32c3ac
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Oct 3 14:50:02 2014 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Oct 3 16:56:03 2014 +0100
----------------------------------------------------------------------
.../entity/basic/ServiceStateLogic.java | 7 +++++--
.../entity/group/DynamicClusterTest.java | 22 +++++++++++++++++++-
.../brooklyn/policy/ha/ServiceReplacer.java | 2 +-
.../brooklyn/policy/ha/ServiceReplacerTest.java | 18 ++++++++++++++--
4 files changed, 43 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1284f911/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java b/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
index 2ba57b4..a9d252b 100644
--- a/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
+++ b/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
@@ -234,6 +234,7 @@ public class ServiceStateLogic {
if (Boolean.TRUE.equals(serviceUp) && (problems==null || problems.isEmpty())) {
return Lifecycle.RUNNING;
} else {
+ log.warn("Setting "+entity+" "+Lifecycle.ON_FIRE+" due to problems when expected running, up="+serviceUp+", problems: "+problems);
return Lifecycle.ON_FIRE;
}
}
@@ -245,10 +246,12 @@ public class ServiceStateLogic {
} else if (problems!=null && !problems.isEmpty()) {
// if there is no expected state, then if service is not up, say stopped, else say on fire (whether service up is true or not present)
- if (Boolean.FALSE.equals(up))
+ if (Boolean.FALSE.equals(up)) {
return Lifecycle.STOPPED;
- else
+ } else {
+ log.warn("Setting "+entity+" "+Lifecycle.ON_FIRE+" due to problems when expected "+stateTransition+" / up="+up+": "+problems);
return Lifecycle.ON_FIRE;
+ }
} else {
// no expected transition and no problems
// if the problems map is non-null, then infer from service up;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1284f911/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java b/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
index ed1d7b6..8f01fb4 100644
--- a/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
+++ b/core/src/test/java/brooklyn/entity/group/DynamicClusterTest.java
@@ -49,10 +49,14 @@ import brooklyn.entity.basic.Attributes;
import brooklyn.entity.basic.BrooklynTaskTags;
import brooklyn.entity.basic.Entities;
import brooklyn.entity.basic.EntityFactory;
+import brooklyn.entity.basic.QuorumCheck;
+import brooklyn.entity.basic.EntitySubscriptionTest.RecordingSensorEventListener;
+import brooklyn.entity.basic.ServiceStateLogic.ComputeServiceIndicatorsFromChildrenAndMembers;
import brooklyn.entity.basic.Lifecycle;
import brooklyn.entity.proxying.EntitySpec;
import brooklyn.entity.trait.Changeable;
import brooklyn.entity.trait.FailingEntity;
+import brooklyn.event.SensorEvent;
import brooklyn.location.Location;
import brooklyn.location.basic.SimulatedLocation;
import brooklyn.management.Task;
@@ -62,7 +66,6 @@ import brooklyn.test.entity.TestEntity;
import brooklyn.test.entity.TestEntityImpl;
import brooklyn.util.collections.MutableMap;
import brooklyn.util.exceptions.Exceptions;
-import brooklyn.util.time.Duration;
import brooklyn.util.time.Time;
import com.google.common.base.Function;
@@ -182,6 +185,23 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport {
}
@Test
+ public void resizeFromZeroToOneDoesNotGoThroughFailing() throws Exception {
+ final DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
+ .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntity.class))
+ .configure(DynamicCluster.INITIAL_SIZE, 1));
+
+ RecordingSensorEventListener r = new RecordingSensorEventListener();
+ app.subscribe(cluster, Attributes.SERVICE_STATE_ACTUAL, r);
+
+ cluster.start(ImmutableList.of(loc));
+ EntityTestUtils.assertAttributeEqualsEventually(cluster, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
+ for (SensorEvent<?> evt: r.events) {
+ if (evt.getValue()==Lifecycle.ON_FIRE)
+ Assert.fail("Should not have published "+Lifecycle.ON_FIRE+" during normal start up: "+r.events);
+ }
+ }
+
+ @Test
public void resizeDownByTwoAndDownByOne() throws Exception {
DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
.configure("factory", new EntityFactory() {
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1284f911/policy/src/main/java/brooklyn/policy/ha/ServiceReplacer.java
----------------------------------------------------------------------
diff --git a/policy/src/main/java/brooklyn/policy/ha/ServiceReplacer.java b/policy/src/main/java/brooklyn/policy/ha/ServiceReplacer.java
index 30c5de4..8f7159e 100644
--- a/policy/src/main/java/brooklyn/policy/ha/ServiceReplacer.java
+++ b/policy/src/main/java/brooklyn/policy/ha/ServiceReplacer.java
@@ -173,7 +173,7 @@ public class ServiceReplacer extends AbstractPolicy {
LOG.info("ServiceReplacer: ignoring error reported from stopping failed node "+failedEntity);
return;
}
- onReplacementFailed("Replace failure (error "+e+") at "+entity+": "+reason);
+ onReplacementFailed("Replace failure ("+Exceptions.collapseText(e)+") at "+entity+": "+reason);
}
}
});
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1284f911/policy/src/test/java/brooklyn/policy/ha/ServiceReplacerTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/brooklyn/policy/ha/ServiceReplacerTest.java b/policy/src/test/java/brooklyn/policy/ha/ServiceReplacerTest.java
index f621536..8d2fb86 100644
--- a/policy/src/test/java/brooklyn/policy/ha/ServiceReplacerTest.java
+++ b/policy/src/test/java/brooklyn/policy/ha/ServiceReplacerTest.java
@@ -27,6 +27,9 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -56,6 +59,7 @@ import brooklyn.test.entity.LocalManagementContextForTests;
import brooklyn.test.entity.TestApplication;
import brooklyn.test.entity.TestEntity;
import brooklyn.util.config.ConfigBag;
+import brooklyn.util.javalang.JavaClassNames;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
@@ -67,6 +71,8 @@ import com.google.common.collect.Sets;
public class ServiceReplacerTest {
+ private static final Logger log = LoggerFactory.getLogger(ServiceReplacerTest.class);
+
private ManagementContext managementContext;
private TestApplication app;
private SimulatedLocation loc;
@@ -138,6 +144,13 @@ public class ServiceReplacerTest {
.configure(ComputeServiceIndicatorsFromChildrenAndMembers.RUNNING_QUORUM_CHECK, QuorumCheck.QuorumChecks.alwaysTrue()));
app.start(ImmutableList.<Location>of(loc));
+ // should not be on fire
+ Assert.assertNotEquals(cluster.getAttribute(Attributes.SERVICE_STATE_ACTUAL), Lifecycle.ON_FIRE);
+ // and should eventually be running
+ EntityTestUtils.assertAttributeEqualsEventually(cluster, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
+
+ log.info("started "+app+" for "+JavaClassNames.niceClassAndMethod());
+
ServiceReplacer policy = new ServiceReplacer(new ConfigBag().configure(ServiceReplacer.FAILURE_SENSOR_TO_MONITOR, HASensors.ENTITY_FAILED));
cluster.addPolicy(policy);
@@ -145,13 +158,14 @@ public class ServiceReplacerTest {
final TestEntity e1 = (TestEntity) Iterables.get(initialMembers, 0);
e1.emit(HASensors.ENTITY_FAILED, new FailureDescriptor(e1, "simulate failure"));
-
+
// Expect cluster to go on-fire when fails to start replacement
// Note that we've set up-quorum and running-quorum to be "alwaysTrue" so that we don't get a transient onFire
// when the failed node fails to start (but before it has been removed from the group to be put in quarantine).
EntityTestUtils.assertAttributeEqualsEventually(cluster, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
-
+
// Expect to have the second failed entity still kicking around as proof (in quarantine)
+ // The cluster should NOT go on fire until after the 2nd failure
Iterable<Entity> members = Iterables.filter(managementContext.getEntityManager().getEntities(), Predicates.instanceOf(FailingEntity.class));
assertEquals(Iterables.size(members), 2);
[2/9] git commit: useful logging if setting expected RUNNING when
service is not set up
Posted by al...@apache.org.
useful logging if setting expected RUNNING when service is not set up
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/afc7daea
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/afc7daea
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/afc7daea
Branch: refs/heads/master
Commit: afc7daea1b3ca0ac8bc0efbf9cffbdc21e6da830
Parents: 2a4e03f
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Oct 3 16:04:16 2014 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Oct 3 16:56:03 2014 +0100
----------------------------------------------------------------------
.../brooklyn/entity/basic/ServiceStateLogic.java | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/afc7daea/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java b/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
index a9d252b..8b0185d 100644
--- a/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
+++ b/core/src/main/java/brooklyn/entity/basic/ServiceStateLogic.java
@@ -51,11 +51,14 @@ import brooklyn.util.collections.MutableMap;
import brooklyn.util.collections.MutableSet;
import brooklyn.util.guava.Functionals;
import brooklyn.util.guava.Maybe;
+import brooklyn.util.repeat.Repeater;
import brooklyn.util.text.Strings;
+import brooklyn.util.time.Duration;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.base.Preconditions;
+import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
@@ -114,6 +117,21 @@ public class ServiceStateLogic {
}
public static void setExpectedState(Entity entity, Lifecycle state) {
+ if (state==Lifecycle.RUNNING) {
+ Boolean up = ((EntityInternal)entity).getAttribute(Attributes.SERVICE_UP);
+ if (!Boolean.TRUE.equals(up)) {
+ // pause briefly to allow any recent problem-clearing processing to complete
+ Stopwatch timer = Stopwatch.createStarted();
+ boolean nowUp = Repeater.create().every(Duration.millis(10)).limitTimeTo(Duration.millis(200)).until(entity,
+ EntityPredicates.attributeEqualTo(Attributes.SERVICE_UP, true)).run();
+ if (nowUp) {
+ log.debug("Had to wait "+Duration.of(timer)+" for "+entity+" "+Attributes.SERVICE_UP+" to be true before setting "+state);
+ } else {
+ log.warn("Service is not up when setting "+state+" on "+entity+"; delayed "+Duration.of(timer)+" "
+ + "but "+Attributes.SERVICE_UP+" did not recover from "+up+"; not-up-indicators="+entity.getAttribute(Attributes.SERVICE_NOT_UP_INDICATORS));
+ }
+ }
+ }
((EntityInternal)entity).setAttribute(Attributes.SERVICE_STATE_EXPECTED, new Lifecycle.Transition(state, new Date()));
Maybe<Enricher> enricher = EntityAdjuncts.tryFindWithUniqueTag(entity.getEnrichers(), ComputeServiceState.DEFAULT_ENRICHER_UNIQUE_TAG);
[5/9] git commit: fix intermittent deleting-dir test failure by
waiting for server shutdown before deleting dir
Posted by al...@apache.org.
fix intermittent deleting-dir test failure by waiting for server shutdown before deleting dir
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/a32c3ac3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/a32c3ac3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/a32c3ac3
Branch: refs/heads/master
Commit: a32c3ac3836c55f31418d98f9ad2e2ac7f6f7067
Parents: 6c1c3b2
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Oct 3 14:49:28 2014 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Oct 3 16:56:03 2014 +0100
----------------------------------------------------------------------
.../rebind/persister/BrooklynMementoPersisterFileBasedTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a32c3ac3/core/src/test/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterFileBasedTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterFileBasedTest.java b/core/src/test/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterFileBasedTest.java
index 7f05fc8..89afd4a 100644
--- a/core/src/test/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterFileBasedTest.java
+++ b/core/src/test/java/brooklyn/entity/rebind/persister/BrooklynMementoPersisterFileBasedTest.java
@@ -48,8 +48,8 @@ public class BrooklynMementoPersisterFileBasedTest extends BrooklynMementoPersis
@Override
@AfterMethod(alwaysRun=true)
public void tearDown() throws Exception {
- mementoDir = Os.deleteRecursively(mementoDir).asNullOrThrowing();
super.tearDown();
+ mementoDir = Os.deleteRecursively(mementoDir).asNullOrThrowing();
}
}
[3/9] git commit: set service up before expected running in
TestEntity to correct test failures
Posted by al...@apache.org.
set service up before expected running in TestEntity to correct test failures
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/2a4e03ff
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/2a4e03ff
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/2a4e03ff
Branch: refs/heads/master
Commit: 2a4e03ff0e0c4a257bbd232516f7992d8cdef059
Parents: 1284f91
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Oct 3 15:47:43 2014 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Oct 3 16:56:03 2014 +0100
----------------------------------------------------------------------
core/src/test/java/brooklyn/test/entity/TestEntityImpl.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2a4e03ff/core/src/test/java/brooklyn/test/entity/TestEntityImpl.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/test/entity/TestEntityImpl.java b/core/src/test/java/brooklyn/test/entity/TestEntityImpl.java
index d58aa86..cef1fee 100644
--- a/core/src/test/java/brooklyn/test/entity/TestEntityImpl.java
+++ b/core/src/test/java/brooklyn/test/entity/TestEntityImpl.java
@@ -126,8 +126,8 @@ public class TestEntityImpl extends AbstractEntity implements TestEntity {
ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING);
counter.incrementAndGet();
addLocations(locs);
- ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING);
setAttribute(SERVICE_UP, true);
+ ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING);
}
@Override
@@ -136,8 +136,8 @@ public class TestEntityImpl extends AbstractEntity implements TestEntity {
callHistory.add("stop");
ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPING);
counter.decrementAndGet();
- ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPED);
setAttribute(SERVICE_UP, false);
+ ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPED);
}
@Override