<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 3, 2013 at 7:33 AM, Flavio Percoco <span dir="ltr"><<a href="mailto:flavio@redhat.com" target="_blank">flavio@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi,<br>
<br>
I'm planning to re-factor current Oslo's jsonutils module and as part<br>
of that re-factor process I'd like to add a better support for datetimes<br>
objects.<br>
<br>
Before going further with the implementation, I'd like to get some<br>
feedback from folks and see if any of you have already done it or at<br>
least thought about it.<br>
<br>
Currently jsonutils serializes datetimes using timeutils.strtime<br>
function, which returns a ISO8601 formatted string. Since this is a<br>
string, there's no easy way to understand, when de-serializing,<br>
whether it is a datetime, was a datetime before and / or should be<br>
de-serialized as datetime.<br>
<br>
The first point is:<br>
<br>
1) Do we really need this?<br>
        From a "compatibiliy" POV I'd prefer not having it and avoid<br>
    sending datetimes that are supposed to be de-serialized. However,<br>
    there are definitely cases were this is useful and makes<br>
    implementations way easier.<br>
<br>
2) Does it make sense to have this in Oslo?<br>
<br>
    My bet is yes. We currently need it in Glance and I think other<br>
    projects can benefit from this - nova does something similar. (We<br>
    can use Glance as a POC for this).<br>
<br>
<br>
3) I've put some thoughts on it that I'd like to share:<br>
<br>
    1) Try always to convert the str to datetime - using<br>
    timeutils.parse_strtime. The drawback is that we might convert to<br>
    datetimes values that weren't datetime before being serialized.<br>
    Similar to what nova's sqlalchemy api does[0].<br>
<br>
    2) Add a prefix / suffix to the serialized datetime. This will<br>
    allow the de-serializer to know whether it should be converted to<br>
    datetime.<br>
<br>
    3) Serialize the datetime as a dictionary with the following<br>
    structure:<br>
<br>
        {"_type": "datetime",          "_value": "....",          "_format": "%Y-%m-%dT%H:%M:%S.%f"}<br>
            The above will allow the de-serializer to know whether it<br>
        should be converted, the object type (datetime, date or time)<br>
        and the format it was serialized with. I don't like this idea<br>
        but I see the benefit of having all that information.<br></blockquote><div><br></div><div style>You could also just include the _type and _value, leaving the interpretation of that value up to the receiver.</div>
<div style><br></div><div style>At the summit there was a proposal in the nova track to support sending arbitrary objects over RPC transparently as part of the versioned object session [1]. I think the final proposal involved using a registry of types with serializers and deserializers. Datetimes could just be another type in that registry system.</div>
<div style><br></div><div style>Doug</div><div style><br></div><div style>[1] <a href="https://etherpad.openstack.org/HavanaVersionedInternalObjects">https://etherpad.openstack.org/HavanaVersionedInternalObjects</a></div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
<br>
[0]<br>
<a href="https://github.com/openstack/nova/blob/master/nova/db/sqlalchemy/api.py#L276" target="_blank">https://github.com/openstack/<u></u>nova/blob/master/nova/db/<u></u>sqlalchemy/api.py#L276</a><br>
<br>
Any thoughts / ideas?<br>
<br>
Cheers,<br>
FF<span class=""><font color="#888888"><br>
<br>
-- <br>
@flaper87<br>
Flavio Percoco<br>
<br>
______________________________<u></u>_________________<br>
OpenStack-dev mailing list<br>
<a href="mailto:OpenStack-dev@lists.openstack.org" target="_blank">OpenStack-dev@lists.openstack.<u></u>org</a><br>
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" target="_blank">http://lists.openstack.org/<u></u>cgi-bin/mailman/listinfo/<u></u>openstack-dev</a><br>
</font></span></blockquote></div><br></div></div>