From 3cdeb25bd01aae5e82ada8bbf82dd2dc23a4346e Mon Sep 17 00:00:00 2001 From: LiuSheng Date: Mon, 22 Jun 2015 21:51:55 +0800 Subject: [PATCH] Clean the re-implemented serializers in Ceilometer The RequestContextSerializer and JsonPayloadSerializer have been implemented in oslo_messaging, This change remove the re-implemented serializers in ceilometer/messaging.py Change-Id: I871ff34a8e1a140273fd10fe1fbb539ff864c9f7 Closes-Bug: 1467524 --- ceilometer/messaging.py | 41 +++++++---------------------------------- requirements.txt | 2 +- 2 files changed, 8 insertions(+), 35 deletions(-) diff --git a/ceilometer/messaging.py b/ceilometer/messaging.py index 2b569cfb..6f5dce5d 100644 --- a/ceilometer/messaging.py +++ b/ceilometer/messaging.py @@ -14,43 +14,13 @@ # under the License. from oslo_config import cfg -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('ceilometer') @@ -88,7 +58,8 @@ def get_rpc_server(transport, topic, endpoint): """Return a configured oslo_messaging rpc server.""" cfg.CONF.import_opt('host', 'ceilometer.service') target = oslo_messaging.Target(server=cfg.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) @@ -97,7 +68,8 @@ def get_rpc_server(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) @@ -113,7 +85,8 @@ 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) diff --git a/requirements.txt b/requirements.txt index 5f9a9d1f..14bf2ab7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,7 +24,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.16.0 # 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.6.0 # Apache-2.0