Skip to content

Commit

Permalink
feat (SE): add getWLCGTokenPath methods
Browse files Browse the repository at this point in the history
  • Loading branch information
chaen committed Oct 7, 2024
1 parent 22efc8f commit c2ce0cb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions dirac.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ Resources
SpaceReservation = LHCb-EOS # Space reservation name if any. Concept like SpaceToken
ArchiveTimeout = 84600 # Timeout for the FTS archiving
BringOnlineTimeout = 84600 # Timeout for the bring online operation used by FTS
WLCGTokenBasePath = /eos/lhcb # EXPERIMENTAL Path from which the token should be relative to
# Protocol section, see http://dirac.readthedocs.io/en/latest/AdministratorGuide/Resources/Storages/index.html#available-protocol-plugins
GFAL2_SRM2
{
Expand Down
1 change: 1 addition & 0 deletions docs/source/AdministratorGuide/Resources/storage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Configuration options are:
* ``SpaceReservation``: just a name of a zone of the physical storage which can have some space reserved. Extends the SRM ``SpaceToken`` concept.
* ``ArchiveTimeout``: for tape SE only. If set to a value in seconds, enables the `FTS Archive Monitoring feature <https://fts3-docs.web.cern.ch/fts3-docs/docs/archive_monitoring.html>`_
* ``BringOnlineTimeout``: for tape SE only. If set to a value in seconds, specify the BringOnline parameter for FTS transfers. Otherwise, the default is whatever is in the ``FTS3Job`` class.
* ``WLCGTokenBasePath``: EXPERIMENTAL Path from which the token should be relative to

VO specific paths
-----------------
Expand Down
15 changes: 15 additions & 0 deletions src/DIRAC/Resources/Storage/StorageBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import shutil
import tempfile

from pathlib import Path

from DIRAC import S_OK, S_ERROR
from DIRAC.Core.Utilities.Pfn import pfnparse, pfnunparse
from DIRAC.Core.Utilities.ReturnValues import returnSingleResult
Expand Down Expand Up @@ -462,3 +464,16 @@ def getOccupancy(self, **kwargs):
finally:
# Clean the temporary dir
shutil.rmtree(tmpDirName)

def getWLCGTokenPath(self, lfn: str, wlcgTokenBasePath: str) -> str:
"""
Returns the path expected to be in a WLCG token
It basically consists of ``basepath - tokenBasePath + LFN``
The tokenBasePath is a configuration on the storage side.
"""

allDict = dict.fromkeys(["Protocol", "Host", "Port", "Path", "FileName", "Options"], "")
allDict.update({"Path": self.protocolParameters["Path"], "FileName": lfn.lstrip("/")})
fullPath = pfnunparse(allDict)["Value"]
return Path(fullPath).relative_to(Path(wlcgTokenBasePath))
22 changes: 21 additions & 1 deletion src/DIRAC/Resources/Storage/StorageElement.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from DIRAC.Core.Utilities import DErrno
from DIRAC.Core.Utilities.File import convertSizeUnits
from DIRAC.Core.Utilities.List import getIndexInList
from DIRAC.Core.Utilities.ReturnValues import S_OK, S_ERROR, returnSingleResult
from DIRAC.Core.Utilities.ReturnValues import S_OK, S_ERROR, returnSingleResult, convertToReturnValue
from DIRAC.Core.Utilities.TimeUtilities import toEpochMilliSeconds
from DIRAC.Resources.Storage.StorageFactory import StorageFactory
from DIRAC.Core.Utilities.Pfn import pfnparse
Expand Down Expand Up @@ -294,6 +294,7 @@ def __init__(self, name, protocolSections=None, vo=None, hideExceptions=False):
"isDirectory",
"isFile",
"getOccupancy",
"getWLCGTokenPath",
]

self.okMethods = [
Expand Down Expand Up @@ -964,6 +965,25 @@ def getLFNFromURL(self, urls):
# This is the generic wrapper for file operations
#

@convertToReturnValue
def getWLCGTokenPath(self, lfn: str):
"""
EXPERIMENTAL
return the path to put in the token, relative to the vo path as configured
in the storage.
"""
wlcgTokenBasePath = self.options.get("WLCGTokenBasePath")
if not wlcgTokenBasePath:
raise ValueError("WLCGTokenBasePath not configured")

for storage in self.storages.values():
try:
return storage.getWLCGTokenPath(lfn, wlcgTokenBasePath)
except Exception:
continue
raise RuntimeError("Could not get WLCGTokenPath")

def getURL(self, lfn, protocol=False, replicaDict=None):
"""execute 'getTransportURL' operation.
Expand Down

0 comments on commit c2ce0cb

Please sign in to comment.