Package net.sf.basedb.plugins.executor
Class ExternalProgramExecutor
java.lang.Object
net.sf.basedb.core.plugin.AbstractPlugin
net.sf.basedb.core.plugin.AbstractAnalysisPlugin
net.sf.basedb.plugins.executor.ExternalProgramExecutor
- All Implemented Interfaces:
InteractivePlugin
,Plugin
,SignalTarget
public class ExternalProgramExecutor
extends AbstractAnalysisPlugin
implements InteractivePlugin, SignalTarget
- Since:
- 2.15
- Author:
- martin, nicklas
- Last modified
- $Date: 2019-02-26 11:10:15 +0100 (tis, 26 feb. 2019) $
-
Nested Class Summary
Modifier and TypeClassDescription(package private) static class
(package private) static class
Nested classes/interfaces inherited from interface net.sf.basedb.core.plugin.Plugin
Plugin.MainType
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final String
private RequestInformation
private RequestInformation
private RequestInformation
private RequestInformation
private IOSupport
private IOSupport
Files that are known to exists in the working directory.static final String
The namespace for the exporter plug-in parameters.static final String
The namespace for the external program parameters.static final String
The namespace for the importer plug-in parameters.static final String
Parameter name for debug mode flag.static final String
Parameter name for the class that has been selected as the exporter.static final String
Parameter name for the command line options to the external program.static final String
Parameter name for the xml holding the parameter definitions to the external program.static final String
Parameter name for the path to the external program.static final String
Parameter name for the class that has been selected as the importer.static final String
Parameter name for the required number of channels.static final String
Parameter name for the required raw data type.static final String
Parameter name for the source bioassay set.static final String
Parameter name for the required intensity transform of the source bioassay set.private ThreadSignalHandler
private File
Temporary working directory at runtime.Fields inherited from class net.sf.basedb.core.plugin.AbstractAnalysisPlugin
CHILD_DESCRIPTION, CHILD_NAME, CONTEXT_BIOASSAYS, CONTEXT_BIOASSAYSET, CONTEXT_DERIVEDBIOASSAY, defaultGuiContexts, nameType, optionalNameType, SOURCE_BIOASSAYS, SOURCE_BIOASSAYSET, SOURCE_DERIVEDBIOASSAY, TRANSFORMATION_NAME
Fields inherited from class net.sf.basedb.core.plugin.AbstractPlugin
annotationSection, configuration, COPY_ANNOTATIONS, job, OVERWRITE_ANNOTATIONS, sc
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate void
addParametersWithNamespace
(List<PluginParameter<?>> to, List<PluginParameter<?>> from, String namespace) Add more parameters to a list of parameters with a different namespace.void
configure
(GuiContext context, Request request, Response response) Configure the plugin.createFile
(String name) Create a new file in the working directory.protected IOSupport
createInstance
(DbControl dc, PluginDefinition plugin, String namespace, boolean runtime) Create and initialize a plug-in instance for the given plug-in definition.protected File
Create a temporary working directory in the local file system.private RequestInformation
private RequestInformation
private RequestInformation
private RequestInformation
Get the bioassay set that is used as the source for the job.private List<PluginParameter<?>>
getExernalPluginParameters
(DbControl dc, BioAssaySet source) protected IOSupport
getExporter
(DbControl dc, boolean forceNew, boolean runtime) Get an instance of the exporter plug-in.protected IOSupport
getImporter
(DbControl dc, boolean forceNew, boolean runtime) Get an instance of the importer plug-in.getParameterDefinitions
(boolean validate) Get the current program parameter definitions.Get all program parameters and their values.getRequestInformation
(GuiContext context, String command) This method will return theRequestInformation
for a given command, i.e.Get the signal handler that is handling signals on behalf of this object.Get the current working directory were data files for the external program are stored.Check the working directory for new files.isInContext
(GuiContext context, Object item) Check that the item is a bioassayset/derived bioassay and that the logged in user has permission to use the current item.boolean
Returns FALSE, since that is how the plugins used to work before this method was introduced.void
run
(Request request, Response response, ProgressReporter progress) Run the plugin.protected void
runExporter
(Request request, Response response, ProgressReporter progress) Execute the exporter plug-in using the supplied parameters.protected void
runExternalProgram
(String program, String cmdLine, File workDir, String stdin, String stdout, ProgressReporter progress) Run the external program.protected void
runImporter
(Request request, Response response, ProgressReporter progress) Execute the importer plug-in using the supplied parameters.boolean
Returns TRUE, since that is how the plugins used to work before this method was introduced.Methods inherited from class net.sf.basedb.core.plugin.AbstractAnalysisPlugin
getChildDescriptionParameter, getChildNameParameter, getCurrentDerivedBioAssay, getCurrentExperiment, getGuiContexts, getMainType, getSourceBioAssays, getSourceBioAssaySet, getSourceBioAssaySetParameter, getSourceBioAssaysParameter, getSourceDerivedBioAssay, getSourceDerivedBioAssayParameter, getTransformationName, getTransformationNameParameter, restrictSource
Methods inherited from class net.sf.basedb.core.plugin.AbstractPlugin
cloneParameterWithDefaultValue, closeLogFile, createLogFile, done, getCopyAnnotationsParmeter, getCurrentConfiguration, getCurrentJob, getJobOrConfigurationValue, getOverwriteAnnotationsParameters, getPermissions, init, isLogging, log, log, storeValue, storeValue, storeValues, validateRequestParameters
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.sf.basedb.core.plugin.InteractivePlugin
getGuiContexts
Methods inherited from interface net.sf.basedb.core.plugin.Plugin
done, getMainType, getPermissions, init
-
Field Details
-
PARAMETER_EXTERNAL_PATH
Parameter name for the path to the external program. This parameter is a String parameter stored in the plug-in configuration.- See Also:
-
PARAMETER_EXTERNAL_CMDLINE
Parameter name for the command line options to the external program. This parameter is a String parameter stored in the plug-in configuration.- See Also:
-
PARAMETER_EXTERNAL_PARAMETERS
Parameter name for the xml holding the parameter definitions to the external program. This parameter is an XML String stored in the plug-in configuration.- See Also:
-
PARAMETER_IMPORTER_CLASS
Parameter name for the class that has been selected as the importer. This parameter is a String parameter stored in the plug-in configuration.- See Also:
-
PARAMETER_EXPORTER_CLASS
Parameter name for the class that has been selected as the exporter. This parameter is a String parameter stored in the plug-in configuration.- See Also:
-
PARAMETER_DEBUG_MODE
Parameter name for debug mode flag.- See Also:
-
PARAMETER_RAW_DATA_TYPE
Parameter name for the required raw data type. This parameter is a String parameter stored in the plug-in configuration.- See Also:
-
PARAMETER_NUM_CHANNELS
Parameter name for the required number of channels. This parameter is an Integer parameter stored in the plug-in configuration.- See Also:
-
PARAMETER_SOURCE_TRANSFORM
Parameter name for the required intensity transform of the source bioassay set. This parameter is a String parameter (corresponding toEnum.name()
) stored in the plug-in configuration.- See Also:
-
PARAMETER_SOURCE_BIOASSSAYSET
Parameter name for the source bioassay set. This parameter is a BioAssaySet parameter stored in the job configuration.- See Also:
-
NAMESPACE_EXPORTER
The namespace for the exporter plug-in parameters.- See Also:
-
NAMESPACE_IMPORTER
The namespace for the importer plug-in parameters.- See Also:
-
NAMESPACE_EXTERNAL
The namespace for the external program parameters.- See Also:
-
COMMAND_CONFIGURE_EXTERNAL_PARAMETERS
- See Also:
-
signalHandler
-
configurePlugin
-
configureExternalParameters
-
configureJob
-
configureExportImportPluginParameters
-
workDir
Temporary working directory at runtime. -
knownFiles
Files that are known to exists in the working directory. Unknown files can be assumed to have been created by the external program. -
exporter
-
importer
-
-
Constructor Details
-
ExternalProgramExecutor
public ExternalProgramExecutor()
-
-
Method Details
-
supportsConfigurations
public boolean supportsConfigurations()Description copied from class:AbstractPlugin
Returns TRUE, since that is how the plugins used to work before this method was introduced.- Specified by:
supportsConfigurations
in interfacePlugin
- Overrides:
supportsConfigurations
in classAbstractPlugin
- Returns:
- TRUE or FALSE
-
requiresConfiguration
public boolean requiresConfiguration()Description copied from class:AbstractPlugin
Returns FALSE, since that is how the plugins used to work before this method was introduced.- Specified by:
requiresConfiguration
in interfacePlugin
- Overrides:
requiresConfiguration
in classAbstractPlugin
- Returns:
- TRUE or FALSE
-
run
Description copied from interface:Plugin
Run the plugin. If a progress reporter object is passed it is recommended that the plugin makes use of it.- Specified by:
run
in interfacePlugin
- Parameters:
request
- Request object with the command and parametersresponse
- Response object in for the plugin to response throughprogress
- AProgressReporter
where the plugin can report its progess, can be null
-
getSignalHandler
Description copied from interface:SignalTarget
Get the signal handler that is handling signals on behalf of this object. Multiple invokations of this method may receive the same or different objects. Null may be returned if, for some reason, the current object instance doesn't want to receive signals. Returning null is the same as not implementing this interface.- Specified by:
getSignalHandler
in interfaceSignalTarget
- Returns:
- A SignalHandler object, or null if the current instance doesn't support signals
-
isInContext
Description copied from class:AbstractAnalysisPlugin
Check that the item is a bioassayset/derived bioassay and that the logged in user has permission to use the current item.- Specified by:
isInContext
in interfaceInteractivePlugin
- Overrides:
isInContext
in classAbstractAnalysisPlugin
- Parameters:
context
- Current guicontextitem
- The item to check.- Returns:
- null if the item is a valid item, an error message otherwise
-
getRequestInformation
public RequestInformation getRequestInformation(GuiContext context, String command) throws BaseException Description copied from interface:InteractivePlugin
This method will return theRequestInformation
for a given command, i.e. the list of parameters and some nice help text.- Specified by:
getRequestInformation
in interfaceInteractivePlugin
- Parameters:
context
- The current context of the client application, it is one of the values found in set returned byInteractivePlugin.getGuiContexts()
command
- The command- Returns:
- The
RequestInformation
for the command - Throws:
BaseException
- if there is an error
-
configure
Description copied from interface:InteractivePlugin
Configure the plugin. Hopefully the client is supplying values for the parameters specified byInteractivePlugin.getRequestInformation(GuiContext, String)
.- Specified by:
configure
in interfaceInteractivePlugin
- Parameters:
context
- The current context of the client application, it is one of the values found in set returned byInteractivePlugin.getGuiContexts()
request
- Request object with the command and parametersresponse
- Response object in for the plugin to response through
-
getCurrentBioAssaySet
Get the bioassay set that is used as the source for the job. This method should only be called at runtime or job configuration time.- Overrides:
getCurrentBioAssaySet
in classAbstractAnalysisPlugin
- Parameters:
dc
- The DbControl to use for database access- Returns:
- The source bioassay set
- See Also:
-
getWorkingDirectory
Get the current working directory were data files for the external program are stored. This method should only be called at runtime. -
inspectWorkingDirectory
Check the working directory for new files. Each call to this method will mark the existing files as "known" files. Subsequent calls will only find files that has been added to the working directory since that last call. The executor calls this method after the exporter plug-in has been executed just before the external program is about to be started. This allows the importer plug-in to call this method to find out which files that were created by the external program.- Returns:
- A list with new files that has been added to the working directory since the last call (the list is empty if no new files exists)
- Since:
- 2.16
-
getParameterDefinitions
Get the current program parameter definitions. This method should only be called at runtime or job configuration time. -
getProgramParameters
Get all program parameters and their values. This method should only be called at runtime. -
createFile
Create a new file in the working directory. If a file with the given name already exists the existing file is used.- Parameters:
name
- The name of the file to create- Returns:
- A new file object pointing to the file
- Throws:
IOException
-
createTemporaryWorkingDirectory
Create a temporary working directory in the local file system. The exporter should export data to this directory. The external program will use the data and store it's output in the same directory. It is recommended that the directory is empty and not used by any other process at the same time. Existing files may be overwritten without notice.- Returns:
- A file object representing a directory
- Throws:
IOException
-
runExporter
Execute the exporter plug-in using the supplied parameters. -
runImporter
Execute the importer plug-in using the supplied parameters. -
runExternalProgram
protected void runExternalProgram(String program, String cmdLine, File workDir, String stdin, String stdout, ProgressReporter progress) Run the external program. The program and active working directory is given by the parameters. No command line options can be sent to the program. It is possible to name one (existing) file that should be piped to standard input to the plug-in and one (non-existing) file that should receive output from the program. Anything the program writes to the standard error stream should cause an error and be reported back to the caller via en exception.- Parameters:
program
- The path to the external programworkDir
- The active working directorystdin
- If given, the named file within the working directory should be piped to the standard input of the external program.stdout
- If given, output from the external program should be piped the named file. If not given any output from the program needs to be read and discarded
-
getExporter
Get an instance of the exporter plug-in.- Parameters:
dc
- A DbControl to use for database accessforceNew
- If TRUE a new instance must always be created, otherwise an already existing instance may be re-usedruntime
- TRUE if the importer is created at runtime, which means that job agent configuration must be taking into account- Returns:
- An exporter instance
-
getImporter
Get an instance of the importer plug-in.- Parameters:
dc
- A DbControl to use for database accessforceNew
- If TRUE a new instance must always be created, otherwise an already existing instance may be re-usedruntime
- TRUE if the importer is created at runtime, which means that job agent configuration must be taking into account- Returns:
- An importer instance
-
createInstance
protected IOSupport createInstance(DbControl dc, PluginDefinition plugin, String namespace, boolean runtime) Create and initialize a plug-in instance for the given plug-in definition. Job and configuration parameters should be wrapped in the given namespace.- Parameters:
plugin
- The plug-in definition we should instantiatenamespace
- The namespace, or null to not wrap the parameters in a namespaceruntime
- TRUE if the importer is created at runtime, which means that job agent configuration must be taking into account- Returns:
- An initialized plug-in instance
-
getConfigurePluginParameters
-
getConfigureExportImportPluginParameters
-
getConfigureExternalParameters
-
getConfigureJobParameters
-
getExernalPluginParameters
-
addParametersWithNamespace
private void addParametersWithNamespace(List<PluginParameter<?>> to, List<PluginParameter<?>> from, String namespace) Add more parameters to a list of parameters with a different namespace.- Parameters:
to
- The parameters list to add the parameters tofrom
- The parameters list to copy parameters fromnamespace
- The namespace to use for the added parameter
-