Merge "Use the Serializer from oslo.messaging"

This commit is contained in:
Jenkins 2015-08-13 11:05:51 +00:00 committed by Gerrit Code Review
commit acd541577f
2 changed files with 8 additions and 35 deletions

View File

@ -13,43 +13,13 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_context import context
import oslo_messaging
from oslo_serialization import jsonutils
from oslo_messaging import serializer as oslo_serializer
DEFAULT_URL = "__default__"
TRANSPORTS = {}
class RequestContextSerializer(oslo_messaging.Serializer):
def __init__(self, base):
self._base = base
def serialize_entity(self, ctxt, entity):
if not self._base:
return entity
return self._base.serialize_entity(ctxt, entity)
def deserialize_entity(self, ctxt, entity):
if not self._base:
return entity
return self._base.deserialize_entity(ctxt, entity)
@staticmethod
def serialize_context(ctxt):
return ctxt.to_dict()
@staticmethod
def deserialize_context(ctxt):
return context.RequestContext(ctxt)
class JsonPayloadSerializer(oslo_messaging.NoOpSerializer):
@classmethod
def serialize_entity(cls, context, entity):
return jsonutils.to_primitive(entity, convert_instances=True)
def setup():
oslo_messaging.set_transport_defaults('aodh')
@ -77,7 +47,8 @@ def get_transport(conf, url=None, optional=False, cache=True):
def get_rpc_server(conf, transport, topic, endpoint):
"""Return a configured oslo_messaging rpc server."""
target = oslo_messaging.Target(server=conf.host, topic=topic)
serializer = RequestContextSerializer(JsonPayloadSerializer())
serializer = oslo_serializer.RequestContextSerializer(
oslo_serializer.JsonPayloadSerializer())
return oslo_messaging.get_rpc_server(transport, target,
[endpoint], executor='eventlet',
serializer=serializer)
@ -86,7 +57,8 @@ def get_rpc_server(conf, transport, topic, endpoint):
def get_rpc_client(transport, retry=None, **kwargs):
"""Return a configured oslo_messaging RPCClient."""
target = oslo_messaging.Target(**kwargs)
serializer = RequestContextSerializer(JsonPayloadSerializer())
serializer = oslo_serializer.RequestContextSerializer(
oslo_serializer.JsonPayloadSerializer())
return oslo_messaging.RPCClient(transport, target,
serializer=serializer,
retry=retry)
@ -102,6 +74,7 @@ def get_notification_listener(transport, targets, endpoints,
def get_notifier(transport, publisher_id):
"""Return a configured oslo_messaging notifier."""
serializer = RequestContextSerializer(JsonPayloadSerializer())
serializer = oslo_serializer.RequestContextSerializer(
oslo_serializer.JsonPayloadSerializer())
notifier = oslo_messaging.Notifier(transport, serializer=serializer)
return notifier.prepare(publisher_id=publisher_id)

View File

@ -19,7 +19,7 @@ oslo.service>=0.1.0 # Apache-2.0
PasteDeploy>=1.5.0
pbr<2.0,>=0.11
pecan>=0.8.0
oslo.messaging!=1.12.0,>=1.8.0 # Apache-2.0
oslo.messaging>1.17.1 # Apache-2.0
oslo.middleware!=2.0.0,>=1.2.0 # Apache-2.0
oslo.serialization>=1.4.0 # Apache-2.0
oslo.utils>=1.9.0 # Apache-2.0