Coverage for ion/services/dm/distribution/events : 100.00%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#!/usr/bin/env python
@file ion/services/dm/distribution/events.py @author Dave Foster <dfoster@asascience.com> @brief Event notification """
# event IDs: https://confluence.oceanobservatories.org/display/syseng/CIAD+DM+SV+Notifications+and+Events # standard Message Types for events. Instead, expect messages of ids 10001, 2001, and 2005.
""" Base publisher for Event Notifications.
Events are published by various items in the ION system with no knowledge or requirement that anything be listening to them. The EventPublisher base class defines a specially derived Publisher class that can be used to create and publish event notification messages. By default, events are published to the exchange point 'events.topic'.
You should not use an instance of EventPublisher directly, rather, use one of its derived implementations.
Call create_event and then publish_event (or the combination method, create_and_publish_event) to send an event notification into the system.
The create_event method takes kwargs which set the message fields. This is meant to be used in a convenience fashion, you may still alter the message create_event returns using normal message semantics.
The message sent by EventPublisher is the basic EventMessage (id 2322) which contains common information about an event, and the additional_data field is defined as another message, specific to the type of event being published.
Implementers: - Override msg_type and event_id in your derived classes. The event_id is unique to each type of event notification, and the msg_type is the type of message that will occupy the additional_data field. - If your message contains any enum fields, you should define convienence classes to allow the user to set the value of those enum fields in create_event without needing to have an instance of the message ahead of time. These classes should follow this model: # enum Direction for 'direction' field in message class Direction: NORTH = 'NORTH' SOUTH = 'SOUTH' EAST = 'EAST' WEST = 'WEST'
Then, when calling create_event, you can use: SomePublisher.create_event(direction=SomePublisher.Direction.EAST)
Alternatly, you may set the field in two steps: msg = yield SomePublisher.create_event() msg.direction = msg.Direction.EAST # using the enum as defined in the message """
""" The enum Status as defined in the EventMessage object. Use this to set the 'status' field using create_event. """
""" Builds the topic that this event should be published to. """
""" Initializer override. Sets defaults for the EventPublisher.
@param origin Sets the origin used in the topic when publishing the event. This can be overridden when calling publish. """
""" Helper method to set fields of a Message instance. Used by create_event.
@param msg The Message instance to set fields on. @param msgargs The dict of field -> values to set fields on the msg with. As fields are found in the message and set, they are removed from the msgarms param. Passed by ref from create_event. When an Enum field is discovered that we are trying to set, this method attempts to find the real enum value by the name of the enum member passed in. """ # is this an enum field and we've passed a string that looks like it could be a name? # translate v into the real value
def create_event(self, **kwargs): """ Creates an EVENT_MESSAGE_TYPE with the additional_data field pointing to a msg of type "msg_type" as defined by this EventPublisher's derivation.
@returns The event message. """
# copy kwargs into local list
# create base event message, assign values from kwargs
# create additional event msg (specific to this event notification), assign values from kwargs
# error checking: see if we have any remaining kwargs
# TODO: perhaps check to make sure additional_event_msg and event_msg have exclusive attribute names, or we'll assign to one and not the other
# link them
""" Publishes an event notification.
@param event_msg The event message to publish. @param origin The origin to use in the topic. If not set, uses the origin set in the initializer. """
def create_and_publish_event(self, **kwargs): """ Convenience method which calls both create_event and publish_event in one shot. """
""" Event Notification Publisher for Resource lifecycle events. Used as a concrete derived class, and as a base for specializations such as ContainerLifecycleEvents and ProcessLifecycleEvents.
The "origin" parameter in this class' initializer should be the resource id (UUID). """
# enum for State
""" Event Notification Publisher for Container lifecycle events.
The "origin" parameter in this class' initializer should be the container name. """
""" Event Notification Publisher for Process lifecycle events.
The "origin" parameter in this class' initializer should be the process' exchange name. """
""" Event Notification Publisher for infrastructure related events. An abstract base class, should be inherited and overridden. """ pass
""" Event Notification Publisher for Applications starting and stopping.
The "origin" parameter in this class' initializer should be the application's name. """
""" Event Notification Publisher for a Container finishing its running and startup apps.
The "origin" parameter in this class' initializer should be the application's name. """
""" Base Publisher class for "triggered" Event Notifications. """
""" Event Notification Publisher for Datasource updates.
The "origin" parameter in this class' initializer should be the datasource resource id (UUID). """
""" Base Publisher class for resource modification Event Notifications. This is distinct from resource lifecycle state Event Notifications. """
""" Event Notification Publisher for the Datasource Unavailable event. """
""" Event Notification Publisher for Dataset Supplement Added.
The "origin" parameter in this class' initializer should be the dataset resource id (UUID). """
""" Event Notification Publisher for Dataset Modifications.
The "origin" parameter in this class' initializer should be the process' exchange name (TODO: correct?) """
""" Event Notification Publisher for Dataset Change Event - Will Cause AIS to clear the cache for this UUID.
The "origin" parameter in this class' initializer should be the dataset resource id (UUID). """
""" Event Notification Publisher for Datasource Change Event - Will Cause AIS to clear the cache for this UUID.
The "origin" parameter in this class' initializer should be the datasource resource id (UUID). """
""" Event Notification Publisher for Ingestion Processing Event - Ingestion telling JAW that it is still working, and increase its delay.
The "origin" parameter in this class' initializer should be the dataset resource id (UUID). """
""" Event Notification Publisher for Subscription Modifications.
The "origin" parameter in this class' initializer should be the dispatcher resource id (UUID). """
""" Event Notification Publisher for Subscription Modifications.
The "origin" parameter in this class' initializer should be the dispatcher resource id (UUID). """
""" Event Notification Publisher for Scheduled events (ie from the Scheduler service). """
""" Base Publisher for logging Event Notifications. """
""" Event Notification Publisher for critical logging events.
The "origin" parameter in this class' initializer should be the process' exchange name (TODO: correct?) """
""" Event Notification Publisher for error logging events.
The "origin" parameter in this class' initializer should be the process' exchange name (TODO: correct?) """
""" Event Notification Publisher for informational logging events.
The "origin" parameter in this class' initializer should be the process' exchange name (TODO: correct?) """
""" Event Notification Publisher for Subscription Modifications.
The "origin" parameter in this class' initializer should be the process' exchange name (TODO: correct?) """
""" Event Notification Publisher for Subscription Modifications.
The "origin" parameter in this class' initializer should be the process' exchange name (TODO: correct?) """
""" Event Notification Publisher for Subscription Modifications.
The "origin" parameter in this class' initializer should be the process' exchange name (TODO: correct?) """ # # # ################################################################################ # #
""" Base Subscriber for event notifications.
This base subscriber is capable of subscribing to any event notification type with any origin. You must assign the on_data callable in your instance (to a callable taking a data param) or use a SubscriberFactory with the subscriber_type set to this class and specify your handler to its build method. """
""" Builds the topic that this event should be published to. If either side of the event_id.origin pair are missing, will subscribe to anything. """
""" Initializer.
You may wish to set either event_id or origin. A normal SubscriberFactory, with this class specified as the subscriber_type, will pass event_id or origin as kwargs here when specified to the build method.
If the queue_name is specified here, the sysname is prefixed automatically to it. This is becuase named queues are not namespaces to their exchanges, so two different systems on the same broker can cross-pollute messages if a named queue is used. """
# prefix the queue_name, if specified, with the sysname
def on_activate(self, *args, **kwargs):
""" Event Notification Subscriber for Resource lifecycle events. Used as a concrete derived class, and as a base for specializations such as ContainerLifecycleEvents and ProcessLifecycleEvents.
The "origin" parameter in this class' initializer should be the resource id (UUID). """
""" Event Notification Subscriber for Container lifecycle events.
The "origin" parameter in this class' initializer should be the container name. """
""" Event Notification Subscriber for Process lifecycle events.
The "origin" parameter in this class' initializer should be the process' exchange name. """
""" Event Notification Subscriber for infrastructure related events. An abstract base class, should be inherited and overridden. """ pass
""" Event Notification Subscriber for Applications starting and stopping.
The "origin" parameter in this class' initializer should be the application's name. """
""" Event Notification Subscriber for a Container finishing its running and startup apps.
The "origin" parameter in this class' initializer should be the application's name. """
""" Base Subscriber class for "triggered" Event Notifications. """ pass
""" Event Notification Subscriber for Datasource updates.
The "origin" parameter in this class' initializer should be the datasource resource id (UUID). """
""" Base Subscriber class for resource modification Event Notifications. This is distinct from resource lifecycle state Event Notifications. """ pass
""" Event Notification Subscriber for the Datasource Unavailable event.
The "origin" parameter in this class' initializer should be the datasource resource id (UUID). """
""" Event Notification Subscriber for Dataset Supplement Added.
The "origin" parameter in this class' initializer should be the dataset resource id (UUID). """
""" Event Notification Subscriber for Data Block changes.
The "origin" parameter in this class' initializer should be the process' exchagne name (TODO: correct?) """
""" Event Notification Subscriber for Dataset Change Event.
The "origin" parameter in this class' initializer should be the dataset resource id (UUID). """
""" Event Notification Subscriber for Datasource Change Event.
The "origin" parameter in this class' initializer should be the datasource resource id (UUID). """
""" Event Notification Subscriber for Ingestion Processing Event - Ingestion telling JAW that it is still working, and increase its delay.
The "origin" parameter in this class' initializer should be the dataset resource id (UUID). """
""" Event Notification Subscriber for Dataset Streaming Event - actual mechanism for getting data from DatasetAgent to Ingestion.
NOTE: There is no "Publisher" of this event - as it only comes from DatasetAgent (Java) and does not use the standard Message Types for events. Instead, expect messages of ids 10001, 2001, and 2005.
The "origin" parameter in this class' initializer should be the dataset resource id (UUID). """
""" Event Notification Subscriber for Subscription Modifications.
The "origin" parameter in this class' initializer should be the dispatcher resource id (UUID). """
""" Event Notification Subscriber for Subscription Modifications.
The "origin" parameter in this class' initializer should be the dispatcher resource id (UUID). """
""" Event Notification Subscriber for Scheduled events (ie from the Scheduler service). """
""" Base Subscriber for logging Event Notifications. """ pass
""" Event Notification Subscriber for critical logging events.
The "origin" parameter in this class' initializer should be the process' exchange name (TODO: correct?) """
""" Event Notification Subscriber for error logging events.
The "origin" parameter in this class' initializer should be the process' exchange name (TODO: correct?) """
""" Event Notification Subscriber for informational logging events.
The "origin" parameter in this class' initializer should be the process' exchange name (TODO: correct?) """
""" Event Notification Subscriber for Data Block changes.
The "origin" parameter in this class' initializer should be the process' exchagne name (TODO: correct?) """ pass
""" Event Notification Subscriber for Data Block changes.
The "origin" parameter in this class' initializer should be the process' exchagne name (TODO: correct?) """
""" Event Notification Subscriber for Instrument Data.
The "origin" parameter in this class' initializer should be the process' exchagne name (TODO: correct?) """
|