Statistics
| Branch: | Tag: | Revision:

root / docs / dev-guide.rst @ aacbeed2

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
7

    
8
Tying it all up with kamaki
9
===========================
10

    
11
kamaki
12
------
13

    
14
IM API (Astakos)
15
================
16

    
17
This is the Identity Management API:
18

    
19
.. toctree::
20
   :maxdepth: 2
21

    
22
   IM API <astakos-api-guide>
23

    
24
Compute API (Cyclades)
25
======================
26

    
27
This is the Cyclades Compute API:
28

    
29
.. toctree::
30
   :maxdepth: 2
31

    
32
   Compute API <cyclades-api-guide>
33

    
34
Network API (Cyclades)
35
======================
36

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

    
40

    
41
Images API (Plankton)
42
=====================
43

    
44
This is the Plankton Image API:
45

    
46
.. toctree::
47
   :maxdepth: 2
48

    
49
   Image API <plankton-api-guide>
50

    
51

    
52
Storage API (Pithos+)
53
=====================
54

    
55
This is the Pithos+ Object Storage API:
56

    
57
.. toctree::
58
   :maxdepth: 2
59

    
60
   Object Storage API <pithos-api-guide>
61

    
62
Implementing new clients
63
========================
64

    
65
In this section we discuss implementation guidelines, that a developer should
66
take into account before writing his own client for the above APIs. Before,
67
starting your client implementation, make sure you have thoroughly read the
68
corresponding Synnefo API.
69

    
70
Pithos+ clients
71
---------------
72

    
73
User Experience
74
~~~~~~~~~~~~~~~
75

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

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

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

    
101
Objects in Pithos+ can be:
102

    
103
 * Moved to trash and then deleted.
104
 * Shared with specific permissions.
105
 * Made public (shared with non-Pithos+ users).
106
 * Restored from previous versions.
107

    
108
Some of these functions are performed by the client software and some by the
109
Pithos+ server.
110

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

    
115
Implementation Guidelines
116
~~~~~~~~~~~~~~~~~~~~~~~~~
117

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

    
128
Object names should use the ``/`` delimiter to impose a hierarchy of folders
129
and files.
130

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

    
138
Public objects are not included in ``shared`` and ``others`` listings. It is
139
suggested that they are marked in a visually distinctive way in ``pithos``
140
listings (for example using an icon overlay).
141

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

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

    
154
Uploading and downloading data
155
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
156

    
157
By using hashmaps to upload and download objects the corresponding operations
158
can complete much faster.
159

    
160
In the case of an upload, only the missing blocks will be submitted to the
161
server:
162

    
163
 * Calculate the hash value for each block of the object to be uploaded. Use
164
   the hash algorithm and block size of the destination container.
165
 * Send a hashmap ``PUT`` request for the object.
166

    
167
   * Server responds with status ``201`` (Created):
168

    
169
     * Blocks are already on the server. The object has been created. Done.
170

    
171
   * Server responds with status ``409`` (Conflict):
172

    
173
     * Server's response body contains the hashes of the blocks that do not
174
       exist on the server.
175
     * For each hash value in the server's response (or all hashes together):
176

    
177
       * Send a ``POST`` request to the destination container with the
178
         corresponding data.
179

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

    
182
Consulting hashmaps when downloading allows for resuming partially transferred
183
objects. The client should retrieve the hashmap from the server and compare it
184
with the hashmap computed from the respective local file. Any missing parts can
185
be downloaded with ``GET`` requests with the additional ``Range`` header.
186

    
187
Syncing
188
~~~~~~~
189

    
190
Consider the following algorithm for synchronizing a local folder with the
191
server. The "state" is the complete object listing, with the corresponding
192
attributes.
193
 
194
.. code-block:: python
195

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

    
235
Notes:
236

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