Statistics
| Branch: | Tag: | Revision:

root / docs / dev-guide.rst @ aab200c6

History | View | Annotate | Download (12.3 kB)

1 bc055d09 Constantinos Venetsanopoulos
.. _dev-guide:
2 bc055d09 Constantinos Venetsanopoulos
3 bc055d09 Constantinos Venetsanopoulos
Synnefo Developer's Guide
4 bc055d09 Constantinos Venetsanopoulos
^^^^^^^^^^^^^^^^^^^^^^^^^
5 bc055d09 Constantinos Venetsanopoulos
6 1fbdb3d7 marioskogias
This is the complete Synnefo Developer's Guide.
7 1fbdb3d7 marioskogias
8 1fbdb3d7 marioskogias
Environment set up
9 1fbdb3d7 marioskogias
==================
10 1fbdb3d7 marioskogias
11 1fbdb3d7 marioskogias
First of all you have to set up a developing environment for Synnefo.
12 1fbdb3d7 marioskogias
13 dd45dcae Giorgos Korfiatis
**1. Create a new VM**
14 dd45dcae Giorgos Korfiatis
15 dd45dcae Giorgos Korfiatis
It has been tested on Debian Wheezy. It is expected to work with other
16 dd45dcae Giorgos Korfiatis
releases (e.g., Squeeze) too, as long as they are supported by
17 dd45dcae Giorgos Korfiatis
``snf-deploy``.
18 1fbdb3d7 marioskogias
19 1fbdb3d7 marioskogias
**2. Build your own Synnefo installation**
20 1fbdb3d7 marioskogias
21 1fbdb3d7 marioskogias
Follow the instructions `here <http://www.synnefo.org/docs/synnefo/latest/quick-install-guide.html>`_
22 1fbdb3d7 marioskogias
to build Synnefo on a single node using ``snf-deploy``.
23 1fbdb3d7 marioskogias
24 1fbdb3d7 marioskogias
**3. Install GitPython**
25 1fbdb3d7 marioskogias
26 1fbdb3d7 marioskogias
.. code-block:: console
27 1fbdb3d7 marioskogias
28 1fbdb3d7 marioskogias
	# pip install gitpython
29 1fbdb3d7 marioskogias
30 1fbdb3d7 marioskogias
**4. Install devflow**
31 1fbdb3d7 marioskogias
32 1fbdb3d7 marioskogias
Devflow is a tool to manage versions, helps implement the git flow development process,
33 1fbdb3d7 marioskogias
and builds Python and Debian packages. You will need it to create your code's version.
34 1fbdb3d7 marioskogias
35 1fbdb3d7 marioskogias
.. code-block:: console
36 1fbdb3d7 marioskogias
37 1fbdb3d7 marioskogias
	# pip install devflow
38 1fbdb3d7 marioskogias
39 1fbdb3d7 marioskogias
**5. Get Synnefo code**
40 1fbdb3d7 marioskogias
41 1fbdb3d7 marioskogias
First you need to install git
42 1fbdb3d7 marioskogias
43 1fbdb3d7 marioskogias
.. code-block:: console
44 1fbdb3d7 marioskogias
45 1fbdb3d7 marioskogias
	# apt-get install git
46 1fbdb3d7 marioskogias
47 1fbdb3d7 marioskogias
And now get the Synnefo code from the official Synnefo repository
48 1fbdb3d7 marioskogias
49 1fbdb3d7 marioskogias
.. code-block:: console
50 1fbdb3d7 marioskogias
51 dd45dcae Giorgos Korfiatis
        # su some_regular_user
52 1fbdb3d7 marioskogias
	$ git clone https://code.grnet.gr/git/synnefo
53 1fbdb3d7 marioskogias
54 dd45dcae Giorgos Korfiatis
Make sure you clone the repository as a regular user. Otherwise you will
55 dd45dcae Giorgos Korfiatis
have problems with file permissions when deploying.
56 1fbdb3d7 marioskogias
57 1fbdb3d7 marioskogias
**6. Code and deploy**
58 1fbdb3d7 marioskogias
59 1fbdb3d7 marioskogias
1. Configure the version
60 1fbdb3d7 marioskogias
61 1fbdb3d7 marioskogias
.. code-block:: console
62 1fbdb3d7 marioskogias
63 1fbdb3d7 marioskogias
	$ devflow-update-version
64 1fbdb3d7 marioskogias
65 1fbdb3d7 marioskogias
2. Code
66 dd45dcae Giorgos Korfiatis
3. In every component you change, run as root
67 dd45dcae Giorgos Korfiatis
68 dd45dcae Giorgos Korfiatis
.. code-block:: console
69 dd45dcae Giorgos Korfiatis
70 dd45dcae Giorgos Korfiatis
	# python setup.py develop -N
71 dd45dcae Giorgos Korfiatis
72 dd45dcae Giorgos Korfiatis
This does not automatically install dependencies, in order to avoid
73 dd45dcae Giorgos Korfiatis
confusion with synnefo packages installed by ``snf-deploy``. External
74 dd45dcae Giorgos Korfiatis
dependencies have already been installed by ``snf-deploy``; if you introduce
75 dd45dcae Giorgos Korfiatis
a new dependency, you will have to explicitly install it.
76 dd45dcae Giorgos Korfiatis
77 dd45dcae Giorgos Korfiatis
4. You will need to restart the server with
78 dd45dcae Giorgos Korfiatis
79 dd45dcae Giorgos Korfiatis
.. code-block:: console
80 dd45dcae Giorgos Korfiatis
81 dd45dcae Giorgos Korfiatis
       # service gunicorn restart
82 dd45dcae Giorgos Korfiatis
83 dd45dcae Giorgos Korfiatis
5. If your changes affected ``snf-dispatcher`` (from package
84 dd45dcae Giorgos Korfiatis
   ``snf-cyclades-app``) or ``snf-ganeti-eventd`` (from
85 dd45dcae Giorgos Korfiatis
   ``snf-cyclades-gtools``) you will need to restart these daemons, too.
86 dd45dcae Giorgos Korfiatis
   Since step 3 installed the former under ``/usr/local/``, you need to
87 dd45dcae Giorgos Korfiatis
   make sure that the correct version is evoked. You can override the
88 dd45dcae Giorgos Korfiatis
   version installed by ``snf-deploy`` with
89 dd45dcae Giorgos Korfiatis
90 dd45dcae Giorgos Korfiatis
.. code-block:: console
91 dd45dcae Giorgos Korfiatis
92 dd45dcae Giorgos Korfiatis
       # ln -sf /usr/local/bin/snf-dispatcher /usr/bin/snf-dispatcher
93 dd45dcae Giorgos Korfiatis
94 dd45dcae Giorgos Korfiatis
and then restart the daemons
95 1fbdb3d7 marioskogias
96 1fbdb3d7 marioskogias
.. code-block:: console
97 1fbdb3d7 marioskogias
98 dd45dcae Giorgos Korfiatis
       # service snf-dispatcher restart
99 dd45dcae Giorgos Korfiatis
       # service snf-ganeti-eventd restart
100 1fbdb3d7 marioskogias
101 dd45dcae Giorgos Korfiatis
6. Refresh the web page and see your changes
102 1fbdb3d7 marioskogias
103 1fbdb3d7 marioskogias
Synnefo REST APIs
104 1fbdb3d7 marioskogias
=================
105 1fbdb3d7 marioskogias
106 1fbdb3d7 marioskogias
Here, we document all Synnefo
107 991d0507 Constantinos Venetsanopoulos
REST APIs, to allow external developers write independent tools that interact
108 991d0507 Constantinos Venetsanopoulos
with Synnefo.
109 bc055d09 Constantinos Venetsanopoulos
110 991d0507 Constantinos Venetsanopoulos
Synnefo exposes the OpenStack APIs for all its operations. Also, extensions
111 991d0507 Constantinos Venetsanopoulos
have been written for advanced operations wherever needed, and minor changes
112 991d0507 Constantinos Venetsanopoulos
for things that were missing or change frequently.
113 8f9976c6 Constantinos Venetsanopoulos
114 73ebcd68 Constantinos Venetsanopoulos
Most Synnefo services have a corresponding OpenStack API:
115 991d0507 Constantinos Venetsanopoulos
116 991d0507 Constantinos Venetsanopoulos
| Cyclades/Compute Service -> OpenStack Compute API
117 991d0507 Constantinos Venetsanopoulos
| Cyclades/Network Service -> OpenStack Compute/Network API (not Quantum yet)
118 73ebcd68 Constantinos Venetsanopoulos
| Cyclades/Image Service -> OpenStack Glance API
119 991d0507 Constantinos Venetsanopoulos
| Pithos/Storage Service -> OpenStack Object Store API
120 991d0507 Constantinos Venetsanopoulos
| Astakos/Identity Service -> Proprietary, moving to OpenStack Keystone API
121 73ebcd68 Constantinos Venetsanopoulos
| Astakos/Quota Service -> Proprietary API
122 73ebcd68 Constantinos Venetsanopoulos
| Astakos/Resource Service -> Proprietary API
123 991d0507 Constantinos Venetsanopoulos
124 991d0507 Constantinos Venetsanopoulos
Below, we will describe all Synnefo APIs with conjuction to the OpenStack APIs.
125 991d0507 Constantinos Venetsanopoulos
126 991d0507 Constantinos Venetsanopoulos
127 991d0507 Constantinos Venetsanopoulos
Identity Service API (Astakos)
128 991d0507 Constantinos Venetsanopoulos
==============================
129 991d0507 Constantinos Venetsanopoulos
130 991d0507 Constantinos Venetsanopoulos
Currently, Astakos which is the Identity Management Service of Synnefo, has a
131 991d0507 Constantinos Venetsanopoulos
proprietary API, but we are moving to the OpenStack Keystone API.
132 991d0507 Constantinos Venetsanopoulos
133 991d0507 Constantinos Venetsanopoulos
The current Identity Management API is:
134 8f9976c6 Constantinos Venetsanopoulos
135 8f9976c6 Constantinos Venetsanopoulos
.. toctree::
136 8f9976c6 Constantinos Venetsanopoulos
   :maxdepth: 2
137 8f9976c6 Constantinos Venetsanopoulos
138 991d0507 Constantinos Venetsanopoulos
    Identity API <astakos-api-guide>
139 991d0507 Constantinos Venetsanopoulos
140 8f9976c6 Constantinos Venetsanopoulos
141 73ebcd68 Constantinos Venetsanopoulos
Resource and Quota Service API (Astakos)
142 73ebcd68 Constantinos Venetsanopoulos
========================================
143 b32b5995 Giorgos Korfiatis
144 b32b5995 Giorgos Korfiatis
.. toctree::
145 b32b5995 Giorgos Korfiatis
    :maxdepth: 2
146 b32b5995 Giorgos Korfiatis
147 b32b5995 Giorgos Korfiatis
    Resource and Quota API <quota-api-guide.rst>
148 b32b5995 Giorgos Korfiatis
149 2556cf45 Giorgos Korfiatis
Project API
150 2556cf45 Giorgos Korfiatis
===========
151 2556cf45 Giorgos Korfiatis
152 2556cf45 Giorgos Korfiatis
.. toctree::
153 2556cf45 Giorgos Korfiatis
    :maxdepth: 2
154 2556cf45 Giorgos Korfiatis
155 2556cf45 Giorgos Korfiatis
    Project API <project-api-guide.rst>
156 bc055d09 Constantinos Venetsanopoulos
157 991d0507 Constantinos Venetsanopoulos
Compute Service API (Cyclades)
158 991d0507 Constantinos Venetsanopoulos
==============================
159 bc055d09 Constantinos Venetsanopoulos
160 991d0507 Constantinos Venetsanopoulos
The Compute part of Cyclades exposes the OpenStack Compute API with minor
161 991d0507 Constantinos Venetsanopoulos
changes wherever needed.
162 991d0507 Constantinos Venetsanopoulos
163 991d0507 Constantinos Venetsanopoulos
This is the Cyclades/Compute API:
164 bc055d09 Constantinos Venetsanopoulos
165 bc055d09 Constantinos Venetsanopoulos
.. toctree::
166 bc055d09 Constantinos Venetsanopoulos
   :maxdepth: 2
167 bc055d09 Constantinos Venetsanopoulos
168 bc055d09 Constantinos Venetsanopoulos
   Compute API <cyclades-api-guide>
169 bc055d09 Constantinos Venetsanopoulos
170 bc055d09 Constantinos Venetsanopoulos
171 991d0507 Constantinos Venetsanopoulos
Network Service API (Cyclades)
172 991d0507 Constantinos Venetsanopoulos
==============================
173 991d0507 Constantinos Venetsanopoulos
174 991d0507 Constantinos Venetsanopoulos
The Network Service is implemented inside Cyclades. It exposes the part of the
175 991d0507 Constantinos Venetsanopoulos
OpenStack Compute API that has to do with Networks. The OpenStack Quantum API
176 991d0507 Constantinos Venetsanopoulos
is not implemented yet.
177 991d0507 Constantinos Venetsanopoulos
178 991d0507 Constantinos Venetsanopoulos
Please consult the :ref:`Cyclades/Network API <cyclades-api-guide>` for more
179 991d0507 Constantinos Venetsanopoulos
details.
180 1837aa54 Giorgos Verigakis
181 bc055d09 Constantinos Venetsanopoulos
182 73ebcd68 Constantinos Venetsanopoulos
Image Service API (Cyclades)
183 73ebcd68 Constantinos Venetsanopoulos
============================
184 bc055d09 Constantinos Venetsanopoulos
185 73ebcd68 Constantinos Venetsanopoulos
The Image Service is implemented inside Cyclades. It exposes the OpenStack
186 73ebcd68 Constantinos Venetsanopoulos
Glance API with minor changes wherever needed.
187 991d0507 Constantinos Venetsanopoulos
188 73ebcd68 Constantinos Venetsanopoulos
This is the Cyclades/Image API:
189 1837aa54 Giorgos Verigakis
190 1837aa54 Giorgos Verigakis
.. toctree::
191 1837aa54 Giorgos Verigakis
   :maxdepth: 2
192 1837aa54 Giorgos Verigakis
193 1837aa54 Giorgos Verigakis
   Image API <plankton-api-guide>
194 1837aa54 Giorgos Verigakis
195 bc055d09 Constantinos Venetsanopoulos
196 991d0507 Constantinos Venetsanopoulos
Storage Service API (Pithos)
197 991d0507 Constantinos Venetsanopoulos
============================
198 991d0507 Constantinos Venetsanopoulos
199 991d0507 Constantinos Venetsanopoulos
Pithos is the Storage Service of Synnefo and it exposes the OpenStack Object
200 991d0507 Constantinos Venetsanopoulos
Storage API with extensions for advanced operations, e.g., syncing.
201 bc055d09 Constantinos Venetsanopoulos
202 301294a9 Constantinos Venetsanopoulos
This is the Pithos Object Storage API:
203 8f9976c6 Constantinos Venetsanopoulos
204 8f9976c6 Constantinos Venetsanopoulos
.. toctree::
205 8f9976c6 Constantinos Venetsanopoulos
   :maxdepth: 2
206 8f9976c6 Constantinos Venetsanopoulos
207 dad708b4 Antony Chazapis
   Object Storage API <pithos-api-guide>
