com.dtolabs.rundeck.core.cli
Class ExecTool

java.lang.Object
  extended by com.dtolabs.rundeck.core.cli.ExecTool
All Implemented Interfaces:
CLILoggerParams, CLITool, CLIToolLogger, IDispatchedExecution, IDispatchedScript, BaseLogger

public class ExecTool
extends java.lang.Object
implements CLITool, IDispatchedScript, CLILoggerParams

Main class for dispatch command line tool. This command will dispatch the command either locally or remotely.


Nested Class Summary
static interface ExecTool.NodeFormatter
           
 
Field Summary
protected  org.apache.commons.cli.CommandLine cli
          Reference to command line params
static java.lang.String DEFAULT_LOG_FORMAT
           
protected  java.io.PrintStream err
           
static java.lang.String FRAMEWORK_LOG_RUNDECK_EXEC_CONSOLE_FORMAT
           
protected  ExecTool.NodeFormatter nodeFormatter
           
static int NODESET_EMPTY_EXIT_CODE
          Exit code for a Nodeset Empty failure exception
protected static org.apache.commons.cli.Options options
          reference to the command line Options instance.
protected  java.io.PrintStream out
           
 
Constructor Summary
ExecTool(Framework framework)
          Create a new ExecTool with the given framework instance.
 
Method Summary
protected  void configurePrintStream(boolean quiet)
          Reconfigures the System.out PrintStream to write to a file output stream.
protected  NodeSet createFilterNodeSelector()
          Crete a NodeSet using the parsed argument values
protected  NodeSet createNodeSet(java.util.Map includeMap, java.util.Map excludeMap)
          Create a NodeSet using the included maps, where exclusion has precedence
protected static NodeSet createNodeSet(java.util.Map includeMap, java.util.Map excludeMap, boolean excludePrecedence, java.lang.Integer threadCount, boolean keepgoing, java.io.File failedNodesfile)
          Create a NodeSet using the included maps, and boolean exclude value
 void debug(java.lang.String message)
          Logs debug message via implementation specific log facility
 void debug(java.lang.String message, java.util.Map<java.lang.String,java.lang.String> context)
           
 void error(java.lang.String message)
          Logs error message via implementation specific log facility
 void error(java.lang.String message, java.util.Map<java.lang.String,java.lang.String> context)
           
 void exit(int exitcode)
          Calls the exit method
 java.lang.String generateExecLine(java.util.Map<java.lang.String,java.lang.String> filterArgs)
          Generates the commandline execution string used.
 int getAntLoglevel()
          Return the Ant loglevel equivalent to the input flags (verbose,debug,quiet).
 java.lang.String getArgFrameworkProject()
           
 java.lang.String[] getArgs()
          Get the argument line definition
 java.lang.String[] getArgsDeferred()
           
 java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> getDataContext()
          Return data context set
 Framework getFramework()
           
 java.lang.String getFrameworkProject()
          Get the framework project name
 java.lang.String getInlineScriptContent()
           
 int getLoglevel()
          Return the loglevel value, using the Ant equivalents: DEBUG=1,
 java.lang.String getNodeRankAttribute()
           
 INodeSet getNodes()
           
 NodesSelector getNodeSelector()
           
 NodeSet getNodeSet()
          Return the nodeset configuration
 java.lang.String getScript()
          Get the full script
 java.io.InputStream getScriptAsStream()
          Get an InputStream that can provide the full script
 java.lang.String getScriptpath()
           
 java.lang.String getScriptURLString()
          Get the script URL
 java.lang.String getServerScriptFilePath()
          Get the server-local script path
 int getThreadCount()
           
 java.lang.String getUser()
           
 void help()
          Writes help message to implementation specific output channel.
 boolean isDebug()
          Return true if debug logging is on
 boolean isInlineScript()
           
 boolean isKeepgoing()
           
 boolean isNodeRankOrderAscending()
           
 boolean isQuiet()
          Return true if quiet logging is on
 boolean isVerbose()
          Return true for verbose logging
 void log(java.lang.String message)
          Logs message via implementation specific log facility
 void log(java.lang.String message, java.util.Map<java.lang.String,java.lang.String> context)
           
static void main(java.lang.String[] args)
          Creates an instance and executes run(String[]).
 org.apache.commons.cli.CommandLine parseArgs(java.lang.String[] args)
          Reads the argument vector and constructs a CommandLine object containing params
protected  java.util.Map parseExcludeArgs(java.lang.String[] keys)
          Parse the value of the -X option
protected static java.util.Map<java.lang.String,java.lang.String> parseFilterArgs(java.lang.String[] keys, org.apache.commons.cli.CommandLine cli, java.lang.String opt)
           
protected  java.util.Map parseIncludeArgs(java.lang.String[] keys)
          Parse the value of the -X option.
protected static java.util.Map<java.lang.String,java.lang.String> parseMultiNodeArgs(java.lang.String[] keys, java.lang.String[] values)
          Parse the values as key=value pairs, using the set of allowed keys.
 void run(java.lang.String[] args)
          The run method carries out the lifecycle of the tool, parsing args, handling exceptions, and exiting with a suitable exit code.
 void setScriptAsStream(java.io.InputStream scriptAsStream)
           
 void verbose(java.lang.String message)
          Logs verbose message via implementation specific log facility
 void verbose(java.lang.String message, java.util.Map<java.lang.String,java.lang.String> context)
           
 void warn(java.lang.String message)
          Logs warning message via implementation specific log facility
 void warn(java.lang.String message, java.util.Map<java.lang.String,java.lang.String> context)
           
protected  java.io.File writeInputToFile(java.io.InputStream input)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

err

protected java.io.PrintStream err

out

protected java.io.PrintStream out

cli

protected org.apache.commons.cli.CommandLine cli
Reference to command line params


options

protected static final org.apache.commons.cli.Options options
reference to the command line Options instance.


nodeFormatter

protected ExecTool.NodeFormatter nodeFormatter

NODESET_EMPTY_EXIT_CODE

public static final int NODESET_EMPTY_EXIT_CODE
Exit code for a Nodeset Empty failure exception

See Also:
Constant Field Values

DEFAULT_LOG_FORMAT

public static final java.lang.String DEFAULT_LOG_FORMAT
See Also:
Constant Field Values

FRAMEWORK_LOG_RUNDECK_EXEC_CONSOLE_FORMAT

public static final java.lang.String FRAMEWORK_LOG_RUNDECK_EXEC_CONSOLE_FORMAT
See Also:
Constant Field Values
Constructor Detail

ExecTool

public ExecTool(Framework framework)
Create a new ExecTool with the given framework instance.

Parameters:
framework - framework instance
Method Detail

parseArgs

public org.apache.commons.cli.CommandLine parseArgs(java.lang.String[] args)
Reads the argument vector and constructs a CommandLine object containing params

Specified by:
parseArgs in interface CLITool
Parameters:
args - the cli arg vector
Returns:
a new instance of CommandLine

generateExecLine

public java.lang.String generateExecLine(java.util.Map<java.lang.String,java.lang.String> filterArgs)
Generates the commandline execution string used. If filterArgs are specified, they are used in place of the commandline filter args when the -F option is not present.

Parameters:
filterArgs - set of filter commandline arguments to insert
Returns:
String of the previously executed commandline, modified with the given filterArgs if present

parseExcludeArgs

protected java.util.Map parseExcludeArgs(java.lang.String[] keys)
Parse the value of the -X option

Parameters:
keys -
Returns:

parseIncludeArgs

protected java.util.Map parseIncludeArgs(java.lang.String[] keys)
Parse the value of the -X option.

Parameters:
keys -
Returns:

run

public void run(java.lang.String[] args)
The run method carries out the lifecycle of the tool, parsing args, handling exceptions, and exiting with a suitable exit code.

Specified by:
run in interface CLITool
Parameters:
args - the cli arg vector

getUser

public java.lang.String getUser()

createFilterNodeSelector

protected NodeSet createFilterNodeSelector()
Crete a NodeSet using the parsed argument values

Returns:
NodeSet

createNodeSet

protected NodeSet createNodeSet(java.util.Map includeMap,
                                java.util.Map excludeMap)
Create a NodeSet using the included maps, where exclusion has precedence

Parameters:
includeMap - include map
excludeMap - exclude map
Returns:
NodeSet

createNodeSet

protected static NodeSet createNodeSet(java.util.Map includeMap,
                                       java.util.Map excludeMap,
                                       boolean excludePrecedence,
                                       java.lang.Integer threadCount,
                                       boolean keepgoing,
                                       java.io.File failedNodesfile)
Create a NodeSet using the included maps, and boolean exclude value

Parameters:
includeMap - include map
excludeMap - exclude map
excludePrecedence - if true, exclusion has precedence
threadCount - the threadcount
keepgoing - keepgoing boolean
failedNodesfile - file indicating list of failed nodes
Returns:
NodeSet

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Creates an instance and executes run(String[]).

Parameters:
args -
Throws:
java.lang.Exception

exit

public void exit(int exitcode)
Calls the exit method

Specified by:
exit in interface CLITool
Parameters:
exitcode - return code to exit with

help

public void help()
Writes help message to implementation specific output channel.

Specified by:
help in interface CLITool

log

public void log(java.lang.String message)
Logs message via implementation specific log facility

Specified by:
log in interface BaseLogger
Parameters:
message - message to log

warn

public void warn(java.lang.String message)
Logs warning message via implementation specific log facility

Specified by:
warn in interface BaseLogger
Parameters:
message - message to log

error

public void error(java.lang.String message)
Logs error message via implementation specific log facility

Specified by:
error in interface BaseLogger
Parameters:
message - message to log

debug

public void debug(java.lang.String message)
Description copied from interface: BaseLogger
Logs debug message via implementation specific log facility

Specified by:
debug in interface BaseLogger
Parameters:
message - message to log

verbose

public void verbose(java.lang.String message)
Logs verbose message via implementation specific log facility

Specified by:
verbose in interface BaseLogger
Parameters:
message - message to log

configurePrintStream

