Adds pre- and post- customize commands
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/cef7f468 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/cef7f468 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/cef7f468 Branch: refs/heads/master Commit: cef7f4683effbd208317f2d558766922bea8cdd4 Parents: 495b1d3 Author: Martin Harris <git...@nakomis.com> Authored: Mon Feb 15 13:11:12 2016 +0000 Committer: Martin Harris <git...@nakomis.com> Committed: Tue Feb 16 15:47:48 2016 +0000 ---------------------------------------------------------------------- .../core/entity/BrooklynConfigKeys.java | 4 +++ .../base/AbstractSoftwareProcessDriver.java | 16 +++++++++-- .../base/AbstractSoftwareProcessSshDriver.java | 18 ++++++++++-- .../AbstractSoftwareProcessWinRmDriver.java | 30 ++++++++++++++++---- .../entity/software/base/SoftwareProcess.java | 6 ++++ .../software/base/VanillaWindowsProcess.java | 6 ++++ ...SoftwareProcessSshDriverIntegrationTest.java | 22 ++++++++++++++ ...laWindowsProcessWinrmExitStatusLiveTest.java | 4 +++ 8 files changed, 97 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cef7f468/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 974f88c..607a22b 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 @@ -102,6 +102,10 @@ public class BrooklynConfigKeys { "Command to be run prior to the install method being called on the driver"); public static final ConfigKey<String> POST_INSTALL_COMMAND = ConfigKeys.newStringConfigKey("post.install.command", "Command to be run after the install method being called on the driver"); + public static final ConfigKey<String> PRE_CUSTOMIZE_COMMAND = ConfigKeys.newStringConfigKey("pre.customize.command", + "Command to be run prior to the customize method being called on the driver"); + public static final ConfigKey<String> POST_CUSTOMIZE_COMMAND = ConfigKeys.newStringConfigKey("post.customize.command", + "Command to be run after the customize method being called on the driver"); public static final ConfigKey<String> PRE_LAUNCH_COMMAND = ConfigKeys.newStringConfigKey("pre.launch.command", "Command to be run prior to the launch method being called on the driver"); public static final ConfigKey<String> POST_LAUNCH_COMMAND = ConfigKeys.newStringConfigKey("post.launch.command", http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cef7f468/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessDriver.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessDriver.java b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessDriver.java index 4ffeb1a..79a150c 100644 --- a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessDriver.java +++ b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessDriver.java @@ -147,8 +147,18 @@ public abstract class AbstractSoftwareProcessDriver implements SoftwareProcessDr }}); DynamicTasks.queue("customize", new Runnable() { public void run() { - waitForConfigKey(BrooklynConfigKeys.CUSTOMIZE_LATCH); - customize(); + DynamicTasks.queue("pre-customize-command", new Runnable() { public void run() { + runPreCustomizeCommand(); + }}); + + DynamicTasks.queue("customize (main)", new Runnable() { public void run() { + waitForConfigKey(BrooklynConfigKeys.CUSTOMIZE_LATCH); + customize(); + }}); + + DynamicTasks.queue("post-customize-command", new Runnable() { public void run() { + runPostCustomizeCommand(); + }}); }}); DynamicTasks.queue("launch", new Runnable() { public void run() { @@ -189,7 +199,9 @@ public abstract class AbstractSoftwareProcessDriver implements SoftwareProcessDr public abstract void setup(); public abstract void install(); public abstract void runPostInstallCommand(); + public abstract void runPreCustomizeCommand(); public abstract void customize(); + public abstract void runPostCustomizeCommand(); public abstract void runPreLaunchCommand(); public abstract void launch(); /** Only run if launch is run (if start is not skipped). */ http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cef7f468/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessSshDriver.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessSshDriver.java b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessSshDriver.java index 240f161..f9ca7ff 100644 --- a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessSshDriver.java +++ b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessSshDriver.java @@ -297,8 +297,8 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP @Override public void runPreInstallCommand() { - if(Strings.isNonBlank(getEntity().getConfig(VanillaSoftwareProcess.PRE_INSTALL_COMMAND))) { - execute(getEntity().getConfig(VanillaSoftwareProcess.PRE_INSTALL_COMMAND), "running pre-install commands"); + if(Strings.isNonBlank(getEntity().getConfig(BrooklynConfigKeys.PRE_INSTALL_COMMAND))) { + execute(ImmutableList.of(getEntity().getConfig(BrooklynConfigKeys.PRE_INSTALL_COMMAND)), "running pre-install commands"); } } @@ -310,6 +310,20 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP } @Override + public void runPreCustomizeCommand() { + if(Strings.isNonBlank(getEntity().getConfig(BrooklynConfigKeys.PRE_CUSTOMIZE_COMMAND))) { + execute(ImmutableList.of(getEntity().getConfig(BrooklynConfigKeys.PRE_CUSTOMIZE_COMMAND)), "running pre-customize commands"); + } + } + + @Override + public void runPostCustomizeCommand() { + if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.POST_CUSTOMIZE_COMMAND))) { + execute(ImmutableList.of(entity.getConfig(BrooklynConfigKeys.POST_CUSTOMIZE_COMMAND)), "running post-customize commands"); + } + } + + @Override public void runPreLaunchCommand() { if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.PRE_LAUNCH_COMMAND))) { execute(ImmutableList.of(entity.getConfig(BrooklynConfigKeys.PRE_LAUNCH_COMMAND)), "running pre-launch commands"); http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cef7f468/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessWinRmDriver.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessWinRmDriver.java b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessWinRmDriver.java index de88cba..897afab 100644 --- a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessWinRmDriver.java +++ b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessWinRmDriver.java @@ -84,9 +84,9 @@ public abstract class AbstractSoftwareProcessWinRmDriver extends AbstractSoftwar @Override public void runPreInstallCommand() { - if (Strings.isNonBlank(getEntity().getConfig(VanillaWindowsProcess.PRE_INSTALL_COMMAND)) || Strings.isNonBlank(getEntity().getConfig(VanillaWindowsProcess.PRE_INSTALL_POWERSHELL_COMMAND))) { + if (Strings.isNonBlank(getEntity().getConfig(BrooklynConfigKeys.PRE_INSTALL_COMMAND)) || Strings.isNonBlank(getEntity().getConfig(VanillaWindowsProcess.PRE_INSTALL_POWERSHELL_COMMAND))) { executeCommandInTask( - getEntity().getConfig(VanillaWindowsProcess.PRE_INSTALL_COMMAND), + getEntity().getConfig(BrooklynConfigKeys.PRE_INSTALL_COMMAND), getEntity().getConfig(VanillaWindowsProcess.PRE_INSTALL_POWERSHELL_COMMAND), "pre-install-command"); } @@ -104,17 +104,37 @@ public abstract class AbstractSoftwareProcessWinRmDriver extends AbstractSoftwar public void runPostInstallCommand() { if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.POST_INSTALL_COMMAND)) || Strings.isNonBlank(getEntity().getConfig(VanillaWindowsProcess.POST_INSTALL_POWERSHELL_COMMAND))) { executeCommandInTask( - getEntity().getConfig(VanillaWindowsProcess.POST_INSTALL_COMMAND), + getEntity().getConfig(BrooklynConfigKeys.POST_INSTALL_COMMAND), getEntity().getConfig(VanillaWindowsProcess.POST_INSTALL_POWERSHELL_COMMAND), "post-install-command"); } } @Override + public void runPreCustomizeCommand() { + if (Strings.isNonBlank(getEntity().getConfig(BrooklynConfigKeys.PRE_CUSTOMIZE_COMMAND)) || Strings.isNonBlank(getEntity().getConfig(VanillaWindowsProcess.PRE_CUSTOMIZE_POWERSHELL_COMMAND))) { + executeCommandInTask( + getEntity().getConfig(BrooklynConfigKeys.PRE_CUSTOMIZE_COMMAND), + getEntity().getConfig(VanillaWindowsProcess.PRE_CUSTOMIZE_POWERSHELL_COMMAND), + "pre-customize-command"); + } + } + + @Override + public void runPostCustomizeCommand() { + if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.POST_CUSTOMIZE_COMMAND)) || Strings.isNonBlank(getEntity().getConfig(VanillaWindowsProcess.POST_CUSTOMIZE_POWERSHELL_COMMAND))) { + executeCommandInTask( + getEntity().getConfig(BrooklynConfigKeys.POST_CUSTOMIZE_COMMAND), + getEntity().getConfig(VanillaWindowsProcess.POST_CUSTOMIZE_POWERSHELL_COMMAND), + "post-customize-command"); + } + } + + @Override public void runPreLaunchCommand() { if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.PRE_LAUNCH_COMMAND)) || Strings.isNonBlank(entity.getConfig(VanillaWindowsProcess.PRE_LAUNCH_POWERSHELL_COMMAND))) { executeCommandInTask( - getEntity().getConfig(VanillaWindowsProcess.PRE_LAUNCH_COMMAND), + getEntity().getConfig(BrooklynConfigKeys.PRE_LAUNCH_COMMAND), getEntity().getConfig(VanillaWindowsProcess.PRE_LAUNCH_POWERSHELL_COMMAND), "pre-launch-command"); } @@ -124,7 +144,7 @@ public abstract class AbstractSoftwareProcessWinRmDriver extends AbstractSoftwar public void runPostLaunchCommand() { if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.POST_LAUNCH_COMMAND)) || Strings.isNonBlank(entity.getConfig(VanillaWindowsProcess.POST_LAUNCH_POWERSHELL_COMMAND))) { executeCommandInTask( - getEntity().getConfig(VanillaWindowsProcess.POST_LAUNCH_COMMAND), + getEntity().getConfig(BrooklynConfigKeys.POST_LAUNCH_COMMAND), getEntity().getConfig(VanillaWindowsProcess.POST_LAUNCH_POWERSHELL_COMMAND), "post-launch-command"); } http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cef7f468/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 c0e87bd..86f7059 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 @@ -112,6 +112,12 @@ public interface SoftwareProcess extends Entity, Startable { @SetFromFlag("postInstallCommand") ConfigKey<String> POST_INSTALL_COMMAND = BrooklynConfigKeys.POST_INSTALL_COMMAND; + @SetFromFlag("preCustomizeCommand") + ConfigKey<String> PRE_CUSTOMIZE_COMMAND = BrooklynConfigKeys.PRE_CUSTOMIZE_COMMAND; + + @SetFromFlag("postCustomizeCommand") + ConfigKey<String> POST_CUSTOMIZE_COMMAND = BrooklynConfigKeys.POST_CUSTOMIZE_COMMAND; + @SetFromFlag("preLaunchCommand") ConfigKey<String> PRE_LAUNCH_COMMAND = BrooklynConfigKeys.PRE_LAUNCH_COMMAND; http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cef7f468/software/base/src/main/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcess.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcess.java b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcess.java index eb64063..6bcbafd 100644 --- a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcess.java +++ b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcess.java @@ -82,6 +82,12 @@ public interface VanillaWindowsProcess extends AbstractVanillaProcess { ConfigKey<String> POST_INSTALL_POWERSHELL_COMMAND = ConfigKeys.newStringConfigKey("post.install.powershell.command", "powershell command to run during the post-install phase"); + ConfigKey<String> PRE_CUSTOMIZE_POWERSHELL_COMMAND = ConfigKeys.newStringConfigKey("pre.customize.powershell.command", + "powershell command to run during the pre-customize phase"); + + ConfigKey<String> POST_CUSTOMIZE_POWERSHELL_COMMAND = ConfigKeys.newStringConfigKey("post.customize.powershell.command", + "powershell command to run during the post-customize phase"); + ConfigKey<String> PRE_LAUNCH_POWERSHELL_COMMAND = ConfigKeys.newStringConfigKey("pre.launch.powershell.command", "powershell command to run during the pre-launch phase"); http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cef7f468/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessSshDriverIntegrationTest.java ---------------------------------------------------------------------- diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessSshDriverIntegrationTest.java b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessSshDriverIntegrationTest.java index 69aeb0a..5a274ab 100644 --- a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessSshDriverIntegrationTest.java +++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessSshDriverIntegrationTest.java @@ -232,6 +232,28 @@ public class SoftwareProcessSshDriverIntegrationTest { } @Test(groups="Integration") + public void testPreAndPostCustomizeCommands() throws IOException { + File tempFile = new File(tempDataDir, "tempFile.txt"); + localhost.config().set(BrooklynConfigKeys.ONBOX_BASE_DIR, tempDataDir.getAbsolutePath()); + app.createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class) + .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "") + .configure(BrooklynConfigKeys.PRE_CUSTOMIZE_COMMAND, String.format("echo inPreCustomize >> %s", tempFile.getAbsoluteFile())) + .configure(VanillaSoftwareProcess.CUSTOMIZE_COMMAND, String.format("echo inCustomize >> %s", tempFile.getAbsoluteFile())) + .configure(BrooklynConfigKeys.POST_CUSTOMIZE_COMMAND, String.format("echo inPostCustomize >> %s", tempFile.getAbsoluteFile())) + .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, String.format("echo inLaunch >> %s", tempFile.getAbsoluteFile()))); + app.start(ImmutableList.of(localhost)); + + List<String> output = Files.readLines(tempFile, Charsets.UTF_8); + assertEquals(output.size(), 4); + assertEquals(output.get(0), "inPreCustomize"); + assertEquals(output.get(1), "inCustomize"); + assertEquals(output.get(2), "inPostCustomize"); + // Launch command is required + assertEquals(output.get(3), "inLaunch"); + tempFile.delete(); + } + + @Test(groups="Integration") public void testPreAndPostLaunchCommands() throws IOException { File tempFile = new File(tempDataDir, "tempFile.txt"); localhost.config().set(BrooklynConfigKeys.ONBOX_BASE_DIR, tempDataDir.getAbsolutePath()); http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cef7f468/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcessWinrmExitStatusLiveTest.java ---------------------------------------------------------------------- diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcessWinrmExitStatusLiveTest.java b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcessWinrmExitStatusLiveTest.java index 998d987..744a8db 100644 --- a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcessWinrmExitStatusLiveTest.java +++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/VanillaWindowsProcessWinrmExitStatusLiveTest.java @@ -232,7 +232,9 @@ public class VanillaWindowsProcessWinrmExitStatusLiveTest { .configure(VanillaWindowsProcess.PRE_INSTALL_COMMAND, phase.equals("pre-install-command") ? INVALID_CMD : "echo install") .configure(VanillaWindowsProcess.INSTALL_COMMAND, phase.equals("install-command") ? INVALID_CMD : "echo install") .configure(VanillaWindowsProcess.POST_INSTALL_COMMAND, phase.equals("post-install-command") ? INVALID_CMD : "echo postinstall") + .configure(VanillaWindowsProcess.PRE_CUSTOMIZE_COMMAND, phase.equals("pre-customize-command") ? INVALID_CMD : "echo preCustomize") .configure(VanillaWindowsProcess.CUSTOMIZE_COMMAND, phase.equals("customize-command") ? INVALID_CMD : "echo customize") + .configure(VanillaWindowsProcess.POST_CUSTOMIZE_COMMAND, phase.equals("post-customize-command") ? INVALID_CMD : "echo postCustomize") .configure(VanillaWindowsProcess.PRE_LAUNCH_COMMAND, phase.equals("pre-launch-command") ? INVALID_CMD : "echo prelaunch") .configure(VanillaWindowsProcess.LAUNCH_COMMAND, phase.equals("launch-command") ? INVALID_CMD : "echo launch") .configure(VanillaWindowsProcess.POST_LAUNCH_COMMAND, phase.equals("post-launch-command") ? INVALID_CMD : "echo postlaunch") @@ -263,7 +265,9 @@ public class VanillaWindowsProcessWinrmExitStatusLiveTest { .configure(VanillaWindowsProcess.PRE_INSTALL_POWERSHELL_COMMAND, phase.equals("pre-install-command") ? INVALID_CMD : "Write-Host install") .configure(VanillaWindowsProcess.INSTALL_POWERSHELL_COMMAND, phase.equals("install-command") ? INVALID_CMD : "Write-Host install") .configure(VanillaWindowsProcess.POST_INSTALL_POWERSHELL_COMMAND, phase.equals("post-install-command") ? INVALID_CMD : "Write-Host postinstall") + .configure(VanillaWindowsProcess.PRE_CUSTOMIZE_POWERSHELL_COMMAND, phase.equals("pre-customize-command") ? INVALID_CMD : "Write-Host preCustomize") .configure(VanillaWindowsProcess.CUSTOMIZE_POWERSHELL_COMMAND, phase.equals("customize-command") ? INVALID_CMD : "Write-Host customize") + .configure(VanillaWindowsProcess.POST_CUSTOMIZE_POWERSHELL_COMMAND, phase.equals("post-customize-command") ? INVALID_CMD : "Write-Host postCustomize") .configure(VanillaWindowsProcess.PRE_LAUNCH_POWERSHELL_COMMAND, phase.equals("pre-launch-command") ? INVALID_CMD : "Write-Host prelaunch") .configure(VanillaWindowsProcess.LAUNCH_POWERSHELL_COMMAND, phase.equals("launch-command") ? INVALID_CMD : "Write-Host launch") .configure(VanillaWindowsProcess.POST_LAUNCH_POWERSHELL_COMMAND, phase.equals("post-launch-command") ? INVALID_CMD : "Write-Host postlaunch")