python-irodsclient icon indicating copy to clipboard operation
python-irodsclient copied to clipboard

Executing `logical_quotas_get_collection_status` with `irods_rule_engine_plugin-logical_quotas-instance` prints nothing

Open mstfdkmn opened this issue 3 years ago • 7 comments

I am not sure enough whether this is a limitation or an issue and also if this is an issue, then should this be here or in the logical quota plugin? But it looks like a client related instead of the plugin itself. That is why created here.

We would like to write some tools that will facilitate using the logical quota plugin. Therefore part of this I would like to know the status of collections. But it seems I cannot get/see the collection status by executing logical_quotas_get_collection_status with irods_rule_engine_plugin-logical_quotas-instance whereas I can by irule. Nothing appears in the terminal where the script runs. And no error or any other result in logs, by the way. Is there a way to get the result of this operation if is being successfully invoked?

Also, the same operation is tried with the irods rule language instance and encountered the same issue here https://github.com/irods/irods_rule_engine_plugin_logical_quotas/issues/81.

script:

import os, os.path
from irods.session import iRODSSession
from irods.rule import Rule
from irods.exception import (FAIL_ACTION_ENCOUNTERED_ERR, RULE_ENGINE_ERROR, UnknowniRODSError)


env_file = os.getenv('IRODS_ENVIRONMENT_FILE', os.path.expanduser('~/.irods/irods_environment.json'))
with iRODSSession(irods_env_file=env_file) as session:
    collection_path = '/icts_icts/home/u0137480'
    
    # Logical quota
    try:
        Rule( session, body = '{"operation": "logical_quotas_get_collection_status", "collection":"/icts_icts/home/u0137480"}', \
              instance_name = 'irods_rule_engine_plugin-logical_quotas-instance' ).execute()
    except Exception as err:
        print(err)
        exit(1)

collection status by irule:

(base) u0137480@CRD-L-07856:~/projects/irods-acl-management$ irule -r irods_rule_engine_plugin-logical_quotas-instance '{"operation": "logical_quotas_get_collection_status", "collection": "/icts_icts/home/u0137480"}' null ruleExecOut
{"irods::logical_quotas::total_number_of_data_objects":"18","irods::logical_quotas::total_size_in_bytes":"192710031"}(base)

Query result of metadata attached:

✔ [Nov/28 22:45] vsc33586@login1 ~ $ imeta ls -C /icts_icts/home/u0137480
AVUs defined for collection /icts_icts/home/u0137480:
attribute: atr
value: val
units:
----
attribute: irods::logical_quotas::total_number_of_data_objects
value: 18
units:
----
attribute: irods::logical_quotas::total_size_in_bytes
value: 192710031
units:

However I can execute and see the effects of other operations such as monitoring start/stop etc., by calling the rule engine via PRC.

mstfdkmn avatar Nov 28 '22 22:11 mstfdkmn

@mstfdkmn STDOUT and STDERR are not automatically printed out from the Python client but may be extracted from structures returned in rule calls. See this line in the rule tests

d-w-moore avatar Nov 29 '22 03:11 d-w-moore

Hi, that was tried but seems nothing exists in the structure returned. But okay, thanks. We are gonna list the lq metadata attached:

col = session.collections.get(collection_path)
for atr, val in col.metadata.items():
if atr.startswith('irods::logical_quotas::'):
    print('attribute: ' + atr)
    print('----')
    print('value: ' + val)

mstfdkmn avatar Nov 29 '22 09:11 mstfdkmn

@mstfdkmn Did you check the stderrBuf as well ?

d-w-moore avatar Nov 29 '22 13:11 d-w-moore

Thanks @d-w-moore , I see now I didnt use the output='' kw argument correctly. Stdout returns exactly the same like how irule does.

mstfdkmn avatar Nov 29 '22 16:11 mstfdkmn

Ah, great. So... does that mean there is no action to be taken to close this issue?

Or... do we need to document getting output a bit more clearly?

trel avatar Nov 29 '22 16:11 trel

From our side this can be indeed closed and as stated above it is already in the test section. However I believe a small note to make it more visible for wider audiences would be useful. But your/Daniel's decision is the best. How we use it:

def get_coll_status(session, collection_path):
    '''
    Documentation
    '''
    try:
        output = Rule( session, body='{"operation": "logical_quotas_get_collection_status", "collection": "/icts_icts/home/u0137480"}', \
                       output='ruleExecOut', instance_name='irods_rule_engine_plugin-logical_quotas-instance' ).execute()
        buf = output.MsParam_PI[0].inOutStruct.stdoutBuf.buf
        if buf is not None:
            buf = buf.decode('utf-8')
            output_string = buf.rstrip('\0').rstrip()
            print(output_string)
    except Exception as err:
        print(err)
        exit(1)

mstfdkmn avatar Nov 29 '22 17:11 mstfdkmn

More documentation probably wouldn't be a bad thing

alanking avatar Nov 29 '22 19:11 alanking