Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncate.m #32

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doxygen/microservices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
- #msiCheckPermission - Check if a data object permission is the same as the one given
- #msiCheckOwner - Check if the user is the owner of the data object
- #msiSetReplComment - Sets the data_comments attribute of a data object
- #msi_replica_truncate - Truncate a replica to the desired size

\subsection msicollection Collection Microservices
- #msiCollCreate - Create a collection
Expand Down
14 changes: 7 additions & 7 deletions lib/api/include/irods/replica_truncate.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ extern "C" {
/// \param[in] _comm A pointer to a RcComm.
/// \param[in] _inp \parblock
/// DataObjInp structure which requires the following inputs:
/// objPath - The full logical path to the target data object.
/// dataSize - The desired size of the replica after truncating.
/// - objPath: The full logical path to the target data object.
/// - dataSize: The desired size of the replica after truncating.
///
/// The condInput supports the following keywords:
/// REPL_NUM_KW - The replica number of the replica to truncate.
/// RESC_NAME_KW - The name of the resource with the replica to truncate. Must be a root resource.
/// DEF_RESC_NAME_KW - The default resource to target in the absence of any other inputs or policy.
/// RESC_HIER_STR_KW - Full resource hierarchy to the replica to truncate. Use with caution.
/// ADMIN_KW - Flag indicating that the operation is to be performed with elevated privileges. No value required.
/// - REPL_NUM_KW: The replica number of the replica to truncate.
/// - RESC_NAME_KW: The name of the resource with the replica to truncate. Must be a root resource.
/// - DEF_RESC_NAME_KW: The default resource to target in the absence of any other inputs or policy.
/// - RESC_HIER_STR_KW: Full resource hierarchy to the replica to truncate. Use with caution.
/// - ADMIN_KW: Flag indicating that the operation is to be performed with elevated privileges. No value required.
/// \endparblock
/// \param[out] _out \parblock
/// Character string representing a JSON structure with the following form:
Expand Down
1 change: 1 addition & 0 deletions scripts/core_tests_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"test_all_rules.Test_AllRules",
"test_all_rules.Test_JSON_microservices",
"test_all_rules.Test_msiDataObjRepl_checksum_keywords",
"test_all_rules.test_msi_replica_truncate",
"test_auth.Test_Auth",
"test_auth.test_iinit",
"test_catalog",
Expand Down
117 changes: 117 additions & 0 deletions scripts/irods/test/test_all_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -2290,3 +2290,120 @@ def do_test(json_ptr, expected_value):
do_test( '/other', 'null')
do_test( '/bool1', 'true')
do_test( '/bool2', 'false')


@unittest.skipUnless(IrodsConfig().default_rule_engine_plugin == 'irods_rule_engine_plugin-irods_rule_language',
'Only implemented for NREP.')
class test_msi_replica_truncate(unittest.TestCase):
"""These test msi_replica_truncate and are not meant to be thorough tests for the replica_truncate API."""

plugin_name = IrodsConfig().default_rule_engine_plugin
rep_instance = plugin_name + '-instance'
other_resource = 'msi_replica_truncate_resource'
original_contents = 'truncate this'
new_size = 100
data_name = 'test_msi_replica_truncate.txt'

@classmethod
def setUpClass(cls):
# Create a test user.
cls.user = session.mkuser_and_return_session('rodsuser', 'smeagol', 'spass', lib.get_hostname())

# Create a test resource.
with session.make_session_for_existing_admin() as admin_session:
lib.create_ufs_resource(admin_session, cls.other_resource, hostname=test.settings.HOSTNAME_2)

@classmethod
def tearDownClass(cls):
with session.make_session_for_existing_admin() as admin_session:
# End the test user session, and remove the test user and test resource.
cls.user.__exit__()
admin_session.assert_icommand(['iadmin', 'rmuser', cls.user.username])
lib.remove_resource(admin_session, cls.other_resource)

def setUp(cls):
# Create a data object to truncate.
cls.logical_path = '/'.join([cls.user.session_collection, cls.data_name])
cls.user.assert_icommand(['istream', 'write', cls.logical_path], input=cls.original_contents)
cls.assertTrue(lib.replica_exists_on_resource(cls.user, cls.logical_path, cls.user.default_resource))
cls.user.assert_icommand(['irepl', '-R', cls.other_resource, cls.logical_path])
cls.assertTrue(lib.replica_exists_on_resource(cls.user, cls.logical_path, cls.other_resource))

def tearDown(cls):
# Remove the data object.
cls.user.assert_icommand(['irm', '-f', cls.logical_path])

def test_empty_string_input(self):
rule_text = "msi_replica_truncate('', *ignored)"
self.user.assert_icommand(
['irule', '-r', self.rep_instance, rule_text, 'null', 'ruleExecOut'],
'STDERR', ['-358000', 'OBJ_PATH_DOES_NOT_EXIST'])
self.assertEqual(len(self.original_contents), int(lib.get_replica_size(self.user, self.data_name, 0)))
self.assertEqual(len(self.original_contents), int(lib.get_replica_size(self.user, self.data_name, 1)))

def test_string_input_that_just_says_null(self):
rule_text = "msi_replica_truncate('null', *ignored)"
self.user.assert_icommand(
['irule', '-r', self.rep_instance, rule_text, 'null', 'ruleExecOut'],
'STDERR', ['-358000', 'OBJ_PATH_DOES_NOT_EXIST'])
self.assertEqual(len(self.original_contents), int(lib.get_replica_size(self.user, self.data_name, 0)))
self.assertEqual(len(self.original_contents), int(lib.get_replica_size(self.user, self.data_name, 1)))

def test_int_input(self):
rule_text = "msi_replica_truncate(1, *ignored)"
self.user.assert_icommand(
['irule', '-r', self.rep_instance, rule_text, 'null', 'ruleExecOut'],
'STDERR', ['-323000', 'USER_PARAM_TYPE_ERR'])
self.assertEqual(len(self.original_contents), int(lib.get_replica_size(self.user, self.data_name, 0)))
self.assertEqual(len(self.original_contents), int(lib.get_replica_size(self.user, self.data_name, 1)))

def test_missing_data_size_keyword(self):
rule_text = "msi_replica_truncate('objPath={}', *ignored)".format(self.logical_path)
self.user.assert_icommand(
['irule', '-r', self.rep_instance, rule_text, 'null', 'ruleExecOut'],
'STDERR', ['-529022', 'UNIX_FILE_TRUNCATE_ERR', 'Invalid argument'])
self.assertEqual(len(self.original_contents), int(lib.get_replica_size(self.user, self.data_name, 0)))
self.assertEqual(len(self.original_contents), int(lib.get_replica_size(self.user, self.data_name, 1)))

def test_invalid_keyword(self):
rule_text = "msi_replica_truncate('objPath={}++++dataSize={}++++replica_number=1', *ignored)".format(
self.logical_path, self.new_size)
self.user.assert_icommand(
['irule', '-r', self.rep_instance, rule_text, 'null', 'ruleExecOut'],
'STDERR', ['-315000', 'USER_BAD_KEYWORD_ERR'])
self.assertEqual(len(self.original_contents), int(lib.get_replica_size(self.user, self.data_name, 0)))
self.assertEqual(len(self.original_contents), int(lib.get_replica_size(self.user, self.data_name, 1)))

def test_minimum_valid_input(self):
rule_text = "msi_replica_truncate('objPath={}++++dataSize={}', *ignored)".format(self.logical_path, self.new_size)
self.user.assert_icommand(['irule', '-r', self.rep_instance, rule_text, 'null', 'ruleExecOut'])
self.assertEqual(self.new_size, int(lib.get_replica_size(self.user, self.data_name, 0)))
self.assertEqual(len(self.original_contents), int(lib.get_replica_size(self.user, self.data_name, 1)))

def test_object_path_keyword(self):
rule_text = "msi_replica_truncate('objPath={}++++dataSize={}', *ignored)".format(self.logical_path, self.new_size)
self.user.assert_icommand(['irule', '-r', self.rep_instance, rule_text, 'null', 'ruleExecOut'])
self.assertEqual(self.new_size, int(lib.get_replica_size(self.user, self.data_name, 0)))
self.assertEqual(len(self.original_contents), int(lib.get_replica_size(self.user, self.data_name, 1)))

def test_replica_number_keyword(self):
rule_text = "msi_replica_truncate('objPath={}++++dataSize={}++++replNum=1', *ignored)".format(
self.logical_path, self.new_size)
self.user.assert_icommand(['irule', '-r', self.rep_instance, rule_text, 'null', 'ruleExecOut'])
self.assertEqual(len(self.original_contents), int(lib.get_replica_size(self.user, self.data_name, 0)))
self.assertEqual(self.new_size, int(lib.get_replica_size(self.user, self.data_name, 1)))

def test_resource_name_keyword(self):
rule_text = "msi_replica_truncate('objPath={}++++dataSize={}++++rescName={}', *ignored)".format(
self.logical_path, self.new_size, self.other_resource)
self.user.assert_icommand(['irule', '-r', self.rep_instance, rule_text, 'null', 'ruleExecOut'])
self.assertEqual(len(self.original_contents), int(lib.get_replica_size(self.user, self.data_name, 0)))
self.assertEqual(self.new_size, int(lib.get_replica_size(self.user, self.data_name, 1)))

def test_admin_keyword(self):
with session.make_session_for_existing_admin() as admin_session:
rule_text = "msi_replica_truncate('objPath={}++++dataSize={}++++irodsAdmin=', *ignored)".format(
self.logical_path, self.new_size)
admin_session.assert_icommand(['irule', '-r', self.rep_instance, rule_text, 'null', 'ruleExecOut'])
self.assertEqual(self.new_size, int(lib.get_replica_size(self.user, self.data_name, 0)))
self.assertEqual(len(self.original_contents), int(lib.get_replica_size(self.user, self.data_name, 1)))
14 changes: 7 additions & 7 deletions server/api/include/irods/rs_replica_truncate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ extern "C" {
/// \param[in] _comm A pointer to a RsComm.
/// \param[in] _inp \parblock
/// DataObjInp structure which requires the following inputs:
/// objPath - The full logical path to the target data object.
/// dataSize - The desired size of the replica after truncating.
/// - objPath: The full logical path to the target data object.
/// - dataSize: The desired size of the replica after truncating.
///
/// The condInput supports the following keywords:
/// REPL_NUM_KW - The replica number of the replica to truncate.
/// RESC_NAME_KW - The name of the resource with the replica to truncate. Must be a root resource.
/// DEF_RESC_NAME_KW - The default resource to target in the absence of any other inputs or policy.
/// RESC_HIER_STR_KW - Full resource hierarchy to the replica to truncate. Use with caution.
/// ADMIN_KW - Flag indicating that the operation is to be performed with elevated privileges. No value required.
/// - REPL_NUM_KW: The replica number of the replica to truncate.
/// - RESC_NAME_KW: The name of the resource with the replica to truncate. Must be a root resource.
/// - DEF_RESC_NAME_KW: The default resource to target in the absence of any other inputs or policy.
/// - RESC_HIER_STR_KW: Full resource hierarchy to the replica to truncate. Use with caution.
/// - ADMIN_KW: Flag indicating that the operation is to be performed with elevated privileges. No value required.
/// \endparblock
/// \param[out] _out \parblock
/// Character string representing a JSON structure with the following form:
Expand Down
2 changes: 2 additions & 0 deletions server/re/include/irods/reAction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ namespace irods
table_[ "msiDataObjPhymv" ] = new irods::ms_table_entry( "msiDataObjPhymv", 6, std::function<int(msParam_t*,msParam_t*,msParam_t*,msParam_t*,msParam_t*,msParam_t*,ruleExecInfo_t*)>( msiDataObjPhymv ) );
table_[ "msiDataObjRename" ] = new irods::ms_table_entry( "msiDataObjRename", 4, std::function<int(msParam_t*,msParam_t*,msParam_t*,msParam_t*,ruleExecInfo_t*)>( msiDataObjRename ) );
table_[ "msiDataObjTrim" ] = new irods::ms_table_entry( "msiDataObjTrim", 6, std::function<int(msParam_t*,msParam_t*,msParam_t*,msParam_t*,msParam_t*,msParam_t*,ruleExecInfo_t*)>( msiDataObjTrim ) );
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
table_[ "msi_replica_truncate" ] = new irods::ms_table_entry( "msi_replica_truncate", 2, std::function<int(msParam_t*,msParam_t*,ruleExecInfo_t*)>( msi_replica_truncate ) );
table_[ "msiCollCreate" ] = new irods::ms_table_entry( "msiCollCreate", 3, std::function<int(msParam_t*,msParam_t*,msParam_t*,ruleExecInfo_t*)>( msiCollCreate ) );
table_[ "msiRmColl" ] = new irods::ms_table_entry( "msiRmColl", 3, std::function<int(msParam_t*,msParam_t*,msParam_t*,ruleExecInfo_t*)>( msiRmColl ) );
table_[ "msiCollRepl" ] = new irods::ms_table_entry( "msiCollRepl", 3, std::function<int(msParam_t*,msParam_t*,msParam_t*,ruleExecInfo_t*)>( msiCollRepl ) );
Expand Down
2 changes: 2 additions & 0 deletions server/re/include/irods/reDataObjOpr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@ msiCollRsync( msParam_t *inpParam1, msParam_t *inpParam2,
int
_rsCollRsync( rsComm_t *rsComm, dataObjInp_t *dataObjInp,
char *srcColl, char *destColl );

auto msi_replica_truncate(MsParam* _inp, MsParam* _out, RuleExecInfo* _rei) -> int;
#endif /* RE_DATA_OBJ_OPR_H */
Loading
Loading