Brooklyn

brooklyn.entity.basic.lifecycle
[Java] Class ScriptHelper

java.lang.Object
  brooklyn.entity.basic.lifecycle.ScriptHelper

public class ScriptHelper

Field Summary
ScriptPart body

protected Predicate executionCheck

protected java.util.Map flags

ScriptPart footer

protected boolean gatherOutput

ScriptPart header

protected boolean isTransient

static Logger log

protected java.lang.Runnable mutexAcquire

protected java.lang.Runnable mutexRelease

protected Predicate resultCodeCheck

protected NaiveScriptRunner runner

protected java.io.ByteArrayOutputStream stderr

protected java.io.ByteArrayOutputStream stdout

java.lang.String summary

protected Task task

 
Constructor Summary
ScriptHelper(NaiveScriptRunner runner, java.lang.String summary)

 
Method Summary
ScriptHelper environmentVariablesReset()

ensures the script runs with no environment variables; by default they will be inherited

ScriptHelper environmentVariablesReset(java.util.Map envVarsToSet)

overrides the default environment variables to use the given set; by default they will be inherited.

int execute()

ScriptHelper executeIf(groovy.lang.Closure c)

Takes a closure which accepts this ScriptHelper and returns true or false as to whether the script needs to run (or can throw error if desired)

ScriptHelper executeIf(Predicate c)

int executeInternal()

ScriptHelper failIfBodyEmpty()

ScriptHelper failOnNonZeroResultCode(boolean val)

ScriptHelper failOnNonZeroResultCode()

ScriptHelper failOnNonZeroResultCodeWithoutUpdatingTask()

ScriptHelper gatherOutput()

ScriptHelper gatherOutput(boolean gather)

java.util.Map getFlags()

java.util.List getLines()

java.lang.String getResultStderr()

java.lang.String getResultStdout()

protected java.lang.RuntimeException logWithDetailsAndThrow(java.lang.String message, java.lang.Throwable optionalCause)

Task newTask()

creates a task which will execute this script; note this can only be run once per instance of this class

Task peekTask()

returns the task, if it has been constructed, or null; use newTask() to build (if it is null and you need a task)

Task queue()

queues the task for execution if we are in a TaskQueueingContext (e.g.

ScriptHelper requireResultCode(groovy.lang.Closure integerFilter)

Convenience for error-checking the result.

ScriptHelper requireResultCode(Predicate integerFilter)

ScriptHelper setFlag(java.lang.String flag, java.lang.Object value)

ScriptHelper setFlag(ConfigKey flag, java.lang.Object value)

void setTransient()

indicates explicitly that the task can be safely forgotten about after it runs; useful for things like check_running which run repeatedly

ScriptHelper skipIfBodyEmpty()

ScriptHelper updateTaskAndFailOnNonZeroResultCode()

ScriptHelper useMutex(WithMutexes mutexSupport, java.lang.String mutexId, java.lang.String description)

indicates that the script should acquire the given mutexId on the given mutexSupport and maintain it for the duration of script execution; typically used to prevent parallel scripts from conflicting in access to a resource (e.g. a folder, or a config file used by a process)

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

body

public final ScriptPart body


executionCheck

protected Predicate executionCheck


flags

protected final java.util.Map flags


footer

public final ScriptPart footer


gatherOutput

protected boolean gatherOutput


header

public final ScriptPart header


isTransient

protected boolean isTransient


log

public static final Logger log


mutexAcquire

protected java.lang.Runnable mutexAcquire


mutexRelease

protected java.lang.Runnable mutexRelease


resultCodeCheck

protected Predicate resultCodeCheck


runner

protected final NaiveScriptRunner runner


stderr

protected java.io.ByteArrayOutputStream stderr


stdout

protected java.io.ByteArrayOutputStream stdout


summary

public final java.lang.String summary


task

protected Task task


 
Constructor Detail

ScriptHelper

public ScriptHelper(NaiveScriptRunner runner, java.lang.String summary)


 
Method Detail

environmentVariablesReset

public ScriptHelper environmentVariablesReset()
ensures the script runs with no environment variables; by default they will be inherited


environmentVariablesReset

public ScriptHelper environmentVariablesReset(java.util.Map envVarsToSet)
overrides the default environment variables to use the given set; by default they will be inherited. TODO would be nice to have a way to add just a few, but there is no way currently to access the getShellEnvironment() from the driver which is what gets inherited (at execution time)


execute

public int execute()


executeIf

public ScriptHelper executeIf(groovy.lang.Closure c)
Takes a closure which accepts this ScriptHelper and returns true or false as to whether the script needs to run (or can throw error if desired)


executeIf

public ScriptHelper executeIf(Predicate c)


executeInternal

public int executeInternal()


failIfBodyEmpty

public ScriptHelper failIfBodyEmpty()


failOnNonZeroResultCode

public ScriptHelper failOnNonZeroResultCode(boolean val)


failOnNonZeroResultCode

public ScriptHelper failOnNonZeroResultCode()


failOnNonZeroResultCodeWithoutUpdatingTask

public ScriptHelper failOnNonZeroResultCodeWithoutUpdatingTask()


gatherOutput

public ScriptHelper gatherOutput()


gatherOutput

public ScriptHelper gatherOutput(boolean gather)


getFlags

public java.util.Map getFlags()


getLines

public java.util.List getLines()


getResultStderr

public java.lang.String getResultStderr()


getResultStdout

public java.lang.String getResultStdout()


logWithDetailsAndThrow

protected java.lang.RuntimeException logWithDetailsAndThrow(java.lang.String message, java.lang.Throwable optionalCause)


newTask

public Task newTask()
creates a task which will execute this script; note this can only be run once per instance of this class


peekTask

public Task peekTask()
returns the task, if it has been constructed, or null; use newTask() to build (if it is null and you need a task)


queue

public Task queue() {
public Task queue()
queues the task for execution if we are in a TaskQueueingContext (e.g. EffectorTaskFactory); or if we aren't in a queueing context, it will submit the task (assuming there is an ExecutionContext _and_ block until completion, throwing on error


requireResultCode

public ScriptHelper requireResultCode(groovy.lang.Closure integerFilter)
Convenience for error-checking the result.

Takes closure which accepts bash exit code (integer), and returns false if it is invalid. Default is that this resultCodeCheck closure always returns true (and the exit code is made available to the caller if they care)


requireResultCode

public ScriptHelper requireResultCode(Predicate integerFilter)


setFlag

public ScriptHelper setFlag(java.lang.String flag, java.lang.Object value)


setFlag

public ScriptHelper setFlag(ConfigKey flag, java.lang.Object value)


setTransient

public void setTransient()
indicates explicitly that the task can be safely forgotten about after it runs; useful for things like check_running which run repeatedly


skipIfBodyEmpty

public ScriptHelper skipIfBodyEmpty()


updateTaskAndFailOnNonZeroResultCode

public ScriptHelper updateTaskAndFailOnNonZeroResultCode()


useMutex

public ScriptHelper useMutex(WithMutexes mutexSupport, java.lang.String mutexId, java.lang.String description)
indicates that the script should acquire the given mutexId on the given mutexSupport and maintain it for the duration of script execution; typically used to prevent parallel scripts from conflicting in access to a resource (e.g. a folder, or a config file used by a process)


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.