208 8f9976c6 Constantinos Venetsanopoulos
209 991d0507 Constantinos Venetsanopoulos
210 8f9976c6 Constantinos Venetsanopoulos
Implementing new clients
211 8f9976c6 Constantinos Venetsanopoulos
========================
212 8f9976c6 Constantinos Venetsanopoulos
213 8f9976c6 Constantinos Venetsanopoulos
In this section we discuss implementation guidelines, that a developer should
214 8f9976c6 Constantinos Venetsanopoulos
take into account before writing his own client for the above APIs. Before,
215 8f9976c6 Constantinos Venetsanopoulos
starting your client implementation, make sure you have thoroughly read the
216 8f9976c6 Constantinos Venetsanopoulos
corresponding Synnefo API.
217 8f9976c6 Constantinos Venetsanopoulos
218 301294a9 Constantinos Venetsanopoulos
Pithos clients
219 301294a9 Constantinos Venetsanopoulos
--------------
220 8f9976c6 Constantinos Venetsanopoulos
221 8f9976c6 Constantinos Venetsanopoulos
User Experience
222 8f9976c6 Constantinos Venetsanopoulos
~~~~~~~~~~~~~~~
223 8f9976c6 Constantinos Venetsanopoulos
224 8f9976c6 Constantinos Venetsanopoulos
Hopefully this API will allow for a multitude of client implementations, each
225 8f9976c6 Constantinos Venetsanopoulos
supporting a different device or operating system. All clients will be able to
226 8f9976c6 Constantinos Venetsanopoulos
manipulate containers and objects - even software only designed for OOS API
227 8f9976c6 Constantinos Venetsanopoulos
compatibility. But a Pithos interface should not be only about showing
228 8f9976c6 Constantinos Venetsanopoulos
containers and folders. There are some extra user interface elements and
229 8f9976c6 Constantinos Venetsanopoulos
functionalities that should be common to all implementations.
230 8f9976c6 Constantinos Venetsanopoulos
231 8f9976c6 Constantinos Venetsanopoulos
Upon entrance to the service, a user is presented with the following elements -
232 8f9976c6 Constantinos Venetsanopoulos
which can be represented as folders or with other related icons:
233 8f9976c6 Constantinos Venetsanopoulos
234 8f9976c6 Constantinos Venetsanopoulos
 * The ``home`` element, which is used as the default entry point to the user's
235 8f9976c6 Constantinos Venetsanopoulos
   "files". Objects under ``home`` are represented in the usual hierarchical
236 8f9976c6 Constantinos Venetsanopoulos
   organization of folders and files.
237 8f9976c6 Constantinos Venetsanopoulos
 * The ``trash`` element, which contains files that have been marked for
238 8f9976c6 Constantinos Venetsanopoulos
   deletion, but can still be recovered.
239 8f9976c6 Constantinos Venetsanopoulos
 * The ``shared`` element, which contains all objects shared by the user to
240 8f9976c6 Constantinos Venetsanopoulos
   other users of the system.
241 8f9976c6 Constantinos Venetsanopoulos
 * The ``others`` element, which contains all objects that other users share
242 8f9976c6 Constantinos Venetsanopoulos
   with the user.
243 8f9976c6 Constantinos Venetsanopoulos
 * The ``groups`` element, which contains the names of groups the user has
244 8f9976c6 Constantinos Venetsanopoulos
   defined. Each group consists of a user list. Group creation, deletion, and
245 8f9976c6 Constantinos Venetsanopoulos
   manipulation is carried out by actions originating here.
246 8f9976c6 Constantinos Venetsanopoulos
 * The ``history`` element, which allows browsing past instances of ``home``
247 8f9976c6 Constantinos Venetsanopoulos
   and - optionally - ``trash``.
248 8f9976c6 Constantinos Venetsanopoulos
249 991d0507 Constantinos Venetsanopoulos
Objects in Pithos can be:
250 8f9976c6 Constantinos Venetsanopoulos
251 8f9976c6 Constantinos Venetsanopoulos
 * Moved to trash and then deleted.
252 8f9976c6 Constantinos Venetsanopoulos
 * Shared with specific permissions.
253 991d0507 Constantinos Venetsanopoulos
 * Made public (shared with non-Pithos users).
254 8f9976c6 Constantinos Venetsanopoulos
 * Restored from previous versions.
255 8f9976c6 Constantinos Venetsanopoulos
256 8f9976c6 Constantinos Venetsanopoulos
Some of these functions are performed by the client software and some by the
257 991d0507 Constantinos Venetsanopoulos
Pithos server.
258 8f9976c6 Constantinos Venetsanopoulos
259 8f9976c6 Constantinos Venetsanopoulos
In the first version of Pithos, objects could also be assigned custom tags.
260 8f9976c6 Constantinos Venetsanopoulos
This is no longer supported. Existing deployments can migrate tags into a
261 8f9976c6 Constantinos Venetsanopoulos
specific metadata value, i.e. ``X-Object-Meta-Tags``.
262 8f9976c6 Constantinos Venetsanopoulos
263 8f9976c6 Constantinos Venetsanopoulos
Implementation Guidelines
264 8f9976c6 Constantinos Venetsanopoulos
~~~~~~~~~~~~~~~~~~~~~~~~~
265 8f9976c6 Constantinos Venetsanopoulos
266 991d0507 Constantinos Venetsanopoulos
Pithos clients should use the ``pithos`` and ``trash`` containers for active
267 8f9976c6 Constantinos Venetsanopoulos
and inactive objects respectively. If any of these containers is not found, the
268 8f9976c6 Constantinos Venetsanopoulos
client software should create it, without interrupting the user's workflow. The
269 8f9976c6 Constantinos Venetsanopoulos
``home`` element corresponds to ``pithos`` and the ``trash`` element to
270 8f9976c6 Constantinos Venetsanopoulos
``trash``. Use ``PUT`` with the ``X-Move-From`` header, or ``MOVE`` to transfer
271 8f9976c6 Constantinos Venetsanopoulos
objects from one container to the other. Use ``DELETE`` to remove from
272 8f9976c6 Constantinos Venetsanopoulos
``pithos`` without trashing, or to remove from ``trash``. When moving objects,
273 8f9976c6 Constantinos Venetsanopoulos
detect naming conflicts with the ``If-Match`` or ``If-None-Match`` headers.
274 8f9976c6 Constantinos Venetsanopoulos
Such conflicts should be resolved by the user.
275 8f9976c6 Constantinos Venetsanopoulos
276 8f9976c6 Constantinos Venetsanopoulos
Object names should use the ``/`` delimiter to impose a hierarchy of folders
277 8f9976c6 Constantinos Venetsanopoulos
and files.
278 8f9976c6 Constantinos Venetsanopoulos
279 8f9976c6 Constantinos Venetsanopoulos
The ``shared`` element should be implemented as a read-only view of the
280 8f9976c6 Constantinos Venetsanopoulos
``pithos`` container, using the ``shared`` parameter when listing objects. The
281 8f9976c6 Constantinos Venetsanopoulos
``others`` element, should start with a top-level ``GET`` to retrieve the list
282 8f9976c6 Constantinos Venetsanopoulos
of accounts accessible to the user. It is suggested that the client software
283 8f9976c6 Constantinos Venetsanopoulos
hides the next step of navigation - the container - if it only includes
284 8f9976c6 Constantinos Venetsanopoulos
``pithos`` and forwards the user directly to the objects.
285 8f9976c6 Constantinos Venetsanopoulos
286 8f9976c6 Constantinos Venetsanopoulos
Public objects are not included in ``shared`` and ``others`` listings. It is
287 8f9976c6 Constantinos Venetsanopoulos
suggested that they are marked in a visually distinctive way in ``pithos``
288 8f9976c6 Constantinos Venetsanopoulos
listings (for example using an icon overlay).
289 8f9976c6 Constantinos Venetsanopoulos
290 8f9976c6 Constantinos Venetsanopoulos
A special application menu, or a section in application preferences, should be
291 8f9976c6 Constantinos Venetsanopoulos
devoted to managing groups (the ``groups`` element). All group-related actions
292 8f9976c6 Constantinos Venetsanopoulos
are implemented at the account level.
293 8f9976c6 Constantinos Venetsanopoulos
294 8f9976c6 Constantinos Venetsanopoulos
Browsing past versions of objects should be available both at the object and
295 8f9976c6 Constantinos Venetsanopoulos
the container level. At the object level, a list of past versions can be
296 8f9976c6 Constantinos Venetsanopoulos
included in the screen showing details or more information on the object
297 8f9976c6 Constantinos Venetsanopoulos
(metadata, permissions, etc.). At the container level, it is suggested that
298 8f9976c6 Constantinos Venetsanopoulos
clients use a ``history`` element, which presents to the user a read-only,
299 8f9976c6 Constantinos Venetsanopoulos
time-variable view of ``pithos`` contents. This can be accomplished via the
300 8f9976c6 Constantinos Venetsanopoulos
``until`` parameter in listings. Optionally, ``history`` may include ``trash``.
301 8f9976c6 Constantinos Venetsanopoulos
302 8f9976c6 Constantinos Venetsanopoulos
Uploading and downloading data
303 8f9976c6 Constantinos Venetsanopoulos
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
304 8f9976c6 Constantinos Venetsanopoulos
305 8f9976c6 Constantinos Venetsanopoulos
By using hashmaps to upload and download objects the corresponding operations
306 8f9976c6 Constantinos Venetsanopoulos
can complete much faster.
307 8f9976c6 Constantinos Venetsanopoulos
308 8f9976c6 Constantinos Venetsanopoulos
In the case of an upload, only the missing blocks will be submitted to the
309 8f9976c6 Constantinos Venetsanopoulos
server:
310 8f9976c6 Constantinos Venetsanopoulos
311 8f9976c6 Constantinos Venetsanopoulos
 * Calculate the hash value for each block of the object to be uploaded. Use
