atlanticwave-sdx / sdx-controller

Central Controller for AtlanticWave SDX.
https://www.atlanticwave-sdx.net
MIT License
2 stars 3 forks source link

Reading database sometimes throws an exception #180

Open sajith opened 1 year ago

sajith commented 1 year ago

I tried to do a POST /connection with a sample test request, without running the local controllers. It caused a crash. It must be that there's no "latest_topo" in the DB, but that should be normal and expected.

sdx-controller-sdx-controller-service-1  | INFO:swagger_server.messaging.rpc_queue_consumer: [MQ] Awaiting requests from queue: topo
sdx-controller-sdx-controller-service-1  | INFO:swagger_server.controllers.connection_controller:Placing connection: {'id': 'id', 'name': 'AMLight', 'start_time': '2000-01-23T04:56:07.000Z', 'end_time': '2000-01-23T04:56:07.000Z', 'bandwidth_required': 10, 'latency_required': 300, 'egress_port': {'id': 'urn:sdx:port:amlight.net:A1:1', 'name': 'Novi100:1', 'node': 'urn:sdx:node:amlight.net:A1', 'status': 'up'}, 'ingress_port': {'id': 'urn:ogf:network:sdx:port:zaoxi:A1:2', 'name': 'Novi100:2', 'node': 'urn:ogf:network:sdx:node:zaoxi:A1', 'status': 'up'}}
sdx-controller-sdx-controller-service-1  | INFO:swagger_server.controllers.connection_controller:Gathered connexion JSON: {'id': 'id', 'name': 'AMLight', 'start_time': '2000-01-23T04:56:07.000Z', 'end_time': '2000-01-23T04:56:07.000Z', 'bandwidth_required': 10, 'latency_required': 300, 'egress_port': {'id': 'urn:sdx:port:amlight.net:A1:1', 'name': 'Novi100:1', 'node': 'urn:sdx:node:amlight.net:A1', 'status': 'up'}, 'ingress_port': {'id': 'urn:ogf:network:sdx:port:zaoxi:A1:2', 'name': 'Novi100:2', 'node': 'urn:ogf:network:sdx:node:zaoxi:A1', 'status': 'up'}}
sdx-controller-sdx-controller-service-1  | INFO:swagger_server.controllers.connection_controller:Placing connection. Saving to database.
sdx-controller-sdx-controller-service-1  | DEBUG:swagger_server.utils.db_utils:Adding key value pair connection_data:{"id": "id", "name": "AMLight", "start_time": "2000-01-23T04:56:07.000Z", "end_time": "2000-01-23T04:56:07.000Z", "bandwidth_required": 10, "latency_required": 300, "egress_port": {"id": "urn:sdx:port:amlight.net:A1:1", "name": "Novi100:1", "node": "urn:sdx:node:amlight.net:A1", "status": "up"}, "ingress_port": {"id": "urn:ogf:network:sdx:port:zaoxi:A1:2", "name": "Novi100:2", "node": "urn:ogf:network:sdx:node:zaoxi:A1", "status": "up"}} to DB.
sdx-controller-mongodb-service-1         | 2023-07-26T15:11:40.523+0000 I STORAGE  [conn4] createCollection: sdx-controllder-test-db.sdx-controllder-test-db.sdx-controller-test-table with generated UUID: 1ba44083-3486-4ff5-8be3-4361fa3b4371
sdx-controller-sdx-controller-service-1  | INFO:swagger_server.controllers.connection_controller:Saving to database complete.
sdx-controller-sdx-controller-service-1  | ERROR:__main__:Exception on /SDX-Controller/1.0.0/conection [POST]
sdx-controller-sdx-controller-service-1  | Traceback (most recent call last):
sdx-controller-sdx-controller-service-1  |   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2529, in wsgi_app
sdx-controller-sdx-controller-service-1  |     response = self.full_dispatch_request()
sdx-controller-sdx-controller-service-1  |   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1825, in full_dispatch_request
sdx-controller-sdx-controller-service-1  |     rv = self.handle_user_exception(e)
sdx-controller-sdx-controller-service-1  |   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1823, in full_dispatch_request
sdx-controller-sdx-controller-service-1  |     rv = self.dispatch_request()
sdx-controller-sdx-controller-service-1  |   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1799, in dispatch_request
sdx-controller-sdx-controller-service-1  |     return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
sdx-controller-sdx-controller-service-1  |   File "/usr/local/lib/python3.9/site-packages/connexion/decorators/decorator.py", line 68, in wrapper
sdx-controller-sdx-controller-service-1  |     response = function(request)
sdx-controller-sdx-controller-service-1  |   File "/usr/local/lib/python3.9/site-packages/connexion/decorators/uri_parsing.py", line 149, in wrapper
sdx-controller-sdx-controller-service-1  |     response = function(request)
sdx-controller-sdx-controller-service-1  |   File "/usr/local/lib/python3.9/site-packages/connexion/decorators/validation.py", line 196, in wrapper
sdx-controller-sdx-controller-service-1  |     response = function(request)
sdx-controller-sdx-controller-service-1  |   File "/usr/local/lib/python3.9/site-packages/connexion/decorators/parameter.py", line 120, in wrapper
sdx-controller-sdx-controller-service-1  |     return function(**kwargs)
sdx-controller-sdx-controller-service-1  |   File "/usr/src/app/swagger_server/controllers/connection_controller.py", line 92, in place_connection
sdx-controller-sdx-controller-service-1  |     topo_val = db_instance.read_from_db("latest_topo")["latest_topo"]
sdx-controller-sdx-controller-service-1  | TypeError: 'NoneType' object is not subscriptable
sdx-controller-sdx-controller-service-1  | INFO:werkzeug:174.170.111.107 - - [26/Jul/2023 15:11:40] "POST /SDX-Controller/1.0.0/conection HTTP/1.1" 500 -
congwang09 commented 1 year ago

As Sajith mentioned in the above PR, we should refactor the DB class to make it more resilient and easier to use. Pasting the comments here: