Welcome to Pacifica Dispatcher’s documentation!

Pacifica Dispatcher receives and handles CloudEvents notifications.

Installation

The Pacifica software is available through PyPi so creating a virtual environment to install is what is shown below. Please keep in mind compatibility with the Pacifica Core services.

Installation in Virtual Environment

These installation instructions are intended to work on both Windows, Linux, and Mac platforms. Please keep that in mind when following the instructions.

Please install the appropriate tested version of Python for maximum chance of success.

Linux and Mac Installation

mkdir ~/.virtualenvs
python -m virtualenv ~/.virtualenvs/pacifica
. ~/.virtualenvs/pacifica/bin/activate
pip install pacifica-dispatcher

Windows Installation

This is done using PowerShell. Please do not use Batch Command.

mkdir "$Env:LOCALAPPDATA\virtualenvs"
python.exe -m virtualenv "$Env:LOCALAPPDATA\virtualenvs\pacifica"
& "$Env:LOCALAPPDATA\virtualenvs\pacifica\Scripts\activate.ps1"
pip install pacifica-dispatcher

Dispatcher Python Module

Downloader Runners Python Module

Download runner module.

This module contains two download runners. The first is for downloading from a local directory (works well for testing). The second is for downloading from a remote Pacifica Cartd service.

Additional methods for downloading could be used in the future.

class pacifica.dispatcher.downloader_runners.DownloaderRunner[source]

Abstract downloader class for downloading files.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 42
_abc_registry = <_weakrefset.WeakSet object>
download(basedir_name: str, files: List[pacifica.dispatcher.models.File] = None, timeout: int = 180) → List[Callable[Dict[str, Any], TextIO]][source]

Abstract download method to define interface for downloading files.

class pacifica.dispatcher.downloader_runners.LocalDownloaderRunner(basedir_name: str)[source]

Local download class.

This class is used for running the handlers on previously downloaded data relative to some base directory.

__init__(basedir_name: str) → None[source]

Save the base directory to the instance of the class.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 42
_abc_registry = <_weakrefset.WeakSet object>
download(basedir_name: str, files: List[pacifica.dispatcher.models.File] = None, timeout: int = 180) → List[Callable[Dict[str, Any], TextIO]][source]

Download the files locally.

The download base directory may not match the class instance base directory. If that’s the case symlink the files from the instance base directory to the called base directory.

Either case return a list of methods used to open the files.

class pacifica.dispatcher.downloader_runners.RemoteDownloaderRunner(downloader: pacifica.downloader.downloader.Downloader)[source]

Remote download runner class.

This class downloads data from a Pacifica Cartd service to a local directory.

__init__(downloader: pacifica.downloader.downloader.Downloader) → None[source]

Initialize the remote downloader class.

The class is initialized with an instance of the pacifica.downloader.Downloader class.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 42
_abc_registry = <_weakrefset.WeakSet object>
download(basedir_name: str, files: List[pacifica.dispatcher.models.File] = None, timeout: int = 180) → List[Callable[Dict[str, Any], TextIO]][source]

Download the files using the downloader.

The downloader is used to setup a cart of data from the Cartd service. The downloader used in it’s blocking form, setting up the cart, waiting for it to complete and downloading it.

Once complete a list of methods is returned for opening files.

Event Handlers Python Module

Event handlers module.

This module contains classes for handling the events. Users of this library should create their own instances of the abstract class EventHandler to process on the downloaded data.

class pacifica.dispatcher.event_handlers.EventHandler[source]

Event handler abstract class.

This class defines the interface for handling a cloud event.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 42
_abc_registry = <_weakrefset.WeakSet object>
handle(event: cloudevents.model.Event) → None[source]

Abstract method for event handling.

This method is called to process data after download.

class pacifica.dispatcher.event_handlers.NoopEventHandler[source]

The Noop event handler class.

This class is a stub that does nothing when an event is received. This class maybe useful if the act of downloading and uploading is desired with no processing.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 42
_abc_registry = <_weakrefset.WeakSet object>
handle(event: cloudevents.model.Event) → None[source]

Method does nothing, intentionally.

class pacifica.dispatcher.event_handlers.ExceptionEventHandler[source]

The exception event handler class.

This class is a stub that raises an exception when an event is received. This class is useful for testing error handling in the overall workflow.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 42
_abc_registry = <_weakrefset.WeakSet object>
handle(event: cloudevents.model.Event) → None[source]

Method raises an exception, because you are bad.

Exceptions Python Module

Exceptions module.

This module contains specific exceptions that can happen during the dispatching process.

exception pacifica.dispatcher.exceptions.EventError(event: cloudevents.model.Event)[source]

Base event dispatcher error class.

This the base event class used by all other error classes.

__init__(event: cloudevents.model.Event) → None[source]

Save the event for later use.

exception pacifica.dispatcher.exceptions.TransactionDuplicateAttributeError(event: cloudevents.model.Event, name: str)[source]

Duplicate event error.

Events can be sent multiple times, this error is raised if a transaction event has already been seen.

__init__(event: cloudevents.model.Event, name: str) → None[source]

Add the name of the event as well.

Models Python Module

Models module.

This class contains the data structure models for the dispatcher.

class pacifica.dispatcher.models.PacificaModel[source]

Abstract base class for all Dispatcher models.

Contains method interface definitions for all model classes.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 42
_abc_registry = <_weakrefset.WeakSet object>
classmethod from_cloudevents_model(event: cloudevents.model.Event) → Union[pacifica.dispatcher.models.PacificaModel, List[pacifica.dispatcher.models.PacificaModel]][source]

