You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2016/10/25 13:52:31 UTC
[3/4] brooklyn-server git commit: Add a stop latch to SoftwareProcess.
Add a stop latch to SoftwareProcess.
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/1a875982
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/1a875982
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/1a875982
Branch: refs/heads/pr/388
Commit: 1a875982ffebaad3a43c0302649dddbc0df78925
Parents: 0b474bb
Author: Geoff Macartney <ge...@cloudsoftcorp.com>
Authored: Wed Oct 19 13:00:54 2016 +0100
Committer: Geoff Macartney <ge...@cloudsoftcorp.com>
Committed: Tue Oct 25 14:49:55 2016 +0100
----------------------------------------------------------------------
.../core/entity/BrooklynConfigKeys.java | 5 +++
.../entity/software/base/SoftwareProcess.java | 3 ++
.../MachineLifecycleEffectorTasks.java | 6 ++-
.../base/SoftwareProcessEntityLatchTest.java | 46 +++++++++++++++++---
4 files changed, 51 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1a875982/core/src/main/java/org/apache/brooklyn/core/entity/BrooklynConfigKeys.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/BrooklynConfigKeys.java b/core/src/main/java/org/apache/brooklyn/core/entity/BrooklynConfigKeys.java
index 4070a35..a97a5d9 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/BrooklynConfigKeys.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/BrooklynConfigKeys.java
@@ -23,6 +23,7 @@ import static org.apache.brooklyn.core.config.ConfigKeys.newConfigKey;
import static org.apache.brooklyn.core.config.ConfigKeys.newConfigKeyWithPrefix;
import static org.apache.brooklyn.core.config.ConfigKeys.newStringConfigKey;
+import com.google.common.annotations.Beta;
import org.apache.brooklyn.api.location.Location;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.config.BasicConfigInheritance;
@@ -179,6 +180,10 @@ public class BrooklynConfigKeys {
public static final ConfigKey<Boolean> PROVISION_LATCH = newBooleanConfigKey("provision.latch", "Latch for blocking location provision until ready");
public static final ConfigKey<Boolean> START_LATCH = newBooleanConfigKey("start.latch", "Latch for blocking start until ready");
+
+ @Beta // on stop DSLs time out after a minute and unblock; may be easier to fix after https://github.com/apache/brooklyn-server/pull/390
+ public static final ConfigKey<Boolean> STOP_LATCH = newBooleanConfigKey("stop.latch", "Latch for blocking stop until a condition is met; will block for at most 1 minute and then time out");
+
public static final ConfigKey<Boolean> SETUP_LATCH = newBooleanConfigKey("setup.latch", "Latch for blocking setup until ready");
public static final ConfigKey<Boolean> PRE_INSTALL_RESOURCES_LATCH = newBooleanConfigKey("resources.preInstall.latch", "Latch for blocking pre-install resources until ready");
public static final ConfigKey<Boolean> INSTALL_RESOURCES_LATCH = newBooleanConfigKey("resources.install.latch", "Latch for blocking install resources until ready");
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1a875982/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcess.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcess.java b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcess.java
index d28bdc6..e612d1e 100644
--- a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcess.java
+++ b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcess.java
@@ -73,6 +73,9 @@ public interface SoftwareProcess extends Entity, Startable {
@SetFromFlag("startLatch")
ConfigKey<Boolean> START_LATCH = BrooklynConfigKeys.START_LATCH;
+ @SetFromFlag("stopLatch")
+ ConfigKey<Boolean> STOP_LATCH = BrooklynConfigKeys.STOP_LATCH;
+
@SetFromFlag("setupLatch")
ConfigKey<Boolean> SETUP_LATCH = BrooklynConfigKeys.SETUP_LATCH;
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1a875982/software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java
index fda9ad6..fc738b1 100644
--- a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java
+++ b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/MachineLifecycleEffectorTasks.java
@@ -604,7 +604,7 @@ public abstract class MachineLifecycleEffectorTasks {
// Opportunity to block startup until other dependent components are available
Object val = entity().getConfig(SoftwareProcess.START_LATCH);
- if (val != null) log.debug("{} finished waiting for start-latch; continuing...", entity(), val);
+ if (val != null) log.debug("{} finished waiting for start-latch {}; continuing...", entity(), val);
}
protected Map<String, Object> obtainProvisioningFlags(final MachineProvisioningLocation<?> location) {
@@ -951,7 +951,9 @@ public abstract class MachineLifecycleEffectorTasks {
* Throw if stop should be aborted.
*/
protected void preStopConfirmCustom() {
- // nothing needed here
+ // Opportunity to block stop() until other dependent components are ready for it
+ Object val = entity().getConfig(SoftwareProcess.STOP_LATCH);
+ if (val != null) log.debug("{} finished waiting for stop-latch {}; continuing...", entity(), val);
}
protected void preStopCustom() {
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1a875982/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessEntityLatchTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessEntityLatchTest.java b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessEntityLatchTest.java
index 20bc6a6..ba62208 100644
--- a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessEntityLatchTest.java
+++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessEntityLatchTest.java
@@ -18,24 +18,27 @@
*/
package org.apache.brooklyn.entity.software.base;
+import static org.apache.brooklyn.core.mgmt.BrooklynTaskTags.getEffectorName;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import java.util.List;
+import java.util.Set;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntityLocal;
import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.location.LocationSpec;
import org.apache.brooklyn.api.mgmt.Task;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.entity.Attributes;
import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
import org.apache.brooklyn.core.sensor.DependentConfiguration;
+import org.apache.brooklyn.core.sensor.Sensors;
import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
-import org.apache.brooklyn.entity.software.base.SoftwareProcess;
import org.apache.brooklyn.entity.software.base.SoftwareProcessEntityTest.MyService;
import org.apache.brooklyn.entity.software.base.SoftwareProcessEntityTest.SimulatedDriver;
import org.apache.brooklyn.entity.stock.BasicEntity;
@@ -51,7 +54,6 @@ import org.apache.brooklyn.util.time.Duration;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
@@ -116,14 +118,36 @@ public class SoftwareProcessEntityLatchTest extends BrooklynAppUnitTestSupport {
runTestLatchBlocks(SoftwareProcess.LAUNCH_LATCH, ImmutableList.of("setup", "copyInstallResources", "install", "customize", "copyRuntimeResources"));
}
+ @Test
+ public void testStopLatchBlocks() throws Exception {
+ final AttributeSensor<Boolean> stopper = Sensors.newBooleanSensor("stop.now");
+ final BasicEntity triggerEntity = app.createAndManageChild(EntitySpec.create(BasicEntity.class));
+ final MyService entity = app.createAndManageChild(EntitySpec.create(MyService.class)
+ .configure(SoftwareProcess.STOP_LATCH, DependentConfiguration.attributeWhenReady(app, stopper)));
+
+ final Task<Void> startTask = Entities.invokeEffector(app, app, MyService.START, ImmutableMap.of("locations", ImmutableList.of(loc)));
+ ((EntityLocal)triggerEntity).sensors().set(Attributes.SERVICE_UP, true);
+ startTask.get(Duration.THIRTY_SECONDS);
+
+ final Task<Void> stopTask = Entities.invokeEffector(app, app, MyService.STOP);
+
+ assertEffectorBlockingDetailsEventually(entity, MyService.STOP.getName(), "Waiting for config " + SoftwareProcess.STOP_LATCH.getName());
+
+ app.sensors().set(stopper, true);
+ stopTask.get(Asserts.DEFAULT_LONG_TIMEOUT);
+
+ assertDriverEventsEquals(entity, ImmutableList.of("setup", "copyInstallResources", "install", "customize", "copyRuntimeResources", "launch", "stop"));
+ }
+
+
protected void runTestLatchBlocks(final ConfigKey<Boolean> latch, List<String> preLatchEvents) throws Exception {
final BasicEntity triggerEntity = app.createAndManageChild(EntitySpec.create(BasicEntity.class));
final MyService entity = app.createAndManageChild(EntitySpec.create(MyService.class)
.configure(latch, DependentConfiguration.attributeWhenReady(triggerEntity, Attributes.SERVICE_UP)));
-
+
final Task<Void> task = Entities.invokeEffector(app, app, MyService.START, ImmutableMap.of("locations", ImmutableList.of(loc)));
-
- assertEffectorBlockingDetailsEventually(entity, "Waiting for config "+latch.getName());
+
+ assertEffectorBlockingDetailsEventually(entity, MyService.START.getName(), "Waiting for config " + latch.getName());
assertDriverEventsEquals(entity, preLatchEvents);
assertFalse(task.isDone());
@@ -137,10 +161,18 @@ public class SoftwareProcessEntityLatchTest extends BrooklynAppUnitTestSupport {
assertEquals(events, expectedEvents, "events="+events);
}
- private void assertEffectorBlockingDetailsEventually(final Entity entity, final String blockingDetailsSnippet) {
+ private void assertEffectorBlockingDetailsEventually(final Entity entity, final String effectorName, final String blockingDetailsSnippet) {
Asserts.succeedsEventually(new Runnable() {
@Override public void run() {
- Task<?> entityTask = Iterables.getOnlyElement(mgmt.getExecutionManager().getTasksWithAllTags(ImmutableList.of(BrooklynTaskTags.EFFECTOR_TAG, BrooklynTaskTags.tagForContextEntity(entity))));
+ final Set<Task<?>> tasksWithAllTags = mgmt.getExecutionManager().getTasksWithAllTags(ImmutableList.of(BrooklynTaskTags.EFFECTOR_TAG, BrooklynTaskTags.tagForContextEntity(entity)));
+ Task<?> entityTask = null;
+ for (Task<?> item : tasksWithAllTags) {
+ final String itemName = getEffectorName(item);
+ entityTask = itemName.equals(effectorName) ? item : entityTask;
+ }
+ if (entityTask == null) {
+ Asserts.fail("Could not find task for effector " + effectorName);
+ }
String blockingDetails = getBlockingDetails(entityTask);
assertTrue(blockingDetails.contains(blockingDetailsSnippet));
}});