Don't block infinitely if any of the customize steps fail.

When changePassword fails the stop task won't ever get executed, but the 
execution blocks on it, so it waits forever. The change will execute stop even 
if there was a failure (as long as launch was successful), propagating the 
initial error.


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

Branch: refs/heads/master
Commit: 15038ce2a85c83d7f7500b799f92484f80c37f0a
Parents: ad6ac1e
Author: Svetoslav Neykov <[email protected]>
Authored: Fri Oct 16 14:00:35 2015 +0300
Committer: Svetoslav Neykov <[email protected]>
Committed: Mon Oct 19 16:49:06 2015 +0300

----------------------------------------------------------------------
 .../entity/database/mysql/MySqlSshDriver.java   | 28 +++++++++++++++-----
 1 file changed, 22 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/15038ce2/software/database/src/main/java/org/apache/brooklyn/entity/database/mysql/MySqlSshDriver.java
----------------------------------------------------------------------
diff --git 
a/software/database/src/main/java/org/apache/brooklyn/entity/database/mysql/MySqlSshDriver.java
 
b/software/database/src/main/java/org/apache/brooklyn/entity/database/mysql/MySqlSshDriver.java
index 01ee983..24b2d61 100644
--- 
a/software/database/src/main/java/org/apache/brooklyn/entity/database/mysql/MySqlSshDriver.java
+++ 
b/software/database/src/main/java/org/apache/brooklyn/entity/database/mysql/MySqlSshDriver.java
@@ -34,6 +34,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.brooklyn.api.location.OsDetails;
+import org.apache.brooklyn.api.mgmt.Task;
 import org.apache.brooklyn.core.effector.EffectorTasks;
 import org.apache.brooklyn.core.effector.ssh.SshEffectorTasks;
 import org.apache.brooklyn.core.entity.Attributes;
@@ -44,6 +45,7 @@ import 
org.apache.brooklyn.entity.software.base.AbstractSoftwareProcessSshDriver
 import org.apache.brooklyn.location.ssh.SshMachineLocation;
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.core.task.DynamicTasks;
+import org.apache.brooklyn.util.core.task.Tasks;
 import org.apache.brooklyn.util.core.task.ssh.SshTasks;
 import org.apache.brooklyn.util.core.task.system.ProcessTaskWrapper;
 import org.apache.brooklyn.util.exceptions.Exceptions;
@@ -163,18 +165,32 @@ public class MySqlSshDriver extends 
AbstractSoftwareProcessSshDriver implements
         // launch, then we will configure it
         launch();
 
-        CountdownTimer timer = Duration.seconds(20).countdownTimer();
-        boolean hasCreationScript = copyDatabaseCreationScript();
-        timer.waitForExpiryUnchecked();
+        // Wrap in inessential task to allow the stop step to execute even if 
any of the nested
+        // tasks fail - poor man's try-catch for tasks.
+        Task<Void> configTask = DynamicTasks.<Void>queue("execute scripts", 
new Runnable() {
+            @Override
+            public void run() {
+                Tasks.markInessential();
+                CountdownTimer timer = Duration.seconds(20).countdownTimer();
+                boolean hasCreationScript = copyDatabaseCreationScript();
+                timer.waitForExpiryUnchecked();
 
-        changePassword("", getPassword());
+                changePassword("", getPassword());
 
-        if (hasCreationScript)
-            
executeScriptFromInstalledFileAsync("creation-script.sql").asTask().getUnchecked();
+                if (hasCreationScript)
+                    
executeScriptFromInstalledFileAsync("creation-script.sql").asTask().getUnchecked();
+            }
+        });
 
         // not sure necessary to stop then subsequently launch, but seems 
safest
         // (if skipping, use a flag in launch to indicate we've just launched 
it)
         stop();
+
+        // Fail if any of the tasks above failed, they are marked inessential 
so the
+        // errors don't propagate automatically.
+        if (configTask.isError()) {
+            configTask.getUnchecked();
+        }
     }
 
     @Override

Reply via email to