Skip to content

Commit 61dcb4f

Browse files
committed
feat: add scitag support
1 parent 931e647 commit 61dcb4f

File tree

1 file changed

+51
-9
lines changed

1 file changed

+51
-9
lines changed

src/DIRAC/DataManagementSystem/Client/FTS3Job.py

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
import datetime
44
import errno
5-
from packaging.version import Version
65

6+
import fts3.rest.client.easy as fts3
7+
import requests
8+
from cachetools import TTLCache, cached
79

810
# Requires at least version 3.3.3
911
from fts3 import __version__ as fts3_version
10-
import fts3.rest.client.easy as fts3
1112
from fts3.rest.client.exceptions import FTS3ClientException, NotFound
13+
from packaging.version import Version
1214

1315
# There is a breaking change in the API in 3.13
1416
# https://gitlab.cern.ch/fts/fts-rest-flask/-/commit/5faa283e0cd4b80a0139a547c4a6356522c8449d
@@ -22,21 +24,56 @@
2224
# default pycurl. See https://its.cern.ch/jira/browse/FTS-261
2325
from fts3.rest.client.request import Request as ftsSSLRequest
2426

25-
from DIRAC.Resources.Storage.StorageElement import StorageElement
26-
27-
from DIRAC.FrameworkSystem.Client.Logger import gLogger
28-
from DIRAC.FrameworkSystem.Client.TokenManagerClient import gTokenManager
29-
30-
from DIRAC.Core.Utilities.ReturnValues import S_OK, S_ERROR
3127
from DIRAC.Core.Utilities.DErrno import cmpError
32-
3328
from DIRAC.Core.Utilities.JEncode import JSerializable
29+
from DIRAC.Core.Utilities.ReturnValues import S_ERROR, S_OK
3430
from DIRAC.DataManagementSystem.Client.FTS3File import FTS3File
31+
from DIRAC.FrameworkSystem.Client.Logger import gLogger
32+
from DIRAC.FrameworkSystem.Client.TokenManagerClient import gTokenManager
33+
from DIRAC.Resources.Storage.StorageElement import StorageElement
3534

3635
# 3 days in seconds
3736
BRING_ONLINE_TIMEOUT = 259200
3837

3938

39+
def get_scitag(vo: str, activity: str = None):
40+
"""
41+
Get the scitag based on the VO and activity.
42+
If the VO is not found in the scitag.json, it defaults to 1.
43+
If no specific activity is provided, it defaults to the "default" activityName.
44+
45+
:param vo: The VO for which to get the scitag
46+
:param activity: The activity for which to get the scitag
47+
:return: The scitag value
48+
"""
49+
50+
# Create a TTL cache: max 1 item, expires after 84400 seconds (1 day)
51+
json_cache = TTLCache(maxsize=1, ttl=86400)
52+
53+
@cached(json_cache)
54+
def get_remote_json():
55+
gLogger.verbose("Fetching https://scitags.org/api.json from the network")
56+
response = requests.get("https://scitags.org/api.json")
57+
response.raise_for_status()
58+
return response.json()
59+
60+
# Load the JSON data from the cache or network
61+
sj = get_remote_json()
62+
63+
vo_id = 1 # Default VO ID
64+
activity_id = 1 # Default activity ID
65+
66+
for experiment in sj.get("experiments", []):
67+
if experiment.get("expName") == vo.lower():
68+
vo_id = experiment.get("expId")
69+
for act in experiment.get("activities", []):
70+
if act.get("activityName") == activity:
71+
activity_id = act.get("activityId")
72+
73+
# Logic to determine the scitag based on vo and activity (this is what FTS wants)
74+
return vo_id << 6 | activity_id # Example logic, replace with actual implementation
75+
76+
4077
class FTS3Job(JSerializable):
4178
"""Abstract class to represent a job to be executed by FTS. It belongs
4279
to an FTS3Operation
@@ -467,6 +504,9 @@ def _constructTransferJob(self, pinTime, allLFNs, target_spacetoken, protocols=N
467504
# * stageProto://myFile -> stageProto://myFile
468505
# * srcProto://myFile -> destProto://myFile
469506

507+
# scitag 65 is 1 << 6 | 1 (default experiment, default activity)
508+
scitag = get_scitag(vo=self.vo, activity=self.activity)
509+
470510
if stageURL:
471511
# We do not set a fileID in the metadata
472512
# such that we do not update the DB when monitoring
@@ -485,6 +525,7 @@ def _constructTransferJob(self, pinTime, allLFNs, target_spacetoken, protocols=N
485525
filesize=ftsFile.size,
486526
metadata=stageTrans_metadata,
487527
activity=self.activity,
528+
scitag=scitag,
488529
)
489530
transfers.append(stageTrans)
490531

@@ -553,6 +594,7 @@ def _constructTransferJob(self, pinTime, allLFNs, target_spacetoken, protocols=N
553594
activity=self.activity,
554595
source_token=srcToken,
555596
destination_token=dstToken,
597+
scitag=scitag,
556598
)
557599

558600
transfers.append(trans)

0 commit comments

Comments
 (0)