From b45fad87d81b0dc86a3ac974d973d0641756840a Mon Sep 17 00:00:00 2001 From: David Ribeiro Alves Date: Fri, 20 Jul 2012 22:23:16 +0100 Subject: [PATCH] corrected destroyNodes bug --- .../internal/EagerNodePoolComputeServiceAdapter.java | 9 ++++++--- .../jclouds/nodepool/NodePoolComputeServiceLiveTest.java | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/labs/nodepool/src/main/java/org/jclouds/nodepool/internal/EagerNodePoolComputeServiceAdapter.java b/labs/nodepool/src/main/java/org/jclouds/nodepool/internal/EagerNodePoolComputeServiceAdapter.java index 8cacf8904a..2777e55de6 100644 --- a/labs/nodepool/src/main/java/org/jclouds/nodepool/internal/EagerNodePoolComputeServiceAdapter.java +++ b/labs/nodepool/src/main/java/org/jclouds/nodepool/internal/EagerNodePoolComputeServiceAdapter.java @@ -144,10 +144,13 @@ public class EagerNodePoolComputeServiceAdapter extends BaseNodePoolComputeServi logger.info(">> destroying node %s", id); metadataStore.deleteMapping(id); if (removeDestroyed) { - logger.info(">> policy is replace detroyed node, replacing node with id %s", id); backendComputeService.get().destroyNode(id); - Set replacement = addToPool(1); - logger.info("<< node %s replaced with %s", id, Iterables.getOnlyElement(replacement)); + if (currentSize() < minSize) { + logger.info(">> policy is remove destroyed node and pool " + + "would fall below minsize, replacing node with id %s", id); + Set replacement = addToPool(1); + logger.info("<< node %s replaced with %s", id, Iterables.getOnlyElement(replacement)); + } } // TODO we should allow the user to hook a way to "clean" the node else { diff --git a/labs/nodepool/src/test/java/org/jclouds/nodepool/NodePoolComputeServiceLiveTest.java b/labs/nodepool/src/test/java/org/jclouds/nodepool/NodePoolComputeServiceLiveTest.java index a1320ff589..440c8019f0 100644 --- a/labs/nodepool/src/test/java/org/jclouds/nodepool/NodePoolComputeServiceLiveTest.java +++ b/labs/nodepool/src/test/java/org/jclouds/nodepool/NodePoolComputeServiceLiveTest.java @@ -108,7 +108,6 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest { @Override @Test(enabled = true, groups = "live") public void testCreateAndRunAService() throws Exception { - this.group = this.group + "s"; final String configuration = Strings2.toStringAndClose(RunScriptData.class .getResourceAsStream("/standalone-basic.xml")); @@ -179,6 +178,10 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest { }), "jboss", node, JBOSS_PATTERN); } + public void testListNodeInGroup() { + + } + @Test(enabled = true, groups = "live", dependsOnMethods = "testCreateAndRunAService") public void testRebuildPoolStateFromStore() { tearDownContext(); @@ -213,7 +216,7 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest { NodePredicates.inGroup(ctx.getPoolGroupName())).size(), 2); } - @Test(enabled = false, groups = "live", dependsOnMethods = "testGetBackendComputeServiceContext") + @Test(enabled = true, groups = "live", dependsOnMethods = "testGetBackendComputeServiceContext") public void testDestroyPoolNodes() { client.destroyNodesMatching(NodePredicates.inGroup(this.group)); // after we destroy all nodes we should still have minsize nodes in the pool @@ -221,7 +224,7 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest { assertSame(ctx.getPoolStats().currentSize(), 1); } - @Test(enabled = true, groups = "live", dependsOnMethods = "testGetBackendComputeServiceContext") + @Test(enabled = true, groups = "live", dependsOnMethods = "testDestroyPoolNodes") public void testDestroyPool() { // TODO get the ctx without the injector NodePoolComputeServiceContext ctx = context.utils().injector().getInstance(NodePoolComputeServiceContext.class);