|
| 1 | +#! /usr/bin/env python3 |
| 2 | + |
| 3 | +""" |
| 4 | +A small bit of example python code to send traces to Rucio. |
| 5 | +
|
| 6 | +The loop over all the existing replicas can be used if one does not know which replica was accessed. |
| 7 | +Then it is safer, in a way, to mark all the replicas as accessed. But if one knows, just send a single trace with |
| 8 | +the known replica. |
| 9 | +
|
| 10 | +The trace server runs unauthenticated on port 80, so a simple curl will suffice. The regular Rucio client requires |
| 11 | +X509 or token authentication to find the RSEs of the replicas. As such the hostname of the trace server is redacted. |
| 12 | +""" |
| 13 | + |
| 14 | +import subprocess |
| 15 | +from json import dumps |
| 16 | + |
| 17 | +from rucio.client import Client |
| 18 | + |
| 19 | +FILE = '/store/mc/Run3Summer23BPixNanoAODv12/GluGlutoH0PHto2Zto2E2Mu_M-125_Ga-SM_M4L-70_4LFilter_newPS_TuneCP5_13p6TeV_mcfm-pythia8/NANOAODSIM/130X_mcRun3_2023_realistic_postBPix_v6-v4/2820000/34bc470c-1909-4722-9bde-0607b43b4c29.root' |
| 20 | + |
| 21 | +cl = Client() |
| 22 | + |
| 23 | +dids = [{'scope': 'cms', 'name': FILE}] |
| 24 | + |
| 25 | +rr = cl.list_replicas(dids) |
| 26 | +for replica in rr: |
| 27 | + for rse, availability in replica['states'].items(): |
| 28 | + if availability == 'AVAILABLE': |
| 29 | + touch_frame = {'eventType': 'touch', 'clientState': 'DONE', 'account': None, 'localSite': rse, |
| 30 | + 'remoteSite': rse, 'scope': 'cms', 'filename': FILE} |
| 31 | + |
| 32 | + command = ['curl', '-X', 'POST', 'http://xxx.xxx.xxx/traces/', '-H', |
| 33 | + 'Content-Type: application/json', '-d', dumps(touch_frame)] |
| 34 | + |
| 35 | + result = subprocess.run(command, capture_output=True, text=True) |
| 36 | + print() |
| 37 | + print(result) |
0 commit comments