Skip to content

Commit

Permalink
YDA-5912: add support for msi_atomic_apply_metadata_operations
Browse files Browse the repository at this point in the history
  • Loading branch information
lwesterhof committed Aug 21, 2024
1 parent 5fc5482 commit c39aafd
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
56 changes: 52 additions & 4 deletions integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ def _test_msvc_add_avu_object(ctx):


def _test_msvc_add_avu_collection(ctx):
tmp_object = _create_tmp_collection(ctx)
ctx.msi_add_avu('-c', tmp_object, "foo", "bar", "baz")
result = [(m.attr, m.value, m.unit) for m in avu.of_coll(ctx, tmp_object)]
collection.remove(ctx, tmp_object)
tmp_coll = _create_tmp_collection(ctx)
ctx.msi_add_avu('-c', tmp_coll, "foo", "bar", "baz")
result = [(m.attr, m.value, m.unit) for m in avu.of_coll(ctx, tmp_coll)]
collection.remove(ctx, tmp_coll)
return result


Expand Down Expand Up @@ -126,6 +126,46 @@ def _test_folder_set_retry_avus(ctx):
return True


def _test_msvc_apply_atomic_operations_collection(ctx):
tmp_coll = _create_tmp_collection(ctx)
operations = {
"entity_name": tmp_coll,
"entity_type": "collection",
"operations": [
{
"operation": "add",
"attribute": "foo",
"value": "bar",
"units": "baz"
}
]
}
avu.apply_atomic_operations(ctx, operations)
result = [(m.attr, m.value, m.unit) for m in avu.of_coll(ctx, tmp_coll)]
collection.remove(ctx, tmp_coll)
return result


def _test_msvc_apply_atomic_operations_object(ctx):
tmp_object = _create_tmp_object(ctx)
operations = {
"entity_name": tmp_object,
"entity_type": "data_object",
"operations": [
{
"operation": "add",
"attribute": "foo",
"value": "bar",
"units": "baz"
}
]
}
avu.apply_atomic_operations(ctx, operations)
result = [(m.attr, m.value, m.unit) for m in avu.of_data(ctx, tmp_object)]
data_object.remove(ctx, tmp_object)
return result


def _test_folder_cronjob_status(ctx):
tmp_coll = _create_tmp_collection(ctx)
result_set = folder.set_cronjob_status(ctx, constants.CRONJOB_STATE['RETRY'], tmp_coll)
Expand Down Expand Up @@ -402,6 +442,14 @@ def _test_folder_secure_func(ctx, func):
"check": lambda x: (("aap", "noot", "mies") in x
and len([a for a in x if a[0] not in ["org_replication_scheduled"]]) == 1
)},
{"name": "avu.apply_atomic_operations.collection",
"test": lambda ctx: _test_msvc_apply_atomic_operations_collection(ctx),
"check": lambda x: (("foo", "bar", "baz") in x and len(x) == 1)},
{"name": "avu.apply_atomic_operations.object",
"test": lambda ctx: _test_msvc_apply_atomic_operations_object(ctx),
"check": lambda x: (("foo", "bar", "baz") in x
and len([a for a in x if a[0] not in ["org_replication_scheduled"]]) == 1
)},
{"name": "data_access_token.get_all_tokens",
"test": lambda ctx: data_access_token.get_all_tokens(ctx),
"check": lambda x: isinstance(x, list)},
Expand Down
19 changes: 19 additions & 0 deletions util/avu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
__license__ = 'GPLv3, see LICENSE'

import itertools
import json
from collections import namedtuple

import genquery
Expand Down Expand Up @@ -170,3 +171,21 @@ def rmw_from_data(ctx, obj, a, v, u=''):
def rmw_from_group(ctx, group, a, v, u=''):
"""Remove AVU from group with wildcards."""
msi.rmw_avu(ctx, '-u', group, a, v, u)


def apply_atomic_operations(ctx, operations):
"""Sequentially executes all operations as a single transaction.
Operations should be a dict with structure as defined in
https://docs.irods.org/4.2.12/doxygen/libmsi__atomic__apply__metadata__operations_8cpp.html
If an error occurs, all updates are rolled back and an error is returned.
Result will contain specific information about the error.
:param ctx: Combined type of a callback and rei struct
:param operations: Dict containing the batch of metadata operations
:returns: Dict containing the error information on failure
"""
ret = msi.atomic_apply_metadata_operations(ctx, json.dumps(operations), "")
return json.loads(ret['arguments'][1])
2 changes: 2 additions & 0 deletions util/msi.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def _make_exception(name, message):
add_avu, AddAvuError = make('_add_avu', 'Could not add metadata to object')
rmw_avu, RmwAvuError = make('_rmw_avu', 'Could not remove metadata to object')

atomic_apply_metadata_operations, AtomicApplyMetadataOperationsError = make('_atomic_apply_metadata_operations', 'Could not apply atomic metadata operations')

sudo_obj_acl_set, SudoObjAclSetError = make('SudoObjAclSet', 'Could not set ACLs as admin')
sudo_obj_meta_set, SudoObjMetaSetError = make('SudoObjMetaSet', 'Could not set metadata as admin')
sudo_obj_meta_remove, SudoObjMetaRemoveError = make('SudoObjMetaRemove', 'Could not remove metadata as admin')
Expand Down

0 comments on commit c39aafd

Please sign in to comment.