msmonitor 2.3.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- Utils/CPMetrics.py +270 -0
- Utils/CertTools.py +62 -0
- Utils/EmailAlert.py +50 -0
- Utils/ExtendedUnitTestCase.py +62 -0
- Utils/FileTools.py +182 -0
- Utils/IteratorTools.py +80 -0
- Utils/MathUtils.py +31 -0
- Utils/MemoryCache.py +119 -0
- Utils/Patterns.py +24 -0
- Utils/Pipeline.py +137 -0
- Utils/PortForward.py +97 -0
- Utils/ProcessStats.py +103 -0
- Utils/PythonVersion.py +17 -0
- Utils/Signals.py +36 -0
- Utils/TemporaryEnvironment.py +27 -0
- Utils/Throttled.py +227 -0
- Utils/Timers.py +130 -0
- Utils/Timestamps.py +86 -0
- Utils/TokenManager.py +143 -0
- Utils/Tracing.py +60 -0
- Utils/TwPrint.py +98 -0
- Utils/Utilities.py +308 -0
- Utils/__init__.py +11 -0
- WMCore/Algorithms/Alarm.py +39 -0
- WMCore/Algorithms/MathAlgos.py +274 -0
- WMCore/Algorithms/MiscAlgos.py +67 -0
- WMCore/Algorithms/ParseXMLFile.py +115 -0
- WMCore/Algorithms/Permissions.py +27 -0
- WMCore/Algorithms/Singleton.py +58 -0
- WMCore/Algorithms/SubprocessAlgos.py +129 -0
- WMCore/Algorithms/__init__.py +7 -0
- WMCore/Cache/GenericDataCache.py +98 -0
- WMCore/Cache/WMConfigCache.py +572 -0
- WMCore/Cache/__init__.py +0 -0
- WMCore/Configuration.py +651 -0
- WMCore/DAOFactory.py +47 -0
- WMCore/DataStructs/File.py +177 -0
- WMCore/DataStructs/Fileset.py +140 -0
- WMCore/DataStructs/Job.py +182 -0
- WMCore/DataStructs/JobGroup.py +142 -0
- WMCore/DataStructs/JobPackage.py +49 -0
- WMCore/DataStructs/LumiList.py +734 -0
- WMCore/DataStructs/Mask.py +219 -0
- WMCore/DataStructs/MathStructs/ContinuousSummaryHistogram.py +197 -0
- WMCore/DataStructs/MathStructs/DiscreteSummaryHistogram.py +92 -0
- WMCore/DataStructs/MathStructs/SummaryHistogram.py +117 -0
- WMCore/DataStructs/MathStructs/__init__.py +0 -0
- WMCore/DataStructs/Pickleable.py +24 -0
- WMCore/DataStructs/Run.py +256 -0
- WMCore/DataStructs/Subscription.py +175 -0
- WMCore/DataStructs/WMObject.py +47 -0
- WMCore/DataStructs/WorkUnit.py +112 -0
- WMCore/DataStructs/Workflow.py +60 -0
- WMCore/DataStructs/__init__.py +8 -0
- WMCore/Database/CMSCouch.py +1349 -0
- WMCore/Database/ConfigDBMap.py +29 -0
- WMCore/Database/CouchUtils.py +118 -0
- WMCore/Database/DBCore.py +198 -0
- WMCore/Database/DBCreator.py +113 -0
- WMCore/Database/DBExceptionHandler.py +57 -0
- WMCore/Database/DBFactory.py +110 -0
- WMCore/Database/DBFormatter.py +177 -0
- WMCore/Database/Dialects.py +13 -0
- WMCore/Database/ExecuteDAO.py +327 -0
- WMCore/Database/MongoDB.py +241 -0
- WMCore/Database/MySQL/Destroy.py +42 -0
- WMCore/Database/MySQL/ListUserContent.py +20 -0
- WMCore/Database/MySQL/__init__.py +9 -0
- WMCore/Database/MySQLCore.py +132 -0
- WMCore/Database/Oracle/Destroy.py +56 -0
- WMCore/Database/Oracle/ListUserContent.py +19 -0
- WMCore/Database/Oracle/__init__.py +9 -0
- WMCore/Database/ResultSet.py +44 -0
- WMCore/Database/Transaction.py +91 -0
- WMCore/Database/__init__.py +9 -0
- WMCore/Database/ipy_profile_couch.py +438 -0
- WMCore/GroupUser/CouchObject.py +127 -0
- WMCore/GroupUser/Decorators.py +51 -0
- WMCore/GroupUser/Group.py +33 -0
- WMCore/GroupUser/Interface.py +73 -0
- WMCore/GroupUser/User.py +96 -0
- WMCore/GroupUser/__init__.py +11 -0
- WMCore/Lexicon.py +836 -0
- WMCore/MicroService/CherryPyThreads/HeartbeatMonitor.py +6 -0
- WMCore/MicroService/CherryPyThreads/__init__.py +0 -0
- WMCore/MicroService/DataStructs/DefaultStructs.py +101 -0
- WMCore/MicroService/DataStructs/__init__.py +0 -0
- WMCore/MicroService/MSCore/MSAuth.py +153 -0
- WMCore/MicroService/MSCore/MSCore.py +113 -0
- WMCore/MicroService/MSCore/MSManager.py +484 -0
- WMCore/MicroService/MSCore/TaskManager.py +218 -0
- WMCore/MicroService/MSCore/__init__.py +0 -0
- WMCore/MicroService/MSMonitor/MSMonitor.py +270 -0
- WMCore/MicroService/MSMonitor/__init__.py +0 -0
- WMCore/MicroService/Service/Data.py +225 -0
- WMCore/MicroService/Service/RestApiHub.py +46 -0
- WMCore/MicroService/Service/__init__.py +0 -0
- WMCore/MicroService/Tools/Common.py +579 -0
- WMCore/MicroService/Tools/PycurlRucio.py +419 -0
- WMCore/MicroService/Tools/__init__.py +0 -0
- WMCore/MicroService/WebGui/FrontPage.py +56 -0
- WMCore/MicroService/WebGui/__init__.py +0 -0
- WMCore/REST/Auth.py +202 -0
- WMCore/REST/CherryPyPeriodicTask.py +166 -0
- WMCore/REST/Error.py +333 -0
- WMCore/REST/Format.py +642 -0
- WMCore/REST/HeartbeatMonitorBase.py +90 -0
- WMCore/REST/Main.py +623 -0
- WMCore/REST/Server.py +2435 -0
- WMCore/REST/Services.py +24 -0
- WMCore/REST/Test.py +120 -0
- WMCore/REST/Tools.py +38 -0
- WMCore/REST/Validation.py +250 -0
- WMCore/REST/__init__.py +1 -0
- WMCore/ReqMgr/DataStructs/RequestStatus.py +209 -0
- WMCore/ReqMgr/DataStructs/RequestType.py +13 -0
- WMCore/ReqMgr/DataStructs/__init__.py +0 -0
- WMCore/ReqMgr/__init__.py +1 -0
- WMCore/Services/AlertManager/AlertManagerAPI.py +111 -0
- WMCore/Services/AlertManager/__init__.py +0 -0
- WMCore/Services/CRIC/CRIC.py +238 -0
- WMCore/Services/CRIC/__init__.py +0 -0
- WMCore/Services/DBS/DBS3Reader.py +1044 -0
- WMCore/Services/DBS/DBSConcurrency.py +44 -0
- WMCore/Services/DBS/DBSErrors.py +113 -0
- WMCore/Services/DBS/DBSReader.py +23 -0
- WMCore/Services/DBS/DBSUtils.py +139 -0
- WMCore/Services/DBS/DBSWriterObjects.py +381 -0
- WMCore/Services/DBS/ProdException.py +133 -0
- WMCore/Services/DBS/__init__.py +8 -0
- WMCore/Services/FWJRDB/FWJRDBAPI.py +118 -0
- WMCore/Services/FWJRDB/__init__.py +0 -0
- WMCore/Services/HTTPS/HTTPSAuthHandler.py +66 -0
- WMCore/Services/HTTPS/__init__.py +0 -0
- WMCore/Services/LogDB/LogDB.py +201 -0
- WMCore/Services/LogDB/LogDBBackend.py +191 -0
- WMCore/Services/LogDB/LogDBExceptions.py +11 -0
- WMCore/Services/LogDB/LogDBReport.py +85 -0
- WMCore/Services/LogDB/__init__.py +0 -0
- WMCore/Services/MSPileup/__init__.py +0 -0
- WMCore/Services/MSUtils/MSUtils.py +54 -0
- WMCore/Services/MSUtils/__init__.py +0 -0
- WMCore/Services/McM/McM.py +173 -0
- WMCore/Services/McM/__init__.py +8 -0
- WMCore/Services/MonIT/Grafana.py +133 -0
- WMCore/Services/MonIT/__init__.py +0 -0
- WMCore/Services/PyCondor/PyCondorAPI.py +154 -0
- WMCore/Services/PyCondor/PyCondorUtils.py +105 -0
- WMCore/Services/PyCondor/__init__.py +0 -0
- WMCore/Services/ReqMgr/ReqMgr.py +261 -0
- WMCore/Services/ReqMgr/__init__.py +0 -0
- WMCore/Services/ReqMgrAux/ReqMgrAux.py +419 -0
- WMCore/Services/ReqMgrAux/__init__.py +0 -0
- WMCore/Services/RequestDB/RequestDBReader.py +267 -0
- WMCore/Services/RequestDB/RequestDBWriter.py +39 -0
- WMCore/Services/RequestDB/__init__.py +0 -0
- WMCore/Services/Requests.py +624 -0
- WMCore/Services/Rucio/Rucio.py +1287 -0
- WMCore/Services/Rucio/RucioUtils.py +74 -0
- WMCore/Services/Rucio/__init__.py +0 -0
- WMCore/Services/RucioConMon/RucioConMon.py +128 -0
- WMCore/Services/RucioConMon/__init__.py +0 -0
- WMCore/Services/Service.py +400 -0
- WMCore/Services/StompAMQ/__init__.py +0 -0
- WMCore/Services/TagCollector/TagCollector.py +155 -0
- WMCore/Services/TagCollector/XMLUtils.py +98 -0
- WMCore/Services/TagCollector/__init__.py +0 -0
- WMCore/Services/UUIDLib.py +13 -0
- WMCore/Services/UserFileCache/UserFileCache.py +160 -0
- WMCore/Services/UserFileCache/__init__.py +8 -0
- WMCore/Services/WMAgent/WMAgent.py +63 -0
- WMCore/Services/WMAgent/__init__.py +0 -0
- WMCore/Services/WMArchive/CMSSWMetrics.py +526 -0
- WMCore/Services/WMArchive/DataMap.py +463 -0
- WMCore/Services/WMArchive/WMArchive.py +33 -0
- WMCore/Services/WMArchive/__init__.py +0 -0
- WMCore/Services/WMBS/WMBS.py +97 -0
- WMCore/Services/WMBS/__init__.py +0 -0
- WMCore/Services/WMStats/DataStruct/RequestInfoCollection.py +300 -0
- WMCore/Services/WMStats/DataStruct/__init__.py +0 -0
- WMCore/Services/WMStats/WMStatsPycurl.py +145 -0
- WMCore/Services/WMStats/WMStatsReader.py +445 -0
- WMCore/Services/WMStats/WMStatsWriter.py +273 -0
- WMCore/Services/WMStats/__init__.py +0 -0
- WMCore/Services/WMStatsServer/WMStatsServer.py +134 -0
- WMCore/Services/WMStatsServer/__init__.py +0 -0
- WMCore/Services/WorkQueue/WorkQueue.py +492 -0
- WMCore/Services/WorkQueue/__init__.py +0 -0
- WMCore/Services/__init__.py +8 -0
- WMCore/Services/pycurl_manager.py +574 -0
- WMCore/WMBase.py +50 -0
- WMCore/WMConnectionBase.py +164 -0
- WMCore/WMException.py +183 -0
- WMCore/WMExceptions.py +269 -0
- WMCore/WMFactory.py +76 -0
- WMCore/WMInit.py +228 -0
- WMCore/WMLogging.py +108 -0
- WMCore/Wrappers/JsonWrapper/JSONThunker.py +342 -0
- WMCore/Wrappers/JsonWrapper/__init__.py +7 -0
- WMCore/Wrappers/__init__.py +6 -0
- WMCore/__init__.py +10 -0
- msmonitor-2.3.10.data/data/bin/wmc-dist-patch +15 -0
- msmonitor-2.3.10.data/data/bin/wmc-dist-unpatch +8 -0
- msmonitor-2.3.10.data/data/bin/wmc-httpd +3 -0
- msmonitor-2.3.10.dist-info/LICENSE +202 -0
- msmonitor-2.3.10.dist-info/METADATA +21 -0
- msmonitor-2.3.10.dist-info/NOTICE +16 -0
- msmonitor-2.3.10.dist-info/RECORD +210 -0
- msmonitor-2.3.10.dist-info/WHEEL +5 -0
- msmonitor-2.3.10.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Python thread pool, see
|
|
3
|
+
http://code.activestate.com/recipes/577187-python-thread-pool/
|
|
4
|
+
Author: Valentin Kuznetsov <vkuznet [AT] gmail [DOT] com>
|
|
5
|
+
"""
|
|
6
|
+
# futures
|
|
7
|
+
from __future__ import division
|
|
8
|
+
|
|
9
|
+
from builtins import range, object
|
|
10
|
+
from future import standard_library
|
|
11
|
+
standard_library.install_aliases()
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# system modules
|
|
15
|
+
import time
|
|
16
|
+
import json
|
|
17
|
+
import hashlib
|
|
18
|
+
import threading
|
|
19
|
+
from queue import Queue
|
|
20
|
+
|
|
21
|
+
# WMCore modules
|
|
22
|
+
from Utils.PythonVersion import PY3
|
|
23
|
+
from WMCore.MicroService.Tools.Common import getMSLogger
|
|
24
|
+
from Utils.Utilities import encodeUnicodeToBytesConditional
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def genkey(query):
|
|
28
|
+
"""
|
|
29
|
+
Generate a new key-hash for a given query. We use md5 hash for the
|
|
30
|
+
query and key is just hex representation of this hash.
|
|
31
|
+
"""
|
|
32
|
+
if isinstance(query, dict):
|
|
33
|
+
record = dict(query)
|
|
34
|
+
query = json.JSONEncoder(sort_keys=True).encode(record)
|
|
35
|
+
keyhash = hashlib.md5()
|
|
36
|
+
keyhash.update(encodeUnicodeToBytesConditional(query, condition=PY3))
|
|
37
|
+
return keyhash.hexdigest()
|
|
38
|
+
|
|
39
|
+
def set_thread_name(ident, name):
|
|
40
|
+
"Set thread name for given identified"
|
|
41
|
+
for thr in threading.enumerate():
|
|
42
|
+
if thr.ident == ident:
|
|
43
|
+
thr.name = name
|
|
44
|
+
break
|
|
45
|
+
|
|
46
|
+
class StoppableThread(threading.Thread):
|
|
47
|
+
"""Thread class with a stop() method. The thread itself has to check
|
|
48
|
+
regularly for the stopped() condition."""
|
|
49
|
+
|
|
50
|
+
def __init__(self, target, name, args):
|
|
51
|
+
super(StoppableThread, self).__init__(target=target, name=name, args=args)
|
|
52
|
+
self._stop_event = threading.Event()
|
|
53
|
+
|
|
54
|
+
def stop(self):
|
|
55
|
+
"Set event to stop the thread"
|
|
56
|
+
self._stop_event.set()
|
|
57
|
+
|
|
58
|
+
def stopped(self):
|
|
59
|
+
"Return stopped status of the thread"
|
|
60
|
+
return self._stop_event.is_set()
|
|
61
|
+
|
|
62
|
+
def running(self):
|
|
63
|
+
"Return running status of the thread"
|
|
64
|
+
return not self._stop_event.is_set()
|
|
65
|
+
|
|
66
|
+
def start_new_thread(name, func, args, unique=False):
|
|
67
|
+
"Wrapper wroung standard thread.strart_new_thread call"
|
|
68
|
+
if unique:
|
|
69
|
+
threads = sorted(threading.enumerate())
|
|
70
|
+
for thr in threads:
|
|
71
|
+
if name == thr.name:
|
|
72
|
+
return thr
|
|
73
|
+
# thr = threading.Thread(target=func, name=name, args=args)
|
|
74
|
+
thr = StoppableThread(target=func, name=name, args=args)
|
|
75
|
+
thr.daemon = True
|
|
76
|
+
thr.start()
|
|
77
|
+
return thr
|
|
78
|
+
|
|
79
|
+
class UidSet(object):
|
|
80
|
+
"UID holder keeps track of uid frequency"
|
|
81
|
+
def __init__(self):
|
|
82
|
+
self.set = {}
|
|
83
|
+
|
|
84
|
+
def add(self, uid):
|
|
85
|
+
"Add given uid or increment uid occurence in a set"
|
|
86
|
+
if not uid:
|
|
87
|
+
return
|
|
88
|
+
if uid in self.set:
|
|
89
|
+
self.set[uid] += 1
|
|
90
|
+
else:
|
|
91
|
+
self.set[uid] = 1
|
|
92
|
+
|
|
93
|
+
def discard(self, uid):
|
|
94
|
+
"Either discard or downgrade uid occurence in a set"
|
|
95
|
+
if uid in self.set:
|
|
96
|
+
self.set[uid] -= 1
|
|
97
|
+
if uid in self.set and not self.set[uid]:
|
|
98
|
+
del self.set[uid]
|
|
99
|
+
|
|
100
|
+
def __contains__(self, uid):
|
|
101
|
+
"Check if uid present in a set"
|
|
102
|
+
if uid in self.set:
|
|
103
|
+
return True
|
|
104
|
+
return False
|
|
105
|
+
|
|
106
|
+
def get(self, uid):
|
|
107
|
+
"Get value for given uid"
|
|
108
|
+
return self.set.get(uid, 0)
|
|
109
|
+
|
|
110
|
+
class Worker(threading.Thread):
|
|
111
|
+
"""Thread executing worker from a given tasks queue"""
|
|
112
|
+
def __init__(self, name, taskq, pidq, uidq, logger=None):
|
|
113
|
+
self.logger = getMSLogger(verbose=True, logger=logger)
|
|
114
|
+
threading.Thread.__init__(self, name=name)
|
|
115
|
+
self.exit = 0
|
|
116
|
+
self.tasks = taskq
|
|
117
|
+
self.pids = pidq
|
|
118
|
+
self.uids = uidq
|
|
119
|
+
self.daemon = True
|
|
120
|
+
self.start()
|
|
121
|
+
|
|
122
|
+
def force_exit(self):
|
|
123
|
+
"""Force run loop to exit in a hard way"""
|
|
124
|
+
self.exit = 1
|
|
125
|
+
|
|
126
|
+
def run(self):
|
|
127
|
+
"""Run thread loop"""
|
|
128
|
+
while True:
|
|
129
|
+
if self.exit:
|
|
130
|
+
return
|
|
131
|
+
task = self.tasks.get()
|
|
132
|
+
if task is None:
|
|
133
|
+
return
|
|
134
|
+
if self.exit:
|
|
135
|
+
return
|
|
136
|
+
evt, pid, func, args, kwargs = task
|
|
137
|
+
try:
|
|
138
|
+
func(*args, **kwargs)
|
|
139
|
+
self.pids.discard(pid)
|
|
140
|
+
except Exception as exc:
|
|
141
|
+
self.pids.discard(pid)
|
|
142
|
+
msg = "func=%s args=%s kwargs=%s" % (func, args, kwargs)
|
|
143
|
+
self.logger.error('error %s, call %s', str(exc), msg)
|
|
144
|
+
evt.set()
|
|
145
|
+
|
|
146
|
+
class TaskManager(object):
|
|
147
|
+
"""
|
|
148
|
+
Task manager class based on thread module which
|
|
149
|
+
executes assigned tasks concurently. It uses a
|
|
150
|
+
pool of thread workers, queue of tasks and pid
|
|
151
|
+
set to monitor jobs execution.
|
|
152
|
+
|
|
153
|
+
.. doctest::
|
|
154
|
+
|
|
155
|
+
Use case:
|
|
156
|
+
mgr = TaskManager()
|
|
157
|
+
jobs = []
|
|
158
|
+
jobs.append(mgr.spawn(func, args))
|
|
159
|
+
mgr.joinall(jobs)
|
|
160
|
+
|
|
161
|
+
"""
|
|
162
|
+
def __init__(self, nworkers=10, name='TaskManager', logger=None):
|
|
163
|
+
self.logger = getMSLogger(verbose=True, logger=logger)
|
|
164
|
+
self.name = name
|
|
165
|
+
self.pids = set()
|
|
166
|
+
self.uids = UidSet()
|
|
167
|
+
self.tasks = Queue()
|
|
168
|
+
self.workers = [Worker(name, self.tasks, self.pids, self.uids, logger) \
|
|
169
|
+
for _ in range(0, nworkers)]
|
|
170
|
+
|
|
171
|
+
def status(self):
|
|
172
|
+
"Return status of task manager queue"
|
|
173
|
+
info = {'qsize':self.tasks.qsize(), 'full':self.tasks.full(),
|
|
174
|
+
'unfinished':self.tasks.unfinished_tasks,
|
|
175
|
+
'nworkers':len(self.workers)}
|
|
176
|
+
return {self.name: info}
|
|
177
|
+
|
|
178
|
+
def nworkers(self):
|
|
179
|
+
"""Return number of workers associated with this manager"""
|
|
180
|
+
return len(self.workers)
|
|
181
|
+
|
|
182
|
+
def spawn(self, func, *args, **kwargs):
|
|
183
|
+
"""Spawn new process for given function"""
|
|
184
|
+
pid = kwargs.get('pid', genkey(str(args) + str(kwargs)))
|
|
185
|
+
evt = threading.Event()
|
|
186
|
+
if not pid in self.pids:
|
|
187
|
+
self.pids.add(pid)
|
|
188
|
+
task = (evt, pid, func, args, kwargs)
|
|
189
|
+
self.tasks.put(task)
|
|
190
|
+
else:
|
|
191
|
+
# the event was not added to task list, invoke set()
|
|
192
|
+
# to pass it in wait() call, see joinall
|
|
193
|
+
evt.set()
|
|
194
|
+
return evt, pid
|
|
195
|
+
|
|
196
|
+
def remove(self, pid):
|
|
197
|
+
"""Remove pid and associative process from the queue"""
|
|
198
|
+
self.pids.discard(pid)
|
|
199
|
+
|
|
200
|
+
def is_alive(self, pid):
|
|
201
|
+
"""Check worker queue if given pid of the process is still running"""
|
|
202
|
+
return pid in self.pids
|
|
203
|
+
|
|
204
|
+
def clear(self, tasks):
|
|
205
|
+
"""
|
|
206
|
+
Clear all tasks in a queue. It allows current jobs to run, but will
|
|
207
|
+
block all new requests till workers event flag is set again
|
|
208
|
+
"""
|
|
209
|
+
_ = [t[0].clear() for t in tasks] # each task is return from spawn, i.e. a pair (evt, pid)
|
|
210
|
+
|
|
211
|
+
def joinall(self, tasks):
|
|
212
|
+
"""Join all tasks in a queue and quit"""
|
|
213
|
+
_ = [t[0].wait() for t in tasks] # each task is return from spawn, i.e. a pair (evt, pid)
|
|
214
|
+
|
|
215
|
+
def quit(self):
|
|
216
|
+
"""Put None task to all workers and let them quit"""
|
|
217
|
+
_ = [self.tasks.put(None) for _ in self.workers]
|
|
218
|
+
time.sleep(1) # let workers threads cool-off and quit
|
|
File without changes
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"""
|
|
2
|
+
File : MSMonitor.py
|
|
3
|
+
Author : Valentin Kuznetsov <vkuznet AT gmail dot com>
|
|
4
|
+
Alan Malta <alan dot malta AT cern dot ch >
|
|
5
|
+
Description: MSMonitor class provide whole logic behind
|
|
6
|
+
the transferor monitoring module.
|
|
7
|
+
"""
|
|
8
|
+
# futures
|
|
9
|
+
from __future__ import division, print_function
|
|
10
|
+
|
|
11
|
+
# system modules
|
|
12
|
+
import time
|
|
13
|
+
|
|
14
|
+
# WMCore modules
|
|
15
|
+
from WMCore.MicroService.DataStructs.DefaultStructs import MONITOR_REPORT
|
|
16
|
+
from WMCore.MicroService.MSCore.MSCore import MSCore
|
|
17
|
+
from WMCore.Services.Rucio.Rucio import Rucio
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class MSMonitor(MSCore):
|
|
21
|
+
"""
|
|
22
|
+
MSMonitor class provide whole logic behind
|
|
23
|
+
the transferor monitoring module.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self, msConfig, logger=None):
|
|
27
|
+
super(MSMonitor, self).__init__(msConfig, logger=logger)
|
|
28
|
+
# update interval is used to check records in CouchDB and update them
|
|
29
|
+
# after this interval, default 6h
|
|
30
|
+
self.updateInterval = self.msConfig.get('updateInterval', 6 * 60 * 60)
|
|
31
|
+
self.rucio = Rucio(acct=self.msConfig['rucioAccount'],
|
|
32
|
+
hostUrl=self.msConfig['rucioUrl'],
|
|
33
|
+
authUrl=self.msConfig['rucioAuthUrl'],
|
|
34
|
+
configDict={"logger": self.logger, "user_agent": "WMCore-MSMonitor"})
|
|
35
|
+
|
|
36
|
+
def updateCaches(self):
|
|
37
|
+
"""
|
|
38
|
+
Fetch some data required for the monitoring logic, e.g.:
|
|
39
|
+
* all campaign configuration
|
|
40
|
+
* all transfer records from backend DB
|
|
41
|
+
:return: True if all of them succeeded, else False
|
|
42
|
+
"""
|
|
43
|
+
campaigns = self.reqmgrAux.getCampaignConfig("ALL_DOCS")
|
|
44
|
+
transferRecords = self.reqmgrAux.getTransferInfo('ALL_DOCS')
|
|
45
|
+
cdict = {}
|
|
46
|
+
if not campaigns:
|
|
47
|
+
self.logger.warning("Failed to fetch campaign configurations")
|
|
48
|
+
if not transferRecords:
|
|
49
|
+
self.logger.warning("Failed to fetch transfer records")
|
|
50
|
+
else:
|
|
51
|
+
for camp in campaigns:
|
|
52
|
+
cdict[camp['CampaignName']] = camp
|
|
53
|
+
return cdict, transferRecords
|
|
54
|
+
|
|
55
|
+
def filterTransferDocs(self, requests, transferDocs):
|
|
56
|
+
"""
|
|
57
|
+
Given a list of requests in the `staging` status and all the
|
|
58
|
+
transfer documents; select the transfer documents that:
|
|
59
|
+
* match against a workflow in requests
|
|
60
|
+
* haven't been updated over the last updateInterval seconds
|
|
61
|
+
:param requests: list of workflow names
|
|
62
|
+
:param transferDocs: list of transfer documents
|
|
63
|
+
:return: a filtered out list of transfer documents
|
|
64
|
+
"""
|
|
65
|
+
now = time.time()
|
|
66
|
+
newTransferDocs = []
|
|
67
|
+
self.logger.info("Matching %d requests to %d transfer documents...",
|
|
68
|
+
len(requests), len(transferDocs))
|
|
69
|
+
for record in transferDocs:
|
|
70
|
+
if record['workflowName'] in requests:
|
|
71
|
+
if now - record['lastUpdate'] > self.updateInterval:
|
|
72
|
+
newTransferDocs.append(record)
|
|
73
|
+
msg = "Only %d transfer documents passed the status and timestamp filter."
|
|
74
|
+
self.logger.info(msg, len(newTransferDocs))
|
|
75
|
+
return newTransferDocs
|
|
76
|
+
|
|
77
|
+
def execute(self, reqStatus):
|
|
78
|
+
"""
|
|
79
|
+
Executes the MS monitoring logic, see
|
|
80
|
+
https://github.com/dmwm/WMCore/wiki/ReqMgr2-MicroService-Monitor
|
|
81
|
+
|
|
82
|
+
:param reqStatus: request status to process
|
|
83
|
+
:return: a summary of the activity of the last cycle
|
|
84
|
+
"""
|
|
85
|
+
summary = dict(MONITOR_REPORT)
|
|
86
|
+
try:
|
|
87
|
+
# get requests from ReqMgr2 data-service for given status
|
|
88
|
+
# here with detail=False we get back list of records
|
|
89
|
+
requests = self.reqmgr2.getRequestByStatus([reqStatus], detail=False)
|
|
90
|
+
self.logger.info(' retrieved %s requests in status: %s', len(requests), reqStatus)
|
|
91
|
+
|
|
92
|
+
campaigns, transferRecords = self.updateCaches()
|
|
93
|
+
self.updateReportDict(summary, "total_num_campaigns", len(campaigns))
|
|
94
|
+
self.updateReportDict(summary, "total_num_transfers", len(transferRecords))
|
|
95
|
+
if not campaigns or not transferRecords:
|
|
96
|
+
# then wait until the next cycle
|
|
97
|
+
msg = "Failed to fetch data from one of the data sources. Retrying again in the next cycle"
|
|
98
|
+
self.logger.error(msg)
|
|
99
|
+
self.updateReportDict(summary, "error", msg)
|
|
100
|
+
return summary
|
|
101
|
+
transferRecords = self.filterTransferDocs(requests, transferRecords)
|
|
102
|
+
self.updateReportDict(summary, "filtered_transfer_docs", len(transferRecords))
|
|
103
|
+
except Exception as ex: # general error
|
|
104
|
+
msg = 'Unknown exception bootstrapping the MSMonitor thread. Error: %s', str(ex)
|
|
105
|
+
self.logger.exception(msg)
|
|
106
|
+
self.updateReportDict(summary, "error", msg)
|
|
107
|
+
return summary
|
|
108
|
+
|
|
109
|
+
try:
|
|
110
|
+
# keep track of request and their new statuses
|
|
111
|
+
skippedWorkflows = self.getTransferInfo(transferRecords)
|
|
112
|
+
requestsToStage = self.getCompletedWorkflows(transferRecords, campaigns)
|
|
113
|
+
failedDocs = self.updateTransferDocs(transferRecords, skippedWorkflows)
|
|
114
|
+
self.updateReportDict(summary, "success_transfer_doc_update",
|
|
115
|
+
len(transferRecords) - len(failedDocs) - len(skippedWorkflows))
|
|
116
|
+
self.updateReportDict(summary, "failed_transfer_doc_update", len(failedDocs))
|
|
117
|
+
# finally, update statuses for requests
|
|
118
|
+
for reqName in requestsToStage:
|
|
119
|
+
if reqName in failedDocs:
|
|
120
|
+
msg = "Can't proceed with status transition for %s, because" % reqName
|
|
121
|
+
msg += "the transfer document failed to get updated"
|
|
122
|
+
self.logger.warning(msg)
|
|
123
|
+
continue
|
|
124
|
+
self.change(reqName, 'staged', self.__class__.__name__)
|
|
125
|
+
self.updateReportDict(summary, "request_status_updated",
|
|
126
|
+
summary['success_transfer_doc_update'] - summary['failed_transfer_doc_update'])
|
|
127
|
+
msg = "%s processed %d transfer records, where " % (self.__class__.__name__, len(transferRecords))
|
|
128
|
+
msg += "%d completed their data transfers, " % len(requestsToStage)
|
|
129
|
+
msg += "%d failed to contact the DM system and were skipped in this cycle and " % len(skippedWorkflows)
|
|
130
|
+
msg += "%d failed to get their transfer documents updated in CouchDB." % len(failedDocs)
|
|
131
|
+
self.logger.info(msg)
|
|
132
|
+
except Exception as ex:
|
|
133
|
+
msg = "Unknown exception processing the transfer records. Error: %s" % str(ex)
|
|
134
|
+
self.logger.exception(msg)
|
|
135
|
+
self.updateReportDict(summary, "error", msg)
|
|
136
|
+
return summary
|
|
137
|
+
|
|
138
|
+
def getTransferInfo(self, transferRecords):
|
|
139
|
+
"""
|
|
140
|
+
Contact the data management tool in order to get a status
|
|
141
|
+
update for the transfer request.
|
|
142
|
+
:param transferRecords: list of transfer records
|
|
143
|
+
:return skippedWorkflows: a list of workflow names which a call to the data
|
|
144
|
+
management system did not succeed
|
|
145
|
+
"""
|
|
146
|
+
# FIXME: create concurrent rucio calls using multi_getdata
|
|
147
|
+
skippedWorkflows = []
|
|
148
|
+
tstamp = int(time.time())
|
|
149
|
+
for doc in transferRecords:
|
|
150
|
+
self.logger.debug("Checking transfers for: %s", doc['workflowName'])
|
|
151
|
+
if not doc['transfers']:
|
|
152
|
+
# nothing to be done, simply update the document last timestamp
|
|
153
|
+
doc['lastUpdate'] = tstamp
|
|
154
|
+
continue
|
|
155
|
+
|
|
156
|
+
try:
|
|
157
|
+
for rec in doc['transfers']:
|
|
158
|
+
# obtain new transfer ids and completion for given dataset
|
|
159
|
+
completion = self._getRucioTransferstatus(rec['transferIDs'])
|
|
160
|
+
rec['completion'].append(round(completion, 3))
|
|
161
|
+
doc['lastUpdate'] = tstamp
|
|
162
|
+
except Exception as exc:
|
|
163
|
+
msg = "Unknown exception checking workflow %s. Error: %s"
|
|
164
|
+
self.logger.exception(msg, doc['workflowName'], str(exc))
|
|
165
|
+
skippedWorkflows.append(doc['workflowName'])
|
|
166
|
+
return skippedWorkflows
|
|
167
|
+
|
|
168
|
+
def _getRucioTransferstatus(self, rulesList):
|
|
169
|
+
"""
|
|
170
|
+
Given a list of Rucio rules ID - for a given input data - check the
|
|
171
|
+
overall transfer status from Rucio
|
|
172
|
+
:param rulesList: list of rules ID
|
|
173
|
+
:return: the overall transfers percent completion
|
|
174
|
+
|
|
175
|
+
The Rucio getRule API returns data in the form of:
|
|
176
|
+
{u'account': u'transfer_ops',
|
|
177
|
+
u'grouping': u'ALL',
|
|
178
|
+
u'id': u'40cbe787a42b4f6e991611f6fac3bb11',
|
|
179
|
+
u'locked': True,
|
|
180
|
+
u'locks_ok_cnt': 8,
|
|
181
|
+
u'locks_replicating_cnt': 0,
|
|
182
|
+
u'locks_stuck_cnt': 0,
|
|
183
|
+
u'meta': None,
|
|
184
|
+
etc etc
|
|
185
|
+
NOTE: completion in Rucio is different than in PhEDEx. PhEDEx gives the
|
|
186
|
+
percentage value; while Rucio gives the ratio (0 - 1).
|
|
187
|
+
"""
|
|
188
|
+
completion = []
|
|
189
|
+
for ruleID in rulesList:
|
|
190
|
+
# if we query by dataset and the subscription was at block level,
|
|
191
|
+
# we get an empty response. So always wildcard the block parameter
|
|
192
|
+
data = self.rucio.getRule(ruleID)
|
|
193
|
+
if not data:
|
|
194
|
+
msg = "Failed to retrieve rule information from Rucio for rule ID: {}".format(ruleID)
|
|
195
|
+
raise RuntimeError(msg)
|
|
196
|
+
|
|
197
|
+
if data['state'] == "OK":
|
|
198
|
+
lockCompletion = 100.0
|
|
199
|
+
else:
|
|
200
|
+
totalLocks = data['locks_ok_cnt'] + data['locks_replicating_cnt'] + data['locks_stuck_cnt']
|
|
201
|
+
try:
|
|
202
|
+
lockCompletion = (data['locks_ok_cnt'] / totalLocks) * 100
|
|
203
|
+
except ZeroDivisionError:
|
|
204
|
+
self.logger.warning("Rule does not have any lock counts yet. Rule data: %s", data)
|
|
205
|
+
lockCompletion = 0
|
|
206
|
+
completion.append(lockCompletion)
|
|
207
|
+
self.logger.info("Rule ID: %s has a completion rate of: %s%%", ruleID, lockCompletion)
|
|
208
|
+
self.logger.debug("Rule ID: %s, DID: %s, state: %s, grouping: %s, rse_expression: %s",
|
|
209
|
+
ruleID, data['name'], data['state'], data['grouping'], data['rse_expression'])
|
|
210
|
+
if not completion:
|
|
211
|
+
return 0
|
|
212
|
+
return sum(completion) / len(completion)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def getCompletedWorkflows(self, transfers, campaigns):
|
|
216
|
+
"""
|
|
217
|
+
Parse the transfer documents, compare against the campaign settings
|
|
218
|
+
and decide whether the workflow is completed or not.
|
|
219
|
+
:param transfers: list of transfers records
|
|
220
|
+
:param campaigns: dictionary of campaigns
|
|
221
|
+
:return: completion status
|
|
222
|
+
"""
|
|
223
|
+
completedWfs = []
|
|
224
|
+
for record in transfers:
|
|
225
|
+
reqName = record['workflowName']
|
|
226
|
+
if not record['transfers']:
|
|
227
|
+
self.logger.info("%s OK, no input data transfers, move it on.", reqName)
|
|
228
|
+
completedWfs.append(reqName)
|
|
229
|
+
continue
|
|
230
|
+
# check completion of all transfers
|
|
231
|
+
statuses = []
|
|
232
|
+
for transfer in record['transfers']:
|
|
233
|
+
try:
|
|
234
|
+
cdict = campaigns[transfer['campaignName']]
|
|
235
|
+
partialCopy = cdict['PartialCopy']
|
|
236
|
+
except Exception as ex:
|
|
237
|
+
# Just log the error and stop checking any further transfers for the current request.
|
|
238
|
+
status = 0
|
|
239
|
+
statuses.append(status)
|
|
240
|
+
msg = "Missing or broken campaign configuration at ReqMgr for request: %s. Error: %s"
|
|
241
|
+
self.logger.exception(msg, reqName, str(ex))
|
|
242
|
+
break
|
|
243
|
+
# compare against the last completion number, which is from the last cycle execution
|
|
244
|
+
if transfer['completion'][-1] >= partialCopy * 100:
|
|
245
|
+
status = 1
|
|
246
|
+
else:
|
|
247
|
+
status = 0
|
|
248
|
+
statuses.append(status)
|
|
249
|
+
if all(statuses):
|
|
250
|
+
self.logger.info("%s OK, all transfers completed or above threshold, move it on.", reqName)
|
|
251
|
+
completedWfs.append(reqName)
|
|
252
|
+
return completedWfs
|
|
253
|
+
|
|
254
|
+
def updateTransferDocs(self, docs, workflowsToSkip):
|
|
255
|
+
"""
|
|
256
|
+
Given a list of transfer documents, update all of them in
|
|
257
|
+
ReqMgrAux database.
|
|
258
|
+
:param docs: list of transfer docs
|
|
259
|
+
:param workflowsToSkip: list of workflow names that should not be updated in CouchDB
|
|
260
|
+
:return: a list of request names that failed to be updated
|
|
261
|
+
"""
|
|
262
|
+
failedWfs = []
|
|
263
|
+
for rec in docs:
|
|
264
|
+
if rec['workflowName'] in workflowsToSkip:
|
|
265
|
+
self.logger.warning("Not updating transfer record in CouchDB for: %s", rec['workflowName'])
|
|
266
|
+
continue
|
|
267
|
+
if not self.reqmgrAux.updateTransferInfo(rec['workflowName'], rec):
|
|
268
|
+
# then it failed to update the doc, ReqMgrAux client is logging it already
|
|
269
|
+
failedWfs.append(rec['workflowName'])
|
|
270
|
+
return failedWfs
|
|
File without changes
|