public class ExecuteCmd extends TypedAtomicActor
Connects to a remote host using Ssh protocol (or does nothing for the local host) and executes a command. It returns the stdout, stderr and exit code after the command terminates.
This actor uses the org.kepler.ssh package to have longlasting connections.
If the target is empty string or equals local, the Java Runtime will be used for local execution instead of ssh. It behaves similarly to other local command-line exec actors of Kepler but you do not need to change your workflow for remote/local executions by using this actor.
If the timeoutSeconds is set greater than zero, the command will be timeouted after the specified amount of time (in seconds).
In case there is an ssh connection related error (or timeout) the exitcode will be -32767, errors will contain the error message, stdout and stderr will be empty string.
To ensure fixed rate of token production for SDF, the actor emits an empty string on errors if the command is executed without ssh related errors.
If cleanupAfterError is set, the remote process and its children will be killed (provided, we have the connection still alive). Very useful in case of timeout because that leaves remote processes running. Use only when connecting to a unix machine. In case of local, this flag is not used.
Streaming of output during the command execution is not supported by this actor.
Third party operation
If the remote command is expected to ask for a password (or passphrase when
connecting to a remote host with public-key authentication) set the expert
parameter thirdParty for the user@host:port of that third party (it
can be the same as target if a sudo command is executed).
The authentication to the third party should be the same from the target host and from Kepler's local host. Kepler authenticates (by opening a channel) to the third party and then it provides the password/passphrase used for the authentication to the command on the target host. Therefore, this actor cannot be used to reach a remote host through a proxy machine and execute a command there.
The third party execution can be used e.g. to execute and ssh/scp command that connects to another host, also reachable from Kepler's host, to execute external data transfer commands (bbcp, GridFTP, SRM-Lite etc) or sudo commands.
The actor will first authenticate Kepler to the third party host (if not yet done by other actors, e.g. SshSession). During the execution of the command, it looks for the appearance of the string 'password' or 'passphrase' in the stdout/stderr streams (case-insensitively). If such string is found, it writes the authentication code stored within Kepler used for the authentication. Therefore, the command must read the password on the standard input, not directly from the terminal device. This process is performed only once!
The underlying java code does not have pseudo-terminal emulation, so if you cannot force the command to read passwords from the stdin (e.g. scp command), you have to use an external tool to execute the command through a pseudo-terminal. ptyexec is provided in the org.kepler.ssh package, a C program, that should be compiled and put into the path on the target machine. Then you can execute "ptyexec scp ...".
Entity.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
Parameter |
cleanupAfterError
Enforce killing remote process(es) after an error or timeout.
|
TypedIOPort |
command
The command to be executed on the remote host.
|
TypedIOPort |
errors
The string representation of all the errors that happened during the
execution of the actor, if there are any.
|
TypedIOPort |
exitcode
The exit code of the command.
|
SingletonParameter |
hideTP
_hide parameter of thirdParty.
|
Parameter |
isThirdPartyOperation
Specifying whether third party is to be defined.
|
SingletonParameter |
shownameTP
_showname parameter of thirdParty.
|
TypedIOPort |
stderr
The error that were reported by the remote execution or while connecting.
|
TypedIOPort |
stdout
Output of the command as it would output to the standard shell output.
|
Parameter |
streamingMode
Specifying whether the output should be sent in a streaming mode.
|
PortParameter |
target
Target in user@host:port format.
|
PortParameter |
thirdParty
Third party target in user@host:port format.
|
Parameter |
timeoutSeconds
Timeout in seconds for the command to be executed. 0 means waiting
indefinitely for command termination.
|
_typesValid
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
COMPLETED, NOT_READY, STOP_ITERATING
Constructor and Description |
---|
ExecuteCmd(CompositeEntity container,
java.lang.String name)
Construct an ExecuteCmd actor with the given container and name.
|
Modifier and Type | Method and Description |
---|---|
void |
attributeChanged(Attribute attribute)
If the specified attribute is showTriggerPort, then get the value
of it and re-render the trigger port.
|
void |
fire()
Send the token in the value parameter to the output.
|
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, initialize, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
addInitializable, initialize, preinitialize, removeInitializable, wrapup
description, getContainer, getDisplayName, getFullName, getName, getName, setName
getDerivedLevel, getDerivedList, propagateValue
public PortParameter target
public TypedIOPort command
public PortParameter thirdParty
public SingletonParameter hideTP
public SingletonParameter shownameTP
public TypedIOPort stdout
public TypedIOPort stderr
public TypedIOPort exitcode
public TypedIOPort errors
public Parameter timeoutSeconds
public Parameter cleanupAfterError
public Parameter streamingMode
public Parameter isThirdPartyOperation
public ExecuteCmd(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
container
- The container.name
- The name of this actor.IllegalActionException
- If the entity cannot be contained by the proposed
container.NameDuplicationException
- If the container already has an actor with this name.public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class NamedObj
attribute
- The attribute that has changed.IllegalActionException.
IllegalActionException
- If the change is not acceptable
to this container (not thrown in this base class).public void fire() throws IllegalActionException
fire
in interface Executable
fire
in class AtomicActor<TypedIOPort>
IllegalActionException
- If it is thrown by the send() method sending out the
token.