Repository: incubator-brooklyn Updated Branches: refs/heads/master 761f471ab -> e0e56f485
Improvements to SoftwareProcess lifecycle phases Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/c6d148d3 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/c6d148d3 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/c6d148d3 Branch: refs/heads/master Commit: c6d148d3b042ed9c486e5f5737284ccc8611a861 Parents: 761f471 Author: Andrew Kennedy <[email protected]> Authored: Mon Aug 25 18:33:44 2014 +0100 Committer: Andrew Kennedy <[email protected]> Committed: Sat Aug 30 17:21:23 2014 +0100 ---------------------------------------------------------------------- .../entity/basic/BrooklynConfigKeys.java | 11 ++++- .../basic/PortAttributeSensorAndConfigKey.java | 5 ++- .../basic/AbstractSoftwareProcessDriver.java | 43 ++++++++++++++++---- .../basic/AbstractSoftwareProcessSshDriver.java | 24 +++++++++++ .../brooklyn/entity/basic/SoftwareProcess.java | 39 +++++++++++++++--- .../basic/VanillaSoftwareProcessSshDriver.java | 2 - .../java/JavaSoftwareProcessSshDriver.java | 8 ++-- .../entity/messaging/qpid/QpidBroker.java | 10 ----- 8 files changed, 109 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c6d148d3/core/src/main/java/brooklyn/entity/basic/BrooklynConfigKeys.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/brooklyn/entity/basic/BrooklynConfigKeys.java b/core/src/main/java/brooklyn/entity/basic/BrooklynConfigKeys.java index 1972983..d2f690f 100644 --- a/core/src/main/java/brooklyn/entity/basic/BrooklynConfigKeys.java +++ b/core/src/main/java/brooklyn/entity/basic/BrooklynConfigKeys.java @@ -59,10 +59,15 @@ public class BrooklynConfigKeys { + "this should include something readable, and must include a hash of all data which differentiates an installation " + "(e.g. version, plugins, etc), but should be the same where install dirs can be shared to allow for re-use"); - 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<Boolean> SKIP_INSTALLATION = newBooleanConfigKey("install.skip", "Skip the driver install commands entirely, for pre-installed software", Boolean.FALSE); // The implementation in AbstractSoftwareSshDriver runs this command as an SSH command + public static final ConfigKey<String> PRE_INSTALL_COMMAND = ConfigKeys.newStringConfigKey("pre.install.command", + "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_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", "Command to be run after the launch method being called on the driver"); @@ -111,8 +116,10 @@ public class BrooklynConfigKeys { * component is up, but this entity does not care about the dependent component's actual config values. */ public static final ConfigKey<Boolean> START_LATCH = newBooleanConfigKey("start.latch", "Latch for blocking start until ready"); + public static final ConfigKey<Boolean> SETUP_LATCH = newBooleanConfigKey("setup.latch", "Latch for blocking setup until ready"); public static final ConfigKey<Boolean> INSTALL_LATCH = newBooleanConfigKey("install.latch", "Latch for blocking install until ready"); public static final ConfigKey<Boolean> CUSTOMIZE_LATCH = newBooleanConfigKey("customize.latch", "Latch for blocking customize until ready"); + public static final ConfigKey<Boolean> RESOURCES_LATCH = newBooleanConfigKey("resources.latch", "Latch for blocking resources until ready"); public static final ConfigKey<Boolean> LAUNCH_LATCH = newBooleanConfigKey("launch.latch", "Latch for blocking launch until ready"); public static final ConfigKey<Duration> START_TIMEOUT = newConfigKey( http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c6d148d3/core/src/main/java/brooklyn/event/basic/PortAttributeSensorAndConfigKey.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/brooklyn/event/basic/PortAttributeSensorAndConfigKey.java b/core/src/main/java/brooklyn/event/basic/PortAttributeSensorAndConfigKey.java index c059542..fbee6ba 100644 --- a/core/src/main/java/brooklyn/event/basic/PortAttributeSensorAndConfigKey.java +++ b/core/src/main/java/brooklyn/event/basic/PortAttributeSensorAndConfigKey.java @@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory; import brooklyn.config.ConfigKey; import brooklyn.entity.Entity; +import brooklyn.entity.basic.BrooklynConfigKeys; import brooklyn.event.Sensor; import brooklyn.location.Location; import brooklyn.location.MachineProvisioningLocation; @@ -37,6 +38,7 @@ import brooklyn.management.ManagementContext; import brooklyn.util.flags.TypeCoercions; import brooklyn.util.guava.Maybe; +import com.google.common.base.Optional; import com.google.common.base.Predicates; import com.google.common.collect.Iterables; @@ -92,7 +94,8 @@ public class PortAttributeSensorAndConfigKey extends AttributeSensorAndConfigKey } if (lo.isPresent()) { Location l = lo.get(); - if (l instanceof PortSupplier) { + Boolean skip = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_INSTALLATION)).or(false); + if (l instanceof PortSupplier && !skip) { int p = ((PortSupplier)l).obtainPort(value); if (p!=-1) { LOG.debug(""+entity+" choosing port "+p+" for "+getName()); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c6d148d3/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java index e9ab449..18c5e06 100644 --- a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java +++ b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java @@ -36,6 +36,7 @@ import brooklyn.util.text.Strings; import brooklyn.util.text.TemplateProcessor; import com.google.common.annotations.Beta; +import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; /** @@ -78,27 +79,52 @@ public abstract class AbstractSoftwareProcessDriver implements SoftwareProcessDr */ @Override public void start() { - DynamicTasks.queue("install", new Runnable() { public void run() { - waitForConfigKey(BrooklynConfigKeys.INSTALL_LATCH); - install(); - }}); + if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.PRE_INSTALL_COMMAND))) { + DynamicTasks.queue("pre-install command", new Runnable() { public void run() { + runPreInstallCommand(entity.getConfig(BrooklynConfigKeys.PRE_INSTALL_COMMAND)); + }}); + }; + + Boolean skip = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_INSTALLATION)).or(false); + if (!skip) { + DynamicTasks.queue("setup", new Runnable() { public void run() { + waitForConfigKey(BrooklynConfigKeys.SETUP_LATCH); + setup(); + }}); + + DynamicTasks.queue("install", new Runnable() { public void run() { + waitForConfigKey(BrooklynConfigKeys.INSTALL_LATCH); + install(); + }}); + } + + if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.POST_INSTALL_COMMAND))) { + DynamicTasks.queue("post-install command", new Runnable() { public void run() { + runPostInstallCommand(entity.getConfig(BrooklynConfigKeys.POST_INSTALL_COMMAND)); + }}); + }; DynamicTasks.queue("customize", new Runnable() { public void run() { waitForConfigKey(BrooklynConfigKeys.CUSTOMIZE_LATCH); customize(); }}); + DynamicTasks.queue("resources", new Runnable() { public void run() { + waitForConfigKey(BrooklynConfigKeys.RESOURCES_LATCH); + resources(); + }}); + if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.PRE_LAUNCH_COMMAND))) { DynamicTasks.queue("pre-launch command", new Runnable() { public void run() { runPreLaunchCommand(entity.getConfig(BrooklynConfigKeys.PRE_LAUNCH_COMMAND)); }}); }; - + DynamicTasks.queue("launch", new Runnable() { public void run() { waitForConfigKey(BrooklynConfigKeys.LAUNCH_LATCH); launch(); }}); - + if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.POST_LAUNCH_COMMAND))) { DynamicTasks.queue("post-launch command", new Runnable() { public void run() { runPostLaunchCommand(entity.getConfig(BrooklynConfigKeys.POST_LAUNCH_COMMAND)); @@ -113,12 +139,15 @@ public abstract class AbstractSoftwareProcessDriver implements SoftwareProcessDr @Override public abstract void stop(); + public abstract void runPreInstallCommand(String command); + public abstract void setup(); public abstract void install(); + public abstract void runPostInstallCommand(String command); public abstract void customize(); + public abstract void resources(); public abstract void runPreLaunchCommand(String command); public abstract void launch(); public abstract void runPostLaunchCommand(String command); - @Override public void kill() { http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c6d148d3/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java index da1efe2..eb51e7d 100644 --- a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java +++ b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java @@ -279,6 +279,25 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP if (!flags.containsKey("logPrefix")) flags.put("logPrefix", ""+entity.getId()+"@"+getLocation().getDisplayName()); return getMachine().execScript(flags, summaryForLogging, script, environment); } + + @Override + public void resources() { + Map runtimeFiles = entity.getConfig(SoftwareProcess.RUNTIME_FILES); + copyResources(runtimeFiles); + + Map runtimeTemplates = entity.getConfig(SoftwareProcess.RUNTIME_TEMPLATES); + copyTemplates(runtimeTemplates); + } + + @Override + public void runPreInstallCommand(String command) { + execute(ImmutableList.of(command), "running pre-install commands"); + } + + @Override + public void runPostInstallCommand(String command) { + execute(ImmutableList.of(command), "running post-install commands"); + } @Override public void runPreLaunchCommand(String command) { @@ -599,6 +618,8 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP if (!groovyTruth(flags.get(INSTALL_INCOMPLETE))) { s.footer.append("date > $INSTALL_DIR/BROOKLYN"); } + // don't set vars during install phase, prevent dependency resolution + s.environmentVariablesReset(); } if (ImmutableSet.of(CUSTOMIZING, LAUNCHING, CHECK_RUNNING, STOPPING, KILLING, RESTARTING).contains(phase)) { s.header.append( @@ -713,4 +734,7 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP return result; } + @Override + public void setup() { } + } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c6d148d3/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java index 0551840..d71375f 100644 --- a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java +++ b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcess.java @@ -33,6 +33,8 @@ import brooklyn.util.collections.MutableMap; import brooklyn.util.flags.SetFromFlag; import brooklyn.util.time.Duration; +import com.google.common.reflect.TypeToken; + public interface SoftwareProcess extends Entity, Startable { public static final AttributeSensor<String> HOSTNAME = Attributes.HOSTNAME; @@ -46,21 +48,36 @@ public interface SoftwareProcess extends Entity, Startable { @SetFromFlag("startLatch") public static final ConfigKey<Boolean> START_LATCH = BrooklynConfigKeys.START_LATCH; + @SetFromFlag("setupLatch") + public static final ConfigKey<Boolean> SETUP_LATCH = BrooklynConfigKeys.SETUP_LATCH; + @SetFromFlag("installLatch") public static final ConfigKey<Boolean> INSTALL_LATCH = BrooklynConfigKeys.INSTALL_LATCH; @SetFromFlag("customizeLatch") public static final ConfigKey<Boolean> CUSTOMIZE_LATCH = BrooklynConfigKeys.CUSTOMIZE_LATCH; - + + @SetFromFlag("resourcesLatch") + public static final ConfigKey<Boolean> RESOURCES_LATCH = BrooklynConfigKeys.RESOURCES_LATCH; + + @SetFromFlag("launchLatch") + public static final ConfigKey<Boolean> LAUNCH_LATCH = BrooklynConfigKeys.LAUNCH_LATCH; + + @SetFromFlag("skipInstall") + public static final ConfigKey<Boolean> SKIP_INSTALLATION = BrooklynConfigKeys.SKIP_INSTALLATION; + + @SetFromFlag("preInstallCommand") + public static final ConfigKey<String> PRE_INSTALL_COMMAND = BrooklynConfigKeys.PRE_INSTALL_COMMAND; + + @SetFromFlag("postInstallCommand") + public static final ConfigKey<String> POST_INSTALL_COMMAND = BrooklynConfigKeys.POST_INSTALL_COMMAND; + @SetFromFlag("preLaunchCommand") public static final ConfigKey<String> PRE_LAUNCH_COMMAND = BrooklynConfigKeys.PRE_LAUNCH_COMMAND; - + @SetFromFlag("postLaunchCommand") public static final ConfigKey<String> POST_LAUNCH_COMMAND = BrooklynConfigKeys.POST_LAUNCH_COMMAND; - @SetFromFlag("launchLatch") - public static final ConfigKey<Boolean> LAUNCH_LATCH = BrooklynConfigKeys.LAUNCH_LATCH; - @SetFromFlag("version") public static final ConfigKey<String> SUGGESTED_VERSION = BrooklynConfigKeys.SUGGESTED_VERSION; @@ -72,7 +89,7 @@ public interface SoftwareProcess extends Entity, Startable { @SetFromFlag("installLabel") public static final ConfigKey<String> INSTALL_UNIQUE_LABEL = BrooklynConfigKeys.INSTALL_UNIQUE_LABEL; - + @SetFromFlag("expandedInstallDir") BasicAttributeSensorAndConfigKey<String> EXPANDED_INSTALL_DIR = BrooklynConfigKeys.EXPANDED_INSTALL_DIR; @@ -86,6 +103,16 @@ public interface SoftwareProcess extends Entity, Startable { @Deprecated public static final ConfigKey<String> SUGGESTED_RUN_DIR = BrooklynConfigKeys.SUGGESTED_RUN_DIR; + /** Files to be copied to the server, map of "subpath/file.name": "classpath://foo/file.txt" (or other url) */ + @SetFromFlag("runtimeFiles") + ConfigKey<Map<String, String>> RUNTIME_FILES = ConfigKeys.newConfigKey(new TypeToken<Map<String, String>>() { }, + "files.runtime", "Map of files to be copied, keyed by destination name relative to runDir"); + + /** Templates to be filled in and then copied to the server. See {@link #RUNTIME_FILES}. */ + @SetFromFlag("runtimeTemplates") + ConfigKey<Map<String, String>> RUNTIME_TEMPLATES = ConfigKeys.newConfigKey(new TypeToken<Map<String, String>>() { }, + "templates.runtime", "Map of templates to be filled in and copied, keyed by destination name relative to runDir"); + @SetFromFlag("env") public static final MapConfigKey<Object> SHELL_ENVIRONMENT = new MapConfigKey<Object>(Object.class, "shell.env", "Map of environment variables to pass to the runtime shell", MutableMap.<String,Object>of()); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c6d148d3/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcessSshDriver.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcessSshDriver.java b/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcessSshDriver.java index 389807a..b3c0d26 100644 --- a/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcessSshDriver.java +++ b/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcessSshDriver.java @@ -64,8 +64,6 @@ public class VanillaSoftwareProcessSshDriver extends AbstractSoftwareProcessSshD int result = newScript(INSTALLING) .failOnNonZeroResultCode(false) - // don't set vars yet -- it resolves dependencies (e.g. DB) which we don't want until we start - .environmentVariablesReset() .body.append(commands) .execute(); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c6d148d3/software/base/src/main/java/brooklyn/entity/java/JavaSoftwareProcessSshDriver.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/java/JavaSoftwareProcessSshDriver.java b/software/base/src/main/java/brooklyn/entity/java/JavaSoftwareProcessSshDriver.java index 95ed43b..d4e5156 100644 --- a/software/base/src/main/java/brooklyn/entity/java/JavaSoftwareProcessSshDriver.java +++ b/software/base/src/main/java/brooklyn/entity/java/JavaSoftwareProcessSshDriver.java @@ -438,13 +438,13 @@ public abstract class JavaSoftwareProcessSshDriver extends AbstractSoftwareProce } @Override - public void start() { + public void setup() { DynamicTasks.queue("install java", new Runnable() { public void run() { installJava(); }}); - + // TODO check java version - + if (isJmxEnabled()) { DynamicTasks.queue("install jmx", new Runnable() { public void run() { installJmxSupport(); }}); @@ -454,8 +454,6 @@ public abstract class JavaSoftwareProcessSshDriver extends AbstractSoftwareProce DynamicTasks.queue("check java hostname bug", new Runnable() { public void run() { checkJavaHostnameBug(); }}); } - - super.start(); } } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c6d148d3/software/messaging/src/main/java/brooklyn/entity/messaging/qpid/QpidBroker.java ---------------------------------------------------------------------- diff --git a/software/messaging/src/main/java/brooklyn/entity/messaging/qpid/QpidBroker.java b/software/messaging/src/main/java/brooklyn/entity/messaging/qpid/QpidBroker.java index 0ad7c56..6fd2e82 100644 --- a/software/messaging/src/main/java/brooklyn/entity/messaging/qpid/QpidBroker.java +++ b/software/messaging/src/main/java/brooklyn/entity/messaging/qpid/QpidBroker.java @@ -68,16 +68,6 @@ public interface QpidBroker extends SoftwareProcess, MessageBroker, UsesJmx, Amq @SetFromFlag("httpManagementPort") public static final PortAttributeSensorAndConfigKey HTTP_MANAGEMENT_PORT = new PortAttributeSensorAndConfigKey("qpid.http-management.port", "Qpid HTTP management plugin port"); - /** Files to be copied to the server, map of "subpath/file.name": "classpath://foo/file.txt" (or other url) */ - @SetFromFlag("runtimeFiles") - public static final BasicConfigKey<Map<String, String>> RUNTIME_FILES = new BasicConfigKey( - Map.class, "qpid.files.runtime", "Map of files to be copied, keyed by destination name relative to runDir"); - - /** Templates to be filled in and then copied to the server. See {@link #RUNTIME_FILES}. */ - @SetFromFlag("runtimeTemplates") - public static final BasicConfigKey<Map<String, String>> RUNTIME_TEMPLATES = new BasicConfigKey( - Map.class, "qpid.templates.runtime", "Map of templates to be filled in and copied, keyed by destination name relative to runDir"); - @SetFromFlag("jmxUser") public static final BasicAttributeSensorAndConfigKey<String> JMX_USER = new BasicAttributeSensorAndConfigKey<String>( UsesJmx.JMX_USER, "admin");
