Skip to content

Commit

Permalink
feat: implement log file download from the server
Browse files Browse the repository at this point in the history
  • Loading branch information
martynia committed Sep 13, 2023
1 parent 21f3471 commit f5613fa
Showing 1 changed file with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
from DIRAC.Core.Utilities.Proxy import executeWithUserProxy
from DIRAC.WorkloadManagementSystem.Client.PilotLoggingPlugins.DownloadPlugin import DownloadPlugin
from DIRAC.WorkloadManagementSystem.Client.TornadoPilotLoggingClient import TornadoPilotLoggingClient

sLog = gLogger.getSubLogger(__name__)

Expand All @@ -20,10 +21,10 @@ class FileCacheDownloadPlugin(DownloadPlugin):

def __init__(self):
"""
Sets the pilot log files location for a WebServer.
Sets the client for downloading incomplete log files from the server cache.
"""
pass
self.tornadoClient = TornadoPilotLoggingClient()

def getRemotePilotLogs(self, pilotStamp, vo=None):
"""
Expand All @@ -39,8 +40,7 @@ def getRemotePilotLogs(self, pilotStamp, vo=None):
uploadPath = opsHelper.getValue("Pilot/UploadPath", "")
lfn = os.path.join(uploadPath, pilotStamp + ".log")
sLog.info("LFN to download: ", lfn)
filepath = tempfile.TemporaryDirectory().name
os.makedirs(filepath, exist_ok=True)

# get pilot credentials which uploaded logs to an external storage:
res = opsHelper.getOptionsDict("Shifter/DataManager")
if not res["OK"]:
Expand All @@ -53,9 +53,22 @@ def getRemotePilotLogs(self, pilotStamp, vo=None):

sLog.info(f"Proxy used for retrieving pilot logs: VO: {vo}, User: {proxyUser}, Group: {proxyGroup}")

res = self._downloadLogs( # pylint: disable=unexpected-keyword-arg
lfn, filepath, proxyUserName=proxyUser, proxyUserGroup=proxyGroup
)
# attempt to get logs from server first:
res = self._getLogsFromServer(pilotStamp, vo)
if not res["OK"]:
# from SE:
res = self._downloadLogs( # pylint: disable=unexpected-keyword-arg
lfn, pilotStamp, proxyUserName=proxyUser, proxyUserGroup=proxyGroup
)

return res

@executeWithUserProxy
def _downloadLogs(self, lfn, pilotStamp):
filepath = tempfile.TemporaryDirectory().name
os.makedirs(filepath, exist_ok=True)

res = DataManager().getFile(lfn, destinationDir=filepath)
sLog.debug("getFile result:", res)
if not res["OK"]:
sLog.error(f"Failed to contact storage")
Expand All @@ -76,5 +89,19 @@ def getRemotePilotLogs(self, pilotStamp, vo=None):
return S_OK(resultDict)

@executeWithUserProxy
def _downloadLogs(self, lfn, filepath):
return DataManager().getFile(lfn, destinationDir=filepath)
def _getLogsFromServer(self, logfile, vo):
"""
Get a file from the server cache area. The file is most likely not finalised, since finalised files
are copied to an SE and deleted. Both logfile.log and logfile are tried should the finalised file still
be on the server.
:param str logfile: pilot log filename
:param str vo: VO name
:return: S_OK or S_ERROR
:rtype: dict
"""

res = self.tornadoClient.getLogs(logfile, vo)
if not res["OK"]:
res = self.tornadoClient.getLogs(logfile + ".log", vo)
return res

0 comments on commit f5613fa

Please sign in to comment.