Skip to content

Commit

Permalink
resilience
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-merzky committed Apr 29, 2024
1 parent 35e4ca7 commit 7bdb0fd
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 83 deletions.
47 changes: 0 additions & 47 deletions src/radical/utils/json_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,52 +99,5 @@ def parse_json_str(json_str):
return as_string(parse_json(json_str))


# ------------------------------------------------------------------------------
#
def metric_expand(data):
'''
iterate through the given dictionary, and when encountering a key string of
the form `ru.XYZ` or `rp.ABC`, expand them to their actually defined values.
This the following dict::
{
"ru.EVENT" : "foo"
}
becomes::
{
2 : "foo"
}
'''

try : import radical.pilot as rp # noqa: F401
except: pass
try : import radical.saga as rs # noqa: F401
except: pass
try : import radical.utils as ru # noqa: F401
except: pass

if isinstance(data, str):

if data.count('.') == 1:
elems = data.split('.')
if len(elems[0]) == 2 and elems[0][0] == 'r':
try:
data = eval(data)
except:
pass
return data

elif isinstance(data, list):
return [metric_expand(elem) for elem in data]

elif isinstance(data, dict):
return {metric_expand(k) : metric_expand(v) for k,v in data.items()}

else:
return data


# ------------------------------------------------------------------------------

37 changes: 1 addition & 36 deletions tests/unittests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,12 @@
# noqa: E201


import radical.utils as ru


# ------------------------------------------------------------------------------
#
def test_metric_expand():

d_in = {'total' : [{'ru.EVENT': 'bootstrap_0_start'},
{'ru.EVENT': 'bootstrap_0_stop' }],
'boot' : [{'ru.EVENT': 'bootstrap_0_start'},
{'ru.EVENT': 'sync_rel' }],
'setup_1' : [{'ru.EVENT': 'sync_rel' },
{'ru.STATE': 'rp.PMGR_ACTIVE' }],
'ignore' : [{'ru.STATE': 'rp.PMGR_ACTIVE' },
{'ru.EVENT': 'cmd' ,
'ru.MSG ': 'cancel_pilot' }],
'term' : [{'ru.EVENT': 'cmd' ,
'ru.MSG ': 'cancel_pilot' },
{'ru.EVENT': 'bootstrap_0_stop' }]}

d_out = {'total' : [{1 : 'bootstrap_0_start'},
{1 : 'bootstrap_0_stop' }],
'boot' : [{1 : 'bootstrap_0_start'},
{1 : 'sync_rel' }],
'setup_1' : [{1 : 'sync_rel' },
{5 : 'PMGR_ACTIVE' }],
'ignore' : [{5 : 'PMGR_ACTIVE' },
{1 : 'cmd' ,
6 : 'cancel_pilot' }],
'term' : [{1 : 'cmd' ,
6 : 'cancel_pilot' },
{1 : 'bootstrap_0_stop' }]}

assert ru.metric_expand(d_in) == d_out


# ------------------------------------------------------------------------------
# run tests if called directly
if __name__ == "__main__":

test_metric_expand()
pass


# ------------------------------------------------------------------------------
Expand Down

0 comments on commit 7bdb0fd

Please sign in to comment.