gssa package¶
Subpackages¶
Submodules¶
gssa.client module¶
-
class
gssa.client.
GoSmartSimulationClientComponent
(x, gssa_file, subdirectory, output_files, tmp_transferrer='/tmp', input_files=None, definition_files=None, skip_clean=False, server=None)[source]¶ Bases:
autobahn.asyncio.wamp.ApplicationSession
gssa.config module¶
-
gssa.config.
get
(key, default=None)[source]¶ Get a value from the global configuration.
If the config file is not loaded, it will be loaded when this is called.
Parameters: - key (str) – A dot-separated hierarchical key to find in the YAML configuration file.
- default (Optional) – Fall-back to return if the key is not found. Defaults to None.
gssa.database module¶
-
class
gssa.database.
SQLiteSimulationDatabase
(database)[source]¶ Bases:
object
-
delete
(simulation, soft=True)[source]¶ Remove a simulation from the database.
Parameters: - simulation (str) – GUID of the simulation.
- soft (Optional[bool]) – do a soft delete.
-
markAllOld
()[source]¶ Mark simulations as exited if still appearing to run - usually on server start-up.
-
gssa.definition module¶
-
class
gssa.definition.
GoSmartSimulationDefinition
(guid, xml_string, tmpdir, translator, finalized=False, ignore_development=False, update_status_callback=None)[source]¶ Bases:
object
Routines for working with a single specific simulation.
-
create_xml_from_string
(xml)[source]¶ Turn the string XML into an ElementTree object.
Parameters: xml (str) – string-version of GSSA-XML.
-
gssa.docker module¶
-
class
gssa.docker.
OutputHandler
(lock, loop=None, **kwargs)[source]¶ Bases:
hachiko.hachiko.AIOEventHandler
,watchdog.events.FileSystemEventHandler
-
class
gssa.docker.
Submitter
[source]¶ Bases:
object
Utility to manage communication with dockerlaunch.
Submit the request to run an instance to the dockerlaunch daemon, also handling some of the standard bits and pieces of interface.
-
add_input
(input_file)[source]¶ Set additional input.
Make a note that this file should be transferred to the Docker volume for the simulation
-
copy_output
(requested, target)[source]¶ Retrieve output.
Copy output files from the Docker volume to the simulation ‘working directory’
-
output
(requested, exists_only=False)[source]¶ Return the content of the file
requested
Parameters: - requested (str) – file name to request
- exists_only (Optional[bool]) – only check existence, don’t load
Returns: file content unless exists_only set, then existence True/False.
Return type: str|bool
-
reader
= None¶
-
run_script
(loop, working_directory, image, files_required=[], magic_script=None)[source]¶ Run the simulation.
Parameters: - loop (asyncio.BaseEventLoop) – look to use for asynchronous calls.
- working_directory (str) – location of simulation configuration/definition.
- image (str) – a container image name. This must be known to dockerlaunch or it will refuse to run.
- files_required (Optional[array(str) – files to return as output.
- magic_script (Optional[str]) – DEPRECATED: script to upload to simulation container after all else in place as a trigger (default off).
-
set_update_socket
(socket_location)[source]¶ Set the socket that the bridge container should use to communicate.
-
writer
= None¶
-
gssa.error module¶
-
class
gssa.error.
Error
[source]¶ Bases:
enum.Enum
Go-Smart error families.
These are the canonical errors for client use - wherever possible, the most applicable of these should be returned. They indicate where the fault is likely to lie.
-
exception
gssa.error.
ErrorException
(ref, message, *args, **kwargs)[source]¶ Bases:
RuntimeError
An exception wrapping
Error
.
-
class
gssa.error.
ErrorMessage
[source]¶ Bases:
dict
A trivial subclass of dict marking an ErrorMessage.
-
gssa.error.
makeError
(ref, message)[source]¶ A full error message (as returned via WAMP).
Parameters: - ref (gssa.error.Error|str) – a enum (or enum name) to categorize the error.
- message (str) – free-form error information string.
Returns: a dictionary with entries
id
(int),code
(str) andmessage
. The former two are representations of theError
enum, the integer (ordinal) value and string name respectively.Return type:
gssa.family module¶
-
class
gssa.family.
Family
[source]¶ Bases:
object
Essential routines for Families.
-
family_name
= None¶
-
get_needle_parameter
(needle_index, key, try_json=True)[source]¶ Retrieve a parameter for a given needle.
Needle index can be either needle index (as given in XML input) or an integer n indicating the nth needle in the order of the needles XML block.
-
get_parameter
(key, try_json=True, parameters=None)[source]¶ Retrieve a parameter from the global (not needle) list.
-
gssa.http_transferrer module¶
-
class
gssa.http_transferrer.
HTTPTransferrer
[source]¶ Bases:
object
gssa.parameters module¶
gssa.server module¶
-
class
gssa.server.
GoSmartSimulationServerComponent
(server_id, database, publish_cb, ignore_development=False, use_observant=True, simdata_path='/tmp')[source]¶ Bases:
object
This subclasses ApplicationSession, which runs inside an Autobahn WAMP session
-
client
= None¶
-
current
= None¶
-
doApi
()[source]¶ com.gosmartsimulation.api
Find the current API version in use. The API version only needs to be bumped when backward-incompatible changes occur on either side
-
doClean
(guid)[source]¶ com.gosmartsimulation.clean
Remove anything in simulation working directory, for instance
-
doCompare
(this_xml, that_xml)[source]¶ com.gosmartsimulation.compare
Check whether two GSSA-XML files match and, if not, what their differences are.
-
doFinalize
(guid, client_directory_prefix)[source]¶ com.gosmartsimulation.finalize
Do any remaining preparation before the simulation can start.
-
doLogs
(guid, only=None)[source]¶ com.gosmartsimulation.logs
Retrieve the container logs for a simulation.
-
doProperties
(guid)[source]¶ com.gosmartsimulation.properties
Return important server-side simulation properties.
-
doRequestDiagnostic
(guid, target)[source]¶ com.gosmartsimulation.request_diagnostic
Push a bundle of diagnostic files through the transferrer. If target is None, assume gateway is running a temporary HTTP on default client port
FIXME: this should be made asynchronous!
-
doRequestFiles
(guid, files)[source]¶ com.gosmartsimulation.request_files
Push the requested output files through the transferrer and return the list that was sent.
-
doRequestResults
(guid, target)[source]¶ com.gosmartsimulation.request_results
Push a bundle of output files through the transferrer. If target is None, assume gateway is running a temporary HTTP on default client port
FIXME: this should be made asynchronous!
-
doRetrieveStatus
(guid, allow_resync=True)[source]¶ com.gosmartsimulation.retrieve_status
Get the latest status for a simulation. allow_resync permits the server to update the DB if it finds an inconsistency.
-
doSimulate
(guid)[source]¶ Start the simulation
This occurs in a separately scheduled coro from the RPC call so it will almost certainly have returned by time we do. This does not have an API endpoint as
doStart()
is responsible for launching it asynchronously.
-
doUpdateFiles
(guid, files)[source]¶ com.gosmartsimulation.update_files
Add the passed files to the simulation’s reference dictionary of required input files (available to be requested later)
-
doUpdateSettingsXml
(guid, xml)[source]¶ com.gosmartsimulation.update_settings_xml
Set the GSSA-XML for a given simulation
-
eventComplete
(guid)[source]¶ Called when simulation completes
Publishes a completion event:
com.gosmartsimulation.complete
-
eventFail
(guid, message)[source]¶ Called when simulation fails
Publishes a failure event:
com.gosmartsimulation.failed
-
getProperties
(guid)[source]¶ Server-specific properties for this simulation
At present, just working directory location.
-
onRequestAnnounce
()[source]¶ com.gosmartsimulation.request_announce
Release a status report on each simulation in the database
TODO: this gets unwieldy, perhaps it should have an earliest simulation timestamp argument?
-
onRequestIdentify
()[source]¶ com.gosmartsimulation.request_identify
Publish basic server information.
$$ score = #cores - #active_simulations $$
This gives an availability estimate, the higher the better
-
setDatabase
(database)[source]¶ Update database backend.
Mainly for start-up. Mark everything in-progress in the DB as not-in-progress/unfinished.
-
setStatus
(id, key, message, percentage, timestamp)[source]¶ Record a status change in the database and on the filesystem.
Note that, for both those reasons, this could be slow and so should always be run with call_soon_threadsafe
FIXME: we need some sort of rate limiting here, or producer-consumer pattern with ability to skip once getting behind
-
gssa.session module¶
-
class
gssa.session.
GoSmartSimulationServerSession
(x, server_id, database, ignore_development=False, simdata_path='/tmp')[source]¶ Bases:
autobahn.asyncio.wamp.ApplicationSession
This subclasses ApplicationSession, which runs inside an Autobahn WAMP session.
-
doApi
()[source]¶ com.gosmartsimulation.api
gssa.server.GoSmartSimulationServerComponent.doApi()
Find the current API version in use. The API version only needs to be bumped when backward-incompatible changes occur on either side.
-
doCancel
(guid)[source]¶ com.gosmartsimulation.cancel
gssa.server.GoSmartSimulationServerComponent.doCancel()
Prematurely stop a running simulation but bear in mind that no request for confirmation exists!
-
doClean
(guid)[source]¶ com.gosmartsimulation.clean
gssa.server.GoSmartSimulationServerComponent.doClean()
Remove anything in simulation directory, for instance.
-
doCompare
(this_xml, that_xml)[source]¶ com.gosmartsimulation.compare
gssa.server.GoSmartSimulationServerComponent.doCompare()
Check whether two GSSA-XML files match and, if not, what their differences are.
-
doFinalize
(guid, client_directory_prefix)[source]¶ com.gosmartsimulation.finalize
gssa.server.GoSmartSimulationServerComponent.doFinalize()
Do any remaining preparation before the simulation can start.
-
doInit
(guid)[source]¶ com.gosmartsimulation.init
gssa.server.GoSmartSimulationServerComponent.doInit()
Dummy call for the moment.
-
doLogs
(guid, only=None)[source]¶ com.gosmartsimulation.logs
gssa.server.GoSmartSimulationServerComponent.doLogs()
Retrieve the container logs for a simulation.
-
doProperties
(guid)[source]¶ com.gosmartsimulation.properties
gssa.server.GoSmartSimulationServerComponent.doProperties()
Return important server-side simulation properties.
-
doRequestDiagnostic
(guid, target)[source]¶ com.gosmartsimulation.request_diagnostic
gssa.server.GoSmartSimulationServerComponent.doRequestDiagnostic()
Push a bundle of diagnostic files through the transferrer.
-
doRequestFiles
(guid, files)[source]¶ com.gosmartsimulation.request_files
gssa.server.GoSmartSimulationServerComponent.doRequestFiles()
Push the requested output files through the transferrer and return the list that was sent.
-
doRequestResults
(guid, target)[source]¶ com.gosmartsimulation.request_results
gssa.server.GoSmartSimulationServerComponent.doRequestResults()
Push a bundle of result files through the transferrer.
-
doRetrieveStatus
(guid)[source]¶ com.gosmartsimulation.retrieve_status
gssa.server.GoSmartSimulationServerComponent.doRetrieveStatus()
Get the latest status for a simulation.
-
doSearch
(guid, limit=None)[source]¶ com.gosmartsimulation.search
gssa.server.GoSmartSimulationServerComponent.doSearch()
Check for matching definitions.
-
doStart
(guid)[source]¶ com.gosmartsimulation.start
gssa.server.GoSmartSimulationServerComponent.doStart()
Execute the simulation in a coro.
-
doUpdateFiles
(guid, files)[source]¶ com.gosmartsimulation.update_files
gssa.server.GoSmartSimulationServerComponent.doUpdateFiles()
Add the passed files to simulation’s reference dictionary of required input files (available to be requested later).
-
doUpdateSettingsXml
(guid, xml)[source]¶ com.gosmartsimulation.update_settings_xml
gssa.server.GoSmartSimulationServerComponent.doUpdateSettingsXml()
Set the GSSA-XML for a given simulation.
-
onJoin
(details)[source]¶ Register methods and subscribes.
Fired when we first join the router - this gives us a chance to register everything.
-
onRequestAnnounce
()[source]¶ com.gosmartsimulation.request_announce
gssa.server.GoSmartSimulationServerComponent.onRequestAnnounce()
Release a status report on each simulation in the database. TODO: this gets unwieldy, perhaps it should have an earliest simulation timestamp argument?.
-
onRequestIdentify
()[source]¶ com.gosmartsimulation.request_identify
gssa.server.GoSmartSimulationServerComponent.onRequestIdentify()
Publish basic server information.
-
gssa.sftp_transferrer module¶
gssa.shadow_watcher module¶
gssa.tmp_transferrer module¶
gssa.transferrer module¶
gssa.translator module¶
-
class
gssa.translator.
GoSmartSimulationTranslator
[source]¶ Bases:
object
This extracts basic information, common to all families, from GSSA-XML.