Skip to content

Commit

Permalink
Parameterize the start effector
Browse files Browse the repository at this point in the history
- customize.skip as Brooklyn config key
- if customize.skip is set to true for an entity the driver will 
  skip the the customize commands
- added skipInstallation as a parameter to the SoftwareProcess start 
  effector
- if skipInstallation is used during the start effector invoking
  install.skip and customize.skip parameters will be set to true so
  install and customize phases are skipped and only launch is
  executed
  • Loading branch information
ygy committed Jan 7, 2016
1 parent cd504e2 commit fa253d9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public class BrooklynConfigKeys {
*/
public static final ConfigKey<Boolean> SKIP_ENTITY_INSTALLATION = newBooleanConfigKey("install.skip", "Skip the driver install commands entirely, for pre-installed software");

/**
* This will skip only the customize phase of the lifecycle and then continue with the launching of the entity.
*/
public static final ConfigKey<Boolean> SKIP_ENTITY_CUSTOMIZATION = newBooleanConfigKey("customize.skip", "Skip the driver customize commands entirely");

// 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.os.Os;
import org.apache.brooklyn.util.stream.ReaderInputStream;
import org.apache.brooklyn.util.text.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -122,6 +121,9 @@ public void start() {

Optional<Boolean> locationInstalled = Optional.fromNullable(getLocation().getConfig(BrooklynConfigKeys.SKIP_ENTITY_INSTALLATION));
Optional<Boolean> entityInstalled = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_ENTITY_INSTALLATION));

boolean skipCustomized = Optional.fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_ENTITY_CUSTOMIZATION)).or(false);

boolean skipInstall = locationInstalled.or(entityInstalled).or(false);
if (!skipInstall) {
DynamicTasks.queue("setup", new Runnable() { public void run() {
Expand All @@ -144,10 +146,12 @@ public void start() {
runPostInstallCommand();
}});

DynamicTasks.queue("customize", new Runnable() { public void run() {
waitForConfigKey(BrooklynConfigKeys.CUSTOMIZE_LATCH);
customize();
}});
if (!skipCustomized) {
DynamicTasks.queue("customize", new Runnable() { public void run() {
waitForConfigKey(BrooklynConfigKeys.CUSTOMIZE_LATCH);
customize();
}});
}

DynamicTasks.queue("copy-runtime-resources", new Runnable() { public void run() {
waitForConfigKey(BrooklynConfigKeys.RUNTIME_RESOURCES_LATCH);
Expand All @@ -163,9 +167,9 @@ public void start() {
launch();
}});

DynamicTasks.queue("post-launch-command", new Runnable() { public void run() {
runPostLaunchCommand();
}});
DynamicTasks.queue("post-launch-command", new Runnable() { public void run() {
runPostLaunchCommand();
}});
}

DynamicTasks.queue("post-launch", new Runnable() { public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@ private ChildStartableMode(boolean isDisabled, boolean isBackground, boolean isL

AttributeSensor<String> PID_FILE = Sensors.newStringSensor("softwareprocess.pid.file", "PID file");

@Beta
public static class StartSoftwareParameters {
@Beta /** @since 0.9.0 */
public static final ConfigKey<Boolean> SKIP_INSTALLATION = ConfigKeys.newConfigKey(Boolean.class, "skipInstallation",
"Just launch the process without installation and customization, if stopped; default false", false);
}

@Beta
public static class RestartSoftwareParameters {
@Beta /** @since 0.7.0 semantics of parameters to restart being explored */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.apache.brooklyn.entity.machine.ProvidesProvisioningFlags;
import org.apache.brooklyn.entity.software.base.SoftwareProcess;
import org.apache.brooklyn.entity.software.base.SoftwareProcess.RestartSoftwareParameters;
import org.apache.brooklyn.entity.software.base.SoftwareProcess.StartSoftwareParameters;
import org.apache.brooklyn.entity.software.base.SoftwareProcess.StopSoftwareParameters;
import org.apache.brooklyn.entity.software.base.SoftwareProcess.RestartSoftwareParameters.RestartMachineMode;
import org.apache.brooklyn.entity.software.base.SoftwareProcess.StopSoftwareParameters.StopMode;
Expand Down Expand Up @@ -140,7 +141,10 @@ public void attachLifecycleEffectors(Entity entity) {
* the behaviour in this lifecycle class instance.
*/
public Effector<Void> newStartEffector() {
return Effectors.effector(Startable.START).impl(newStartEffectorTask()).build();
return Effectors.effector(Startable.START)
.parameter(StartSoftwareParameters.SKIP_INSTALLATION)
.impl(newStartEffectorTask())
.build();
}

/** @see {@link #newStartEffector()} */
Expand Down Expand Up @@ -183,6 +187,12 @@ public EffectorBody<Void> newStartEffectorTask() {
public Void call(ConfigBag parameters) {
Collection<? extends Location> locations = null;

Boolean isSkipInstallation = parameters.get(StartSoftwareParameters.SKIP_INSTALLATION);
if (isSkipInstallation != null && isSkipInstallation) {
entity().config().set(BrooklynConfigKeys.SKIP_ENTITY_INSTALLATION, isSkipInstallation);
entity().config().set(BrooklynConfigKeys.SKIP_ENTITY_CUSTOMIZATION, isSkipInstallation);
}

Object locationsRaw = parameters.getStringKey(LOCATIONS.getName());
locations = Locations.coerceToCollection(entity().getManagementContext(), locationsRaw);

Expand All @@ -203,6 +213,12 @@ private class StartEffectorBody extends EffectorBody<Void> {
public Void call(ConfigBag parameters) {
Collection<? extends Location> locations = null;

Boolean isSkipInstallation = parameters.get(StartSoftwareParameters.SKIP_INSTALLATION);
if (isSkipInstallation != null && isSkipInstallation) {
entity().config().set(BrooklynConfigKeys.SKIP_ENTITY_INSTALLATION, isSkipInstallation);
entity().config().set(BrooklynConfigKeys.SKIP_ENTITY_CUSTOMIZATION, isSkipInstallation);
}

Object locationsRaw = parameters.getStringKey(LOCATIONS.getName());
locations = Locations.coerceToCollection(entity().getManagementContext(), locationsRaw);

Expand Down

0 comments on commit fa253d9

Please sign in to comment.