+"""
+A1 entrypoint
+"""
# ==================================================================================
# Copyright (c) 2019 Nokia
# Copyright (c) 2018-2019 AT&T Intellectual Property.
# 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()