Abstract method for creating a model from a cloud event.

class pacifica.dispatcher.models.File(**attrs)[source]

File model class.

This holds all information about a file from a cloud event.

__init__(**attrs) → None[source]

Build the file attributes from the dictionary keywords.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 42
_abc_registry = <_weakrefset.WeakSet object>
_id = None
ctime = None
encoding = None
classmethod from_cloudevents_model(event: cloudevents.model.Event) → List[pacifica.dispatcher.models.File][source]

Factory creating instances of File from a cloud event.

hashsum = None
hashtype = None
mimetype = None
mtime = None
name = None
path

Path property accessor.

size = None
subdir = None
suspense_date = None
class pacifica.dispatcher.models.Transaction(**attrs)[source]

Transaction model clas.

This class holds all the information about a transaction from a cloud event.

__init__(**attrs) → None[source]

Build the transaction from the attrs in keywords.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 42
_abc_registry = <_weakrefset.WeakSet object>
_id = None
analytical_tool = None
description = None
classmethod from_cloudevents_model(event: cloudevents.model.Event) → pacifica.dispatcher.models.Transaction[source]

Factory creating a transaction class from a cloud event.

instrument = None
project = None
submitter = None
suspense_date = None
class pacifica.dispatcher.models.TransactionKeyValue(**attrs)[source]

Transaction key value model.

This holds the transaction key value pairs from a cloud event.

__init__(**attrs) → None[source]

Construct the attributes from keywords.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 42
_abc_registry = <_weakrefset.WeakSet object>
classmethod from_cloudevents_model(event: cloudevents.model.Event) → List[pacifica.dispatcher.models.TransactionKeyValue][source]

Factory creating all the key value pairs for a cloud event.

Receiver Python Module

Receiver module.

Contains a factory returning a receiver class that can create PeeWee models and CherryPy endpoints.

pacifica.dispatcher.receiver.create_peewee_model(passed_db: peewee.Database) → object[source]

Factory creating a receiver class.

Router Python Module

Router module.

This module contains classes to handle routing of events to event handlers.

class pacifica.dispatcher.router.Route(path: jsonpath2.path.Path, event_handler: pacifica.dispatcher.event_handlers.EventHandler)[source]

Route class.

This class routes an event to an event handler.

__init__(path: jsonpath2.path.Path, event_handler: pacifica.dispatcher.event_handlers.EventHandler) → None[source]

Save the path and event handler in the route.

match(event_data: Dict[str, Any]) → bool[source]

Determine if the event matches the route.

class pacifica.dispatcher.router.Router[source]

Router handles a list of routes.

__init__() → None[source]

Initialize the internal list of routes.

add_route(*args, **kwargs) → None[source]

Append new route objects based on keywords and args.

match(event_data: Dict[str, Any]) → Generator[[pacifica.dispatcher.router.Route, None], None][source]

Yield all route objects that match the event.

match_first_or_raise(event_data: Dict[str, Any]) → pacifica.dispatcher.router.Route[source]

Return the first route that matches the event.

exception pacifica.dispatcher.router.RouterError(router: pacifica.dispatcher.router.Router)[source]

Router base exception class.

__init__(router: pacifica.dispatcher.router.Router) → None[source]

Save the router as a part of the class.

exception pacifica.dispatcher.router.RouteNotFoundRouterError(router: pacifica.dispatcher.router.Router, event_data: Dict[str, Any])[source]

No route found exception.

__init__(router: pacifica.dispatcher.router.Router, event_data: Dict[str, Any]) → None[source]

Save the event as well as the router.

Uploader Runners Python Module

Uploader runner module.

This module contains the methods for uploading data either remotely or locally.

class pacifica.dispatcher.uploader_runners.UploaderRunner[source]

Abstract base class for uploading.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 48
_abc_registry = <_weakrefset.WeakSet object>
upload(basedir_name: str, transaction: pacifica.dispatcher.models.Transaction = None, transaction_key_values: List[pacifica.dispatcher.models.TransactionKeyValue] = None, timeout: int = 180) → Tuple[pacifica.uploader.bundler.bundler.Bundler, int, Dict[str, Any]][source]

Upload interface method.

class pacifica.dispatcher.uploader_runners.LocalUploaderRunner[source]

Handle uploading to a local directory.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 48
_abc_registry = <_weakrefset.WeakSet object>
upload(basedir_name: str, transaction: pacifica.dispatcher.models.Transaction = None, transaction_key_values: List[pacifica.dispatcher.models.TransactionKeyValue] = None, timeout: int = 180) → Tuple[pacifica.uploader.bundler.bundler.Bundler, int, Dict[str, Any]][source]

Fake upload by bundling up data to output directory.

class pacifica.dispatcher.uploader_runners.RemoteUploaderRunner(uploader: pacifica.uploader.uploader.Uploader)[source]

Handle uploading to a remote Pacifica instance.

__init__(uploader: pacifica.uploader.uploader.Uploader)[source]

Save the uploader class instance.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 48
_abc_registry = <_weakrefset.WeakSet object>
upload(basedir_name: str, transaction: pacifica.dispatcher.models.Transaction = None, transaction_key_values: List[pacifica.dispatcher.models.TransactionKeyValue] = None, timeout: int = 180) → Tuple[pacifica.uploader.bundler.bundler.Bundler, int, Dict[str, Any]][source]

Perform the upload to Pacifica.

Pacifica Dispatcher Module.

Indices and tables