-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: pilot log download enhancement: Add remote logs download to dir…
…ac-admin-get-pilot-output and dirac-admin-get-job-pilot-outpu
- Loading branch information
Showing
6 changed files
with
180 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/DIRAC/WorkloadManagementSystem/Client/PilotLoggingPlugins/DownloadPlugin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
Pilot logging plugin abstract class. | ||
""" | ||
from abc import ABC, abstractmethod | ||
from DIRAC import S_OK, S_ERROR, gLogger | ||
|
||
sLog = gLogger.getSubLogger(__name__) | ||
|
||
|
||
class DownloadPlugin(ABC): | ||
""" | ||
Remote pilot log retriever base abstract class. It defines abstract methods used to download log files from a remote | ||
storage to the server. | ||
Any pilot logger download plugin should inherit from this class and implement a (sub)set of methods required by | ||
:class:`PilotManagerHandler`. | ||
""" | ||
|
||
@abstractmethod | ||
def getRemotePilotLogs(self, pilotStamp, vo): | ||
""" | ||
Pilot log getter method, carrying the unique pilot identity and a VO name. | ||
:param str pilotStamp: pilot stamp. | ||
:param str vo: VO name of a pilot which generated the logs. | ||
:return: S_OK or S_ERROR | ||
:rtype: dict | ||
""" | ||
|
||
pass |
63 changes: 63 additions & 0 deletions
63
src/DIRAC/WorkloadManagementSystem/Client/PilotLoggingPlugins/FileCacheDownloadPlugin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
""" | ||
File cache pilot log downloader. | ||
""" | ||
import os | ||
import tempfile | ||
from DIRAC import S_OK, S_ERROR, gLogger, gConfig | ||
from DIRAC.DataManagementSystem.Client.DataManager import DataManager | ||
from DIRAC.ConfigurationSystem.Client.Helpers import Registry | ||
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations | ||
from DIRAC.Core.Utilities.Proxy import executeWithUserProxy | ||
from DIRAC.WorkloadManagementSystem.Client.PilotLoggingPlugins.DownloadPlugin import DownloadPlugin | ||
|
||
sLog = gLogger.getSubLogger(__name__) | ||
|
||
|
||
class FileCacheDownloadPlugin(DownloadPlugin): | ||
""" | ||
Class to handle log file download from an SE | ||
""" | ||
|
||
def __init__(self): | ||
""" | ||
Sets the pilot log files location for a WebServer. | ||
""" | ||
self.setup = gConfig.getValue("/DIRAC/Setup", None) | ||
|
||
@executeWithUserProxy | ||
def getRemotePilotLogs(self, pilotStamp, vo=None): | ||
""" | ||
Pilot log getter method, carrying the unique pilot identity and a VO name. | ||
:param str pilotStamp: pilot stamp. | ||
:param str vo: VO name of a user/pilot which generated the logs. | ||
:return: S_OK or S_ERROR | ||
:rtype: dict | ||
""" | ||
|
||
opsHelper = Operations(vo=vo, setup=self.setup) | ||
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) | ||
res = DataManager().getFile(lfn, destinationDir=filepath) | ||
sLog.debug("getFile result:", res) | ||
if not res["OK"]: | ||
sLog.error(f"Failed to contact storage") | ||
return res | ||
if lfn in res["Value"]["Failed"]: | ||
sLog.error("Failed to retrieve a log file:", res["Value"]["Failed"]) | ||
return res | ||
try: | ||
filename = os.path.join(filepath, pilotStamp + ".log") | ||
with open(filename) as f: | ||
stdout = f.read() | ||
except FileNotFoundError as err: | ||
sLog.error(f"Error opening a log file:{filename}", err) | ||
return S_ERROR(repr(err)) | ||
|
||
resultDict = {} | ||
resultDict["StdOut"] = stdout | ||
return S_OK(resultDict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters