Skip to content

Commit

Permalink
Merge pull request #774 from dynamic-entropy/master
Browse files Browse the repository at this point in the history
Add fetching locality instructions to helper scripts
  • Loading branch information
dynamic-entropy authored Apr 17, 2024
2 parents 4986389 + 0391c8a commit c07a4cc
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
17 changes: 16 additions & 1 deletion helpers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,19 @@ This is to test HTTP REST API readiness for all our Tapes.
9. Finally, set update_from_json to true for both the main and test _Tape RSEs.
PS: Start with a small functional test transfer, the default dataset is a good example.
If it works, then try with a larger dataset for stress testing.
If it works, then try with a larger dataset for stress testing.
----
Adding scripts for retrieving file locality information on buffer and tape.
```bash
curl -X POST --cert $X509_USER_PROXY --key $X509_USER_PROXY --capath /etc/grid-security/certificates https://<hostname>:<port>/api/v1/tape/archiveinfo> \
--data '{"paths":[
<file_path1>,
<file_path2>,
]}' | jq
```

The document for rest api specification can be found [here](https://cernbox.cern.ch/pdf-viewer/public/vLhBpHDdaXJSqwW/WLCG%20Tape%20REST%20API%20reference%20document.pdf)
47 changes: 47 additions & 0 deletions helpers/fetch_locality.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import requests
import json
from urllib.parse import urlparse
import os


def parse_apihost_path_map(urls):
parsed_urls = [urlparse(url) for url in urls]

host_files_map = {}
for url in parsed_urls:
hostname = 'https://' + url.netloc
if hostname not in host_files_map:
host_files_map[hostname] = []
host_files_map[hostname].append(url.path)

api_host_files_map = {}
for hostname, files in host_files_map.items():
response = requests.get(hostname + '/.well-known/wlcg-tape-rest-api',
verify='/etc/grid-security/certificates',
cert=(os.environ['X509_USER_PROXY'],
os.environ['X509_USER_PROXY']),
timeout=180
)
tape_host = response.json()["endpoints"][0]["uri"]
api_host_files_map[tape_host] = files
return api_host_files_map


def get_locality(urls):
host_files_map = parse_apihost_path_map(urls)

for hostname, files in host_files_map.items():
response = requests.post(hostname + '/archiveinfo',
data=json.dumps({"paths": files}),
verify='/etc/grid-security/certificates',
cert=(os.environ['X509_USER_PROXY'],
os.environ['X509_USER_PROXY']),
headers={'Content-Type': 'application/json'},
timeout=180
)
print(response.text)


if __name__ == "__main__":
urls = ["davs://<hostname>:<port><path>"]
get_locality(urls)

0 comments on commit c07a4cc

Please sign in to comment.