Skip to content

Commit

Permalink
feat: using owner instead of ownerDN
Browse files Browse the repository at this point in the history
  • Loading branch information
fstagni committed Jul 26, 2023
1 parent 16030a4 commit 0096b56
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/DIRAC/TransformationSystem/Agent/RequestTaskAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ def initialize(self):

return S_OK()

def _getClients(self, ownerDN=None, ownerGroup=None):
def _getClients(self, owner=None, ownerGroup=None):
"""Set the clients for task submission.
Here the taskManager becomes a RequestTasks object.
See :func:`DIRAC.TransformationSystem.TaskManagerAgentBase._getClients`.
"""
res = super()._getClients(ownerDN=ownerDN, ownerGroup=ownerGroup)
threadTaskManager = self.requestTasksCls(ownerDN=ownerDN, ownerGroup=ownerGroup)
res = super()._getClients(owner=owner, ownerGroup=ownerGroup)
threadTaskManager = self.requestTasksCls(owner=owner, ownerGroup=ownerGroup)
res.update({"TaskManager": threadTaskManager})
return res
26 changes: 11 additions & 15 deletions src/DIRAC/TransformationSystem/Agent/TaskManagerAgentBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from DIRAC.Core.Utilities.List import breakListIntoChunks
from DIRAC.Core.Utilities.Dictionaries import breakDictionaryIntoChunks
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getDNForUsername, getUsernameForDN
from DIRAC.TransformationSystem.Client.FileReport import FileReport
from DIRAC.TransformationSystem.Client.WorkflowTasks import WorkflowTasks
from DIRAC.TransformationSystem.Client.TransformationClient import TransformationClient
Expand Down Expand Up @@ -249,21 +248,21 @@ def _selectTransformations(self, transType=None, status=None, agentType=None):

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

def _getClients(self, ownerDN=None, ownerGroup=None):
def _getClients(self, owner=None, ownerGroup=None):
"""Returns the clients used in the threads
This is another function that should be extended.
The clients provided here are defaults, and should be adapted
If ownerDN and ownerGroup are not None the clients will delegate to these credentials
If owner and ownerGroup are not None the clients will delegate to these credentials
:param str ownerDN: DN of the owner of the submitted jobs
:param str owner: owner of the submitted jobs
:param str ownerGroup: group of the owner of the submitted jobs
:returns: dict of Clients
"""
threadTransformationClient = TransformationClient()
threadTaskManager = WorkflowTasks(ownerDN=ownerDN, ownerGroup=ownerGroup)
threadTaskManager = WorkflowTasks(owner=owner, ownerGroup=ownerGroup)
threadTaskManager.pluginLocation = self.pluginLocation

return {"TransformationClient": threadTransformationClient, "TaskManager": threadTaskManager}
Expand All @@ -274,7 +273,7 @@ def _execute(self, transDict):
clients = (
self._getClients()
if self.shifterProxy
else self._getClients(ownerGroup=self.credTuple[1], ownerDN=self.credTuple[2])
else self._getClients(owner=self.credTuple[0], ownerGroup=self.credTuple[1])
if self.credentials
else None
)
Expand All @@ -288,8 +287,8 @@ def _execute(self, transDict):
transID = transDict["TransformationID"]
operations = transDict["Operations"]
if not (self.credentials or self.shifterProxy):
ownerDN, group = transDict["OwnerDN"], transDict["OwnerGroup"]
clients = self._getClients(ownerDN=ownerDN, ownerGroup=group)
owner, group = transDict["Owner"], transDict["OwnerGroup"]
clients = self._getClients(owner=owner, ownerGroup=group)
self._logInfo("Start processing transformation", method=method, transID=transID)
for operation in operations:
self._logInfo(f"Executing {operation}", method=method, transID=transID)
Expand Down Expand Up @@ -651,30 +650,28 @@ def _addOperationForTransformations(
transformations,
owner=None,
ownerGroup=None,
ownerDN=None,
):
"""Fill the operationsOnTransformationDict"""

transformationIDsAndBodies = (
(
transformation["TransformationID"],
transformation["Body"],
transformation["AuthorDN"],
transformation["Author"],
transformation["AuthorGroup"],
)
for transformation in transformations["Value"]
)
for transID, body, t_ownerDN, t_ownerGroup in transformationIDsAndBodies:
for transID, body, t_owner, t_ownerGroup in transformationIDsAndBodies:
if transID in operationsOnTransformationDict:
operationsOnTransformationDict[transID]["Operations"].append(operation)
else:
operationsOnTransformationDict[transID] = {
"TransformationID": transID,
"Body": body,
"Operations": [operation],
"Owner": owner if owner else getUsernameForDN(t_ownerDN)["Value"],
"Owner": owner if owner else t_owner,
"OwnerGroup": ownerGroup if owner else t_ownerGroup,
"OwnerDN": ownerDN if owner else t_ownerDN,
}

def __getCredentials(self):
Expand All @@ -691,7 +688,6 @@ def __getCredentials(self):
owner = resCred["Value"]["User"]
ownerGroup = resCred["Value"]["Group"]
# returns a list
ownerDN = getDNForUsername(owner)["Value"][0]
self.credTuple = (owner, ownerGroup, ownerDN)
self.credTuple = (owner, ownerGroup)
self.log.info(f"Cred: Tasks will be submitted with the credentials {owner}:{ownerGroup}")
return S_OK()
10 changes: 6 additions & 4 deletions src/DIRAC/TransformationSystem/Client/RequestTasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from DIRAC import S_OK, S_ERROR, gLogger

from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getDNForUsername
from DIRAC.Core.Security.ProxyInfo import getProxyInfo
from DIRAC.Core.Utilities.JEncode import decode

from DIRAC.RequestManagementSystem.Client.ReqClient import ReqClient
from DIRAC.RequestManagementSystem.Client.Request import Request
from DIRAC.RequestManagementSystem.Client.Operation import Operation
Expand Down Expand Up @@ -35,7 +35,7 @@ def __init__(
requestClient=None,
requestClass=None,
requestValidator=None,
ownerDN=None,
owner=None,
ownerGroup=None,
):
"""c'tor
Expand All @@ -49,11 +49,13 @@ def __init__(
logger = gLogger.getSubLogger(self.__class__.__name__)

super().__init__(transClient, logger)
useCertificates = True if (bool(ownerDN) and bool(ownerGroup)) else False
useCertificates = True if (bool(owner) and bool(ownerGroup)) else False

if not requestClient:
self.requestClient = ReqClient(
useCertificates=useCertificates, delegatedDN=ownerDN, delegatedGroup=ownerGroup
useCertificates=useCertificates,
delegatedDN=getDNForUsername(owner)["Value"][0],
delegatedGroup=ownerGroup,
)
else:
self.requestClient = requestClient
Expand Down
9 changes: 6 additions & 3 deletions src/DIRAC/TransformationSystem/Client/WorkflowTasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from DIRAC import S_OK, S_ERROR, gLogger
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getDNForUsername
from DIRAC.Core.Security.ProxyInfo import getProxyInfo
from DIRAC.Core.Utilities.List import fromChar
from DIRAC.Core.Utilities.DErrno import ETSDATA, ETSUKN
Expand All @@ -29,7 +30,7 @@ def __init__(
jobClass=None,
opsH=None,
destinationPlugin=None,
ownerDN=None,
owner=None,
ownerGroup=None,
):
"""Generates some default objects.
Expand All @@ -42,10 +43,12 @@ def __init__(

super().__init__(transClient, logger)

useCertificates = bool(bool(ownerDN) and bool(ownerGroup))
useCertificates = bool(bool(owner) and bool(ownerGroup))
if not submissionClient:
self.submissionClient = WMSClient(
useCertificates=useCertificates, delegatedDN=ownerDN, delegatedGroup=ownerGroup
useCertificates=useCertificates,
delegatedDN=getDNForUsername(owner)["Value"][0],
delegatedGroup=ownerGroup,
)
else:
self.submissionClient = submissionClient
Expand Down

0 comments on commit 0096b56

Please sign in to comment.