From 0096b56d46c7c2f76651f959b3321950c6033902 Mon Sep 17 00:00:00 2001 From: Federico Stagni Date: Wed, 26 Jul 2023 15:04:29 +0200 Subject: [PATCH] feat: using owner instead of ownerDN --- .../Agent/RequestTaskAgent.py | 6 ++--- .../Agent/TaskManagerAgentBase.py | 26 ++++++++----------- .../Client/RequestTasks.py | 10 ++++--- .../Client/WorkflowTasks.py | 9 ++++--- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/DIRAC/TransformationSystem/Agent/RequestTaskAgent.py b/src/DIRAC/TransformationSystem/Agent/RequestTaskAgent.py index 33f8d94efe2..713f5d89535 100644 --- a/src/DIRAC/TransformationSystem/Agent/RequestTaskAgent.py +++ b/src/DIRAC/TransformationSystem/Agent/RequestTaskAgent.py @@ -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 diff --git a/src/DIRAC/TransformationSystem/Agent/TaskManagerAgentBase.py b/src/DIRAC/TransformationSystem/Agent/TaskManagerAgentBase.py index 0a39a0de0ab..55e1e85b062 100644 --- a/src/DIRAC/TransformationSystem/Agent/TaskManagerAgentBase.py +++ b/src/DIRAC/TransformationSystem/Agent/TaskManagerAgentBase.py @@ -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 @@ -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} @@ -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 ) @@ -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) @@ -651,7 +650,6 @@ def _addOperationForTransformations( transformations, owner=None, ownerGroup=None, - ownerDN=None, ): """Fill the operationsOnTransformationDict""" @@ -659,12 +657,12 @@ def _addOperationForTransformations( ( 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: @@ -672,9 +670,8 @@ def _addOperationForTransformations( "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): @@ -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() diff --git a/src/DIRAC/TransformationSystem/Client/RequestTasks.py b/src/DIRAC/TransformationSystem/Client/RequestTasks.py index d3627313005..8d1b267c357 100644 --- a/src/DIRAC/TransformationSystem/Client/RequestTasks.py +++ b/src/DIRAC/TransformationSystem/Client/RequestTasks.py @@ -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 @@ -35,7 +35,7 @@ def __init__( requestClient=None, requestClass=None, requestValidator=None, - ownerDN=None, + owner=None, ownerGroup=None, ): """c'tor @@ -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 diff --git a/src/DIRAC/TransformationSystem/Client/WorkflowTasks.py b/src/DIRAC/TransformationSystem/Client/WorkflowTasks.py index 9a41c1b0e69..3be2c5dcce4 100644 --- a/src/DIRAC/TransformationSystem/Client/WorkflowTasks.py +++ b/src/DIRAC/TransformationSystem/Client/WorkflowTasks.py @@ -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 @@ -29,7 +30,7 @@ def __init__( jobClass=None, opsH=None, destinationPlugin=None, - ownerDN=None, + owner=None, ownerGroup=None, ): """Generates some default objects. @@ -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