Processes all commands received by the hardware manager.
More...
|
|
| system_handlers |
| |
|
| permission_manager |
| |
|
| pipeline_manager |
| |
|
| session_coordinator |
| |
Processes all commands received by the hardware manager.
This class parses and performs validations on received commands, delegating them to the appropriate command handler.
| def hwm.command.parser.CommandParser.__init__ |
( |
|
self, |
|
|
|
system_command_handlers, |
|
|
|
permission_manager |
|
) |
| |
Sets up the command parser instance.
- Parameters
-
| system_command_handlers | A 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_manager | A 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.
| 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_results | A 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_command | The 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
-
| Raises | a CommandFailed exception which contains information about the failure. |
- Parameters
-
| failure | The Failure object representing the error. |
| failed_command | The 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
-
| This | callback 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_results | The validation results. Always true (because this is a callback and not an errback). |
| valid_command | The 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
-
| May | throw 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_permissions | A dictionary containing the user's permissions. If the command is being running in kernel mode, this will just be None. |
| valid_command | The 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_command | A raw command containing metadata about the command in an arbitrary format (specific Command classes are responsible for parsing different formats). |
| user_id | The 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_mode | Indicates 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: