Jump to: navigation, search

Difference between revisions of "Trove/trove-notifications"

(Reddwarf Notifications)
(Task Manager Events)
Line 5: Line 5:
 
== Task Manager Events ==
 
== Task Manager Events ==
  
Reddwarf taskmanager is responsible for dispatching tasks and sending notification events. Here is a typical example::
+
Reddwarf taskmanager is responsible for dispatching tasks and sending notification events. Here is a typical example:
  
 
<code>
 
<code>
from reddwarf.openstack.common.notifier import api as notifier
+
    from reddwarf.openstack.common.notifier import api as notifier
from reddwarf.openstack.common import timeutils
+
    from reddwarf.openstack.common import timeutils
 +
    class NotifyMixin(object):
 +
        """Notification Mixin
 +
        This adds the ability to send usage events to an Instance object.
 +
        """
 +
        def send_usage_event(self, event_type, **kwargs):
 +
            event_type = 'reddwarf.instance.%s' % event_type
 +
            publisher_id = CONF.host
 +
            # Grab the instance size from the kwargs or from the nova client
 +
            instance_size = kwargs.pop('instance_size', None)
 +
            if instance_size is None:
 +
                flavor = self.nova_client.flavors.get(self.flavor_id)
 +
                instance_size = flavor.ram
 +
            # Default payload
 +
            created_time = timeutils.isotime(self.db_info.created)
 +
            payload = {
 +
                'instance_size': instance_size,
 +
                'tenant_id': self.tenant_id,
 +
                'instance_id': self.id,
 +
                'instance_name': self.name,
 +
                'created_at': created_time,
 +
                'launched_at': created_time,
 +
                'nova_instance_id': self.server_id,
 +
            }
 +
            if CONF.reddwarf_volume_support:
 +
                payload.update({
 +
                    'volume_size': self.volume_size,
 +
                    'nova_volume_id': self.volume_id
 +
                })
 +
            # Update payload with all other kwargs
 +
            payload.update(kwargs)
 +
            notifier.notify(self.context, publisher_id, event_type, 'INFO',
 +
                                payload)</code>
  
class NotifyMixin(object):
 
    """Notification Mixin
 
  
    This adds the ability to send usage events to an Instance object.
 
    """
 
  
    def send_usage_event(self, event_type, **kwargs):
+
=== Create Event ===
        event_type = 'reddwarf.instance.%s' % event_type
 
        publisher_id = CONF.host
 
  
        # Grab the instance size from the kwargs or from the nova client
+
Create Events are emitted when a resource is created:
        instance_size = kwargs.pop('instance_size', None)
 
        if instance_size is None:
 
            flavor = self.nova_client.flavors.get(self.flavor_id)
 
            instance_size = flavor.ram
 
  
        # Default payload
+
<code>self.send_usage_event('create', instance_size=flavor_ram)</code>
        created_time = timeutils.isotime(self.db_info.created)
 
        payload = {
 
            'instance_size': instance_size,
 
            'tenant_id': self.tenant_id,
 
            'instance_id': self.id,
 
            'instance_name': self.name,
 
            'created_at': created_time,
 
            'launched_at': created_time,
 
            'nova_instance_id': self.server_id,
 
        }
 
  
        if CONF.reddwarf_volume_support:
+
Sample Message:
            payload.update({
 
                'volume_size': self.volume_size,
 
                'nova_volume_id': self.volume_id
 
            })
 
  
        # Update payload with all other kwargs
+
<code>
        payload.update(kwargs)
+
{
        notifier.notify(self.context, publisher_id, event_type, 'INFO',
+
      'event_type': 'reddwarf.instance.create',
                        payload)
+
      'instance_size': 512,
 +
      'tenant_id': <UUID>,
 +
      'instance_id': <UUID>,
 +
      'instance_name': 'MyDB,
 +
      'created_at': UTCDATE,
 +
      'launched_at': UTCDATE,
 +
      'nova_instance_id': <UUID>,
 +
      'volume_size': 1,
 +
      'nova_volume_id': <UUID>
 +
}
 
</code>
 
</code>
  
 +
=== Modify Volume Size ===
  
 +
<code>self.send_usage_event('modify_volume',
 +
                                  launched_at=timeutils.isotime(),
 +
                                  modify_at=timeutils.isotime(),
 +
                                  volume_size=new_size)</code>
  
=== Create Event ===
+
Sample::
 +
 
 +
<code>
 +
{
 +
      'event_type': 'reddwarf.instance.modify_volume',
 +
      'instance_size': 512,
 +
      'tenant_id': <UUID>,
 +
      'instance_id': <UUID>,
 +
      'instance_name': 'MyDB,
 +
      'created_at': UTCDATE,
 +
      'launched_at': UTCDATE,
 +
      'modify_at': UTCDATE,
 +
      'nova_instance_id': <UUID>,
 +
      'volume_size': 2,
 +
      'nova_volume_id': <UUID>
 +
}
 +
</code>
  
Create Events are emitted when a resource is created:
+
=== Modify Size (Resize) ===
  
<code>self.send_usage_event('create', instance_size=flavor_ram)</code>
+
<code>self.instance.send_usage_event('modify_flavor',
 +
                                      instance_size=self.new_memory_size,
 +
                                      launched_at=timeutils.isotime(),
 +
                                      modify_at=timeutils.isotime())</code>
  
Sample Message:
+
Sample::
  
 
<code>
 
<code>
{balh}
+
{
 +
      'event_type': 'reddwarf.instance.modify_flavor',
 +
      'instance_size': 1024,
 +
      'tenant_id': <UUID>,
 +
      'instance_id': <UUID>,
 +
      'instance_name': 'MyDB,
 +
      'created_at': UTCDATE,
 +
      'launched_at': UTCDATE,
 +
      'modify_at': UTCDATE,
 +
      'nova_instance_id': <UUID>,
 +
      'volume_size': 2,
 +
      'nova_volume_id': <UUID>
 +
}
 
</code>
 
</code>
  
Line 68: Line 121:
  
 
Delete Events are emitted when a resource is deleted:
 
Delete Events are emitted when a resource is deleted:
 +
 +
<code>self.send_usage_event('delete', deleted_at=timeutils.isotime())</code>
  
 
Sample:
 
Sample:
  
 +
<code>
 +
{
 +
      'event_type': 'reddwarf.instance.delete',
 +
      'instance_size': 1024,
 +
      'tenant_id': <UUID>,
 +
      'instance_id': <UUID>,
 +
      'instance_name': 'MyDB,
 +
      'created_at': UTCDATE,
 +
      'launched_at': UTCDATE,
 +
      'deleted_at': UTCDATE,
 +
      'nova_instance_id': <UUID>,
 +
      'volume_size': 2,
 +
      'nova_volume_id': <UUID>
 +
}
 +
</code>
  
 
=== Exists Event ===
 
=== Exists Event ===
Line 77: Line 147:
  
 
Sample:
 
Sample:
 +
 +
<code>
 +
{
 +
      'event_type': 'reddwarf.instance.exists',
 +
      'instance_size': 512,
 +
      'tenant_id': <UUID>,
 +
      'instance_id': <UUID>,
 +
      'instance_name': 'MyDB',
 +
      'created_at': UTCDATE,
 +
      'launched_at': UTCDATE,
 +
      'nova_instance_id': <UUID>,
 +
      'volume_size': 1,
 +
      'nova_volume_id': <UUID>
 +
}
 +
</code>

Revision as of 17:54, 1 April 2013

Reddwarf Notifications

Reddwarf 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

