9
9
from DIRAC .ConfigurationSystem .Client .Helpers .Operations import Operations
10
10
from DIRAC .Core .Utilities .Proxy import executeWithUserProxy
11
11
from DIRAC .WorkloadManagementSystem .Client .PilotLoggingPlugins .DownloadPlugin import DownloadPlugin
12
+ from DIRAC .WorkloadManagementSystem .Client .TornadoPilotLoggingClient import TornadoPilotLoggingClient
12
13
13
14
sLog = gLogger .getSubLogger (__name__ )
14
15
@@ -20,10 +21,10 @@ class FileCacheDownloadPlugin(DownloadPlugin):
20
21
21
22
def __init__ (self ):
22
23
"""
23
- Sets the pilot log files location for a WebServer .
24
+ Sets the client for downloading incomplete log files from the server cache .
24
25
25
26
"""
26
- pass
27
+ self . tornadoClient = TornadoPilotLoggingClient ()
27
28
28
29
def getRemotePilotLogs (self , pilotStamp , vo = None ):
29
30
"""
@@ -39,8 +40,7 @@ def getRemotePilotLogs(self, pilotStamp, vo=None):
39
40
uploadPath = opsHelper .getValue ("Pilot/UploadPath" , "" )
40
41
lfn = os .path .join (uploadPath , pilotStamp + ".log" )
41
42
sLog .info ("LFN to download: " , lfn )
42
- filepath = tempfile .TemporaryDirectory ().name
43
- os .makedirs (filepath , exist_ok = True )
43
+
44
44
# get pilot credentials which uploaded logs to an external storage:
45
45
res = opsHelper .getOptionsDict ("Shifter/DataManager" )
46
46
if not res ["OK" ]:
@@ -53,9 +53,22 @@ def getRemotePilotLogs(self, pilotStamp, vo=None):
53
53
54
54
sLog .info (f"Proxy used for retrieving pilot logs: VO: { vo } , User: { proxyUser } , Group: { proxyGroup } " )
55
55
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 )
59
72
sLog .debug ("getFile result:" , res )
60
73
if not res ["OK" ]:
61
74
sLog .error (f"Failed to contact storage" )
@@ -76,5 +89,19 @@ def getRemotePilotLogs(self, pilotStamp, vo=None):
76
89
return S_OK (resultDict )
77
90
78
91
@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