Esempio n. 1
0
 def get(self):
     '''List FEQoR Metrics'''
     try:
         self_logger = logger.bind(request_id=str(uuid.uuid4()), request_url=request.url)
         query = json.loads(request.args.get('query', '{}'))
         sort = json.loads(request.args.get('sort', '{}'))
         projection = json.loads(request.args.get('projection', '{}'))
         skip = int(request.args.get('skip', 0))
         limit = int(request.args.get('limit', constants.MAX_PAGE_SIZE))
         db_con_obj = DB(self_logger)
         data = db_con_obj.fetch(
             constants.HANDOFF,query,
             sort=sort, projection=projection, skip=skip, limit=limit
         )
         self_logger = db_con_obj.logger
         return {
             "status": http.SUCCESS.status,
             "data": data
         }
     except Exception as e:
         exc_type, exc_value, exc_traceback = sys.exc_info()
         message = repr(traceback.format_exception(exc_type, exc_value,
                                                   exc_traceback))
         self_logger.error(message)
         result = {"status": http.BAD_REQUEST.status, "message": str(e)}
         return result, http.BAD_REQUEST.code
Esempio n. 2
0
 def post(self, *args, **kwargs):
     try:
         self_logger = logger.bind(request_id=str(uuid.uuid4()), request_url=request.url)
         payload = self.api.payload
         db_con_obj = DB(self_logger)
         self_logger = db_con_obj.logger
         created_doc = db_con_obj.create(constants.FEQOR_METRICS, payload)
         self_logger.info("created document id {}".format(created_doc['_id']))
         return {
             "status": http.SUCCESS.status,
             "data": created_doc
         }
     except Exception as e:
         exc_type, exc_value, exc_traceback = sys.exc_info()
         message = repr(traceback.format_exception(exc_type, exc_value,
                                                   exc_traceback))
         self_logger.error(message)
         result = {"status": http.BAD_REQUEST.status, "message": str(e)}
         return result, http.BAD_REQUEST.code