public class AccessorSSHCodeGenerator extends AccessorCodeGenerator
Accessors are a technology, developed by the TerraSwarm Research Center, for composing heterogeneous devices and services in the Internet of Things (IoT). For more information, see http://accessors.org.
The model can only contain JavaScript and JSAccessor actors.
To generate an Accessor version of a model, use:
java -classpath $PTII ptolemy.cg.kernel.generic.accessor.AccessorSSHCodeGenerator -language accessor $PTII/ptolemy/cg/kernel/generic/accessor/demo/TestComposite/TestComposite.xml; cat $PTII/org/terraswarm/accessor/accessors/web/hosts/node/TestComposite.jswhich is shorthand for:
java -classpath $PTII ptolemy.cg.kernel.generic.accessor.AccessorSSHCodeGenerator -generatorPackage ptolemy.cg.kernel.generic.accessor -generatorPackageList generic.accessor $PTII/ptolemy/cg/adapter/generic/accessor/adapters/org/test/auto/TestComposite.xml; cat ~/cg/TestComposite.jsTo use Cape Code, invoke:
$PTII/bin/vergil -capecode $PTII/ptolemy/cg/kernel/generic/accessor/test/auto/RampJSTextDisplay.xml
This actor runs $PTII/ptolemy/cg/kernel/generic/accessor/accessorInvokeSSH, which does the following on the remote machine:
~/cg/ModelName
,
for example ~/cg/MyCompositeAccessor
@terraswarm/accessors
and
pm2
modules in
~/cg/ModelName
. Note
that this means that to run a composite accessor with the
latest accessors, the npm @terraswarm/accessors
module must be updated. See
NPM Upload
in the accessors Wiki.
In addition, any modules listed in the comma-separated
modules parameter are also installed. invoke.js
to
run the composite accessor.runit
that uses
pm2
to stop any processes with the same name as the accessor
started with forever name and then invokes node on the remote
machine using pm2
. If the director of the model
has a stopTime parameter, then the value is multiplied by
1000 and used as the value of the timeout parameter on the
remote machine. If the stopTime parameter is not set,
then a default value (currently 15000 ms.) is used.The accessorInvokeSSH
script should work on any
machine that has node and npm installed.
pm2 is a Node package installed using npm that can run a process forever and can cause it to be started upon reboot. Note that for the process to be started after reboot, a command needs to be run once as root on the host machine. The command is displayed during code generation. The command is specific to the user account on the remote machine.
To use a SwarmBox, add your ~/.ssh/id_rsa.pub
file
to swarmboxadmin/ansible/keys/sbuser_authorized_keys
.
See https://www.terraswarm.org/testbeds/wiki/Main/SbuserSSHAccess.
For more information, see the Code Generation wiki.
NamedObj.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
Parameter |
runForever
If true, then use npm forever to run the Node composite
accessor forever.
|
Parameter |
stopForeverAccessors
If true, then connect to the remote machine and stop any npm
forever processes with the same basename as the model.
|
StringParameter |
userHost
The username and hostname that is used with ssh.
|
_checkForLocalModules, modules, npmInstall
_runCommandDefault, _substituteMap, run, runCommand
_codeFileName, _eol, _executeCommands, _generateInSubdirectory, _model, _sanitizedModelName, codeDirectory, generateInSubdirectory, generatorPackage, generatorPackageList, INDENT1, INDENT2, INDENT3, overwriteFiles
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
Constructor and Description |
---|
AccessorSSHCodeGenerator(NamedObj container,
java.lang.String name)
Create a new instance of the AccessorSSHCodeGenerator.
|
Modifier and Type | Method and Description |
---|---|
protected java.util.List<java.lang.String> |
_setupCommands()
Return a list of setup commands to be invoked before the run
command.
|
protected void |
_updateSubstituteMap()
Update the substitute map for the setup and run commands.
|
_generateCode, _getAdapterClassFilter, comment
_executeCommands, _reset, _runCommand, clone, updateCommandOptions
_copyCFilesTosrc, _copyCFileTosrc, _getAdapter, _getAutoGeneratedAdapter, _getOutputFilename, _instantiateAdapter, _isTopLevel, _printTimeAndMemory, _resetAll, _writeCode, _writeCodeFileName, attributeChanged, createDecoratorAttributes, decoratedObjects, generateCode, generateCode, generateCode, generateCopyright, getAdapter, getCodeFileName, getComponent, getExecuteCommands, getMethodExceptionString, getMethodVisibilityString, isGlobalDecorator, main, setCodeGenerator, setContainer, setExecuteCommands
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _description, _executeChangeRequests, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
description, getContainer, getDisplayName, getFullName, getName, getName, setName
public Parameter runForever
public Parameter stopForeverAccessors
accessorInvokeSSH
script is invoked on the remote
machine with a stop
argument.
The default value is false, indicating that
the remote machine will invoke the Node accessor host
composite accessor.public StringParameter userHost
public AccessorSSHCodeGenerator(NamedObj container, java.lang.String name) throws IllegalActionException, NameDuplicationException
generic.accessor
container
- The container.name
- The name of the AccessorSSHCodeGenerator.IllegalActionException
- If the super class throws the
exception or error occurs when setting the file path.NameDuplicationException
- If the super class throws the
exception or an error occurs when setting the file path.protected java.util.List<java.lang.String> _setupCommands() throws IllegalActionException
_setupCommands
in class AccessorCodeGenerator
IllegalActionException
- If thrown in a base class.protected void _updateSubstituteMap() throws IllegalActionException
_updateSubstituteMap
in class AccessorCodeGenerator
IllegalActionException
- If the modules parameter
contains spaces or if thrown by a base class.