Archive

Posts Tagged ‘django’

On the protocol adopted by Dycapo

March 17th, 2010 bodom_lx 3 comments

It took us more than two months of discussions in order to decide which protocol to adopt for procedure calls in Dycapo.

As we are trying to extend an existing XML-based protocol, the first solution we took in consideration was to implement a remote procedure call protocol based on OpenTrip. That is, directly passing OpenTrip objects over HTTP methods.

Unfortunately, the most elegant solution immediately appeared as unsuitable for those reasons:

  1. It is against the DRY principle, as there exist many other RPC protocols out there
  2. A new RPC protocol implies the creation of new parsers and utilities for (Un)Marshalling data: nobody would write a client for Dycapo if he/she has to implement everything else from scratch
  3. OpenTrip is at a “0.1 draft” status. It may change very often in the future. I would not have the time to create and update parsers and utilities while developing Dycapo.

Therefore, we took the decision to adopt OpenTrip entities and propose OpenTrip Dynamic over some existing protocol. We looked at REST, XML-RPC and SOAP.

REST was seriously taken into consideration, as it is successfully used by Flickr, Delicious, Yahoo and Twitter (and many others). Even if it is not a protocol, it permits to define coincise locations for resources, and imposes some rules on the vocabulary used, creating self-descriptive messages. Moreover, there are many Django extensions that support REST.
Unfortunately, I could find more reasons against the adoption of REST than in favor:

  1. It is NOT a protocol but an architecture, or a set of conventions. Therefore, it does not define a format for data exchange. There exist SON, YAML 1.0, YAML 2.0, arbitrary XML formats. Every successful REST-ful WS either defines its own XML format or provides support for all these formats. We would like to be completely architecture independent. Therefore we need a strong data exchange format in order to handle our quite complex objects sent and received by and from clients.
  2. REST is a Resource-Oriented Architecture. Everything is thought around representation of resources. Dycapo implementation would fit with difficulty in this way of thinking. A Service-Oriented Architecture fits our needs and way of thinking.
  3. It may still require a lot of work on the client side caller of the library to make use of data (custom serialization and so forth)

Regarding XML-RPC and Soap, we know that they are very similar (first drafts of Soap were about XML-RPC with namespaces). After analyzing both of them, we agreed on the adoption of XML-RPC because

  1. It is lighter than SOAP: you just put objects/method calls encoded in XML in HTTP methods. SOAP adds overheads by using namespaces, envelopes, a header, body and fault sections.
  2. It exists since 1998. It is supported by all mobile devices, from iPhone to Android to Symbian. Moreover, its data exchange and message formats are very simple. It would be easy even to write a library from scratch. As an example, look at how tiny and simple is android-xmlrpc. SOAP is not widespread on mobile devices as XML-RPC is. Its complexity is also a barrier to write libraries and parsers.
  3. XML-RPC permits us to exchange quite complex objects regardless the implementation of server and clients. Automatic marshalling of data is often possible. Developers just have to look at our method signature and object structure and forget about the RPC structure and formats. Everything should be automatically handled by existing libraries

As a tiny example, look at the following code. It is a snippet of the current method call when searching for a ride. I just included the generated XML-RPC for the second parameter, as the first one is an object of the same type.

dycapo.search_trip ( Location source , Location destination )

< ?xml version=‘1.0′?>
<methodcall>
  <methodname>dycapo.search_trip</methodname>
    <params>
      [..]
      <param>
        <value>
          <struct>
            <member>
              <name>georss_point</name>
              <value><string>1.0,1.0</string></value>
            </member>
            <member>
               <name>point</name>
               <value><string>dest</string></value>
            </member>
            <member>
                <name>leaves</name>
                <value><string>2010-03-12 14:36:54.772156</string></value>
            </member>
            <member>
                <name>label</name>
                <value><string>office</string></value>
            </member>
          </struct>
        </value>
      </param>
    </params>
 </methodcall>
 

See how simple and elegant it is? We are simply passing an object, represented as a struct, with 4 attributes:

  • georss_point: “1.0,1.0″
  • point: “dest”
  • leaves: “2010-03-12 14:36:54.772156″
  • label: “office”

Don’t try to reason about types, names and quality: we are still experimenting.

Related posts

What comes next? Short run roadmap

March 2nd, 2010 bodom_lx No comments

The second part of my internship has just begun. I spent some hours to think about what will be next in Dycapo development, in a short run.

A CS school mate joined the project. He will write a client for Dycapo using Android. Moreover, I will write my thesis on this project.
Therefore, there is a strong demand for documentation here. I also hope that someone joins the project.

Here is a short run to-do list for Dycapo:

  • Update all the UML diagrams (class diagram, add new sequence diagrams)
  • Write a short post about the decision of using XML-RPC as communication protocol
  • Update the existing methods to use the new features provided by RPC4Django
  • Write and export a first draft of documentation to be used as API

