[openstack-dev] A proposal for RPC-friendly objects

Russell Bryant rbryant at redhat.com
Wed May 8 14:13:39 UTC 2013


On 05/07/2013 07:01 PM, Dan Smith wrote:
>> 'args': {
>>     'arg1': {
>>         'oslo.object_name': 'nova.MyObject',
> 
> That looks good to me.
> 
>> jsonutils.dumps() will automatically call jsonutils.to_primitive() on
>> anything that is not a primitive type.  We could add a check in there
>> to see if the object has a to_primitive() method and if so, call that.
> 
> Hmm, I'll have to look at this a bit. I had it hacked into RpcProxy,
> since we have easy access to the args, each of which we can check for
> object-ness and serialize as needed. I liked this because of the
> symmetry of putting the deserialization in RpcDispatcher. Just to be
> clear, you're suggesting keeping jsonutils.to_primitive() and making it
> stop recursing at an object with to_primitive() and call that instead?

Not exactly.  What happens is json.dumps() is doing its thing and once
it hits something it can't serialize (one of these objects), *then* it
calls our to_primitive() to figure it out.  So, it wouldn't recurse at all.

I actually like doing this in RpcProxy better, anyway.

>> On the deserialize side, there's no hook really.  You could subclass
>> RpcDispatcher, override the dispatch() method and do it there, and
>> then let the base dispatch() do its thing after you do
>> deserialization magic.
> 
> Yeah, that was the plan. Would it be better to add "serialize_args()"
> and "deserialize_args()" to Proxy and Dispatcher so that it's all in
> one place and very clear?

Yep, +1.

-- 
Russell Bryant



More information about the OpenStack-dev mailing list