Skip to content

Commit f5613fa

Browse files
committed
feat: implement log file download from the server
1 parent 21f3471 commit f5613fa

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

src/DIRAC/WorkloadManagementSystem/Client/PilotLoggingPlugins/FileCacheDownloadPlugin.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
1010
from DIRAC.Core.Utilities.Proxy import executeWithUserProxy
1111
from DIRAC.WorkloadManagementSystem.Client.PilotLoggingPlugins.DownloadPlugin import DownloadPlugin
12+
from DIRAC.WorkloadManagementSystem.Client.TornadoPilotLoggingClient import TornadoPilotLoggingClient
1213

1314
sLog = gLogger.getSubLogger(__name__)
1415

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

2122
def __init__(self):
2223
"""
23-
Sets the pilot log files location for a WebServer.
24+
Sets the client for downloading incomplete log files from the server cache.
2425
2526
"""
26-
pass
27+
self.tornadoClient = TornadoPilotLoggingClient()
2728

2829
def getRemotePilotLogs(self, pilotStamp, vo=None):
2930
"""
@@ -39,8 +40,7 @@ def getRemotePilotLogs(self, pilotStamp, vo=None):
3940
uploadPath = opsHelper.getValue("Pilot/UploadPath", "")
4041
lfn = os.path.join(uploadPath, pilotStamp + ".log")
4142
sLog.info("LFN to download: ", lfn)
42-
filepath = tempfile.TemporaryDirectory().name
43-
os.makedirs(filepath, exist_ok=True)
43+
4444
# get pilot credentials which uploaded logs to an external storage:
4545
res = opsHelper.getOptionsDict("Shifter/DataManager")
4646
if not res["OK"]:
@@ -53,9 +53,22 @@ def getRemotePilotLogs(self, pilotStamp, vo=None):
5353

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

56-
res = self._downloadLogs( # pylint: disable=unexpected-keyword-arg
57-
lfn, filepath, proxyUserName=proxyUser, proxyUserGroup=proxyGroup
58-
)
56+
# attempt to get logs from server first:
57+
res = self._getLogsFromServer(pilotStamp, vo)
58+
if not res["OK"]:
59+
# from SE:
60+
res = self._downloadLogs( # pylint: disable=unexpected-keyword-arg
61+
lfn, pilotStamp, proxyUserName=proxyUser, proxyUserGroup=proxyGroup
62+
)
63+
64+
return res
65+
66+
@executeWithUserProxy
67+
def _downloadLogs(self, lfn, pilotStamp):
68+
filepath = tempfile.TemporaryDirectory().name
69+
os.makedirs(filepath, exist_ok=True)
70+
71+
res = DataManager().getFile(lfn, destinationDir=filepath)
5972
sLog.debug("getFile result:", res)
6073
if not res["OK"]:
6174
sLog.error(f"Failed to contact storage")
@@ -76,5 +89,19 @@ def getRemotePilotLogs(self, pilotStamp, vo=None):
7689
return S_OK(resultDict)
7790

7891
@executeWithUserProxy
79-
def _downloadLogs(self, lfn, filepath):
80-
return DataManager().getFile(lfn, destinationDir=filepath)
92+
def _getLogsFromServer(self, logfile, vo):
93+
"""
94+
Get a file from the server cache area. The file is most likely not finalised, since finalised files
95+
are copied to an SE and deleted. Both logfile.log and logfile are tried should the finalised file still
96+
be on the server.
97+
98+
:param str logfile: pilot log filename
99+
:param str vo: VO name
100+
:return: S_OK or S_ERROR
101+
:rtype: dict
102+
"""
103+
104+
res = self.tornadoClient.getLogs(logfile, vo)
105+
if not res["OK"]:
106+
res = self.tornadoClient.getLogs(logfile + ".log", vo)
107+
return res

0 commit comments

Comments
 (0)