Commit d32c21e2 authored by Clovis NZOUENDJOU's avatar Clovis NZOUENDJOU
Browse files

Adding comments in files connection, entity, exchange, message

parent 27e4657af330
......@@ -7,6 +7,24 @@ from tools.translate import _
class anybusConnection(osv.Model):
""" Class used to establish the connection between your ERP and server RabbitMQ
.. Note::
The BrokerConnection class supports additional keyword arguments,
these are: hostname: Default host name if not provided in the URL.
userid: Default user name if not provided in the URL. password: Default password
if not provided in the URL. virtual_host: Default virtual host if not provided in the URL.
port: Default port if not provided in the URL. transport: Default transport if not provided in
the URL. Can be a string specifying the path to the class. (e.g. kombu.transport.pyamqplib.
Transport), or one of the aliases: amqplib, pika, redis, memory, and so on. ssl: Use SSL to
connect to the server. Default is False. Only supported by the amqp transport. insist:
Insist on connecting to a server. In a configuration with multiple load-sharing servers,
the insist option tells the server that the client is insisting on a connection to the
specified server. Default is False. Only supported by the amqp and pika transports, and not by
AMQP 0-9-1. connect_timeout: Timeout in seconds for connecting to the server. May not be
supported by the specified transport. transport_options: A dict of additional connection
arguments to pass to alternate kombu channel implementations. Consult the transport
documentation for available options.
"""
_name = 'anybus.connection'
_description = 'anybus connection'
......@@ -31,9 +49,14 @@ class anybusConnection(osv.Model):
}
def _get_uri(self, cr, uid, connection, context=None):
""" return the uri of the connexion
"""
return connection.uri % {'dbname': cr.dbname}
def action_declare(self, cr, uid, ids, context=None):
""" Function to declare a connection. When a connection is declared,
then you are connected to the RabbitMQ server.
"""
for connection in self.browse(cr, uid, ids, context=context):
try:
uri = self._get_uri(cr, uid, connection, context=context)
......@@ -52,6 +75,9 @@ class anybusConnection(osv.Model):
return {}
def action_redraft(self, cr, uid, ids, context=None):
""" This function searches all exchanges and queues that are reported
and changes their state in ``draft``
"""
exchange_obj = self.pool.get('anybus.entity.exchange')
exchange_ids = exchange_obj.search(
cr, uid, [('state', '=', 'declared')], context=context)
......@@ -64,6 +90,9 @@ class anybusConnection(osv.Model):
return {}
def action_declare_all(self, cr, uid, ids, context=None):
""" This function searches all exchanges and queues which are at the draft state
and ``declare`` it.
"""
exchange_obj = self.pool.get('anybus.entity.exchange')
exchange_ids = exchange_obj.search(
cr, uid, [('state', '=', 'draft')], context=context)
......@@ -75,6 +104,8 @@ class anybusConnection(osv.Model):
return {}
def action_purge_all(self, cr, uid, ids, context=None):
""" Purge all queues which are at the draft state
"""
queue_obj = self.pool.get('anybus.entity.queue')
queue_ids = queue_obj.search(
cr, uid, [('state', '=', 'draft')], context=context)
......@@ -82,6 +113,8 @@ class anybusConnection(osv.Model):
return {}
def get_actions(self, cr, uid, ids, model, context=None):
"""
"""
model_ids = self.pool.get(model).search(cr, uid, [], context=context)
res = {}
for id in ids:
......
......@@ -6,6 +6,8 @@ from tools.translate import _
class AbstractAnybusEntity(osv.AbstractModel):
""" Abstract class used to define the columns and common methods between exchanges and queues
"""
_name = 'abstract.anybus.entity'
_description = 'Abstract anybus entity'
......@@ -46,6 +48,11 @@ class AbstractAnybusEntity(osv.AbstractModel):
}
def copy(self, cr, uid, id, default=None, context=None):
""" This method duplicates the entity. By default, the new entity is in draft state
and bears the name of copied entity, preceded by the word "Copie"
:param id: id of entity (ie. exchange or queue)
"""
if default is None:
default = {}
entity = self.browse(cr, uid, id, context=context)
......@@ -54,6 +61,10 @@ class AbstractAnybusEntity(osv.AbstractModel):
cr, uid, id, default, context=context)
def unlink(self, cr, uid, ids, context=None):
""" This method delete the entity, only if she's in the draft state
:param ids: list of entity_ids to delete
"""
for entity in self.browse(cr, uid, ids, context=context):
if entity.state != 'draft':
raise osv.except_osv(
......@@ -63,6 +74,10 @@ class AbstractAnybusEntity(osv.AbstractModel):
cr, uid, ids, context=context)
def name_get(self, cr, uid, ids, context=None):
""" Default name_get of entity class
:param ids: list of entity_ids to delete
"""
if not len(ids):
return []
res = {}
......@@ -71,6 +86,10 @@ class AbstractAnybusEntity(osv.AbstractModel):
return res.items()
def _get_entity_name(self, cr, uid, id, context=None):
""" Return the entity's name
:param id: entity's id
"""
r = self.read(cr, uid, id, ['name'], context=context)
return r['name'] % {'dbname': cr.dbname}
......@@ -89,6 +108,11 @@ class AbstractAnybusEntity(osv.AbstractModel):
def _action_method(self, cr, uid, ids, method="declare", onerror=True,
write={'state': 'declared'}, context=None):
""" Method used to declare an entity. When an entity is declared,
her state become 'declare'.
:param ids: list of entity's id
"""
for entity in self.browse(cr, uid, ids, context=context):
if entity.connection_id.state == 'draft':
entity.connection_id.action_declare()
......
......@@ -6,6 +6,12 @@ import time
class AnybusExchange(osv.Model):
""" Class representing an exchange within the meaning of RabbitMQ.
The exchange is the point where a message can be deposited and from there, the message
will then follow a path to finally be placed in the queues or destination, where it will be
stored until use. Several different customer can send messages on the same exchange, and
several messages will follow the same mapping.
"""
_name = 'anybus.entity.exchange'
_description = 'anybus Exchange'
_inherit = 'abstract.anybus.entity'
......@@ -31,6 +37,12 @@ class AnybusExchange(osv.Model):
]
def _get_entity(self, cr, uid, exchange, channel, context=None, **kwargs):
""" This function return an entity containing the informations of exchange and channel
:param exchange: Object exchange
:param channel: Object channel
:return: Object Exchange
"""
if context is None:
context = {}
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
......@@ -53,6 +65,12 @@ class AnybusExchange(osv.Model):
def _get_already_declared_entity(self, cr, uid, exchange, channel,
context=None, **kwargs):
""" This function return declared entity
:param exchange: Object exchange
:param channel: Object channel
:return: Object Exchange
"""
name = self._get_entity_name(cr, uid, exchange.id, context=context)
return Exchange(
name=name,
......@@ -60,6 +78,20 @@ class AnybusExchange(osv.Model):
)
def publish(self, cr, uid, id, body, key, context=None):
""" Function used to publish a message on an exchange
:param body: body of our message
:param key: routing key
:param id: Exchange_id
.. Note::
In order to customize the directions taken by a message, system binding / routing
key is available. Each binding may define its own key binding which will be a
string identifying a precise mapping. Messages will in turn define a routing key
that will define through which the message must pass binding. A routing key is
simply written in the form of dot-separated identifier names.
"""
exchange = self.browse(cr, uid, id, context=context)
ex_name = self._get_entity_name(cr, uid, id, context=context)
uri = self.pool.get('anybus.connection')._get_uri(
......
......@@ -76,6 +76,8 @@ class AbstractAnybusMessage(osv.AbstractModel):
return [('state', '=', 'blocked')]
def unlink(self, cr, uid, ids, context=None):
""" Method use to delete a list of message
"""
for message in self.browse(cr, uid, ids, context=context):
if message.state == "blocked":
raise osv.except_osv(_('Message error'),
......@@ -136,4 +138,4 @@ class AbstractAnybusMessage(osv.AbstractModel):
res['value'] = read
return res
## vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment