NONRTRIC-955: Add uvicorn, fix for appl/json
[sim/a1-interface.git] / near-rt-ric-simulator / src / STD_1.1.3 / main.py
index b7ecdcd..df021d1 100644 (file)
@@ -1,5 +1,6 @@
 #  ============LICENSE_START===============================================
-#  Copyright (C) 2020 Nordix Foundation. All rights reserved.
+#  Copyright (C) 2023 Nordix Foundation. All rights reserved.
+#  Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved.
 #  ========================================================================
 #  Licensed under the Apache License, Version 2.0 (the "License");
 #  you may not use this file except in compliance with the License.
@@ -23,9 +24,9 @@ import requests
 
 
 from pathlib import Path
-from flask import Flask, escape, request, Response
+from flask import Flask, request, Response
 from jsonschema import validate
-from var_declaration import policy_instances, policy_status, callbacks, forced_settings, policy_fingerprint, hosts_set
+from var_declaration import policy_instances, policy_status, callbacks, forced_settings, policy_fingerprint, hosts_set, app
 from maincommon import check_apipath, apipath, get_supported_interfaces_response, extract_host_name
 
 #Constants
@@ -33,7 +34,9 @@ TEXT_PLAIN='text/plain'
 
 check_apipath()
 
-app = connexion.App(__name__, specification_dir=apipath)
+# app is created in var_declarations
+
+import payload_logging   # app var need to be initialized
 
 #Check alive function
 @app.route('/', methods=['GET'])
@@ -127,7 +130,7 @@ def sendstatus():
   cb=callbacks[policyid]
   try:
     resp=requests.post(cb,json=json.dumps(ps), verify=False) # NOSONAR
-  except:
+  except Exception:
     return Response('Post status failed, could not send to: '+str(cb), status=500, mimetype=TEXT_PLAIN)
   if (resp.status_code<199 & resp.status_code > 299):
     return Response('Post status failed with code: '+resp.status_code, status=500, mimetype=TEXT_PLAIN)
@@ -163,6 +166,8 @@ def getcounter(countername):
   elif (countername == "remote_hosts"):
     hosts=",".join(hosts_set)
     return str(hosts),200
+  elif (countername == "datadelivery"):
+    return Response(str(0),200, mimetype=TEXT_PLAIN)
   else:
     return Response("Counter name: "+countername+" not found.",404, mimetype=TEXT_PLAIN)
 
@@ -174,4 +179,4 @@ if len(sys.argv) >= 2:
 app.add_api('STD_A1.yaml')
 
 if __name__ == '__main__':
-  app.run(port=port_number, host="127.0.0.1", threaded=False)
\ No newline at end of file
+  app.run(port=port_number, host="127.0.0.1")
\ No newline at end of file