org.rhq.plugins.script
Class ScriptServerComponent

java.lang.Object
  extended by org.rhq.plugins.script.ScriptServerComponent
All Implemented Interfaces:
AvailabilityFacet, ResourceComponent, MeasurementFacet, OperationFacet

public class ScriptServerComponent
extends Object
implements ResourceComponent, MeasurementFacet, OperationFacet

Represents a managed resource whose management interface is a command line executable or script, sometimes referred to as the "CLI" (command line interface).

Author:
John Mazzitelli

Field Summary
protected static String METRIC_PROPERTY_ARGUMENTS
           
protected static String METRIC_PROPERTY_EXITCODE
           
protected static String METRIC_PROPERTY_REGEX
           
protected static String OPERATION_PARAM_ARGUMENTS
           
protected static String OPERATION_RESULT_EXITCODE
           
protected static String OPERATION_RESULT_OUTPUT
           
protected static String PLUGINCONFIG_AVAIL_ARGS
           
protected static String PLUGINCONFIG_AVAIL_EXECUTE_CHECK
           
protected static String PLUGINCONFIG_AVAIL_EXITCODE_REGEX
           
protected static String PLUGINCONFIG_AVAIL_OUTPUT_REGEX
           
protected static String PLUGINCONFIG_DESC_ARGS
           
protected static String PLUGINCONFIG_DESC_REGEX
           
protected static String PLUGINCONFIG_ENVVAR_NAME
           
protected static String PLUGINCONFIG_ENVVAR_VALUE
           
protected static String PLUGINCONFIG_ENVVARS
           
protected static String PLUGINCONFIG_EXECUTABLE
           
protected static String PLUGINCONFIG_FIXED_DESC
           
protected static String PLUGINCONFIG_FIXED_VERSION
           
protected static String PLUGINCONFIG_VERSION_ARGS
           
protected static String PLUGINCONFIG_VERSION_REGEX
           
protected static String PLUGINCONFIG_WORKINGDIR
           
 
Constructor Summary
ScriptServerComponent()
           
 
Method Summary
protected  ProcessExecutionResults executeExecutable(String args, long wait, boolean captureOutput)
          Executes the CLI executable with the given arguments.
protected static ProcessExecutionResults executeExecutable(SystemInfo sysInfo, Configuration pluginConfig, String args, long wait, boolean captureOutput)
           
 AvailabilityType getAvailability()
           
protected  ResourceContext getResourcContext()
           
 void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> requests)
          Executes the CLI and based on the measurement property, collects the appropriate measurement value.
 OperationResult invokeOperation(String name, Configuration configuration)
          Invokes the CLI executable.
protected  Map<String,String> parseMetricProperty(String metricPropertyName)
          Given a metric property name, this parses it into its different pieces and returns a map of the different tokens.
 void start(ResourceContext context)
           
 void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PLUGINCONFIG_EXECUTABLE

protected static final String PLUGINCONFIG_EXECUTABLE
See Also:
Constant Field Values

PLUGINCONFIG_WORKINGDIR

protected static final String PLUGINCONFIG_WORKINGDIR
See Also:
Constant Field Values

PLUGINCONFIG_ENVVARS

protected static final String PLUGINCONFIG_ENVVARS
See Also:
Constant Field Values

PLUGINCONFIG_ENVVAR_NAME

protected static final String PLUGINCONFIG_ENVVAR_NAME
See Also:
Constant Field Values

PLUGINCONFIG_ENVVAR_VALUE

protected static final String PLUGINCONFIG_ENVVAR_VALUE
See Also:
Constant Field Values

PLUGINCONFIG_AVAIL_EXECUTE_CHECK

protected static final String PLUGINCONFIG_AVAIL_EXECUTE_CHECK
See Also:
Constant Field Values

PLUGINCONFIG_AVAIL_EXITCODE_REGEX

protected static final String PLUGINCONFIG_AVAIL_EXITCODE_REGEX
See Also:
Constant Field Values

PLUGINCONFIG_AVAIL_OUTPUT_REGEX

protected static final String PLUGINCONFIG_AVAIL_OUTPUT_REGEX
See Also:
Constant Field Values

PLUGINCONFIG_AVAIL_ARGS

protected static final String PLUGINCONFIG_AVAIL_ARGS
See Also:
Constant Field Values

PLUGINCONFIG_VERSION_ARGS

protected static final String PLUGINCONFIG_VERSION_ARGS
See Also:
Constant Field Values

PLUGINCONFIG_VERSION_REGEX

protected static final String PLUGINCONFIG_VERSION_REGEX
See Also:
Constant Field Values

