Mercury2 Hardware Manager  1.0dev
The hardware manager component of the Mercury2 ground station suite.
 All Classes Namespaces Functions Variables Pages
hwm.command.parser.CommandParser Class Reference

Processes all commands received by the hardware manager. More...

Public Member Functions

def __init__
 Sets up the command parser instance. More...
 
def system_command_handlers
 Provides access to the loaded system command handlers. More...
 
def parse_command
 Processes all commands received by the ground station. More...
 

Public Attributes

 system_handlers
 
 permission_manager
 
 pipeline_manager
 
 session_coordinator
 

Private Member Functions

def _load_permissions
 Loads the user's permissions, if required. More...
 
def _run_command
 Executes the command after it has been validated. More...
 
def _command_complete
 Builds a complete response for the successful command. More...
 
def _command_error
 Generates an appropriate error response for the command failure. More...
 

Detailed Description

Processes all commands received by the hardware manager.

This class parses and performs validations on received commands, delegating them to the appropriate command handler.

Constructor & Destructor Documentation

def hwm.command.parser.CommandParser.__init__ (   self,
  system_command_handlers,
  permission_manager 
)

Sets up the command parser instance.

Parameters
system_command_handlersA array containing references to all of the system command handlers. If a command's destination field references an element in this dictionary, that command handler will be used. Otherwise, it will be delegated to a device command handler.
permission_managerA reference to the permissions manager instance that will be used to determine if a user has the permissions to execute a given command.
Note
This class requires that a SessionCoordinator instance be initialized with an instance of this class before it can parse commands. It needs the session coordinator to load the user's active sessions, and the session coordinator needs this class so that it can pass it to newly created sessions for their setup commands.
This class requires that a PipelineManager instance be initialized with an instance of this class before it can parse device commands. This is required so that it can relay device commands to the specified device.

Member Function Documentation

def hwm.command.parser.CommandParser._command_complete (   self,
  command_results,
  successful_command 
)
private

Builds a complete response for the successful command.

 This callback generates a successful command response. It is called after the command has been executed in a new
 thread. 
Parameters
command_resultsA dictionary containing additional data to embed with the command response (in the "result" field of the JSON response). This is returned by the individual command functions in the command handlers.
successful_commandThe command that just completed.
Returns
Returns the constructed command response dictionary. This dictionary is fed into callbacks waiting for the command results.
def hwm.command.parser.CommandParser._command_error (   self,
  failure,
  failed_command 
)
private

Generates an appropriate error response for the command failure.

 This errback generates an error response for the indicated failure, which is then loaded into a CommandFailed
 exception and re-raised. If the incoming failure is wrapping an exception of type CommandError then it may contain a 
 dictionary with additional information about the error.
Exceptions
Raisesa CommandFailed exception which contains information about the failure.
Parameters
failureThe Failure object representing the error.
failed_commandThe Command object of the failed command.
def hwm.command.parser.CommandParser._load_permissions (   self,
  validation_results,
  valid_command 
)
private

Loads the user's permissions, if required.

 This callback runs after the command has been validated and is responsible for loading a user's permissions to make
 sure that the user has permission to execute the command. If the command is being executed in kernel mode, then this
 step will be skipped and a pre-fired deferred will be returned to continue the execution process.
Exceptions
Thiscallback may throw several exceptions indicating errors about the command. These exceptions will automatically be picked up by the errback chain on the parent deferred.
Parameters
validation_resultsThe validation results. Always true (because this is a callback and not an errback).
valid_commandThe Command object being executed.
Returns
Returns a deferred that will eventually be fired with the user's command execution permissions (or None if the command is being run in kernel mode).
def hwm.command.parser.CommandParser._run_command (   self,
  user_permissions,
  valid_command 
)
private

Executes the command after it has been validated.

 This callback sends the command to it's specified destination after it has been validated by previous callbacks. It
 will eventually return the command response via a deferred.
Exceptions
Maythrow CommandError and other exceptions indicating that the command has failed. A subsequent errback in the main command deferred chain will automatically handle all command errors.
Parameters
user_permissionsA dictionary containing the user's permissions. If the command is being running in kernel mode, this will just be None.
valid_commandThe Command object for the currently executing command.
Returns
Returns a deferred that will eventually be fired with the results of the command execution.
def hwm.command.parser.CommandParser.parse_command (   self,
  raw_command,
  user_id = None,
  kernel_mode = False 
)

Processes all commands received by the ground station.

 When a raw command is passed to this function, it performs the following operations via a series of callbacks:
 * Constructs a new Command and validates it against that command's schema
 * Verifies that the indicated command exists
 * Checks that the user can execute the command
 * Executes the command in a new thread
 * Returns a deferred that will be fired with the results of the command

 Some of these steps may be skipped depending on the type of command. For example, kernel level commands skip the 
 permission checking phase.
Note
In the event of an error with the command (e.g. invalid schema or permission error), the error will be logged and an error response will be returned via the returned deerred's errback chain.
The callback/errback chain for the deferred returned from this function will be fired with a dictionary containing the results of the command. In the event of an error, these results can be accessed using the returned Failure like so: Failure.value.results['response']. In the event of a success, these results can be accessed via the 'response' key of the callback parameter. The calling module is responsible for converting this dictionary into an appropriate format.
Parameters
raw_commandA raw command containing metadata about the command in an arbitrary format (specific Command classes are responsible for parsing different formats).
user_idThe user's ID for the purpose of loading command execution settings. If set, this probably came from the user's SSL certificate or reservation schedule.
kernel_modeIndicates if the command should be run in kernel mode. That is, whether permission and session restrictions should be ignored. This is done, for example, when pipeline setup commands get run as a new session is being setup.
Returns
Returns the results of the command in a dictionary using a deferred. May be the output of the command or a Failure (containing details about the failure) in the event of an error.
def hwm.command.parser.CommandParser.system_command_handlers (   self)

Provides access to the loaded system command handlers.

Returns
Returns the dictionary containing references to the available system command handlers.

The documentation for this class was generated from the following file: