Skip to content

Commit dfd248e

Browse files
authored
Merge pull request #7124 from fstagni/81_TS_RemoveDN
[8.1] TS: username instead of DN
2 parents 63ef9e1 + 1fbf0ab commit dfd248e

18 files changed

+127
-253
lines changed

src/DIRAC/TransformationSystem/Agent/RequestTaskAgent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ def initialize(self):
6565

6666
return S_OK()
6767

68-
def _getClients(self, ownerDN=None, ownerGroup=None):
68+
def _getClients(self, owner=None, ownerGroup=None):
6969
"""Set the clients for task submission.
7070
7171
Here the taskManager becomes a RequestTasks object.
7272
7373
See :func:`DIRAC.TransformationSystem.TaskManagerAgentBase._getClients`.
7474
"""
75-
res = super()._getClients(ownerDN=ownerDN, ownerGroup=ownerGroup)
76-
threadTaskManager = self.requestTasksCls(ownerDN=ownerDN, ownerGroup=ownerGroup)
75+
res = super()._getClients(owner=owner, ownerGroup=ownerGroup)
76+
threadTaskManager = self.requestTasksCls(owner=owner, ownerGroup=ownerGroup)
7777
res.update({"TaskManager": threadTaskManager})
7878
return res

src/DIRAC/TransformationSystem/Agent/TaskManagerAgentBase.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from DIRAC.Core.Utilities.List import breakListIntoChunks
1919
from DIRAC.Core.Utilities.Dictionaries import breakDictionaryIntoChunks
2020
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
21-
from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getDNForUsername, getUsernameForDN
2221
from DIRAC.TransformationSystem.Client.FileReport import FileReport
2322
from DIRAC.TransformationSystem.Client.WorkflowTasks import WorkflowTasks
2423
from DIRAC.TransformationSystem.Client.TransformationClient import TransformationClient
@@ -50,7 +49,7 @@ def __init__(self, *args, **kwargs):
5049
# credentials
5150
self.shifterProxy = None
5251
self.credentials = None
53-
self.credTuple = (None, None, None)
52+
self.credTuple = (None, None)
5453

5554
self.pluginLocation = ""
5655
self.bulkSubmissionFlag = False
@@ -101,17 +100,16 @@ def execute(self):
101100
"""The execution method is transformations that need to be processed"""
102101

103102
# 1. determining which credentials will be used for the submission
104-
owner, ownerGroup, ownerDN = None, None, None
103+
owner, ownerGroup = None, None
105104
# getting the credentials for submission
106105
resProxy = getProxyInfo(proxy=False, disableVOMS=False)
107106
if resProxy["OK"]: # there is a shifterProxy
108107
proxyInfo = resProxy["Value"]
109108
owner = proxyInfo["username"]
110109
ownerGroup = proxyInfo["group"]
111-
ownerDN = proxyInfo["identity"]
112110
self.log.info(f"ShifterProxy: Tasks will be submitted with the credentials {owner}:{ownerGroup}")
113111
elif self.credentials:
114-
owner, ownerGroup, ownerDN = self.credTuple
112+
owner, ownerGroup = self.credTuple
115113
else:
116114
self.log.info("Using per Transformation Credentials!")
117115

@@ -137,7 +135,6 @@ def execute(self):
137135
transformations,
138136
owner=owner,
139137
ownerGroup=ownerGroup,
140-
ownerDN=ownerDN,
141138
)
142139

143140
# 2.2. Determine whether the task files status is to be monitored and updated
@@ -159,7 +156,6 @@ def execute(self):
159156
transformations,
160157
owner=owner,
161158
ownerGroup=ownerGroup,
162-
ownerDN=ownerDN,
163159
)
164160

165161
# Determine whether the checking of reserved tasks is to be performed
@@ -181,7 +177,6 @@ def execute(self):
181177
transformations,
182178
owner=owner,
183179
ownerGroup=ownerGroup,
184-
ownerDN=ownerDN,
185180
)
186181

187182
# Determine whether the submission of tasks is to be performed
@@ -210,7 +205,6 @@ def execute(self):
210205
transformations,
211206
owner=owner,
212207
ownerGroup=ownerGroup,
213-
ownerDN=ownerDN,
214208
)
215209

216210
# now call _execute...
@@ -254,21 +248,21 @@ def _selectTransformations(self, transType=None, status=None, agentType=None):
254248

255249
#############################################################################
256250

