74 args, unknown = parser.parse_known_args()
76 def require_arg(arg_val, arg_name):
83 runNumber = require_arg(args.r,
'r')
84 lumiSince = require_arg(args.ls,
'ls')
85 xint = require_arg(args.xint,
'xint')
88 host = require_arg(args.host,
'host')
89 tag = require_arg(args.tag,
'tag')
90 gtag = require_arg(args.gtag,
'gtag')
91 label = require_arg(args.label,
'label')
94 record = args.record
if args.record
is not None else 'test_record'
96 if args.remove
and host.startswith(tempfile.gettempdir()):
97 print(
"Only remove tag from CREST server")
101 if host.startswith(tempfile.gettempdir()):
102 api_instance = CrestApiFs(host)
103 log.debug(
'>== Using CREST file system')
105 log.debug(f
'>== Using CREST server: {host}')
106 api_instance = CrestApi(host=host)
109 gtag_dto=GlobalTagDto(
111 description=
'Test global tag for hlt workflow',
119 log.debug(f
'>== Looking for global tag {gtag} in CREST ...')
122 if host.startswith(
'http'):
123 existing_gtag = api_instance.find_global_tag(name=gtag)
124 elif os.path.exists(f
'{host}/globaltags/{gtag}/globaltag.json'):
125 existing_gtag = api_instance.find_global_tag(name=gtag)
126 if existing_gtag
is not None and isinstance(existing_gtag, GlobalTagDto):
127 log.debug(f
'>== Found existing global tag {existing_gtag.name}. Will not recreate.')
129 log.debug(f
'>== Creating new global tag: {gtag}')
130 if host.startswith(
'http'):
131 api_response = api_instance.create_global_tag(gtag_dto,
'false')
133 api_response = api_instance.create_global_tag(gtag_dto)
134 if isinstance(api_response, GlobalTagDto):
135 log.debug(f
'>== Created global tag: {api_response.name}')
137 print(f
'>== Error creating global tag {gtag}: {api_response}')
139 except Exception
as e:
140 print(
'Exception when calling CrestApi->create_global_tag:')
146 log.debug(f
'>== Removing global tag map for tag: {tag}')
148 api_instance.delete_global_tag_map(gtag, tag, label)
149 except Exception
as e:
150 print(
'Exception when calling CrestApi->delete_global_tag_map:')
153 log.debug(f
'>== Removing tag with name: {tag}')
155 api_instance.remove_tag(tag)
156 except Exception
as e:
157 print(
'Exception when calling CrestApi->remove_tag:')
163 description =
'<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"40774348\" /></addrHeader><typeName>AthenaAttributeList</typeName>'
166 'channel_list': [{
'0':
'channel_0'}],
167 'node_description': description,
168 'payload_spec': [{
'xint':
'Int32'}]
174 description=description,
175 time_type=
'run-lumi',
176 payload_spec=
'xint:Int32',
178 synchronization=
'ALL',
179 last_validated_time=-1,
183 tag_meta_dto = TagMetaDto(
185 description=description,
186 tag_info=json.dumps(tag_info),
191 log.debug(f
'>== Looking for tag {tag} in CREST ...')
194 if host.startswith(
'http'):
195 existing_tag = api_instance.find_tag(name=tag)
196 elif os.path.exists(f
'{host}/tags/{tag}/tag.json'):
197 existing_tag = api_instance.find_tag(name=tag)
198 if existing_tag
and isinstance(existing_tag, TagDto):
199 log.debug(f
'>== Found existing tag {existing_tag.name}. Will not recreate.')
201 log.debug(f
'>== Creating new tag: {tag}')
202 api_response = api_instance.create_tag(tag_dto)
203 if isinstance(api_response, TagDto):
204 log.debug(f
'>== Created new tag with name: {api_response.name}')
206 print(f
'>== Error creating tag {tag}: {api_response}')
208 except Exception
as e:
209 print(
'Exception when calling CrestApi->create_tag:')
214 log.debug(f
'>== Looking for tag metadata for tag {tag} ...')
217 if host.startswith(
'http'):
218 tag_meta = api_instance.find_tag_meta(name=tag)
219 elif os.path.exists(f
'{host}/tags/{tag}/tagmetainfo.json'):
220 tag_meta = api_instance.find_tag_meta(name=tag)
221 if tag_meta
and isinstance(tag_meta, TagMetaSetDto)
and len(tag_meta.resources) > 0:
222 log.debug(f
'>== Found existing metadata for tag {tag_meta.resources[0].tag_name}. Will not recreate.')
223 elif tag_meta
and isinstance(tag_meta, TagMetaDto):
224 log.debug(f
'>== Found existing metadata for tag {tag_meta.tag_name}. Will not recreate.')
226 log.debug(f
'>== Creating new tag metadata for tag: {tag}')
227 api_response = api_instance.create_tag_meta(tag_meta_dto)
228 if isinstance(api_response, TagMetaDto):
229 log.debug(f
'>== Created tag meta for tag: {api_response.tag_name}')
231 print(f
'>== Error creating tag meta for tag {tag}: {api_response}')
233 except Exception
as e:
234 print(
'Exception when calling CrestApi->create_tag_meta:')
241 sinfo = {
'run-lumi': f
'{runNumber}-{lumiSince}'}
242 lumi_pyld = {
'0': [int(xint)]}
246 since=int(lumiSince),
247 data=json.dumps(lumi_pyld),
248 streamer_info=json.dumps(sinfo)
252 format=
"StoreSetDto",
257 log.debug(f
'>== Storing data in CREST: tag={tag}, run={runNumber}, LB={lumiSince}, xint={xint}')
259 api_response = api_instance.store_data(tag=tag, store_set=ssdto)
260 except Exception
as e:
261 print(
'Exception when calling CrestApi->store_data:')
266 global_tag_map_dto = GlobalTagMapDto(
267 global_tag_name=gtag,
272 log.debug(f
'>== Checking/Creating global tag map for tag={tag}, gtag={gtag}, label={label}')
275 if host.startswith(
'http'):
276 globalTagMap = api_instance.find_global_tag_map(name=tag, mode=
'BackTrace')
277 elif os.path.exists(f
'{host}/globaltags/{gtag}/maps.json'):
278 globalTagMap = api_instance.find_global_tag_map(name=gtag)
279 if isinstance(globalTagMap, GlobalTagMapSetDto)
and len(globalTagMap.resources) > 0:
280 log.debug(f
'>== Found existing global tag map entries for tag {tag}. Will not recreate.')
282 log.debug(f
'>== Creating global tag map for tag: {tag}')
283 api_instance.create_global_tag_map(global_tag_map_dto)
284 except Exception
as e:
285 print(
'Exception when calling CrestApi->create_global_tag_map:')
292 parser = argparse.ArgumentParser(
293 description=
'CREST Commands',
294 formatter_class=argparse.RawDescriptionHelpFormatter,
296 "Required to create a tag:\n"
297 "--host=<host url or path> --tag=<tag> --gtag=<global tag> --label=<label> --r=<run number> --ls=<lumi since> --xint=<payload>\n\n"
298 "Required to remove a tag:\n"
299 "--remove --host=<host url> --tag=<tag> --gtag=<global tag> --label=<label>"
304 parser.add_argument(
'--host', default=
None, help=
'Host URL of the CREST service')
305 parser.add_argument(
'--tag', default=
None, help=
'CREST tag name')
306 parser.add_argument(
'--gtag', default=
None, help=
'CREST global tag name')
307 parser.add_argument(
'--label', default=
None, help=
'Label used in the global tag map')
308 parser.add_argument(
'--record', default=
None, help=
'Record name for the global tag map')
309 parser.add_argument(
'--remove', action=
'store_true', help=
'Remove the specified CREST tag')
310 parser.add_argument(
'--r', type=int, default=int(0), help=
'Single run number (for CREST run-lumi info)')
311 parser.add_argument(
'--ls', type=int, default=
None, help=
'Single lumi block (for CREST run-lumi info)')
312 parser.add_argument(
'--xint', type=int, default=
None,
313 help=
'Integer payload value to store in COOL and/or CREST')
314 parser.add_argument(
'--debug', action=
'store_true', help=
'Enable debugging information')
316 args, unknown = parser.parse_known_args()
318 logging_level = logging.ERROR
320 logging_level = logging.DEBUG
321 logging.basicConfig(level=logging_level, format =
"%(name)s %(levelname)s: %(message)s")
324 if args.host
is None: