Trove/trove-notifications-v2

Trove Notifications
Trove will emit events for resources as they are manipulated. These events can be used to meter the service and possibly used to calculate bills.

Task Manager Events
Trove taskmanager is responsible for dispatching tasks and sending notification events. Here is a typical example:

from trove.openstack.common.notifier import api as notifier from trove.openstack.common import timeutils class NotifyMixin(object): """Notification Mixin       This adds the ability to send usage events to an Instance object.         """ def send_stack_usage_even(self, event_type, **kwargs): az = kwargs.pop('az') name = kwargs.pop('name') event_type = 'trove.instance.%s' % event_type publisher_id = CONF.host created_time = timeutils.isotime(self.db_info.created) compute_instance_id = kwargs.pop('compute_instance_id') payload = {'availability_zone': az, 'created_at': created_time, 'name': name, 'instance_id': self.id, 'instance_name': name, 'flavor_name': self.new_flavor['name'], 'flavor_id': self.new_flavor['id'], 'launched_at': created_time, 'compute_instance_id': compute_instance_id, 'region': CONF.region, 'state_description': self.status.description, 'state': self.status, 'tenant_id': self.tenant_id, 'user_id': self.context.user, 'service_id': self._get_service_id(                                               self.datastore_version.manager,                                                 CONF.notification_service_id)}

if CONF.trove_volume_support: payload.update({                                  'volume_size': self.db_info.volume_size,                                   'volume_id': self.db_info.volume_id                          }) # Update payload with all other kwargs payload.update(kwargs) LOG.debug(_('Sending event: %(event_type)s, %(payload)s') %                                    {'event_type': event_type, 'payload': payload}) notifier.notify(self.context, publisher_id, event_type, 'INFO', payload)

Create Event
Create Events are emitted when a resource is created:

self.send_usage_event('create', az, flavor, compute_instance_id, name, volume_size)

Sample Message:

{     'event_type': 'trove.instance.create', 'flavor_name': m1.small, 'flavor_id':  or , 'tenant_id': , 'instance_id': , 'instance_name': 'MyDB, 'created_at': UTCDATE, 'launched_at': UTCDATE, 'compute_instance_id': , 'volume_size': 1, 'volume_id': , 'state_description': , 'state': , 'user_id': , 'service_id':  }

Modify Volume Size
self.send_usage_event('modify_volume', launched_at=timeutils.isotime, modify_at=timeutils.isotime, volume_size=new_size)

Sample::

{     'event_type': 'trove.instance.create', 'flavor_name': m1.small, 'flavor_id':  or , 'tenant_id': , 'instance_id': , 'instance_name': 'MyDB, 'created_at': UTCDATE, 'launched_at': UTCDATE, 'compute_instance_id': , 'volume_size': NEW_SIZE, 'volume_id': , 'state_description': <String>, 'state': <String>, 'user_id': <String>, 'service_id': <UUID> }

Modify Size (Resize)
self.instance.send_usage_event('modify_flavor', flavor, launched_at=NOW, modify_at=NOW)

Sample::

{     'event_type': 'trove.instance.create', 'flavor_name': m1.small, 'flavor_id': <UUID> or <Integer>, 'tenant_id': <UUID>, 'instance_id': <UUID>, 'instance_name': 'MyDB, 'created_at': UTCDATE, 'launched_at': UTCDATE, 'compute_instance_id': <UUID>, 'volume_size': NEW_SIZE, 'volume_id': <UUID>, 'state_description': <String>, 'state': <String>, 'user_id': <String>, 'service_id': <UUID> }

Delete Event
Delete Events are emitted when a resource is deleted:

self.send_usage_event('delete', deleted_at=DELETE_AD)

Sample:

{     'event_type': 'trove.instance.create', 'flavor_name': m1.small, 'flavor_id': <UUID> or <Integer>, 'tenant_id': <UUID>, 'instance_id': <UUID>, 'instance_name': 'MyDB, 'created_at': UTCDATE, 'launched_at': UTCDATE, 'compute_instance_id': <UUID>, 'volume_size': NEW_SIZE, 'volume_id': <UUID>, 'state_description': <String>, 'state': <String>, 'user_id': <String>, 'service_id': <UUID> 'delete_at': UTCDATE }

Exists Event
Exists Events are emitted periodically signifying that the resource exists.

Sample:

{     'event_type': 'trove.instance.create', 'flavor_name': m1.small, 'flavor_id': <UUID> or <Integer>, 'tenant_id': <UUID>, 'instance_id': <UUID>, 'instance_name': 'MyDB, 'created_at': UTCDATE, 'launched_at': UTCDATE, 'compute_instance_id': <UUID>, 'volume_size': NEW_SIZE, 'volume_id': <UUID>, 'state_description': <String>, 'state': <String>, 'user_id': <String>, 'service_id': <UUID> }