protected void configurePrintStream(boolean quiet)
Reconfigures the System.out PrintStream to write to a file output stream.

Parameters:
quiet - If true, configures to write to a file.

getArgFrameworkProject

public java.lang.String getArgFrameworkProject()

getArgsDeferred

public java.lang.String[] getArgsDeferred()

getScriptpath

public java.lang.String getScriptpath()

isInlineScript

public boolean isInlineScript()

getInlineScriptContent

public java.lang.String getInlineScriptContent()

getFramework

public Framework getFramework()

getNodeSelector

public NodesSelector getNodeSelector()

getNodes

public INodeSet getNodes()

getThreadCount

public int getThreadCount()

getNodeRankAttribute

public java.lang.String getNodeRankAttribute()

isNodeRankOrderAscending

public boolean isNodeRankOrderAscending()

isKeepgoing

public boolean isKeepgoing()

getFrameworkProject

public java.lang.String getFrameworkProject()
Description copied from interface: IDispatchedScript
Get the framework project name

Specified by:
getFrameworkProject in interface IDispatchedScript
Returns:
project name

getScript

public java.lang.String getScript()
Description copied from interface: IDispatchedScript
Get the full script

Specified by:
getScript in interface IDispatchedScript
Returns:
the script string

getScriptAsStream

public java.io.InputStream getScriptAsStream()
Description copied from interface: IDispatchedScript
Get an InputStream that can provide the full script

Specified by:
getScriptAsStream in interface IDispatchedScript
Returns:
the inputstream

setScriptAsStream

public void setScriptAsStream(java.io.InputStream scriptAsStream)

getServerScriptFilePath

public java.lang.String getServerScriptFilePath()
Description copied from interface: IDispatchedScript
Get the server-local script path

Specified by:
getServerScriptFilePath in interface IDispatchedScript
Returns:
server-side script path

getNodeSet

public NodeSet getNodeSet()
Description copied from interface: IDispatchedExecution
Return the nodeset configuration

Specified by:
getNodeSet in interface IDispatchedExecution
Returns:
nodeset

getArgs

public java.lang.String[] getArgs()
Description copied from interface: IDispatchedExecution
Get the argument line definition

Specified by:
getArgs in interface IDispatchedExecution
Returns:
the arg

getLoglevel

public int getLoglevel()
Description copied from interface: IDispatchedExecution
Return the loglevel value, using the Ant equivalents: DEBUG=1,

Specified by:
getLoglevel in interface IDispatchedExecution
Returns:
log level from 0-4: ERR,WARN,INFO,VERBOSE,DEBUG

getDataContext

public java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> getDataContext()
Description copied from interface: IDispatchedExecution
Return data context set

Specified by:
getDataContext in interface IDispatchedExecution
Returns:
map of data contexts keyed by name

parseMultiNodeArgs

protected static java.util.Map<java.lang.String,java.lang.String> parseMultiNodeArgs(java.lang.String[] keys,
                                                                                     java.lang.String[] values)
Parse the values as key=value pairs, using the set of allowed keys. If there is only one entry in the values array without a key, then the first key of the allowed keys is used as the default

Parameters:
keys - allowed keys for the key=value strings, the first key is used as the default key
values - array of key=value strings, or merely 1 value string if the array is size 1
Returns:
map of the key to values

parseFilterArgs

protected static java.util.Map<java.lang.String,java.lang.String> parseFilterArgs(java.lang.String[] keys,
                                                                                  org.apache.commons.cli.CommandLine cli,
                                                                                  java.lang.String opt)

getScriptURLString

public java.lang.String getScriptURLString()
Description copied from interface: IDispatchedScript
Get the script URL

Specified by:
getScriptURLString in interface IDispatchedScript
Returns:
URL

writeInputToFile

protected java.io.File writeInputToFile(java.io.InputStream input)

getAntLoglevel

public int getAntLoglevel()
Return the Ant loglevel equivalent to the input flags (verbose,debug,quiet).

Returns:
loglevel

isDebug

public boolean isDebug()
Description copied from interface: CLILoggerParams
Return true if debug logging is on

Specified by:
isDebug in interface CLILoggerParams
Returns:
true for debug logging

isVerbose

public boolean isVerbose()
Description copied from interface: CLILoggerParams
Return true for verbose logging

Specified by:
isVerbose in interface CLILoggerParams
Returns:
true for verbose

isQuiet

public boolean isQuiet()
Description copied from interface: CLILoggerParams
Return true if quiet logging is on

Specified by:
isQuiet in interface CLILoggerParams
Returns:
true for quiet logging

log

public void log(java.lang.String message,
                java.util.Map<java.lang.String,java.lang.String> context)

error

public void error(java.lang.String message,
                  java.util.Map<java.lang.String,java.lang.String> context)

warn

public void warn(java.lang.String message,
                 java.util.Map<java.lang.String,java.lang.String> context)

verbose

public void verbose(java.lang.String message,
                    java.util.Map<java.lang.String,java.lang.String> context)

debug

public void debug(java.lang.String message,
                  java.util.Map<java.lang.String,java.lang.String> context)