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.
Files changed (210) hide show
  1. Utils/CPMetrics.py +270 -0
  2. Utils/CertTools.py +62 -0
  3. Utils/EmailAlert.py +50 -0
  4. Utils/ExtendedUnitTestCase.py +62 -0
  5. Utils/FileTools.py +182 -0
  6. Utils/IteratorTools.py +80 -0
  7. Utils/MathUtils.py +31 -0
  8. Utils/MemoryCache.py +119 -0
  9. Utils/Patterns.py +24 -0
  10. Utils/Pipeline.py +137 -0
  11. Utils/PortForward.py +97 -0
  12. Utils/ProcessStats.py +103 -0
  13. Utils/PythonVersion.py +17 -0
  14. Utils/Signals.py +36 -0
  15. Utils/TemporaryEnvironment.py +27 -0
  16. Utils/Throttled.py +227 -0
  17. Utils/Timers.py +130 -0
  18. Utils/Timestamps.py +86 -0
  19. Utils/TokenManager.py +143 -0
  20. Utils/Tracing.py +60 -0
  21. Utils/TwPrint.py +98 -0
  22. Utils/Utilities.py +308 -0
  23. Utils/__init__.py +11 -0
  24. WMCore/Algorithms/Alarm.py +39 -0
  25. WMCore/Algorithms/MathAlgos.py +274 -0
  26. WMCore/Algorithms/MiscAlgos.py +67 -0
  27. WMCore/Algorithms/ParseXMLFile.py +115 -0
  28. WMCore/Algorithms/Permissions.py +27 -0
  29. WMCore/Algorithms/Singleton.py +58 -0
  30. WMCore/Algorithms/SubprocessAlgos.py +129 -0
  31. WMCore/Algorithms/__init__.py +7 -0
  32. WMCore/Cache/GenericDataCache.py +98 -0
  33. WMCore/Cache/WMConfigCache.py +572 -0
  34. WMCore/Cache/__init__.py +0 -0
  35. WMCore/Configuration.py +651 -0
  36. WMCore/DAOFactory.py +47 -0
  37. WMCore/DataStructs/File.py +177 -0
  38. WMCore/DataStructs/Fileset.py +140 -0
  39. WMCore/DataStructs/Job.py +182 -0
  40. WMCore/DataStructs/JobGroup.py +142 -0
  41. WMCore/DataStructs/JobPackage.py +49 -0
  42. WMCore/DataStructs/LumiList.py +734 -0
  43. WMCore/DataStructs/Mask.py +219 -0
  44. WMCore/DataStructs/MathStructs/ContinuousSummaryHistogram.py +197 -0
  45. WMCore/DataStructs/MathStructs/DiscreteSummaryHistogram.py +92 -0
  46. WMCore/DataStructs/MathStructs/SummaryHistogram.py +117 -0
  47. WMCore/DataStructs/MathStructs/__init__.py +0 -0
  48. WMCore/DataStructs/Pickleable.py +24 -0
  49. WMCore/DataStructs/Run.py +256 -0
  50. WMCore/DataStructs/Subscription.py +175 -0
  51. WMCore/DataStructs/WMObject.py +47 -0
  52. WMCore/DataStructs/WorkUnit.py +112 -0
  53. WMCore/DataStructs/Workflow.py +60 -0
  54. WMCore/DataStructs/__init__.py +8 -0
  55. WMCore/Database/CMSCouch.py +1349 -0
  56. WMCore/Database/ConfigDBMap.py +29 -0
  57. WMCore/Database/CouchUtils.py +118 -0
  58. WMCore/Database/DBCore.py +198 -0
  59. WMCore/Database/DBCreator.py +113 -0
  60. WMCore/Database/DBExceptionHandler.py +57 -0
  61. WMCore/Database/DBFactory.py +110 -0
  62. WMCore/Database/DBFormatter.py +177 -0
  63. WMCore/Database/Dialects.py +13 -0
  64. WMCore/Database/ExecuteDAO.py +327 -0
  65. WMCore/Database/MongoDB.py +241 -0
  66. WMCore/Database/MySQL/Destroy.py +42 -0
  67. WMCore/Database/MySQL/ListUserContent.py +20 -0
  68. WMCore/Database/MySQL/__init__.py +9 -0
  69. WMCore/Database/MySQLCore.py +132 -0
  70. WMCore/Database/Oracle/Destroy.py +56 -0
  71. WMCore/Database/Oracle/ListUserContent.py +19 -0
  72. WMCore/Database/Oracle/__init__.py +9 -0
  73. WMCore/Database/ResultSet.py +44 -0
  74. WMCore/Database/Transaction.py +91 -0
  75. WMCore/Database/__init__.py +9 -0
  76. WMCore/Database/ipy_profile_couch.py +438 -0
  77. WMCore/GroupUser/CouchObject.py +127 -0
  78. WMCore/GroupUser/Decorators.py +51 -0
  79. WMCore/GroupUser/Group.py +33 -0
  80. WMCore/GroupUser/Interface.py +73 -0
  81. WMCore/GroupUser/User.py +96 -0
  82. WMCore/GroupUser/__init__.py +11 -0
  83. WMCore/Lexicon.py +836 -0
  84. WMCore/MicroService/CherryPyThreads/HeartbeatMonitor.py +6 -0
  85. WMCore/MicroService/CherryPyThreads/__init__.py +0 -0
  86. WMCore/MicroService/DataStructs/DefaultStructs.py +101 -0
  87. WMCore/MicroService/DataStructs/__init__.py +0 -0
  88. WMCore/MicroService/MSCore/MSAuth.py +153 -0
  89. WMCore/MicroService/MSCore/MSCore.py +113 -0
  90. WMCore/MicroService/MSCore/MSManager.py +484 -0
  91. WMCore/MicroService/MSCore/TaskManager.py +218 -0
  92. WMCore/MicroService/MSCore/__init__.py +0 -0
  93. WMCore/MicroService/MSMonitor/MSMonitor.py +270 -0
  94. WMCore/MicroService/MSMonitor/__init__.py +0 -0
  95. WMCore/MicroService/Service/Data.py +225 -0
  96. WMCore/MicroService/Service/RestApiHub.py +46 -0
  97. WMCore/MicroService/Service/__init__.py +0 -0
  98. WMCore/MicroService/Tools/Common.py +579 -0
  99. WMCore/MicroService/Tools/PycurlRucio.py +419 -0
  100. WMCore/MicroService/Tools/__init__.py +0 -0
  101. WMCore/MicroService/WebGui/FrontPage.py +56 -0
  102. WMCore/MicroService/WebGui/__init__.py +0 -0
  103. WMCore/REST/Auth.py +202 -0
  104. WMCore/REST/CherryPyPeriodicTask.py +166 -0
  105. WMCore/REST/Error.py +333 -0
  106. WMCore/REST/Format.py +642 -0
  107. WMCore/REST/HeartbeatMonitorBase.py +90 -0
  108. WMCore/REST/Main.py +623 -0
  109. WMCore/REST/Server.py +2435 -0
  110. WMCore/REST/Services.py +24 -0
  111. WMCore/REST/Test.py +120 -0
  112. WMCore/REST/Tools.py +38 -0
  113. WMCore/REST/Validation.py +250 -0
  114. WMCore/REST/__init__.py +1 -0
  115. WMCore/ReqMgr/DataStructs/RequestStatus.py +209 -0
  116. WMCore/ReqMgr/DataStructs/RequestType.py +13 -0
  117. WMCore/ReqMgr/DataStructs/__init__.py +0 -0
  118. WMCore/ReqMgr/__init__.py +1 -0
  119. WMCore/Services/AlertManager/AlertManagerAPI.py +111 -0
  120. WMCore/Services/AlertManager/__init__.py +0 -0
  121. WMCore/Services/CRIC/CRIC.py +238 -0
  122. WMCore/Services/CRIC/__init__.py +0 -0
  123. WMCore/Services/DBS/DBS3Reader.py +1044 -0
  124. WMCore/Services/DBS/DBSConcurrency.py +44 -0
  125. WMCore/Services/DBS/DBSErrors.py +113 -0
  126. WMCore/Services/DBS/DBSReader.py +23 -0
  127. WMCore/Services/DBS/DBSUtils.py +139 -0
  128. WMCore/Services/DBS/DBSWriterObjects.py +381 -0
  129. WMCore/Services/DBS/ProdException.py +133 -0
  130. WMCore/Services/DBS/__init__.py +8 -0
  131. WMCore/Services/FWJRDB/FWJRDBAPI.py +118 -0
  132. WMCore/Services/FWJRDB/__init__.py +0 -0
  133. WMCore/Services/HTTPS/HTTPSAuthHandler.py +66 -0
  134. WMCore/Services/HTTPS/__init__.py +0 -0
  135. WMCore/Services/LogDB/LogDB.py +201 -0
  136. WMCore/Services/LogDB/LogDBBackend.py +191 -0
  137. WMCore/Services/LogDB/LogDBExceptions.py +11 -0
  138. WMCore/Services/LogDB/LogDBReport.py +85 -0
  139. WMCore/Services/LogDB/__init__.py +0 -0
  140. WMCore/Services/MSPileup/__init__.py +0 -0
  141. WMCore/Services/MSUtils/MSUtils.py +54 -0
  142. WMCore/Services/MSUtils/__init__.py +0 -0
  143. WMCore/Services/McM/McM.py +173 -0
  144. WMCore/Services/McM/__init__.py +8 -0
  145. WMCore/Services/MonIT/Grafana.py +133 -0
  146. WMCore/Services/MonIT/__init__.py +0 -0
  147. WMCore/Services/PyCondor/PyCondorAPI.py +154 -0
  148. WMCore/Services/PyCondor/PyCondorUtils.py +105 -0
  149. WMCore/Services/PyCondor/__init__.py +0 -0
  150. WMCore/Services/ReqMgr/ReqMgr.py +261 -0
  151. WMCore/Services/ReqMgr/__init__.py +0 -0
  152. WMCore/Services/ReqMgrAux/ReqMgrAux.py +419 -0
  153. WMCore/Services/ReqMgrAux/__init__.py +0 -0
  154. WMCore/Services/RequestDB/RequestDBReader.py +267 -0
  155. WMCore/Services/RequestDB/RequestDBWriter.py +39 -0
  156. WMCore/Services/RequestDB/__init__.py +0 -0
  157. WMCore/Services/Requests.py +624 -0
  158. WMCore/Services/Rucio/Rucio.py +1287 -0
  159. WMCore/Services/Rucio/RucioUtils.py +74 -0
  160. WMCore/Services/Rucio/__init__.py +0 -0
  161. WMCore/Services/RucioConMon/RucioConMon.py +128 -0
  162. WMCore/Services/RucioConMon/__init__.py +0 -0
  163. WMCore/Services/Service.py +400 -0
  164. WMCore/Services/StompAMQ/__init__.py +0 -0
  165. WMCore/Services/TagCollector/TagCollector.py +155 -0
  166. WMCore/Services/TagCollector/XMLUtils.py +98 -0
  167. WMCore/Services/TagCollector/__init__.py +0 -0
  168. WMCore/Services/UUIDLib.py +13 -0
  169. WMCore/Services/UserFileCache/UserFileCache.py +160 -0
  170. WMCore/Services/UserFileCache/__init__.py +8 -0
  171. WMCore/Services/WMAgent/WMAgent.py +63 -0
  172. WMCore/Services/WMAgent/__init__.py +0 -0
  173. WMCore/Services/WMArchive/CMSSWMetrics.py +526 -0
  174. WMCore/Services/WMArchive/DataMap.py +463 -0
  175. WMCore/Services/WMArchive/WMArchive.py +33 -0
  176. WMCore/Services/WMArchive/__init__.py +0 -0
  177. WMCore/Services/WMBS/WMBS.py +97 -0
  178. WMCore/Services/WMBS/__init__.py +0 -0
  179. WMCore/Services/WMStats/DataStruct/RequestInfoCollection.py +300 -0
  180. WMCore/Services/WMStats/DataStruct/__init__.py +0 -0
  181. WMCore/Services/WMStats/WMStatsPycurl.py +145 -0
  182. WMCore/Services/WMStats/WMStatsReader.py +445 -0
  183. WMCore/Services/WMStats/WMStatsWriter.py +273 -0
  184. WMCore/Services/WMStats/__init__.py +0 -0
  185. WMCore/Services/WMStatsServer/WMStatsServer.py +134 -0
  186. WMCore/Services/WMStatsServer/__init__.py +0 -0
  187. WMCore/Services/WorkQueue/WorkQueue.py +492 -0
  188. WMCore/Services/WorkQueue/__init__.py +0 -0
  189. WMCore/Services/__init__.py +8 -0
  190. WMCore/Services/pycurl_manager.py +574 -0
  191. WMCore/WMBase.py +50 -0
  192. WMCore/WMConnectionBase.py +164 -0
  193. WMCore/WMException.py +183 -0
  194. WMCore/WMExceptions.py +269 -0
  195. WMCore/WMFactory.py +76 -0
  196. WMCore/WMInit.py +228 -0
  197. WMCore/WMLogging.py +108 -0
  198. WMCore/Wrappers/JsonWrapper/JSONThunker.py +342 -0
  199. WMCore/Wrappers/JsonWrapper/__init__.py +7 -0
  200. WMCore/Wrappers/__init__.py +6 -0
  201. WMCore/__init__.py +10 -0
  202. msmonitor-2.3.10.data/data/bin/wmc-dist-patch +15 -0
  203. msmonitor-2.3.10.data/data/bin/wmc-dist-unpatch +8 -0
  204. msmonitor-2.3.10.data/data/bin/wmc-httpd +3 -0
  205. msmonitor-2.3.10.dist-info/LICENSE +202 -0
  206. msmonitor-2.3.10.dist-info/METADATA +21 -0
  207. msmonitor-2.3.10.dist-info/NOTICE +16 -0
  208. msmonitor-2.3.10.dist-info/RECORD +210 -0
  209. msmonitor-2.3.10.dist-info/WHEEL +5 -0
  210. msmonitor-2.3.10.dist-info/top_level.txt +2 -0