257-
def _getClients(self, ownerDN=None, ownerGroup=None):
251+
def _getClients(self, owner=None, ownerGroup=None):
258252
"""Returns the clients used in the threads
259253
260254
This is another function that should be extended.
261255
262256
The clients provided here are defaults, and should be adapted
263257
264-
If ownerDN and ownerGroup are not None the clients will delegate to these credentials
258+
If owner and ownerGroup are not None the clients will delegate to these credentials
265259
266-
:param str ownerDN: DN of the owner of the submitted jobs
260+
:param str owner: owner of the submitted jobs
267261
:param str ownerGroup: group of the owner of the submitted jobs
268262
:returns: dict of Clients
269263
"""
270264
threadTransformationClient = TransformationClient()
271-
threadTaskManager = WorkflowTasks(ownerDN=ownerDN, ownerGroup=ownerGroup)
265+
threadTaskManager = WorkflowTasks(owner=owner, ownerGroup=ownerGroup)
272266
threadTaskManager.pluginLocation = self.pluginLocation
273267

274268
return {"TransformationClient": threadTransformationClient, "TaskManager": threadTaskManager}
@@ -279,7 +273,7 @@ def _execute(self, transDict):
279273
clients = (
280274
self._getClients()
281275
if self.shifterProxy
282-
else self._getClients(ownerGroup=self.credTuple[1], ownerDN=self.credTuple[2])
276+
else self._getClients(owner=self.credTuple[0], ownerGroup=self.credTuple[1])
283277
if self.credentials
284278
else None
285279
)
@@ -293,8 +287,8 @@ def _execute(self, transDict):
293287
transID = transDict["TransformationID"]
294288
operations = transDict["Operations"]
295289
if not (self.credentials or self.shifterProxy):
296-
ownerDN, group = transDict["OwnerDN"], transDict["OwnerGroup"]
297-
clients = self._getClients(ownerDN=ownerDN, ownerGroup=group)
290+
owner, group = transDict["Owner"], transDict["OwnerGroup"]
291+
clients = self._getClients(owner=owner, ownerGroup=group)
298292
self._logInfo("Start processing transformation", method=method, transID=transID)
299293
for operation in operations:
300294
self._logInfo(f"Executing {operation}", method=method, transID=transID)
@@ -656,30 +650,28 @@ def _addOperationForTransformations(
656650
transformations,
657651
owner=None,
658652
ownerGroup=None,
659-
ownerDN=None,
660653
):
661654
"""Fill the operationsOnTransformationDict"""
662655

663656
transformationIDsAndBodies = (
664657
(
665658
transformation["TransformationID"],
666659
transformation["Body"],
667-
transformation["AuthorDN"],
660+
transformation["Author"],
668661
transformation["AuthorGroup"],
669662
)
670663
for transformation in transformations["Value"]
671664
)
672-
for transID, body, t_ownerDN, t_ownerGroup in transformationIDsAndBodies:
665+
for transID, body, t_owner, t_ownerGroup in transformationIDsAndBodies:
673666
if transID in operationsOnTransformationDict:
674667
operationsOnTransformationDict[transID]["Operations"].append(operation)
675668
else:
676669
operationsOnTransformationDict[transID] = {
677670
"TransformationID": transID,
678671
"Body": body,
679672
"Operations": [operation],
680-
"Owner": owner if owner else getUsernameForDN(t_ownerDN)["Value"],
673+
"Owner": owner if owner else t_owner,
681674
"OwnerGroup": ownerGroup if owner else t_ownerGroup,
682-
"OwnerDN": ownerDN if owner else t_ownerDN,
683675
}
684676

685677
def __getCredentials(self):
@@ -696,7 +688,6 @@ def __getCredentials(self):
696688
owner = resCred["Value"]["User"]
697689
ownerGroup = resCred["Value"]["Group"]
698690
# returns a list
699-
ownerDN = getDNForUsername(owner)["Value"][0]
700-
self.credTuple = (owner, ownerGroup, ownerDN)
691+
self.credTuple = (owner, ownerGroup)
701692
self.log.info(f"Cred: Tasks will be submitted with the credentials {owner}:{ownerGroup}")
702693
return S_OK()

src/DIRAC/TransformationSystem/Agent/TransformationCleaningAgent.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ def execute(self):
148148
self._executeClean(transDict)
149149
else:
150150
self.log.info(
151-
f"Cleaning transformation {transDict['TransformationID']} with {transDict['AuthorDN']}, {transDict['AuthorGroup']}"
151+
f"Cleaning transformation {transDict['TransformationID']} with {transDict['Author']}, {transDict['AuthorGroup']}"
152152
)
153153
executeWithUserProxy(self._executeClean)(
154-
transDict, proxyUserDN=transDict["AuthorDN"], proxyUserGroup=transDict["AuthorGroup"]
154+
transDict, proxyUserName=transDict["Author"], proxyUserGroup=transDict["AuthorGroup"]
155155
)
156156
else:
157157
self.log.error("Failed to get transformations", res["Message"])
@@ -164,11 +164,11 @@ def execute(self):
164164
self._executeRemoval(transDict)
165165
else:
166166
self.log.info(
167-
"Removing files for transformation %(TransformationID)s with %(AuthorDN)s, %(AuthorGroup)s"
167+
"Removing files for transformation %(TransformationID)s with %(Author)s, %(AuthorGroup)s"
168168
% transDict
169169
)
170170
executeWithUserProxy(self._executeRemoval)(
171-
transDict, proxyUserDN=transDict["AuthorDN"], proxyUserGroup=transDict["AuthorGroup"]
171+
transDict, proxyUserName=transDict["Author"], proxyUserGroup=transDict["AuthorGroup"]
172172
)
173173
else:
174174
self.log.error("Could not get the transformations", res["Message"])
@@ -186,11 +186,11 @@ def execute(self):
186186
self._executeArchive(transDict)
187187
else:
188188
self.log.info(
189-
"Archiving files for transformation %(TransformationID)s with %(AuthorDN)s, %(AuthorGroup)s"
189+
"Archiving files for transformation %(TransformationID)s with %(Author)s, %(AuthorGroup)s"
190190
% transDict
191191
)
192192
executeWithUserProxy(self._executeArchive)(
193-
transDict, proxyUserDN=transDict["AuthorDN"], proxyUserGroup=transDict["AuthorGroup"]
193+
transDict, proxyUserName=transDict["Author"], proxyUserGroup=transDict["AuthorGroup"]
194194
)
195195
else:
196196
self.log.error("Could not get the transformations", res["Message"])
@@ -244,22 +244,22 @@ def finalize(self):
244244
self._executeClean(transDict)
245245
else:
246246
self.log.info(
247-
f"Cleaning transformation {transDict['TransformationID']} with {transDict['AuthorDN']}, {transDict['AuthorGroup']}"
247+
f"Cleaning transformation {transDict['TransformationID']} with {transDict['Author']}, {transDict['AuthorGroup']}"
248248
)
249249
executeWithUserProxy(self._executeClean)(
250-
transDict, proxyUserDN=transDict["AuthorDN"], proxyUserGroup=transDict["AuthorGroup"]
250+
transDict, proxyUserName=transDict["Author"], proxyUserGroup=transDict["AuthorGroup"]
251251
)
252252

253253
for transDict in toArchive:
254254
if self.shifterProxy:
255255
self._executeArchive(transDict)
256256
else:
257257
self.log.info(
258-
"Archiving files for transformation %(TransformationID)s with %(AuthorDN)s, %(AuthorGroup)s"
258+
"Archiving files for transformation %(TransformationID)s with %(Author)s, %(AuthorGroup)s"
259259
% transDict
260260
)
261261
executeWithUserProxy(self._executeArchive)(
262-
transDict, proxyUserDN=transDict["AuthorDN"], proxyUserGroup=transDict["AuthorGroup"]
262+
transDict, proxyUserName=transDict["Author"], proxyUserGroup=transDict["AuthorGroup"]
263263
)
264264

265265
# Remove JobIDs that were unknown to the TransformationSystem

src/DIRAC/TransformationSystem/Agent/test/Test_Agent_TransformationSystem.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,8 @@ def test_checkReservedTasks(
148148
"TransformationID": 1,
149149
"Operations": ["op1", "op2"],
150150
"Body": "veryBigBody",
151-
"Owner": "prodMan",
152-
"OwnerDN": "/ca=man/user=prodMan",
153-
"OwnerGroup": "prodMans",
151+
"Owner": "prod",
152+
"OwnerGroup": "prods",
154153
}
155154
sOkJobDict = {"OK": True, "Value": {"JobDictionary": {123: "foo", 456: "bar"}}}
156155
sOkJobs = {"OK": True, "Value": {123: "foo", 456: "bar"}}

