-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Integration] Modify dirac-admin-get-pilot-output to get remote pilot log #7105
Merged
fstagni
merged 4 commits into
DIRACGrid:integration
from
martynia:integration_janusz_pilotlogsWrapper_get_dev
Sep 19, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5109e00
feat: pilot log download enhancement: Add remote logs download possib…
martynia 21f3471
feat: add a remote non-finalised log file getter from Tornado
martynia f5613fa
feat: implement log file download from the server
martynia bad7e9e
fix: get classic logs first by default
martynia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
107 changes: 107 additions & 0 deletions
107
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,107 @@ | ||
""" | ||
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 | ||
from DIRAC.WorkloadManagementSystem.Client.TornadoPilotLoggingClient import TornadoPilotLoggingClient | ||
|
||
sLog = gLogger.getSubLogger(__name__) | ||
|
||
|
||
class FileCacheDownloadPlugin(DownloadPlugin): | ||
""" | ||
Class to handle log file download from an SE | ||
""" | ||
|
||
def __init__(self): | ||
""" | ||
Sets the client for downloading incomplete log files from the server cache. | ||
|
||
""" | ||
self.tornadoClient = TornadoPilotLoggingClient() | ||
|
||
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) | ||
uploadPath = opsHelper.getValue("Pilot/UploadPath", "") | ||
lfn = os.path.join(uploadPath, pilotStamp + ".log") | ||
sLog.info("LFN to download: ", lfn) | ||
|
||
# get pilot credentials which uploaded logs to an external storage: | ||
res = opsHelper.getOptionsDict("Shifter/DataManager") | ||
if not res["OK"]: | ||
message = f"No shifter defined for VO: {vo} - needed to retrieve the logs !" | ||
sLog.error(message) | ||
return S_ERROR(message) | ||
|
||
proxyUser = res["Value"].get("User") | ||
proxyGroup = res["Value"].get("Group") | ||
|
||
sLog.info(f"Proxy used for retrieving pilot logs: VO: {vo}, User: {proxyUser}, Group: {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") | ||
return res | ||
if lfn in res["Value"]["Failed"]: | ||
sLog.error("Failed to retrieve a log file:", res["Value"]["Failed"]) | ||
return S_ERROR(f"Failed to retrieve a log file: {res['Value']['Failed']}") | ||
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) | ||
fstagni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@executeWithUserProxy | ||
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 |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really an LFN? Looks like just a path to a file to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is. It is passed to
getFile
laterThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am afraid we have been using this pattern in other places, but
os.path
is not the most precise way to manipulate/create LFNs, as this is OS-dependent. We might argue that we only run on Linux so it does not really matter, but more precise would be to at least to useposixpath
instead (@chaen and @atsareg might comment)