312 8f9976c6 Constantinos Venetsanopoulos
   the hash algorithm and block size of the destination container.
313 8f9976c6 Constantinos Venetsanopoulos
 * Send a hashmap ``PUT`` request for the object.
314 8f9976c6 Constantinos Venetsanopoulos
315 8f9976c6 Constantinos Venetsanopoulos
   * Server responds with status ``201`` (Created):
316 8f9976c6 Constantinos Venetsanopoulos
317 8f9976c6 Constantinos Venetsanopoulos
     * Blocks are already on the server. The object has been created. Done.
318 8f9976c6 Constantinos Venetsanopoulos
319 8f9976c6 Constantinos Venetsanopoulos
   * Server responds with status ``409`` (Conflict):
320 8f9976c6 Constantinos Venetsanopoulos
321 8f9976c6 Constantinos Venetsanopoulos
     * Server's response body contains the hashes of the blocks that do not
322 8f9976c6 Constantinos Venetsanopoulos
       exist on the server.
323 8f9976c6 Constantinos Venetsanopoulos
     * For each hash value in the server's response (or all hashes together):
324 8f9976c6 Constantinos Venetsanopoulos
325 8f9976c6 Constantinos Venetsanopoulos
       * Send a ``POST`` request to the destination container with the
326 8f9976c6 Constantinos Venetsanopoulos
         corresponding data.
327 8f9976c6 Constantinos Venetsanopoulos
328 8f9976c6 Constantinos Venetsanopoulos
 * Repeat hashmap ``PUT``. Fail if the server's response is not ``201``.
