Statistics
| Branch: | Tag: | Revision:

root / docs / dev-guide.rst @ 301294a9

History | View | Annotate | Download (8.2 kB)

1
.. _dev-guide:
2

    
3
Synnefo Developer's Guide
4
^^^^^^^^^^^^^^^^^^^^^^^^^
5

    
6
This is the complete Synnefo Developer's Guide. Here we document all Synnefo APIs
7
to allow external developers write independent tools that interact with Synnefo.
8

    
9
IM API (Astakos)
10
================
11

    
12
This is the Identity Management API:
13

    
14
.. toctree::
15
   :maxdepth: 2
16

    
17
   IM API <astakos-api-guide>
18

    
19
Compute API (Cyclades)
20
======================
21

    
22
This is the Cyclades Compute API:
23

    
24
.. toctree::
25
   :maxdepth: 2
26

    
27
   Compute API <cyclades-api-guide>
28

    
29
Network API (Cyclades)
30
======================
31

    
32
The Network API is currently implemented inside Cyclades. Please consult the
33
:ref:`Compute API <cyclades-api-guide>` for more details.
34

    
35

    
36
Images API (Plankton)
37
=====================
38

    
39
This is the Plankton Image API:
40

    
41
.. toctree::
42
   :maxdepth: 2
43

    
44
   Image API <plankton-api-guide>
45

    
46

    
47
Storage API (Pithos)
48
=====================
49

    
50
This is the Pithos Object Storage API:
51

    
52
.. toctree::
53
   :maxdepth: 2
54

    
55
   Object Storage API <pithos-api-guide>
56

    
57
Implementing new clients
58
========================
59

    
60
In this section we discuss implementation guidelines, that a developer should
61
take into account before writing his own client for the above APIs. Before,
62
starting your client implementation, make sure you have thoroughly read the
63
corresponding Synnefo API.
64

    
65
Pithos clients
66
--------------
67

    
68
User Experience
69
~~~~~~~~~~~~~~~
70

    
71
Hopefully this API will allow for a multitude of client implementations, each
72
supporting a different device or operating system. All clients will be able to
73
manipulate containers and objects - even software only designed for OOS API
74
compatibility. But a Pithos interface should not be only about showing
75
containers and folders. There are some extra user interface elements and
76
functionalities that should be common to all implementations.
77

    
78
Upon entrance to the service, a user is presented with the following elements -
79
which can be represented as folders or with other related icons:
80

    
81
 * The ``home`` element, which is used as the default entry point to the user's
82
   "files". Objects under ``home`` are represented in the usual hierarchical
83
   organization of folders and files.
84
 * The ``trash`` element, which contains files that have been marked for
85
   deletion, but can still be recovered.
86
 * The ``shared`` element, which contains all objects shared by the user to
87
   other users of the system.
88
 * The ``others`` element, which contains all objects that other users share
89
   with the user.
90
 * The ``groups`` element, which contains the names of groups the user has
91
   defined. Each group consists of a user list. Group creation, deletion, and
92
   manipulation is carried out by actions originating here.
93
 * The ``history`` element, which allows browsing past instances of ``home``
94
   and - optionally - ``trash``.
95

    
96
Objects in Pithos+ can be:
97

    
98
 * Moved to trash and then deleted.
99
 * Shared with specific permissions.
100
 * Made public (shared with non-Pithos+ users).
101
 * Restored from previous versions.
