Class AccessorSSHCodeGenerator
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.util.Attribute
-
- ptolemy.cg.kernel.generic.GenericCodeGenerator
-
- ptolemy.cg.kernel.generic.RunnableCodeGenerator
-
- ptolemy.cg.kernel.generic.accessor.AccessorCodeGenerator
-
- ptolemy.cg.kernel.generic.accessor.AccessorSSHCodeGenerator
-
- All Implemented Interfaces:
java.lang.Cloneable
,Changeable
,Debuggable
,DebugListener
,Decorator
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class AccessorSSHCodeGenerator extends AccessorCodeGenerator
Generate a JavaScript composite accessor for a model and deploy it to a remote host.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.js
which 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.js
To 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:
- Creates a directory in
~/cg/ModelName
, for example~/cg/MyCompositeAccessor
- Installs the
@terraswarm/accessors
andpm2
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. - Creates a small node script called
invoke.js
to run the composite accessor. - Copies the composite accessor to the directory.
- Creates a script called
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 usingpm2
. 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 stderr and stdout are then reported using tail
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 toswarmboxadmin/ansible/keys/sbuser_authorized_keys
. See https://www.terraswarm.org/testbeds/wiki/Main/SbuserSSHAccess.For more information, see the Code Generation wiki.
- Since:
- Ptolemy II 11.0
- Version:
- $Id$
- Author:
- Christopher Brooks. Based on HTMLCodeGenerator by Man-Kit Leung, Bert Rodiers
- Pt.AcceptedRating:
- red (cxh)
- Pt.ProposedRating:
- red (cxh)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field 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.-
Fields inherited from class ptolemy.cg.kernel.generic.accessor.AccessorCodeGenerator
_checkForLocalModules, modules, npmInstall
-
Fields inherited from class ptolemy.cg.kernel.generic.RunnableCodeGenerator
_runCommandDefault, _substituteMap, run, runCommand
-
Fields inherited from class ptolemy.cg.kernel.generic.GenericCodeGenerator
_codeFileName, _eol, _executeCommands, _generateInSubdirectory, _model, _sanitizedModelName, codeDirectory, generateInSubdirectory, generatorPackage, generatorPackageList, INDENT1, INDENT2, INDENT3, overwriteFiles
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
-
Constructor Summary
Constructors Constructor Description AccessorSSHCodeGenerator(NamedObj container, java.lang.String name)
Create a new instance of the AccessorSSHCodeGenerator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class ptolemy.cg.kernel.generic.accessor.AccessorCodeGenerator
_generateCode, _getAdapterClassFilter, comment
-
Methods inherited from class ptolemy.cg.kernel.generic.RunnableCodeGenerator
_executeCommands, _reset, _runCommand, clone, updateCommandOptions
-
Methods inherited from class ptolemy.cg.kernel.generic.GenericCodeGenerator
_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
-
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_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
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
runForever
public Parameter runForever
If true, then use npm forever to run the Node composite accessor forever. If false, then run until stopTime ms. has passed. Note that if true, then the process will be restarted after stopTime ms. or until the code generator is run with stopForeverAccessors is true or the remote machine is rebooted. The default value is true, indicating that the process should be run forever.
-
stopForeverAccessors
public Parameter stopForeverAccessors
If true, then connect to the remote machine and stop any npm forever processes with the same basename as the model. Confusingly, to stop any remote processes that have been previously invoked, run should be true so that theaccessorInvokeSSH
script is invoked on the remote machine with astop
argument. The default value is false, indicating that the remote machine will invoke the Node accessor host composite accessor.
-
userHost
public StringParameter userHost
The username and hostname that is used with ssh. The default value is "sbuser@swarmnuc001.eecs.berkeley.edu". To get ssh access, see https://www.terraswarm.org/testbeds/wiki/Main/SbuserSSHAccess.
-
-
Constructor Detail
-
AccessorSSHCodeGenerator
public AccessorSSHCodeGenerator(NamedObj container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Create a new instance of the AccessorSSHCodeGenerator. The value of the generatorPackageList parameter of the base class is set togeneric.accessor
- Parameters:
container
- The container.name
- The name of the AccessorSSHCodeGenerator.- Throws:
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.
-
-
Method Detail
-
_setupCommands
protected java.util.List<java.lang.String> _setupCommands() throws IllegalActionException
Return a list of setup commands to be invoked before the run command. In this class, any commands that start with "npm install" are removed.- Overrides:
_setupCommands
in classAccessorCodeGenerator
- Returns:
- return The list of commands.
- Throws:
IllegalActionException
- If thrown in a base class.
-
_updateSubstituteMap
protected void _updateSubstituteMap() throws IllegalActionException
Update the substitute map for the setup and run commands. The base classes adds codeDirectory, modelName, PTII, modules and npmInstall and timeoutFlagAndValue. This method adds modulesFlagAndValue,runForever, and stopForeverAccessor.- Overrides:
_updateSubstituteMap
in classAccessorCodeGenerator
- Throws:
IllegalActionException
- If the modules parameter contains spaces or if thrown by a base class.
-
-