X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=a1%2Frun.py;h=67f63d6ca2c63851831fb1dbcaf47390bd824eb9;hb=refs%2Fchanges%2F77%2F1177%2F5;hp=903fe856a7c6ab6d320186c3b04365148486449c;hpb=5ad8f03e1fc7683bb59da31f59edc2f6c0b2372b;p=ric-plt%2Fa1.git diff --git a/a1/run.py b/a1/run.py index 903fe85..67f63d6 100644 --- a/a1/run.py +++ b/a1/run.py @@ -1,3 +1,6 @@ +""" +A1 entrypoint +""" # ================================================================================== # Copyright (c) 2019 Nokia # Copyright (c) 2018-2019 AT&T Intellectual Property. @@ -14,27 +17,36 @@ # See the License for the specific language governing permissions and # limitations under the License. # ================================================================================== +import time +from threading import Thread from gevent.pywsgi import WSGIServer from a1 import get_module_logger, app -from a1 import utils, exceptions -from a1.a1rmr import init_rmr -import sys +from a1 import a1rmr logger = get_module_logger(__name__) +def start_rmr_thread(real_init=True): + """ + Start a1s rmr thread + Also called during unit testing + """ + rmr_loop = a1rmr.RmrLoop(real_init) + thread = Thread(target=rmr_loop.loop) + thread.start() + while not rmr_loop.rmr_is_ready(): + time.sleep(0.5) + return rmr_loop # return the handle; useful during unit testing + + def main(): """Entrypoint""" - # Fail fast if we don't have a manifest - try: - utils.get_ric_manifest() - except exceptions.MissingManifest: - logger.error("Failing fast: no A1 manifest found!") - sys.exit(1) + # start rmr thread + logger.debug("Initializing rmr thread. A1s webserver will not start until rmr initialization is complete.") + start_rmr_thread() - logger.debug("Initializing rmr") - init_rmr() + # start webserver logger.debug("Starting gevent server") - http_server = WSGIServer(('', 10000), app) + http_server = WSGIServer(("", 10000), app) http_server.serve_forever()