src/DIRAC/TransformationSystem/Client/RequestTasks.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getDNForUsername
66
from DIRAC.Core.Security.ProxyInfo import getProxyInfo
77
from DIRAC.Core.Utilities.JEncode import decode
8-
98
from DIRAC.RequestManagementSystem.Client.ReqClient import ReqClient
109
from DIRAC.RequestManagementSystem.Client.Request import Request
1110
from DIRAC.RequestManagementSystem.Client.Operation import Operation
@@ -36,7 +35,7 @@ def __init__(
3635
requestClient=None,
3736
requestClass=None,
3837
requestValidator=None,
39-
ownerDN=None,
38+
owner=None,
4039
ownerGroup=None,
4140
):
4241
"""c'tor
@@ -50,11 +49,13 @@ def __init__(
5049
logger = gLogger.getSubLogger(self.__class__.__name__)
5150

5251
super().__init__(transClient, logger)
53-
useCertificates = True if (bool(ownerDN) and bool(ownerGroup)) else False
52+
useCertificates = True if (bool(owner) and bool(ownerGroup)) else False
5453

5554
if not requestClient:
5655
self.requestClient = ReqClient(
57-
useCertificates=useCertificates, delegatedDN=ownerDN, delegatedGroup=ownerGroup
56+
useCertificates=useCertificates,
57+
delegatedDN=getDNForUsername(owner)["Value"][0] if owner else None,
58+
delegatedGroup=ownerGroup,
5859
)
5960
else:
6061
self.requestClient = requestClient

src/DIRAC/TransformationSystem/Client/Transformation.py

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from DIRAC.TransformationSystem.Client.BodyPlugin.BaseBody import BaseBody
1212
from DIRAC.TransformationSystem.Client.TransformationClient import TransformationClient
1313
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
14-
from DIRAC.Core.Security.ProxyInfo import getProxyInfo
1514
from DIRAC.RequestManagementSystem.Client.Operation import Operation
1615

1716
COMPONENT_NAME = "Transformation"
@@ -269,7 +268,7 @@ def getTransformationLogging(self, printOutput=False):
269268
loggingList = res["Value"]
270269
if printOutput:
271270
self._printFormattedDictList(
272-
loggingList, ["Message", "MessageDate", "AuthorDN"], "MessageDate", "MessageDate"
271+
loggingList, ["Message", "MessageDate", "Author"], "MessageDate", "MessageDate"
273272
)
274273
return S_OK(loggingList)
275274

@@ -425,63 +424,19 @@ def getTransformations(
425424
self._printFormattedDictList(res["Value"], outputFields, "TransformationID", orderBy)
426425
return res
427426

428-
#############################################################################
429-
def getAuthorDNfromProxy(self):
430-
"""gets the AuthorDN and username of the transformation from the uploaded proxy"""
431-
username = ""
432-
author = ""
433-
res = getProxyInfo()
434-
if res["OK"]:
435-
author = res["Value"]["identity"]
436-
username = res["Value"]["username"]
437-
else:
438-
gLogger.error(f"Unable to get uploaded proxy Info {res['Message']} ")
439-
return S_ERROR(res["Message"])
440-
441-
res = {"username": username, "authorDN": author}
442-
return S_OK(res)
443-
444427
#############################################################################
445428
def getTransformationsByUser(
446429
self,
447-
authorDN="",
448430
userName="",
449431
transID=[],
450432
transStatus=[],
451-
outputFields=["TransformationID", "Status", "AgentType", "TransformationName", "CreationDate", "AuthorDN"],
433+
outputFields=["TransformationID", "Status", "AgentType", "TransformationName", "CreationDate", "Author"],
452434
orderBy="TransformationID",
453435
printOutput=False,
454436
):
455437
condDict = {}
456-
if authorDN == "":
457-
res = self.getAuthorDNfromProxy()
458-
if not res["OK"]:
459-
gLogger.error(res["Message"])
460-
return S_ERROR(res["Message"])
461-
else:
462-
foundUserName = res["Value"]["username"]
463-
foundAuthor = res["Value"]["authorDN"]
464-
# If the username whom created the uploaded proxy is different than the provided username report error and exit
465-
if not (userName == "" or userName == foundUserName):
466-
gLogger.error(
467-
"Couldn't resolve the authorDN for user '%s' from the uploaded proxy (proxy created by '%s')"
468-
% (userName, foundUserName)
469-
)
470-
return S_ERROR(
471-
"Couldn't resolve the authorDN for user '%s' from the uploaded proxy (proxy created by '%s')"
472-
% (userName, foundUserName)
473-
)
474-
475-
userName = foundUserName
476-
authorDN = foundAuthor
477-
gLogger.info(
478-
"Will list transformations created by user '%s' with status '%s'"
479-
% (userName, ", ".join(transStatus))
480-
)
481-
else:
482-
gLogger.info(f"Will list transformations created by '{authorDN}' with status '{', '.join(transStatus)}'")
483-
484-
condDict["AuthorDN"] = authorDN
438+
gLogger.info(f"Will list transformations created by user '{userName}' with status '{transStatus}'")
439+
condDict["Author"] = userName
485440
if transID:
486441
condDict["TransformationID"] = transID
487442
if transStatus:

0 commit comments

Comments
 (0)