102

    
103
Some of these functions are performed by the client software and some by the
104
Pithos+ server.
105

    
106
In the first version of Pithos, objects could also be assigned custom tags.
107
This is no longer supported. Existing deployments can migrate tags into a
108
specific metadata value, i.e. ``X-Object-Meta-Tags``.
109

    
110
Implementation Guidelines
111
~~~~~~~~~~~~~~~~~~~~~~~~~
112

    
113
Pithos+ clients should use the ``pithos`` and ``trash`` containers for active
114
and inactive objects respectively. If any of these containers is not found, the
115
client software should create it, without interrupting the user's workflow. The
116
``home`` element corresponds to ``pithos`` and the ``trash`` element to
117
``trash``. Use ``PUT`` with the ``X-Move-From`` header, or ``MOVE`` to transfer
118
objects from one container to the other. Use ``DELETE`` to remove from
119
``pithos`` without trashing, or to remove from ``trash``. When moving objects,
120
detect naming conflicts with the ``If-Match`` or ``If-None-Match`` headers.
121
Such conflicts should be resolved by the user.
122

    
123
Object names should use the ``/`` delimiter to impose a hierarchy of folders
124
and files.
125

    
126
The ``shared`` element should be implemented as a read-only view of the
127
``pithos`` container, using the ``shared`` parameter when listing objects. The
128
``others`` element, should start with a top-level ``GET`` to retrieve the list
129
of accounts accessible to the user. It is suggested that the client software
130
hides the next step of navigation - the container - if it only includes
131
``pithos`` and forwards the user directly to the objects.
132

    
133
Public objects are not included in ``shared`` and ``others`` listings. It is
134
suggested that they are marked in a visually distinctive way in ``pithos``
135
listings (for example using an icon overlay).
136

    
137
A special application menu, or a section in application preferences, should be
138
devoted to managing groups (the ``groups`` element). All group-related actions
139
are implemented at the account level.
140

    
141
Browsing past versions of objects should be available both at the object and
142
the container level. At the object level, a list of past versions can be
143
included in the screen showing details or more information on the object
144
(metadata, permissions, etc.). At the container level, it is suggested that
145
clients use a ``history`` element, which presents to the user a read-only,
146
time-variable view of ``pithos`` contents. This can be accomplished via the
147
``until`` parameter in listings. Optionally, ``history`` may include ``trash``.
148

    
149
Uploading and downloading data
150
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
151

    
152
By using hashmaps to upload and download objects the corresponding operations
153
can complete much faster.
154

    
155
In the case of an upload, only the missing blocks will be submitted to the
156
server:
157

    
158
 * Calculate the hash value for each block of the object to be uploaded. Use
159
   the hash algorithm and block size of the destination container.
160
 * Send a hashmap ``PUT`` request for the object.
161

    
162
   * Server responds with status ``201`` (Created):
163

    
164
     * Blocks are already on the server. The object has been created. Done.
165

    
166
   * Server responds with status ``409`` (Conflict):
167

    
168
     * Server's response body contains the hashes of the blocks that do not
169
       exist on the server.
170
     * For each hash value in the server's response (or all hashes together):
171

    
172
       * Send a ``POST`` request to the destination container with the
173
         corresponding data.
174

    
175
 * Repeat hashmap ``PUT``. Fail if the server's response is not ``201``.
176

    
177
Consulting hashmaps when downloading allows for resuming partially transferred
178
objects. The client should retrieve the hashmap from the server and compare it
179
with the hashmap computed from the respective local file. Any missing parts can
180
be downloaded with ``GET`` requests with the additional ``Range`` header.
181

    
182
Syncing
183
~~~~~~~
184

    
185
Consider the following algorithm for synchronizing a local folder with the
186
server. The "state" is the complete object listing, with the corresponding
187
attributes.
188
 
189
.. code-block:: python
190

    
191
  # L: Local State, the last synced state of the object.
192
  # Stored locally (e.g. in an SQLite database)
193
  
194
  # C: Current State, the current local state of the object
195
  # Returned by the filesystem
196
  
197
  # S: Server State, the current server state of the object
198
  # Returned by the server (HTTP request)
199
  
200
  def sync(path):
201
      L = get_local_state(path)   # Database action
202
      C = get_current_state(path) # Filesystem action
203
      S = get_server_state(path)  # Network action
204
  
205
      if C == L:
206
          # No local changes
207
          if S == L:
208
              # No remote changes, nothing to do
209
              return
210
          else:
211
              # Update local state to match that of the server
212
              download(path)
213
              update_local_state(path, S)
214
      else:
215
          # Local changes exist
216
          if S == L:
217
              # No remote changes, update the server and the local state
218
              upload(path)
219
              update_local_state(path, C)
220
          else:
221
              # Both local and server changes exist
222
              if C == S:
223
                  # We were lucky, both did the same
224
                  update_local_state(path, C)
225
              else:
226
                  # Conflicting changes exist
227
                  conflict()
228
  
229

    
230
Notes:
231

    
232
 * States represent file hashes (it is suggested to use Merkle). Deleted or
233
   non-existing files are assumed to have a magic hash (e.g. empty string).