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
This commit is contained in:
LiuSheng 2015-06-22 21:51:55 +08:00 committed by liu-sheng
parent 617ae2b384
commit 3cdeb25bd0
2 changed files with 8 additions and 35 deletions

View File

@ -14,43 +14,13 @@
# under the License. # under the License.
from oslo_config import cfg from oslo_config import cfg
from oslo_context import context
import oslo_messaging import oslo_messaging
from oslo_serialization import jsonutils from oslo_messaging import serializer as oslo_serializer
DEFAULT_URL = "__default__" DEFAULT_URL = "__default__"
TRANSPORTS = {} 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(): def setup():
oslo_messaging.set_transport_defaults('ceilometer') oslo_messaging.set_transport_defaults('ceilometer')
@ -88,7 +58,8 @@ def get_rpc_server(transport, topic, endpoint):
"""Return a configured oslo_messaging rpc server.""" """Return a configured oslo_messaging rpc server."""
cfg.CONF.import_opt('host', 'ceilometer.service') cfg.CONF.import_opt('host', 'ceilometer.service')
target = oslo_messaging.Target(server=cfg.CONF.host, topic=topic) 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, return oslo_messaging.get_rpc_server(transport, target,
[endpoint], executor='eventlet', [endpoint], executor='eventlet',
serializer=serializer) serializer=serializer)
@ -97,7 +68,8 @@ def get_rpc_server(transport, topic, endpoint):
def get_rpc_client(transport, retry=None, **kwargs): def get_rpc_client(transport, retry=None, **kwargs):
"""Return a configured oslo_messaging RPCClient.""" """Return a configured oslo_messaging RPCClient."""
target = oslo_messaging.Target(**kwargs) target = oslo_messaging.Target(**kwargs)
serializer = RequestContextSerializer(JsonPayloadSerializer()) serializer = oslo_serializer.RequestContextSerializer(
oslo_serializer.JsonPayloadSerializer())
return oslo_messaging.RPCClient(transport, target, return oslo_messaging.RPCClient(transport, target,
serializer=serializer, serializer=serializer,
retry=retry) retry=retry)
@ -113,7 +85,8 @@ def get_notification_listener(transport, targets, endpoints,
def get_notifier(transport, publisher_id): def get_notifier(transport, publisher_id):
"""Return a configured oslo_messaging notifier.""" """Return a configured oslo_messaging notifier."""
serializer = RequestContextSerializer(JsonPayloadSerializer()) serializer = oslo_serializer.RequestContextSerializer(
oslo_serializer.JsonPayloadSerializer())
notifier = oslo_messaging.Notifier(transport, serializer=serializer) notifier = oslo_messaging.Notifier(transport, serializer=serializer)
return notifier.prepare(publisher_id=publisher_id) return notifier.prepare(publisher_id=publisher_id)

View File

@ -24,7 +24,7 @@ oslo.service>=0.1.0 # Apache-2.0
PasteDeploy>=1.5.0 PasteDeploy>=1.5.0
pbr<2.0,>=0.11 pbr<2.0,>=0.11
pecan>=0.8.0 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.middleware!=2.0.0,>=1.2.0 # Apache-2.0
oslo.serialization>=1.4.0 # Apache-2.0 oslo.serialization>=1.4.0 # Apache-2.0
oslo.utils>=1.6.0 # Apache-2.0 oslo.utils>=1.6.0 # Apache-2.0