|
33 | 33 |
|
34 | 34 | # # from DIRAC
|
35 | 35 | from DIRAC import S_OK, S_ERROR, gConfig
|
36 |
| -from DIRAC.Core.Base.AgentModule import AgentModule |
37 | 36 | from DIRAC.ConfigurationSystem.Client import PathFinder
|
| 37 | +from DIRAC.Core.Base.AgentModule import AgentModule |
| 38 | +from DIRAC.Core.Utilities.ThreadScheduler import gThreadScheduler |
| 39 | +from DIRAC.Core.Utilities import Time, Network |
| 40 | +from DIRAC.Core.Utilities.DErrno import cmpError |
38 | 41 | from DIRAC.Core.Utilities.ProcessPool import ProcessPool
|
| 42 | +from DIRAC.MonitoringSystem.Client.MonitoringReporter import MonitoringReporter |
39 | 43 | from DIRAC.RequestManagementSystem.Client.ReqClient import ReqClient
|
40 | 44 | from DIRAC.RequestManagementSystem.private.RequestTask import RequestTask
|
41 | 45 |
|
42 |
| -from DIRAC.MonitoringSystem.Client.MonitoringReporter import MonitoringReporter |
43 |
| -from DIRAC.Core.Utilities.ThreadScheduler import gThreadScheduler |
44 |
| -from DIRAC.Core.Utilities import Time, Network |
45 |
| - |
46 |
| -from DIRAC.Core.Utilities.DErrno import cmpError |
47 | 46 |
|
48 | 47 | # # agent name
|
49 | 48 | AGENT_NAME = "RequestManagement/RequestExecutingAgent"
|
| 49 | +# # requests/cycle |
| 50 | +REQUESTSPERCYCLE = 100 |
| 51 | +# # minimal nb of subprocess running |
| 52 | +MINPROCESS = 20 |
| 53 | +# # maximal nb of subprocess executed same time |
| 54 | +MAXPROCESS = 20 |
| 55 | +# # ProcessPool queue size |
| 56 | +QUEUESIZE = 20 |
| 57 | +# # file timeout |
| 58 | +FILETIMEOUT = 300 |
| 59 | +# # operation timeout |
| 60 | +OPERATIONTIMEOUT = 300 |
| 61 | +# # ProcessPool finalization timeout |
| 62 | +POOLTIMEOUT = 900 |
| 63 | +# # ProcessPool sleep time |
| 64 | +POOLSLEEP = 5 |
50 | 65 |
|
51 | 66 |
|
52 | 67 | class AgentConfigError(Exception):
|
@@ -75,111 +90,26 @@ class RequestExecutingAgent(AgentModule):
|
75 | 90 | request processing agent using ProcessPool, Operation handlers and RequestTask
|
76 | 91 | """
|
77 | 92 |
|
78 |
| - # # process pool |
79 |
| - __processPool = None |
80 |
| - # # request cache |
81 |
| - __requestCache = {} |
82 |
| - # # requests/cycle |
83 |
| - __requestsPerCycle = 100 |
84 |
| - # # minimal nb of subprocess running |
85 |
| - __minProcess = 20 |
86 |
| - # # maximal nb of subprocess executed same time |
87 |
| - __maxProcess = 20 |
88 |
| - # # ProcessPool queue size |
89 |
| - __queueSize = 20 |
90 |
| - # # file timeout |
91 |
| - __fileTimeout = 300 |
92 |
| - # # operation timeout |
93 |
| - __operationTimeout = 300 |
94 |
| - # # ProcessPool finalization timeout |
95 |
| - __poolTimeout = 900 |
96 |
| - # # ProcessPool sleep time |
97 |
| - __poolSleep = 5 |
98 |
| - # # placeholder for RequestClient instance |
99 |
| - __requestClient = None |
100 |
| - # # Size of the bulk if use of getRequests. If 0, use getRequest |
101 |
| - __bulkRequest = 0 |
102 |
| - # # Send the monitoring data to ES rather than the Framework/Monitoring |
103 |
| - __rmsMonitoring = False |
104 |
| - |
105 | 93 | def __init__(self, *args, **kwargs):
|
106 | 94 | """c'tor"""
|
107 | 95 | # # call base class ctor
|
108 |
| - AgentModule.__init__(self, *args, **kwargs) |
109 |
| - # # ProcessPool related stuff |
110 |
| - self.__requestsPerCycle = self.am_getOption("RequestsPerCycle", self.__requestsPerCycle) |
111 |
| - self.log.info("Requests/cycle = %d" % self.__requestsPerCycle) |
112 |
| - self.__minProcess = self.am_getOption("MinProcess", self.__minProcess) |
113 |
| - self.log.info("ProcessPool min process = %d" % self.__minProcess) |
114 |
| - self.__maxProcess = self.am_getOption("MaxProcess", self.__maxProcess) |
115 |
| - self.log.info("ProcessPool max process = %d" % self.__maxProcess) |
116 |
| - self.__queueSize = self.am_getOption("ProcessPoolQueueSize", self.__queueSize) |
117 |
| - self.log.info("ProcessPool queue size = %d" % self.__queueSize) |
118 |
| - self.__poolTimeout = int(self.am_getOption("ProcessPoolTimeout", self.__poolTimeout)) |
119 |
| - self.log.info("ProcessPool timeout = %d seconds" % self.__poolTimeout) |
120 |
| - self.__poolSleep = int(self.am_getOption("ProcessPoolSleep", self.__poolSleep)) |
121 |
| - self.log.info("ProcessPool sleep time = %d seconds" % self.__poolSleep) |
122 |
| - self.__bulkRequest = self.am_getOption("BulkRequest", self.__bulkRequest) |
123 |
| - self.log.info("Bulk request size = %d" % self.__bulkRequest) |
124 |
| - self.__rmsMonitoring = self.am_getOption("EnableRMSMonitoring", self.__rmsMonitoring) |
125 |
| - self.log.info("Enable ES RMS Monitoring = %s" % self.__rmsMonitoring) |
126 |
| - |
127 |
| - # # keep config path and agent name |
128 |
| - self.agentName = self.am_getModuleParam("fullName") |
129 |
| - self.__configPath = PathFinder.getAgentSection(self.agentName) |
130 |
| - |
131 |
| - # # operation handlers over here |
132 |
| - opHandlersPath = "%s/%s" % (self.__configPath, "OperationHandlers") |
133 |
| - opHandlers = gConfig.getSections(opHandlersPath) |
134 |
| - if not opHandlers["OK"]: |
135 |
| - self.log.error(opHandlers["Message"]) |
136 |
| - raise AgentConfigError("OperationHandlers section not found in CS under %s" % self.__configPath) |
137 |
| - opHandlers = opHandlers["Value"] |
138 |
| - |
139 |
| - self.timeOuts = dict() |
140 |
| - |
141 |
| - # # handlers dict |
142 |
| - self.handlersDict = dict() |
143 |
| - for opHandler in opHandlers: |
144 |
| - opHandlerPath = "%s/%s/Location" % (opHandlersPath, opHandler) |
145 |
| - opLocation = gConfig.getValue(opHandlerPath, "") |
146 |
| - if not opLocation: |
147 |
| - self.log.error("%s not set for %s operation handler" % (opHandlerPath, opHandler)) |
148 |
| - continue |
149 |
| - self.timeOuts[opHandler] = {"PerFile": self.__fileTimeout, "PerOperation": self.__operationTimeout} |
150 |
| - |
151 |
| - opTimeout = gConfig.getValue("%s/%s/TimeOut" % (opHandlersPath, opHandler), 0) |
152 |
| - if opTimeout: |
153 |
| - self.timeOuts[opHandler]["PerOperation"] = opTimeout |
154 |
| - fileTimeout = gConfig.getValue("%s/%s/TimeOutPerFile" % (opHandlersPath, opHandler), 0) |
155 |
| - if fileTimeout: |
156 |
| - self.timeOuts[opHandler]["PerFile"] = fileTimeout |
157 |
| - |
158 |
| - self.handlersDict[opHandler] = opLocation |
159 |
| - |
160 |
| - self.log.info("Operation handlers:") |
161 |
| - for item in enumerate(self.handlersDict.items()): |
162 |
| - opHandler = item[1][0] |
163 |
| - self.log.info( |
164 |
| - "[%s] %s: %s (timeout: %d s + %d s per file)" |
165 |
| - % ( |
166 |
| - item[0], |
167 |
| - item[1][0], |
168 |
| - item[1][1], |
169 |
| - self.timeOuts[opHandler]["PerOperation"], |
170 |
| - self.timeOuts[opHandler]["PerFile"], |
171 |
| - ) |
172 |
| - ) |
173 |
| - |
174 |
| - if self.__rmsMonitoring: |
175 |
| - self.rmsMonitoringReporter = MonitoringReporter(monitoringType="RMSMonitoring") |
176 |
| - gThreadScheduler.addPeriodicTask(100, self.__rmsMonitoringReporting) |
177 |
| - |
178 |
| - # # create request dict |
179 |
| - self.__requestCache = dict() |
180 |
| - |
181 |
| - # ?? Probably should be removed |
182 |
| - self.FTSMode = self.am_getOption("FTSMode", False) |
| 96 | + super().__init__(*args, **kwargs) |
| 97 | + |
| 98 | + self.__processPool = None |
| 99 | + self.__requestCache = {} |
| 100 | + self.__requestsPerCycle = REQUESTSPERCYCLE |
| 101 | + self.__minProcess = MINPROCESS |
| 102 | + self.__maxProcess = MAXPROCESS |
| 103 | + self.__queueSize = QUEUESIZE |
| 104 | + self.__fileTimeout = FILETIMEOUT |
| 105 | + self.__operationTimeout = OPERATIONTIMEOUT |
| 106 | + self.__poolTimeout = POOLTIMEOUT |
| 107 | + self.__poolSleep = POOLSLEEP |
| 108 | + self.__requestClient = None |
| 109 | + # Size of the bulk if use of getRequests. If 0, use getRequest |
| 110 | + self.__bulkRequest = 0 |
| 111 | + # Send the monitoring data to ES rather than the Framework/Monitoring |
| 112 | + self.__rmsMonitoring = False |
183 | 113 |
|
184 | 114 | def processPool(self):
|
185 | 115 | """facade for ProcessPool"""
|
@@ -270,6 +200,79 @@ def putAllRequests(self):
|
270 | 200 |
|
271 | 201 | def initialize(self):
|
272 | 202 | """initialize agent"""
|
| 203 | + |
| 204 | + # # ProcessPool related stuff |
| 205 | + self.__requestsPerCycle = self.am_getOption("RequestsPerCycle", self.__requestsPerCycle) |
| 206 | + self.log.info("Requests/cycle = %d" % self.__requestsPerCycle) |
| 207 | + self.__minProcess = self.am_getOption("MinProcess", self.__minProcess) |
| 208 | + self.log.info("ProcessPool min process = %d" % self.__minProcess) |
| 209 | + self.__maxProcess = self.am_getOption("MaxProcess", self.__maxProcess) |
| 210 | + self.log.info("ProcessPool max process = %d" % self.__maxProcess) |
| 211 | + self.__queueSize = self.am_getOption("ProcessPoolQueueSize", self.__queueSize) |
| 212 | + self.log.info("ProcessPool queue size = %d" % self.__queueSize) |
| 213 | + self.__poolTimeout = int(self.am_getOption("ProcessPoolTimeout", self.__poolTimeout)) |
| 214 | + self.log.info("ProcessPool timeout = %d seconds" % self.__poolTimeout) |
| 215 | + self.__poolSleep = int(self.am_getOption("ProcessPoolSleep", self.__poolSleep)) |
| 216 | + self.log.info("ProcessPool sleep time = %d seconds" % self.__poolSleep) |
| 217 | + self.__bulkRequest = self.am_getOption("BulkRequest", self.__bulkRequest) |
| 218 | + self.log.info("Bulk request size = %d" % self.__bulkRequest) |
| 219 | + self.__rmsMonitoring = self.am_getOption("EnableRMSMonitoring", self.__rmsMonitoring) |
| 220 | + self.log.info("Enable ES RMS Monitoring = %s" % self.__rmsMonitoring) |
| 221 | + |
| 222 | + # # keep config path and agent name |
| 223 | + self.agentName = self.am_getModuleParam("fullName") |
| 224 | + self.__configPath = PathFinder.getAgentSection(self.agentName) |
| 225 | + |
| 226 | + # # operation handlers over here |
| 227 | + opHandlersPath = "%s/%s" % (self.__configPath, "OperationHandlers") |
| 228 | + opHandlers = gConfig.getSections(opHandlersPath) |
| 229 | + if not opHandlers["OK"]: |
| 230 | + self.log.error(opHandlers["Message"]) |
| 231 | + raise AgentConfigError("OperationHandlers section not found in CS under %s" % self.__configPath) |
| 232 | + opHandlers = opHandlers["Value"] |
| 233 | + |
| 234 | + self.timeOuts = dict() |
| 235 | + |
| 236 | + # # handlers dict |
| 237 | + self.handlersDict = dict() |
| 238 | + for opHandler in opHandlers: |
| 239 | + opHandlerPath = "%s/%s/Location" % (opHandlersPath, opHandler) |
| 240 | + opLocation = gConfig.getValue(opHandlerPath, "") |
| 241 | + if not opLocation: |
| 242 | + self.log.error("%s not set for %s operation handler" % (opHandlerPath, opHandler)) |
| 243 | + continue |
| 244 | + self.timeOuts[opHandler] = {"PerFile": self.__fileTimeout, "PerOperation": self.__operationTimeout} |
| 245 | + |
| 246 | + opTimeout = gConfig.getValue("%s/%s/TimeOut" % (opHandlersPath, opHandler), 0) |
| 247 | + if opTimeout: |
| 248 | + self.timeOuts[opHandler]["PerOperation"] = opTimeout |
| 249 | + fileTimeout = gConfig.getValue("%s/%s/TimeOutPerFile" % (opHandlersPath, opHandler), 0) |
| 250 | + if fileTimeout: |
| 251 | + self.timeOuts[opHandler]["PerFile"] = fileTimeout |
| 252 | + |
| 253 | + self.handlersDict[opHandler] = opLocation |
| 254 | + |
| 255 | + self.log.info("Operation handlers:") |
| 256 | + for item in enumerate(self.handlersDict.items()): |
| 257 | + opHandler = item[1][0] |
| 258 | + self.log.info( |
| 259 | + "[%s] %s: %s (timeout: %d s + %d s per file)" |
| 260 | + % ( |
| 261 | + item[0], |
| 262 | + item[1][0], |
| 263 | + item[1][1], |
| 264 | + self.timeOuts[opHandler]["PerOperation"], |
| 265 | + self.timeOuts[opHandler]["PerFile"], |
| 266 | + ) |
| 267 | + ) |
| 268 | + |
| 269 | + if self.__rmsMonitoring: |
| 270 | + self.rmsMonitoringReporter = MonitoringReporter(monitoringType="RMSMonitoring") |
| 271 | + gThreadScheduler.addPeriodicTask(100, self.__rmsMonitoringReporting) |
| 272 | + |
| 273 | + # # create request dict |
| 274 | + self.__requestCache = dict() |
| 275 | + |
273 | 276 | return S_OK()
|
274 | 277 |
|
275 | 278 | def execute(self):
|
|
0 commit comments