X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fmrstub%2Fmr.py;h=9c5a2c8d602c59e5709591d4aa168a8a428e705a;hb=0b10c7fa768f05ae5146ce2f3a69998bb8f97a9f;hp=45f8cfe58cef5544efa2d7bc059dd6ad75208f8f;hpb=acdd3f361ff7af58b0276789cc5148180a06e552;p=nonrtric.git diff --git a/test/mrstub/mr.py b/test/mrstub/mr.py index 45f8cfe5..9c5a2c8d 100644 --- a/test/mrstub/mr.py +++ b/test/mrstub/mr.py @@ -28,12 +28,12 @@ import traceback app = Flask(__name__) # list of messages to/from Dmaap -msg_requests={} +msg_requests=[] msg_responses={} # Server info -HOST_IP = "0.0.0.0" -HOST_PORT = 3905 +HOST_IP = "127.0.0.1" +HOST_PORT = 2222 # Metrics vars cntr_msg_requests_submitted=0 @@ -106,7 +106,7 @@ def sendrequest(): msg=create_message(oper, correlation_id, payload, url) print(msg) print(APP_WRITE_URL+" MSG(correlationid = "+correlation_id+"): " + json.dumps(json.loads(msg), indent=2)) - msg_requests[correlation_id]=msg + msg_requests.append(msg) cntr_msg_requests_submitted += 1 return Response(correlation_id, status=200, mimetype=MIME_TEXT) except Exception as e: @@ -151,15 +151,26 @@ def receiveresponse(): def events_read(): global msg_requests global cntr_msg_requests_fetched + + limit=request.args.get('limit') + if (limit is None): + limit=4096 + else: + limit=int(limit) + if (limit<0): + limit=0 + if (limit>4096): + limit=4096 + print("Limting number of returned messages to: "+str(limit)) try: msgs='' - for item in msg_requests: + cntr=0 + while(cntr0): if (len(msgs)>1): msgs=msgs+',' - msgs=msgs+msg_requests[item] + msgs=msgs+msg_requests.pop(0) cntr_msg_requests_fetched += 1 - - msg_requests={} + cntr=cntr+1 msgs='['+msgs+']' print(AGENT_READ_URL+" MSGs: "+json.dumps(json.loads(msgs), indent=2)) return Response(msgs, status=200, mimetype=MIME_JSON) @@ -201,9 +212,9 @@ def events_write(): print(AGENT_WRITE_URL+ " msg+status (correlationid="+id+") :" + str(msg_str)) except Exception as e: print(AGENT_WRITE_URL+"-"+CAUGHT_EXCEPTION+" "+str(e) + " "+traceback.format_exc()) - return Response(SERVER_ERROR+" "+str(e), status=500, mimetype=MIME_TEXT) + return Response('{"message": "' + SERVER_ERROR + ' ' + str(e) + '","status":"500"}', status=200, mimetype=MIME_JSON) - return Response('OK', status=200, mimetype=MIME_TEXT) + return Response('{}', status=200, mimetype=MIME_JSON) ### Functions for metrics read out ### @@ -255,7 +266,7 @@ def reset(): cntr_msg_requests_fetched=0 cntr_msg_responses_submitted=0 cntr_msg_responses_fetched=0 - msg_requests={} + msg_requests=[] msg_responses={} return Response('OK', status=200, mimetype=MIME_TEXT)