Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6f049c6
feat: Adding JWT support alongside X509 auth
Sp4cSh1p Mar 17, 2025
bad1332
fix: Isort fixed, authorization header and doc
Robin-Van-de-Merghel Mar 19, 2025
2843494
refactor: Changing the request header to a private field
Robin-Van-de-Merghel Mar 19, 2025
8ba74c8
feat: Adding a choice in sendMessage to allow JWT
Robin-Van-de-Merghel Mar 26, 2025
5bc40fd
feat: Adding DiracX config and fetching JWT
Robin-Van-de-Merghel Apr 1, 2025
1ecb0b6
fix: Avoid backslash space
Robin-Van-de-Merghel Apr 1, 2025
bf612ee
fix: Fix for python2 support
Robin-Van-de-Merghel Apr 2, 2025
3cb9b68
fix: Small fixes and python2/3 compatibility
Robin-Van-de-Merghel Apr 2, 2025
672d30f
fix: Changing diracX url, and parameter in sendMessage
Robin-Van-de-Merghel Apr 8, 2025
7eb8ca5
feat: Changing retrieveJWTIfNeeded by a PilotLogin command
Robin-Van-de-Merghel Apr 9, 2025
82bbda3
fix: Fixing comments (removing TODO and adding Dirac requirements)
Robin-Van-de-Merghel Apr 9, 2025
3025d8b
fix: Fixed pilot argument, and pilot login command
Robin-Van-de-Merghel Apr 30, 2025
131080e
fix: Fixed to match the current PR endpoint
Robin-Van-de-Merghel May 2, 2025
5567abb
fix: Fixed lint in pilotCommands (import error)
Robin-Van-de-Merghel May 5, 2025
33d998e
fix: Fixed the name of the PilotLogin
Robin-Van-de-Merghel May 5, 2025
42be675
feat: Aborting when we fetch a pilot and it does not work
Robin-Van-de-Merghel May 5, 2025
1412a18
fix: Small fix of comment
Robin-Van-de-Merghel May 5, 2025
e2dba24
feat: Add multi thread support to refresh tokens
Robin-Van-de-Merghel May 16, 2025
1267c8c
feat: Add thread to refresh tokens
Robin-Van-de-Merghel May 21, 2025
244a064
fix: PilotLogin is not a command anymore, to log-in before the remote…
Robin-Van-de-Merghel May 22, 2025
82f3fa1
feat: Add working logging system
Robin-Van-de-Merghel May 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions Pilot/dirac-pilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
getCommand,
pythonPathCheck,
)

try:
from Pilot.proxyTools import revokePilotToken
except ImportError:
from proxyTools import revokePilotToken

############################

if __name__ == "__main__":
Expand All @@ -64,7 +70,7 @@
sys.stdout.write(bufContent)
# now the remote logger.
remote = pilotParams.pilotLogging and (pilotParams.loggerURL is not None)
if remote:
if remote and pilotParams.jwt:
# In a remote logger enabled Dirac version we would have some classic logger content from a wrapper,
# which we passed in:
receivedContent = ""
Expand All @@ -76,12 +82,18 @@
bufsize=pilotParams.loggerBufsize,
pilotUUID=pilotParams.pilotUUID,
debugFlag=pilotParams.debugFlag,
wnVO=pilotParams.wnVO,
jwt=pilotParams.jwt
)
log.info("Remote logger activated")
log.buffer.write(receivedContent)
log.buffer.write(log.format_to_json(
"INFO",
receivedContent,
))
log.buffer.flush()
log.buffer.write(bufContent)
log.buffer.write(log.format_to_json(
"INFO",
bufContent,
))
else:
log = Logger("Pilot", debugFlag=pilotParams.debugFlag)

Expand All @@ -104,7 +116,7 @@

log.info("Executing commands: %s" % str(pilotParams.commands))

if remote:
if remote and pilotParams.jwt:
# It's safer to cancel the timer here. Each command has got its own logger object with a timer cancelled by the
# finaliser. No need for a timer in the "else" code segment below.
try:
Expand All @@ -122,5 +134,22 @@
log.error("Command %s could not be instantiated" % commandName)
# send the last message and abandon ship.
if remote:
log.buffer.flush()
log.buffer.flush(force=True)
sys.exit(-1)

log.info("Pilot tasks finished.")

if not remote:
log.buffer.flush()

if pilotParams.jwt:
if remote:
log.buffer.flush(force=True)

log.info("Revoking pilot token.")
revokePilotToken(
pilotParams.diracXServer,
pilotParams.pilotUUID,
pilotParams.jwt,
pilotParams.clientID
)
48 changes: 40 additions & 8 deletions Pilot/pilotCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def __init__(self, pilotParams):
import sys
import time
import traceback
import subprocess
from collections import Counter

############################
Expand All @@ -44,7 +43,7 @@ def __init__(self, pilotParams):
from shlex import quote
except ImportError:
from pipes import quote

try:
from Pilot.pilotTools import (
CommandBase,
Expand All @@ -61,6 +60,16 @@ def __init__(self, pilotParams):
safe_listdir,
sendMessage,
)

try:
from Pilot.proxyTools import BaseRequest, refreshTokenLoop
except ImportError:
from proxyTools import BaseRequest, refreshTokenLoop

try:
from urllib.error import HTTPError, URLError
except ImportError:
from urllib2 import HTTPError, URLError
############################


Expand Down Expand Up @@ -92,16 +101,37 @@ def wrapper(self):
self.log.info(
"Flushing the remote logger buffer for pilot on sys.exit(): %s (exit code:%s)" % (pRef, str(exCode))
)
self.log.buffer.flush() # flush the buffer unconditionally (on sys.exit()).
try:
sendMessage(self.log.url, self.log.pilotUUID, self.log.wnVO, "finaliseLogs", {"retCode": str(exCode)})
except Exception as exc:
self.log.error("Remote logger couldn't be finalised %s " % str(exc))
if self.pp.jwt:
try:
sendMessage(self.log.url, self.log.pilotUUID, self.pp.jwt, [
{
"severity": "ERROR",
"message": str(exCode)
},
{
"severity": "ERROR",
"message": traceback.format_exc()
}
])

self.log.buffer.flush(force=True)
except Exception as exc:
self.log.error("Remote logger couldn't be finalised %s " % str(exc))
raise

# No force here because there's no remote logger if we're here
self.log.buffer.flush()
raise
except Exception as exc:
# unexpected exit: document it and bail out.
self.log.error(str(exc))
self.log.error(traceback.format_exc())

if self.pp.jwt:
# Force flush if it's a remote logger
self.log.buffer.flush(force=True)
else:
self.log.buffer.flush()
raise
finally:
self.log.buffer.cancelTimer()
Expand Down Expand Up @@ -132,7 +162,7 @@ def __init__(self, pilotParams):
@logFinalizer
def execute(self):
"""Get host and local user info, and other basic checks, e.g. space available"""

self.log.info("Uname = %s" % " ".join(os.uname()))
self.log.info("Host Name = %s" % socket.gethostname())
self.log.info("Host FQDN = %s" % socket.getfqdn())
Expand Down Expand Up @@ -1232,3 +1262,5 @@ def execute(self):
"""Standard entry point to a pilot command"""
self._setNagiosOptions()
self._runNagiosProbes()


Loading
Loading