329 8f9976c6 Constantinos Venetsanopoulos
330 8f9976c6 Constantinos Venetsanopoulos
Consulting hashmaps when downloading allows for resuming partially transferred
331 8f9976c6 Constantinos Venetsanopoulos
objects. The client should retrieve the hashmap from the server and compare it
332 8f9976c6 Constantinos Venetsanopoulos
with the hashmap computed from the respective local file. Any missing parts can
333 8f9976c6 Constantinos Venetsanopoulos
be downloaded with ``GET`` requests with the additional ``Range`` header.
334 8f9976c6 Constantinos Venetsanopoulos
335 8f9976c6 Constantinos Venetsanopoulos
Syncing
336 8f9976c6 Constantinos Venetsanopoulos
~~~~~~~
337 8f9976c6 Constantinos Venetsanopoulos
338 8f9976c6 Constantinos Venetsanopoulos
Consider the following algorithm for synchronizing a local folder with the
339 8f9976c6 Constantinos Venetsanopoulos
server. The "state" is the complete object listing, with the corresponding
340 8f9976c6 Constantinos Venetsanopoulos
attributes.
341 1fbdb3d7 marioskogias
342 30aae6bf Giorgos Verigakis
.. code-block:: python
343 30aae6bf Giorgos Verigakis
344 30aae6bf Giorgos Verigakis
  # L: Local State, the last synced state of the object.
345 30aae6bf Giorgos Verigakis
  # Stored locally (e.g. in an SQLite database)
346 1fbdb3d7 marioskogias
347 30aae6bf Giorgos Verigakis
  # C: Current State, the current local state of the object
348 30aae6bf Giorgos Verigakis
  # Returned by the filesystem
349 1fbdb3d7 marioskogias
350 30aae6bf Giorgos Verigakis
  # S: Server State, the current server state of the object
351 30aae6bf Giorgos Verigakis
  # Returned by the server (HTTP request)
352 1fbdb3d7 marioskogias
353 30aae6bf Giorgos Verigakis
  def sync(path):
354 30aae6bf Giorgos Verigakis
      L = get_local_state(path)   # Database action
355 30aae6bf Giorgos Verigakis
      C = get_current_state(path) # Filesystem action
356 30aae6bf Giorgos Verigakis
      S = get_server_state(path)  # Network action
357 1fbdb3d7 marioskogias
358 30aae6bf Giorgos Verigakis
      if C == L:
359 30aae6bf Giorgos Verigakis
          # No local changes
360 30aae6bf Giorgos Verigakis
          if S == L:
361 30aae6bf Giorgos Verigakis
              # No remote changes, nothing to do
362 30aae6bf Giorgos Verigakis
              return
363 30aae6bf Giorgos Verigakis
          else:
364 30aae6bf Giorgos Verigakis
              # Update local state to match that of the server
365 30aae6bf Giorgos Verigakis
              download(path)
366 30aae6bf Giorgos Verigakis
              update_local_state(path, S)
367 8f9976c6 Constantinos Venetsanopoulos
      else:
368 30aae6bf Giorgos Verigakis
          # Local changes exist
369 30aae6bf Giorgos Verigakis
          if S == L:
370 30aae6bf Giorgos Verigakis
              # No remote changes, update the server and the local state
371 30aae6bf Giorgos Verigakis
              upload(path)
372 30aae6bf Giorgos Verigakis
              update_local_state(path, C)
373 8f9976c6 Constantinos Venetsanopoulos
          else:
374 30aae6bf Giorgos Verigakis
              # Both local and server changes exist
375 30aae6bf Giorgos Verigakis
              if C == S:
376 30aae6bf Giorgos Verigakis
                  # We were lucky, both did the same
377 30aae6bf Giorgos Verigakis
                  update_local_state(path, C)
378 30aae6bf Giorgos Verigakis
              else:
379 30aae6bf Giorgos Verigakis
                  # Conflicting changes exist
380 30aae6bf Giorgos Verigakis
                  conflict()
381 1fbdb3d7 marioskogias
382 8f9976c6 Constantinos Venetsanopoulos
383 8f9976c6 Constantinos Venetsanopoulos
Notes:
384 8f9976c6 Constantinos Venetsanopoulos
385 8f9976c6 Constantinos Venetsanopoulos
 * States represent file hashes (it is suggested to use Merkle). Deleted or
386 8f9976c6 Constantinos Venetsanopoulos
   non-existing files are assumed to have a magic hash (e.g. empty string).