Skip to content

Commit 475ad73

Browse files
committed
fix: perform pilot operations with proxies or tokens
1 parent a65399e commit 475ad73

File tree

2 files changed

+52
-11
lines changed

2 files changed

+52
-11
lines changed

src/DIRAC/WorkloadManagementSystem/Service/PilotManagerHandler.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from DIRAC.WorkloadManagementSystem.Client import PilotStatus
1515
from DIRAC.WorkloadManagementSystem.Service.WMSUtilities import (
1616
getPilotCE,
17-
getPilotProxy,
17+
setPilotCredentials,
1818
getPilotRef,
1919
killPilotsInQueues,
2020
)
@@ -135,13 +135,10 @@ def export_getPilotOutput(self, pilotReference):
135135
if not hasattr(ce, "getJobOutput"):
136136
return S_ERROR(f"Pilot output not available for {pilotDict['GridType']} CEs")
137137

138-
result = getPilotProxy(pilotDict)
138+
result = setPilotCredentials(ce, pilotDict)
139139
if not result["OK"]:
140140
return result
141141

142-
proxy = result["Value"]
143-
ce.setProxy(proxy)
144-
145142
result = getPilotRef(pilotReference, pilotDict)
146143
if not result["OK"]:
147144
return result
@@ -213,13 +210,11 @@ def export_getPilotLoggingInfo(self, pilotReference):
213210
self.log.info("Pilot logging not available for", f"{pilotDict['GridType']} CEs")
214211
return S_ERROR(f"Pilot logging not available for {pilotDict['GridType']} CEs")
215212

216-
result = getPilotProxy(pilotDict)
213+
# Set proxy or token for the CE
214+
result = setPilotCredentials(ce, pilotDict)
217215
if not result["OK"]:
218216
return result
219217

220-
proxy = result["Value"]
221-
ce.setProxy(proxy)
222-
223218
result = getPilotRef(pilotReference, pilotDict)
224219
if not result["OK"]:
225220
return result

src/DIRAC/WorkloadManagementSystem/Service/WMSUtilities.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
from DIRAC import S_OK, S_ERROR, gLogger, gConfig
88
from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getQueue
9-
from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getGroupOption
9+
from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getGroupOption, getUsernameForDN
1010
from DIRAC.FrameworkSystem.Client.ProxyManagerClient import gProxyManager
11+
from DIRAC.FrameworkSystem.Client.TokenManagerClient import gTokenManager
1112
from DIRAC.Resources.Computing.ComputingElementFactory import ComputingElementFactory
1213

1314

@@ -49,7 +50,11 @@ def getPilotCE(pilotDict):
4950

5051

5152
def getPilotProxy(pilotDict):
52-
"""Get a proxy bound to a pilot"""
53+
"""Get a proxy bound to a pilot
54+
55+
:param dict pilotDict: pilot parameters
56+
:return: S_OK/S_ERROR with proxy as Value
57+
"""
5358
owner = pilotDict["OwnerDN"]
5459
group = pilotDict["OwnerGroup"]
5560

@@ -62,6 +67,47 @@ def getPilotProxy(pilotDict):
6267
return S_OK(proxy)
6368

6469

70+
def getPilotToken(pilotDict):
71+
"""Get a token corresponding to the pilot
72+
73+
:param dict pilotDict: pilot parameters
74+
:return: S_OK/S_ERROR with token as Value
75+
"""
76+
ownerDN = pilotDict["OwnerDN"]
77+
group = pilotDict["OwnerGroup"]
78+
79+
result = getUsernameForDN(ownerDN)
80+
if not result["OK"]:
81+
return result
82+
username = result["Value"]
83+
result = gTokenManager.getToken(
84+
username=username,
85+
userGroup=group,
86+
requiredTimeLeft=3600,
87+
)
88+
return result
89+
90+
91+
def setPilotCredentials(ce, pilotDict):
92+
"""Instrument the given CE with proxy or token
93+
94+
:param obj ce: CE object
95+
:param pilotDict: pilot parameter dictionary
96+
:return: S_OK/S_ERROR
97+
"""
98+
if "Token" in ce.ceParameters.get("Tag", []):
99+
result = getPilotToken(pilotDict)
100+
if not result["OK"]:
101+
return result
102+
ce.setToken(result["Value"], 3500)
103+
else:
104+
result = getPilotProxy(pilotDict)
105+
if not result["OK"]:
106+
return result
107+
ce.setProxy(result["Value"])
108+
return S_OK()
109+
110+
65111
def getPilotRef(pilotReference, pilotDict):
66112
"""Add the pilotStamp to the pilotReference, if the pilotStamp is in the dictionary,
67113
otherwise return unchanged pilotReference.

0 commit comments

Comments
 (0)