@@ -0,0 +1,6 @@
1
+ from __future__ import (division, print_function)
2
+ from WMCore.REST.HeartbeatMonitorBase import HeartbeatMonitorBase
3
+
4
+ class HeartbeatMonitor(HeartbeatMonitorBase):
5
+
6
+ pass
File without changes
@@ -0,0 +1,101 @@
1
+ """
2
+ It defines and provides some data structures required by the
3
+ Transferor and Monitor threads.
4
+ It isn't yet enforced, if any new keys are needed, it's better
5
+ to get them added here as well.
6
+ """
7
+ from __future__ import division, print_function
8
+
9
+ # summary metrics for the MSMonitor thread
10
+ # (also available through the `info` REST API)
11
+ MONITOR_REPORT = dict(start_time=0,
12
+ end_time=0,
13
+ execution_time=0,
14
+ error="",
15
+ total_num_campaigns=0,
16
+ total_num_transfers=0,
17
+ filtered_transfer_docs=0,
18
+ success_transfer_doc_update=0,
19
+ failed_transfer_doc_update=0,
20
+ request_status_updated=0)
21
+
22
+ # summary metrics for the MSTransferor thread
23
+ # (also available through the `info` REST API)
24
+ TRANSFEROR_REPORT = dict(start_time=0,
25
+ end_time=0,
26
+ execution_time=0,
27
+ error="",
28
+ total_num_requests=0,
29
+ total_num_campaigns=0,
30
+ nodes_out_of_space=None,
31
+ success_request_transition=0,
32
+ failed_request_transition=0,
33
+ problematic_requests=0,
34
+ total_num_active_pileups=0,
35
+ num_datasets_subscribed=0,
36
+ num_blocks_subscribed=0)
37
+
38
+ # structure for a transfer document to be written to central CouchDB
39
+ TRANSFER_COUCH_DOC = dict(workflowName="",
40
+ lastUpdate=0,
41
+ transfers=None)
42
+
43
+ # structure of a transfer record, it corresponds to the `transfers` field in
44
+ # the TRANSFER_COUCH_DOC structure
45
+ TRANSFER_RECORD = dict(dataset="",
46
+ dataType="",
47
+ transferIDs=set(),
48
+ campaignName="",
49
+ completion=[0.0])
50
+
51
+ # summary metrics for the MSOutput thread
52
+ # (also available through the `info` REST API)
53
+ OUTPUT_REPORT = dict(thread_id="",
54
+ start_time=0,
55
+ end_time=0,
56
+ execution_time=0,
57
+ error="",
58
+ total_num_requests=0,
59
+ total_num_campaigns=0,
60
+ num_datasets_subscribed=0,
61
+ num_data_requests=0)
62
+
63
+ # summary metrics for the MSPileup thread
64
+ # (also available through the `info` REST API)
65
+ PILEUP_REPORT = dict(thread_id="",
66
+ start_time=0,
67
+ end_time=0,
68
+ execution_time=0,
69
+ error="",
70
+ total_num_pileups=0,
71
+ total_num_rules=0)
72
+
73
+ # summary metrics for the MSRuleCleaner thread
74
+ # (also available through the `info` REST API)
75
+ RULECLEANER_REPORT = dict(thread_id="",
76
+ start_time=0,
77
+ end_time=0,
78
+ execution_time=0,
79
+ error="",
80
+ total_num_requests=0,
81
+ clean_num_requests=0,
82
+ normal_archived_num_requests=0,
83
+ force_archived_num_requests=0,
84
+ success_block_rules_deleted=0,
85
+ failed_block_rules_deleted=0,
86
+ success_container_rules_deleted=0,
87
+ failed_container_rules_deleted=0,
88
+ success_request_transition=0,
89
+ failed_request_transition=0)
90
+
91
+ # summary metrics for the MSUnmerged thread
92
+ # (also available through the `info` REST API)
93
+ UNMERGED_REPORT = dict(thread_id="",
94
+ start_time=0,
95
+ end_time=0,
96
+ execution_time=0,
97
+ error="",
98
+ total_num_rses=0,
99
+ total_num_files=0,
100
+ num_rses_cleaned=0,
101
+ num_files_deleted=0)
File without changes
@@ -0,0 +1,153 @@
1
+ """
2
+ File : MSAuth.py
3
+ Author : Valentin Kuznetsov <vkuznet AT gmail dot com>
4
+ Description: MSAuth class provides auth/authz functionality for micro-services
5
+
6
+ The auth/authz schema is defined in JSON data-format as list of records, e.g.
7
+ [ record1, record2, ...] where individual record has the following structure
8
+ {"role": string, "group": string, "service": string, "action": string, "method": [string, string]}
9
+ where
10
+ - role defines authorization role, e.g. admin
11
+ - group defines specific group, e.g. reqmgr
12
+ - service identifies MS service, e.g. ms-pileup
13
+ - actions refers to a specific API or action, e.g. create
14
+ - method contains list of allowed HTTP methods, e.g. ["POST", "PUT"]
15
+
16
+ For example, here is a possible list of authz rules for MSPileup service
17
+
18
+ authz_rules = \
19
+ [{"role": "admin", "group": "reqmgr", "service": "ms-pileup", "action": "create", "method": ["POST"]},
20
+ {"role": "production-operator", "group": "dataops", "service": "ms-pileup", "action": "create", "method": ["POST"]},
21
+
22
+ {"role": "admin", "group": "reqmgr", "service": "ms-pileup", "action": "delete", "method": ["DELETE"]},
23
+ {"role": "production-operator", "group": "dataops", "service": "ms-pileup", "action": "delete", "method": ["DELETE"]},
24
+
25
+ {"role": "admin", "group": "reqmgr", "service": "ms-pileup", "action": "update", "method": ["PUT"]},
26
+ {"role": "production-operator", "group": "dataops", "service": "ms-pileup", "action": "update", "method": ["PUT"]}]
27
+ """
28
+
29
+ # system modules
30
+ import os
31
+ import json
32
+ from pathlib import Path
33
+
34
+ # third party modules
35
+ import cherrypy
36
+
37
+ # WMCore modules
38
+ from WMCore.MicroService.Tools.Common import getMSLogger
39
+ from WMCore.REST.Auth import user_info_from_headers
40
+ from Utils.Utilities import lowerCmsHeaders
41
+
42
+
43
+ def readAuthzRules(entry):
44
+ """
45
+ Return authz rules from given entry
46
+ :param entry: either file name or list of authz rules, see docstring of this module
47
+ :return: list of authz rules
48
+ """
49
+ rules = []
50
+ if entry is None:
51
+ return rules
52
+ # of provided is a list data-type it may contaisn our rules
53
+ if isinstance(entry, list) and len(entry) > 0:
54
+ if isinstance(entry[0], dict):
55
+ return entry
56
+ # check if entry is a file name
57
+ if os.path.exists(entry):
58
+ with open(entry, 'r', encoding="utf-8") as fstream:
59
+ rules = json.load(fstream)
60
+ return rules
61
+ msg = f"Unable to read {entry} as authz rules"
62
+ raise Exception(msg)
63
+
64
+
65
+ class MSAuth():
66
+ """
67
+ This class provides auth/authz functionality for micro-services
68
+ """
69
+
70
+ def __init__(self, msConfig, **kwargs):
71
+ """
72
+ Provides a basic setup for all the microservices
73
+
74
+ :param msConfig: MS service configuration
75
+ :param kwargs: optional parameters
76
+ """
77
+ self.logger = getMSLogger(getattr(msConfig, 'verbose', False), kwargs.get("logger"))
78
+ self.msConfig = msConfig
79
+ self.logger.info("Configuration including default values:\n%s", self.msConfig)
80
+
81
+ # load auth/authz configuration
82
+ self.authzRules = readAuthzRules(msConfig.get('authz_rules', None))
83
+ self.authzKey = msConfig['authz_key'] # hmac key of front-end
84
+ # check if provided authz_key is a file name
85
+ if isinstance(self.authzKey, str):
86
+ authFile = Path(self.authzKey)
87
+ if authFile.is_file():
88
+ # msConfig provided file name with authz_key
89
+ with open(authFile, 'rb') as istream:
90
+ self.authzKey = istream.read()
91
+
92
+ def userInfo(self):
93
+ """
94
+ Read incoming HTTP request headers and return user info
95
+ :return: user dict structure with HTTP headers key:value pairs, like
96
+ {'dn': string, 'method': string, 'login': string, 'name': string, 'roles': {...}}
97
+ """
98
+ # skip authorization on localhost or if no remote address is provided
99
+ # this is only valid if no cms auth headers is set, i.e. in unit tests
100
+ headers = lowerCmsHeaders(cherrypy.request.headers)
101
+ if 'cms-auth-status' not in headers:
102
+ remoteAddr = headers.get('Remote-Addr', '')
103
+ if remoteAddr in ['127.0.0.1', '']:
104
+ user = {'dn': 'localhost-user', 'method': None, 'login': None, 'name': None, 'roles': {}}
105
+ return user
106
+
107
+ # get user information
108
+ user = user_info_from_headers(key=self.authzKey)
109
+ return user
110
+
111
+ def authorizeApiAccess(self, service, action, method=None):
112
+ """
113
+ Check auth role based CMS HTTP AUTH headers: cms-auth-status,
114
+ cms-authn, cms-authz, cms-authn-hmac, cms-authn-name, cms-authn-dn.
115
+ It throws cherrypy HTTPError if user is not authorized
116
+
117
+ :param service: service name (string)
118
+ :param action: action name (string
119
+ :param method: method name (string)
120
+ :return: none
121
+ """
122
+ # get user information
123
+ user = self.userInfo()
124
+ if user.get('dn', '') == 'localhost-user':
125
+ # we allow localhost-user to perform any actions (unit test scenario)
126
+ # see userInfo method which generates localhost-user DN. This fixes
127
+ # (403, 'You are not authorized to access this resource.') error in unit tests
128
+ return
129
+
130
+ # CMS AUTH headers
131
+ # cms-auth-status, cms-authn, cms-authz, cms-authn-hmac, cms-authn-name, cms-authn-dn
132
+ for entry in self.authzRules:
133
+ # check that user method is allowed
134
+ if method and method not in entry['method']:
135
+ continue
136
+ userMethod = user.get('method', None)
137
+ if userMethod and userMethod != "X509Cert" and userMethod not in entry['method']:
138
+ continue
139
+
140
+ # check if entry service and action matches
141
+ if entry['service'] == service and entry['action'] == action:
142
+ # if we have match for service and action we'll check used roles
143
+ # 'roles': {'fake': {'site': set(['fake']), 'group': set(['fake'])}}
144
+ for role, obj in user['roles'].items():
145
+ if role != entry['role']:
146
+ continue
147
+ for group in obj['group']:
148
+ if group == entry['group']:
149
+ return
150
+
151
+ # if we reach this place we did not match anything and should through exception
152
+ self.logger.error("ERROR: not authorized access to %s method %s", service, action)
153
+ raise cherrypy.HTTPError(403, "You are not authorized to access this resource.")
@@ -0,0 +1,113 @@
1
+ """
2
+ File : MSCore.py
3
+ Author : Valentin Kuznetsov <vkuznet AT gmail dot com>
4
+ Description: MSCore class provides core functionality of the MS.
5
+ """
6
+ # futures
7
+ from __future__ import division, print_function
8
+
9
+ from builtins import object
10
+ from WMCore.MicroService.Tools.Common import getMSLogger
11
+ from WMCore.Services.ReqMgr.ReqMgr import ReqMgr
12
+ from WMCore.Services.ReqMgrAux.ReqMgrAux import ReqMgrAux
13
+ from WMCore.Services.Rucio.Rucio import Rucio
14
+ from WMCore.Services.AlertManager.AlertManagerAPI import AlertManagerAPI
15
+
16
+
17
+ class MSCore(object):
18
+ """
19
+ This class provides core functionality for
20
+ MSTransferor, MSMonitor, MSOutput, MSPileup, MSRuleCleaner, MSUnmerged classes.
21
+ """
22
+
23
+ def __init__(self, msConfig, **kwargs):
24
+ """
25
+ Provides a basic setup for all the microservices
26
+
27
+ :param config: MS service configuration
28
+ :param kwargs: can be used to skip the initialization of specific services, such as:
29
+ logger: logger object
30
+ skipReqMgr: boolean to skip ReqMgr initialization
31
+ skipReqMgrAux: boolean to skip ReqMgrAux initialization
32
+ skipRucio: boolean to skip Rucio initialization
33
+ """
34
+ self.logger = getMSLogger(getattr(msConfig, 'verbose', False), kwargs.get("logger"))
35
+ self.msConfig = msConfig
36
+ self.logger.info("Configuration including default values:\n%s", self.msConfig)
37
+
38
+ if not kwargs.get("skipReqMgr", False):
39
+ self.reqmgr2 = ReqMgr(self.msConfig['reqmgr2Url'], logger=self.logger)
40
+ if not kwargs.get("skipReqMgrAux", False):
41
+ self.reqmgrAux = ReqMgrAux(self.msConfig['reqmgr2Url'],
42
+ httpDict={'cacheduration': 1.0}, logger=self.logger)
43
+
44
+ self.phedex = None
45
+ self.rucio = None
46
+ if not kwargs.get("skipRucio", False):
47
+ self.rucio = Rucio(acct=self.msConfig['rucioAccount'],
48
+ hostUrl=self.msConfig['rucioUrl'],
49
+ authUrl=self.msConfig['rucioAuthUrl'],
50
+ configDict={"logger": self.logger, "user_agent": "wmcore-microservices"})
51
+ self.alertManagerUrl = self.msConfig.get("alertManagerUrl", None)
52
+ self.alertManagerApi = AlertManagerAPI(self.alertManagerUrl, logger=self.logger)
53
+ # alertDestinationMap is used to define alert routes
54
+ self.alertDestinationMap = self.msConfig.get("alertDestinationMap", {})
55
+
56
+ def unifiedConfig(self):
57
+ """
58
+ Fetches the unified configuration
59
+ :return: unified configuration content
60
+ """
61
+ res = self.reqmgrAux.getUnifiedConfig(docName="config")
62
+ if res:
63
+ if isinstance(res, list):
64
+ return res[0]
65
+ return res
66
+ else:
67
+ return {}
68
+
69
+ def change(self, reqName, reqStatus, prefix='###'):
70
+ """
71
+ Update the request status in ReqMgr2
72
+ """
73
+ try:
74
+ if self.msConfig['enableStatusTransition']:
75
+ self.logger.info('%s updating %s status to: %s', prefix, reqName, reqStatus)
76
+ self.reqmgr2.updateRequestStatus(reqName, reqStatus)
77
+ else:
78
+ self.logger.info('DRY-RUN:: %s updating %s status to: %s', prefix, reqName, reqStatus)
79
+ except Exception as err:
80
+ self.logger.exception("Failed to change request status. Error: %s", str(err))
81
+
82
+ def updateReportDict(self, reportDict, keyName, value):
83
+ """
84
+ Provided a key name and value, validate the key name
85
+ and update the report dictionary if it passes the validation
86
+ :param reportDict: dictionary with a summary of the service
87
+ :param keyName: string with the key name in the report
88
+ :param value: string/integer value with the content of a metric
89
+ :return: the updated dictionary
90
+ """
91
+ if keyName not in reportDict:
92
+ self.logger.error("Report metric '%s' is not supported", keyName)
93
+ else:
94
+ reportDict[keyName] = value
95
+ return reportDict
96
+
97
+ def sendAlert(self, alertName, severity, summary, description, service, tag=None, endSecs=1 * 60 * 60):
98
+ """
99
+ Sends an alert to Prometheus.
100
+ :param alertName: string with unique alert name
101
+ :param severity: string with the alert severity
102
+ :param summary: string with a short summary of the alert
103
+ :param description: string with a longer description of the alert
104
+ :param service: string with the service name generating this alert
105
+ :param tag: string representing desired alert's tag, it can use commas to assign multiple tags, e.g. tag1,tag2
106
+ :param endSecs: integer with an expiration time
107
+ :return: none
108
+ """
109
+ try:
110
+ self.alertManagerApi.sendAlert(alertName, severity, summary, description,
111
+ service, tag=tag, endSecs=endSecs)
112
+ except Exception as ex:
113
+ self.logger.exception("Failed to send alert to %s. Error: %s", self.alertManagerUrl, str(ex))