PLUGINCONFIG_FIXED_VERSION

protected static final String PLUGINCONFIG_FIXED_VERSION
See Also:
Constant Field Values

PLUGINCONFIG_DESC_ARGS

protected static final String PLUGINCONFIG_DESC_ARGS
See Also:
Constant Field Values

PLUGINCONFIG_DESC_REGEX

protected static final String PLUGINCONFIG_DESC_REGEX
See Also:
Constant Field Values

PLUGINCONFIG_FIXED_DESC

protected static final String PLUGINCONFIG_FIXED_DESC
See Also:
Constant Field Values

OPERATION_PARAM_ARGUMENTS

protected static final String OPERATION_PARAM_ARGUMENTS
See Also:
Constant Field Values

OPERATION_RESULT_EXITCODE

protected static final String OPERATION_RESULT_EXITCODE
See Also:
Constant Field Values

OPERATION_RESULT_OUTPUT

protected static final String OPERATION_RESULT_OUTPUT
See Also:
Constant Field Values

METRIC_PROPERTY_ARGUMENTS

protected static final String METRIC_PROPERTY_ARGUMENTS
See Also:
Constant Field Values

METRIC_PROPERTY_REGEX

protected static final String METRIC_PROPERTY_REGEX
See Also:
Constant Field Values

METRIC_PROPERTY_EXITCODE

protected static final String METRIC_PROPERTY_EXITCODE
See Also:
Constant Field Values
Constructor Detail

ScriptServerComponent

public ScriptServerComponent()
Method Detail

start

public void start(ResourceContext context)
Specified by:
start in interface ResourceComponent

stop

public void stop()
Specified by:
stop in interface ResourceComponent

getAvailability

public AvailabilityType getAvailability()
Specified by:
getAvailability in interface AvailabilityFacet

getValues

public void getValues(MeasurementReport report,
                      Set<MeasurementScheduleRequest> requests)
Executes the CLI and based on the measurement property, collects the appropriate measurement value. This supports measurement data and traits. A metric property can be a string that is assumed the arguments to pass to the CLI. However, if the property is in the form "{arguments}|regex", the arguments are passed to the CLI and the metric value is taken from the regex match. Examples of metric properties:

Specified by:
getValues in interface MeasurementFacet
See Also:
MeasurementFacet.getValues(MeasurementReport, Set)

parseMetricProperty

protected Map<String,String> parseMetricProperty(String metricPropertyName)
Given a metric property name, this parses it into its different pieces and returns a map of the different tokens. The format of the metric property one of the following:
 arguments
 {arguments}|regex
 {arguments}|exitcode
 
where "arguments" is the empty or non-empty string of the arguments to pass to the CLI executable, regex is a empty or non-empty regular expresssion string to match the output (if there is a matching group in the regex, its value will be used as the metric value, not the full output of the executable), exitcode is the literal string "exitcode" to indicate that the exit code value is to be used as the metric value.

Parameters:
metricPropertyName - the name of the property in the metric descriptor
Returns:
map containing the pieces that have been parsed out - the keys are either METRIC_PROPERTY_ARGUMENTS or METRIC_PROPERTY_REGEX. The map will be null if the property name is invalid for some reason. A map entry will not exist if it was not specified in the property name.

invokeOperation

public OperationResult invokeOperation(String name,
                                       Configuration configuration)
                                throws Exception
Invokes the CLI executable. User can tell us what arguments to pass to the executable. The result includes the output of the process as well as the exit code.

Specified by:
invokeOperation in interface OperationFacet
Throws:
Exception
See Also:
OperationFacet.invokeOperation(String, Configuration)

getResourcContext

protected ResourceContext getResourcContext()

executeExecutable

protected ProcessExecutionResults executeExecutable(String args,
                                                    long wait,
                                                    boolean captureOutput)
                                             throws InvalidPluginConfigurationException
Executes the CLI executable with the given arguments.

Parameters:
args - the arguments to send to the executable (may be null)
wait - the maximum time in milliseconds to wait for the process to execute; 0 means do not wait
captureOutput - if true, the executables output will be captured and returned
Returns:
the results of the execution
Throws:
InvalidPluginConfigurationException

executeExecutable

protected static ProcessExecutionResults executeExecutable(SystemInfo sysInfo,
                                                           Configuration pluginConfig,
                                                           String args,
                                                           long wait,
                                                           boolean captureOutput)
                                                    throws InvalidPluginConfigurationException
Throws:
InvalidPluginConfigurationException


Copyright © 2008-2011 Red Hat, Inc.. All Rights Reserved.