Revision 5d022141
b/snf-pithos-backend/pithos/backends/modular.py | ||
---|---|---|
124 | 124 |
logger = logging.getLogger(__name__) |
125 | 125 |
|
126 | 126 |
|
127 |
def backend_method(func): |
|
128 |
@wraps(func) |
|
129 |
def wrapper(self, *args, **kw): |
|
130 |
# if we are inside a database transaction |
|
131 |
# just proceed with the method execution |
|
132 |
# otherwise manage a new transaction |
|
133 |
if self.in_transaction: |
|
134 |
return func(self, *args, **kw) |
|
135 |
|
|
136 |
try: |
|
137 |
self.pre_exec() |
|
138 |
result = func(self, *args, **kw) |
|
139 |
success_status = True |
|
140 |
return result |
|
141 |
except: |
|
142 |
success_status = False |
|
143 |
raise |
|
144 |
finally: |
|
145 |
self.post_exec(success_status) |
|
146 |
return wrapper |
|
147 |
|
|
148 |
|
|
127 | 149 |
def debug_method(func): |
128 | 150 |
@wraps(func) |
129 | 151 |
def wrapper(self, *args, **kw): |
... | ... | |
257 | 279 |
|
258 | 280 |
self.lock_container_path = False |
259 | 281 |
|
282 |
self.in_transaction = False |
|
283 |
|
|
260 | 284 |
def pre_exec(self, lock_container_path=False): |
261 | 285 |
self.lock_container_path = lock_container_path |
262 | 286 |
self.wrapper.execute() |
287 |
self.serials = [] |
|
288 |
self.in_transaction = True |
|
263 | 289 |
|
264 | 290 |
def post_exec(self, success_status=True): |
265 | 291 |
if success_status: |
... | ... | |
294 | 320 |
self.commission_serials.delete_many( |
295 | 321 |
r['rejected']) |
296 | 322 |
self.wrapper.rollback() |
323 |
self.in_transaction = False |
|
297 | 324 |
|
298 | 325 |
def close(self): |
299 | 326 |
self.wrapper.close() |
... | ... | |
304 | 331 |
return not isinstance(self.astakosclient, DisabledAstakosClient) |
305 | 332 |
|
306 | 333 |
@debug_method |
334 |
@backend_method |
|
307 | 335 |
def list_accounts(self, user, marker=None, limit=10000): |
308 | 336 |
"""Return a list of accounts the user can access.""" |
309 | 337 |
|
... | ... | |
312 | 340 |
return allowed[start:start + limit] |
313 | 341 |
|
314 | 342 |
@debug_method |
343 |
@backend_method |
|
315 | 344 |
def get_account_meta( |
316 | 345 |
self, user, account, domain, until=None, include_user_defined=True, |
317 | 346 |
external_quota=None): |
... | ... | |
354 | 383 |
return meta |
355 | 384 |
|
356 | 385 |
@debug_method |
386 |
@backend_method |
|
357 | 387 |
def update_account_meta(self, user, account, domain, meta, replace=False): |
358 | 388 |
"""Update the metadata associated with the account for the domain.""" |
359 | 389 |
|
... | ... | |
364 | 394 |
update_statistics_ancestors_depth=-1) |
365 | 395 |
|
366 | 396 |
@debug_method |
397 |
@backend_method |
|
367 | 398 |
def get_account_groups(self, user, account): |
368 | 399 |
"""Return a dictionary with the user groups defined for the account.""" |
369 | 400 |
|
... | ... | |
375 | 406 |
return self.permissions.group_dict(account) |
376 | 407 |
|
377 | 408 |
@debug_method |
409 |
@backend_method |
|
378 | 410 |
def update_account_groups(self, user, account, groups, replace=False): |
379 | 411 |
"""Update the groups associated with the account.""" |
380 | 412 |
|
... | ... | |
391 | 423 |
self.permissions.group_addmany(account, k, v) |
392 | 424 |
|
393 | 425 |
@debug_method |
426 |
@backend_method |
|
394 | 427 |
def get_account_policy(self, user, account, external_quota=None): |
395 | 428 |
"""Return a dictionary with the account policy.""" |
396 | 429 |
|
... | ... | |
406 | 439 |
return policy |
407 | 440 |
|
408 | 441 |
@debug_method |
442 |
@backend_method |
|
409 | 443 |
def update_account_policy(self, user, account, policy, replace=False): |
410 | 444 |
"""Update the policy associated with the account.""" |
411 | 445 |
|
... | ... | |
416 | 450 |
self._put_policy(node, policy, replace, is_account_policy=True) |
417 | 451 |
|
418 | 452 |
@debug_method |
453 |
@backend_method |
|
419 | 454 |
def put_account(self, user, account, policy=None): |
420 | 455 |
"""Create a new account with the given name.""" |
421 | 456 |
|
... | ... | |
432 | 467 |
self._put_policy(node, policy, True, is_account_policy=True) |
433 | 468 |
|
434 | 469 |
@debug_method |
470 |
@backend_method |
|
435 | 471 |
def delete_account(self, user, account): |
436 | 472 |
"""Delete the account with the given name.""" |
437 | 473 |
|
... | ... | |
446 | 482 |
self.permissions.group_destroy(account) |
447 | 483 |
|
448 | 484 |
@debug_method |
485 |
@backend_method |
|
449 | 486 |
def list_containers(self, user, account, marker=None, limit=10000, |
450 | 487 |
shared=False, until=None, public=False): |
451 | 488 |
"""Return a list of containers existing under an account.""" |
... | ... | |
475 | 512 |
return containers[start:start + limit] |
476 | 513 |
|
477 | 514 |
@debug_method |
515 |
@backend_method |
|
478 | 516 |
def list_container_meta(self, user, account, container, domain, |
479 | 517 |
until=None): |
480 | 518 |
"""Return a list of the container's object meta keys for a domain.""" |
... | ... | |
494 | 532 |
CLUSTER_DELETED, allowed) |
495 | 533 |
|
496 | 534 |
@debug_method |
535 |
@backend_method |
|
497 | 536 |
def get_container_meta(self, user, account, container, domain, until=None, |
498 | 537 |
include_user_defined=True): |
499 | 538 |
"""Return a dictionary with the container metadata for the domain.""" |
... | ... | |
528 | 567 |
return meta |
529 | 568 |
|
530 | 569 |
@debug_method |
570 |
@backend_method |
|
531 | 571 |
def update_container_meta(self, user, account, container, domain, meta, |
532 | 572 |
replace=False): |
533 | 573 |
"""Update the metadata associated with the container for the domain.""" |
... | ... | |
546 | 586 |
update_statistics_ancestors_depth=0) |
547 | 587 |
|
548 | 588 |
@debug_method |
589 |
@backend_method |
|
549 | 590 |
def get_container_policy(self, user, account, container): |
550 | 591 |
"""Return a dictionary with the container policy.""" |
551 | 592 |
|
... | ... | |
557 | 598 |
return self._get_policy(node, is_account_policy=False) |
558 | 599 |
|
559 | 600 |
@debug_method |
601 |
@backend_method |
|
560 | 602 |
def update_container_policy(self, user, account, container, policy, |
561 | 603 |
replace=False): |
562 | 604 |
"""Update the policy associated with the container.""" |
... | ... | |
568 | 610 |
self._put_policy(node, policy, replace, is_account_policy=False) |
569 | 611 |
|
570 | 612 |
@debug_method |
613 |
@backend_method |
|
571 | 614 |
def put_container(self, user, account, container, policy=None): |
572 | 615 |
"""Create a new container with the given name.""" |
573 | 616 |
|
... | ... | |
589 | 632 |
self._put_policy(node, policy, True, is_account_policy=False) |
590 | 633 |
|
591 | 634 |
@debug_method |
635 |
@backend_method |
|
592 | 636 |
def delete_container(self, user, account, container, until=None, prefix='', |
593 | 637 |
delimiter=None): |
594 | 638 |
"""Delete/purge the container with the given name.""" |
... | ... | |
759 | 803 |
return allowed |
760 | 804 |
|
761 | 805 |
@debug_method |
806 |
@backend_method |
|
762 | 807 |
def list_objects(self, user, account, container, prefix='', delimiter=None, |
763 | 808 |
marker=None, limit=10000, virtual=True, domain=None, |
764 | 809 |
keys=None, shared=False, until=None, size_range=None, |
... | ... | |
771 | 816 |
virtual, domain, keys, shared, until, size_range, False, public) |
772 | 817 |
|
773 | 818 |
@debug_method |
819 |
@backend_method |
|
774 | 820 |
def list_object_meta(self, user, account, container, prefix='', |
775 | 821 |
delimiter=None, marker=None, limit=10000, |
776 | 822 |
virtual=True, domain=None, keys=None, shared=False, |
... | ... | |
800 | 846 |
return objects |
801 | 847 |
|
802 | 848 |
@debug_method |
849 |
@backend_method |
|
803 | 850 |
def list_object_permissions(self, user, account, container, prefix=''): |
804 | 851 |
"""Return a list of paths enforce permissions under a container.""" |
805 | 852 |
|
... | ... | |
807 | 854 |
True, False) |
808 | 855 |
|
809 | 856 |
@debug_method |
857 |
@backend_method |
|
810 | 858 |
def list_object_public(self, user, account, container, prefix=''): |
811 | 859 |
"""Return a mapping of object paths to public ids under a container.""" |
812 | 860 |
|
... | ... | |
818 | 866 |
return public |
819 | 867 |
|
820 | 868 |
@debug_method |
869 |
@backend_method |
|
821 | 870 |
def get_object_meta(self, user, account, container, name, domain, |
822 | 871 |
version=None, include_user_defined=True): |
823 | 872 |
"""Return a dictionary with the object metadata for the domain.""" |
... | ... | |
855 | 904 |
return meta |
856 | 905 |
|
857 | 906 |
@debug_method |
907 |
@backend_method |
|
858 | 908 |
def update_object_meta(self, user, account, container, name, domain, meta, |
859 | 909 |
replace=False): |
860 | 910 |
"""Update object metadata for a domain and return the new version.""" |
... | ... | |
871 | 921 |
return dest_version_id |
872 | 922 |
|
873 | 923 |
@debug_method |
924 |
@backend_method |
|
874 | 925 |
def get_object_permissions_bulk(self, user, account, container, names): |
875 | 926 |
"""Return the action allowed on the object, the path |
876 | 927 |
from which the object gets its permissions from, |
... | ... | |
900 | 951 |
return nobject_permissions |
901 | 952 |
|
902 | 953 |
@debug_method |
954 |
@backend_method |
|
903 | 955 |
def get_object_permissions(self, user, account, container, name): |
904 | 956 |
"""Return the action allowed on the object, the path |
905 | 957 |
from which the object gets its permissions from, |
... | ... | |
922 | 974 |
self.permissions.access_get(permissions_path)) |
923 | 975 |
|
924 | 976 |
@debug_method |
977 |
@backend_method |
|
925 | 978 |
def update_object_permissions(self, user, account, container, name, |
926 | 979 |
permissions): |
927 | 980 |
"""Update the permissions associated with the object.""" |
... | ... | |
940 | 993 |
self.permissions.access_members(path)}) |
941 | 994 |
|
942 | 995 |
@debug_method |
996 |
@backend_method |
|
943 | 997 |
def get_object_public(self, user, account, container, name): |
944 | 998 |
"""Return the public id of the object if applicable.""" |
945 | 999 |
|
... | ... | |
949 | 1003 |
return p |
950 | 1004 |
|
951 | 1005 |
@debug_method |
1006 |
@backend_method |
|
952 | 1007 |
def update_object_public(self, user, account, container, name, public): |
953 | 1008 |
"""Update the public status of the object.""" |
954 | 1009 |
|
... | ... | |
962 | 1017 |
path, self.public_url_security, self.public_url_alphabet) |
963 | 1018 |
|
964 | 1019 |
@debug_method |
1020 |
@backend_method |
|
965 | 1021 |
def get_object_hashmap(self, user, account, container, name, version=None): |
966 | 1022 |
"""Return the object's size and a list with partial hashes.""" |
967 | 1023 |
|
... | ... | |
1072 | 1128 |
return dest_version_id, hexlified |
1073 | 1129 |
|
1074 | 1130 |
@debug_method |
1131 |
@backend_method |
|
1075 | 1132 |
def update_object_checksum(self, user, account, container, name, version, |
1076 | 1133 |
checksum): |
1077 | 1134 |
"""Update an object's checksum.""" |
... | ... | |
1167 | 1224 |
dest_version_ids) |
1168 | 1225 |
|
1169 | 1226 |
@debug_method |
1227 |
@backend_method |
|
1170 | 1228 |
def copy_object(self, user, src_account, src_container, src_name, |
1171 | 1229 |
dest_account, dest_container, dest_name, type, domain, |
1172 | 1230 |
meta=None, replace_meta=False, permissions=None, |
... | ... | |
1181 | 1239 |
return dest_version_id |
1182 | 1240 |
|
1183 | 1241 |
@debug_method |
1242 |
@backend_method |
|
1184 | 1243 |
def move_object(self, user, src_account, src_container, src_name, |
1185 | 1244 |
dest_account, dest_container, dest_name, type, domain, |
1186 | 1245 |
meta=None, replace_meta=False, permissions=None, |
... | ... | |
1288 | 1347 |
self.permissions.access_clear_bulk(paths) |
1289 | 1348 |
|
1290 | 1349 |
@debug_method |
1350 |
@backend_method |
|
1291 | 1351 |
def delete_object(self, user, account, container, name, until=None, |
1292 | 1352 |
prefix='', delimiter=None): |
1293 | 1353 |
"""Delete/purge an object.""" |
... | ... | |
1295 | 1355 |
self._delete_object(user, account, container, name, until, delimiter) |
1296 | 1356 |
|
1297 | 1357 |
@debug_method |
1358 |
@backend_method |
|
1298 | 1359 |
def list_versions(self, user, account, container, name): |
1299 | 1360 |
"""Return a list of all object (version, version_timestamp) tuples.""" |
1300 | 1361 |
|
... | ... | |
1305 | 1366 |
x[self.CLUSTER] != CLUSTER_DELETED] |
1306 | 1367 |
|
1307 | 1368 |
@debug_method |
1369 |
@backend_method |
|
1308 | 1370 |
def get_uuid(self, user, uuid): |
1309 | 1371 |
"""Return the (account, container, name) for the UUID given.""" |
1310 | 1372 |
|
... | ... | |
1317 | 1379 |
return (account, container, name) |
1318 | 1380 |
|
1319 | 1381 |
@debug_method |
1382 |
@backend_method |
|
1320 | 1383 |
def get_public(self, user, public): |
1321 | 1384 |
"""Return the (account, container, name) for the public id given.""" |
1322 | 1385 |
|
... | ... | |
1556 | 1619 |
# Reporting functions. |
1557 | 1620 |
|
1558 | 1621 |
@debug_method |
1622 |
@backend_method |
|
1559 | 1623 |
def _report_size_change(self, user, account, size, details=None): |
1560 | 1624 |
details = details or {} |
1561 | 1625 |
|
... | ... | |
1585 | 1649 |
self.serials.append(serial) |
1586 | 1650 |
|
1587 | 1651 |
@debug_method |
1652 |
@backend_method |
|
1588 | 1653 |
def _report_object_change(self, user, account, path, details=None): |
1589 | 1654 |
details = details or {} |
1590 | 1655 |
details.update({'user': user}) |
... | ... | |
1593 | 1658 |
details)) |
1594 | 1659 |
|
1595 | 1660 |
@debug_method |
1661 |
@backend_method |
|
1596 | 1662 |
def _report_sharing_change(self, user, account, path, details=None): |
1597 | 1663 |
details = details or {} |
1598 | 1664 |
details.update({'user': user}) |
... | ... | |
1771 | 1837 |
# Domain functions |
1772 | 1838 |
|
1773 | 1839 |
@debug_method |
1840 |
@backend_method |
|
1774 | 1841 |
def get_domain_objects(self, domain, user=None): |
1775 | 1842 |
allowed_paths = self.permissions.access_list_paths( |
1776 | 1843 |
user, include_owned=user is not None, include_containers=False) |
Also available in: Unified diff