Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:58:20

0001 #!/usr/bin/env python
0002 #
0003 # Licensed under the Apache License, Version 2.0 (the "License");
0004 # You may not use this file except in compliance with the License.
0005 # You may obtain a copy of the License at
0006 # http://www.apache.org/licenses/LICENSE-2.0OA
0007 #
0008 # Authors:
0009 # - Wen Guan, <wen.guan@cern.ch>, 2024
0010 
0011 
0012 from traceback import format_exc
0013 
0014 from flask import Blueprint
0015 
0016 from idds.common import exceptions
0017 from idds.common.constants import HTTP_STATUS_CODE
0018 from idds.common.utils import get_asyncresult_config, get_prompt_broker_config
0019 
0020 from idds.rest.v1.controller import IDDSController
0021 
0022 
0023 class MetaInfo(IDDSController):
0024     """ Get Meta info"""
0025 
0026     def get(self, name):
0027         logger = self.get_logger()
0028         try:
0029             logger.info(f"Getting meta info for {name}")
0030 
0031             rets = {}
0032             if name == 'asyncresult_config':
0033                 asyncresult_config = get_asyncresult_config()
0034                 rets = asyncresult_config
0035             elif name == 'prompt_broker':
0036                 prompt_broker_config = get_prompt_broker_config()
0037                 rets = prompt_broker_config
0038 
0039             logger.info(f"Meta info for {name} retrieved successfully: {rets}")
0040 
0041         except exceptions.NoObject as error:
0042             return self.generate_http_response(HTTP_STATUS_CODE.NotFound, exc_cls=error.__class__.__name__, exc_msg=error)
0043         except exceptions.IDDSException as error:
0044             return self.generate_http_response(HTTP_STATUS_CODE.InternalError, exc_cls=error.__class__.__name__, exc_msg=error)
0045         except Exception as error:
0046             print(error)
0047             print(format_exc())
0048             logger.error(f"Error getting meta info for {name}: {error}\n{format_exc()}")
0049             return self.generate_http_response(HTTP_STATUS_CODE.InternalError, exc_cls=exceptions.CoreException.__name__, exc_msg=error)
0050 
0051         return self.generate_http_response(HTTP_STATUS_CODE.OK, data=rets)
0052 
0053 
0054 def get_blueprint():
0055     bp = Blueprint('metainfo', __name__)
0056 
0057     metainfo_view = MetaInfo.as_view('metainfo')
0058     bp.add_url_rule('/metainfo/<name>', view_func=metainfo_view, methods=['get', ])
0059 
0060     return bp