As you can see, there are no plans to add something new to Dycapo yet. I would like first to build a strong working base, even if lacking functionalities. More features will be added afterwards.

Moreover, I will begin to use SemVer versioning system.

Related posts

Dycapo Development Resumes

March 1st, 2010 bodom_lx No comments

Dycapo development resumes from today. I’m going to write a tiny plan to point out the status of the project and what we are going to do next. Meanwhile, a new member joined SoNet and the project, to develop an Android client for Dycapo. Stay tuned for news.

Related posts

Announcing Dycapo 0.0.2

January 10th, 2010 bodom_lx 1 comment

As promised, Dycapo 0.0.2 is out.

Dycapo will be an open client (mobile)/server system that will improve travel experiences of users in a city. The system will let people to define a destination on their mobile phone. DyCaPo will suggest and arrange trips by either using the Public Transport Service or Carpooling volunteers.
That is, DyCaPo will implement full Dynamic Carpooling functionalities as well as static approaches.

More information and download on the official page.

Here are the release notes and the changes since 0.0.1:

RELEASE NOTES
***************
2010-01-10 Daniel Graziotin 
Dycapo 0.0.2 is just for _showing_out_some_functionalities_ of the system and testing the underlying technologies. Dycapo 0.0.2 incorporates and shows:
* OpenTrip Core adoption and OpenTrip Dynamic data structures proposal (in Django Model format)
* Use of XML-RPC with Django (rpc4django over HTTP and HTTPS)
* (Sort of) integration of Dycapo models with Django and rpc4django
* Authentication
* Insertion of a trip by a driver
* Start of a trip by a driver
* Search of a trip by a rider
* Send a ride request to a driver
* Let the driver accept the ride request
No one exported XML-RPC function will surely be included in the final API! No one exported XML-RPC function is either optimized or completely working!
Code is (somewhat) documented. Expect a completely better work for 0.1.0 :)
CHANGES SINCE 0.0.1
***************
Some refactoring to make the code cleaner.
Lots of bugs fixed.
Test suite rewritten and (finally) fully working.

models.py:
- added utility methods (i.e. __unicode__ and to_xmlrpc)
- use of OpenTrip id proposal instead of Django id
- addition of fields to Participation model, regarding a ride request and a request accepted

trip.py:
this module has been splitted in four files:
- driver.py - holds all the XML-RPC methods that a Driver needs.
- rider.py - holds all the XML-RPC methods that a Rider needs.
- commin.py - will hold all the XML-RPC methods shared by Rider and Driver
- utils.py - holds some utility functions.

driver.py (formerly trip.py):
- added check_ride_requests(trip) - checks for ride requests
- added accept_ride_request(trip, person) - for accepting a Rider

rider.py (formerly trip.py):
- added request_ride(trip) - sends a ride request to a trip

tests/:
- Cleaner code and better organization
- Added test_all_simple.py - creates a Driver and a Rider with the same destination as target
- test_all.py - creates 3 drivers and 5 riders with random locations as target

Related posts

Announcing Dycapo 0.0.1

December 29th, 2009 bodom_lx No comments

It’s a pleasure for me to announce Dycapo-0.0.1, the very first release of the project.
Dycapo-0.0.1 is part of the pre-alpha-dontuse releases, to only illustrate some functionalities.
Here are the release notes:

2009-12-26 Daniel Graziotin <daniel DOT graziotin AT gmail DOT com>

Dycapo 0.0.1 is just for showing out some functionalities of the system and
testing the underlying technologies.
Dycapo 0.0.1 incorporates and shows:

  • OpenTrip Core adoption and OpenTrip Dynamic data structures proposal (in Django Model format)
  • Use of XML-RPC with Django (rpc4django over HTTP and HTTPS)
  • (Sort of) integration of Dycapo models with Django and rpc4django
  • Authentication
  • Insertion of a trip by a driver
  • Start of a trip by a driver
  • Search of a trip by a rider
  • Accepting a ride

No one exported XML-RPC function will surely be included in the final API!
No one exported XML-RPC function is either optimized or completely working!

Code is (somewhat) documented. Expect a completely better work for 0.1.0 :)

You can read much more about Dycapo and download it at Dycapo official project page. Project page also hosts installation instructions and configuration steps.

The research behind Dycapo (Dynamic Carpooling system) is illustrated here.

Related posts

First working method, test client written

December 22nd, 2009 bodom_lx No comments

Road to 0.0.1 for Dycapo. Today I succesfully wrote a first xml-rpc method accepting OpenTrip Core objects, that inserts a trip chosen by the driver.

def add_trip(trip, mode, source, destination)

Actually, the driver is automatically retrieved by the system, since we are waiting rpc4django 0.1.6 to come out and access User from requests. Moreover, only a source and a destination Locations can be specified.
But it works. It works fine.
The method is located at: server/trip.py
I also wrote a tiny python client to test the remote call, located at: tests.

In a couple of days I should try to publish Dycapo 0.0.1. That’s what I hope :)

Related posts