Reddwarf taskmanager is responsible for dispatching tasks and sending notification events. Here is a typical example:

   from reddwarf.openstack.common.notifier import api as notifier
   from reddwarf.openstack.common import timeutils
   class NotifyMixin(object):
       """Notification Mixin
       This adds the ability to send usage events to an Instance object.
        """
       def send_usage_event(self, event_type, **kwargs):
           event_type = 'reddwarf.instance.%s' % event_type
           publisher_id = CONF.host
           # Grab the instance size from the kwargs or from the nova client
           instance_size = kwargs.pop('instance_size', None)
           if instance_size is None:
               flavor = self.nova_client.flavors.get(self.flavor_id)
               instance_size = flavor.ram
           # Default payload
           created_time = timeutils.isotime(self.db_info.created)
           payload = {
               'instance_size': instance_size,
               'tenant_id': self.tenant_id,
               'instance_id': self.id,
               'instance_name': self.name,
               'created_at': created_time,
               'launched_at': created_time,
               'nova_instance_id': self.server_id,
           }
           if CONF.reddwarf_volume_support:
               payload.update({
                   'volume_size': self.volume_size,
                   'nova_volume_id': self.volume_id
               })
           # Update payload with all other kwargs
           payload.update(kwargs)
           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', instance_size=flavor_ram)

Sample Message:

{

     'event_type': 'reddwarf.instance.create',
     'instance_size': 512,
     'tenant_id': <UUID>,
     'instance_id': <UUID>,
     'instance_name': 'MyDB,
     'created_at': UTCDATE,
     'launched_at': UTCDATE,
     'nova_instance_id': <UUID>,
     'volume_size': 1,
     'nova_volume_id': <UUID>

}

Modify Volume Size

self.send_usage_event('modify_volume',

                                 launched_at=timeutils.isotime(),
                                 modify_at=timeutils.isotime(),
                                 volume_size=new_size)

Sample::

{

     'event_type': 'reddwarf.instance.modify_volume',
     'instance_size': 512,
     'tenant_id': <UUID>,
     'instance_id': <UUID>,
     'instance_name': 'MyDB,
     'created_at': UTCDATE,
     'launched_at': UTCDATE,
     'modify_at': UTCDATE,
     'nova_instance_id': <UUID>,
     'volume_size': 2,
     'nova_volume_id': <UUID>

}

Modify Size (Resize)

self.instance.send_usage_event('modify_flavor',

                                      instance_size=self.new_memory_size,
                                      launched_at=timeutils.isotime(),
                                      modify_at=timeutils.isotime())

Sample::

{

     'event_type': 'reddwarf.instance.modify_flavor',
     'instance_size': 1024,
     'tenant_id': <UUID>,
     'instance_id': <UUID>,
     'instance_name': 'MyDB,
     'created_at': UTCDATE,
     'launched_at': UTCDATE,
     'modify_at': UTCDATE,
     'nova_instance_id': <UUID>,
     'volume_size': 2,
     'nova_volume_id': <UUID>

}

Delete Event

Delete Events are emitted when a resource is deleted:

self.send_usage_event('delete', deleted_at=timeutils.isotime())

Sample:

{

     'event_type': 'reddwarf.instance.delete',
     'instance_size': 1024,
     'tenant_id': <UUID>,
     'instance_id': <UUID>,
     'instance_name': 'MyDB,
     'created_at': UTCDATE,
     'launched_at': UTCDATE,
     'deleted_at': UTCDATE,
     'nova_instance_id': <UUID>,
     'volume_size': 2,
     'nova_volume_id': <UUID>

}

Exists Event

Exists Events are emitted periodically signifying that the resource exists.

Sample:

{

     'event_type': 'reddwarf.instance.exists',
     'instance_size': 512,
     'tenant_id': <UUID>,
     'instance_id': <UUID>,
     'instance_name': 'MyDB',
     'created_at': UTCDATE,
     'launched_at': UTCDATE,
     'nova_instance_id': <UUID>,
     'volume_size': 1,
     'nova_volume_id': <UUID>

}