Loading my_deploy.sh +1 −1 Original line number Diff line number Diff line Loading @@ -134,7 +134,7 @@ export CRDB_PASSWORD="tfs123" export CRDB_DEPLOY_MODE="single" # Disable flag for dropping database, if it exists. export CRDB_DROP_DATABASE_IF_EXISTS="" export CRDB_DROP_DATABASE_IF_EXISTS="YES" # Disable flag for re-deploying CockroachDB from scratch. export CRDB_REDEPLOY="" Loading src/nbi/service/rest_server/nbi_plugins/camara_qod/Resources.py +27 −29 Original line number Diff line number Diff line Loading @@ -48,15 +48,14 @@ class ProfileList(_Resource): # JSON TO GRPC to store the data in the grpc server try: qos_profile = create_qos_profile_from_json(request_data) except Exception as e: LOGGER.error(e) # track if there is an error raise e except: LOGGER.exception("Error happened while creating QoS profile from json") return {"message": "Failed to create QoS profile"}, 500 # Send to gRPC server using CreateQosProfile try: qos_profile_created = self.qos_profile_client.CreateQoSProfile(qos_profile) except Exception as e: LOGGER.error(e) raise e except: LOGGER.exception("error happened while creating QoS profile") #gRPC message back to JSON using the helper function qos_profile_data = grpc_message_to_qos_table_data(qos_profile_created) LOGGER.info(f'qos_profile_data{qos_profile_data}') Loading Loading @@ -92,8 +91,8 @@ class ProfileDetail(_Resource): return {"error": f"QoSProfile {qos_profile_id} not found"}, 404 LOGGER.error(f"gRPC error while fetching QoSProfile: {exc}") return {"error": "Internal Server Error"}, 500 except Exception as e: LOGGER.error(f"Error while fetching QoSProfile: {e}") except: LOGGER.exception(f"Error while fetching QoSProfile") return {"error": "Internal Server Error"}, 500 Loading @@ -114,8 +113,8 @@ class ProfileDetail(_Resource): return {"error": f"QoSProfile {qos_profile_id} not found"}, 404 LOGGER.error(f"gRPC error while updating QoSProfile: {exc}") return {"error": "Internal Server Error"}, 500 except Exception as e: LOGGER.error(f"Error in PUT /profiles/{qos_profile_id}: {e}") except: LOGGER.exception(f"Error in PUT /profiles/{qos_profile_id}") return {"error": "Internal Server Error"}, 500 def delete(self, qos_profile_id): Loading @@ -130,15 +129,15 @@ class ProfileDetail(_Resource): return {"error": f"QoSProfile {qos_profile_id} not found"}, 404 LOGGER.error(f"gRPC error while deleting QoSProfile: {exc}") return {"error": "Internal Server Error"}, 500 except Exception as e: LOGGER.error(f"Error in DELETE /profiles/{qos_profile_id}: {e}") except: LOGGER.exception(f"Error in DELETE /profiles/{qos_profile_id}") return {"error": "Internal Server Error"}, 500 ###SESSION########################################################## class QodInfo(_Resource): def post(self): if not request.is_json: return (jsonify({'error': 'Unsupported Media Type', 'message': 'JSON payload is required'}), 415) return jsonify({'error': 'Unsupported Media Type', 'message': 'JSON payload is required'}), 415 request_data: Dict = request.get_json() qos_profile_id = request_data.get('qos_profile_id') qos_session_id = request_data.get('qos_session_id') Loading @@ -154,22 +153,25 @@ class QodInfo(_Resource): stripped_service.ClearField('service_constraints') stripped_service.ClearField('service_config') try: response = format_grpc_to_json(self.service_client.CreateService(stripped_service)) response = format_grpc_to_json(self.service_client.UpdateService(service)) except Exception as e: # pylint: disable=broad-except create_response = format_grpc_to_json(self.service_client.CreateService(stripped_service)) update_response = format_grpc_to_json(self.service_client.UpdateService(service)) response = { "create_response": create_response, "update_response": update_response } except Exception as e: LOGGER.error(f"Unexpected error: {str(e)}", exc_info=True) return jsonify({'error': 'Internal Server Error', 'message': 'An unexpected error occurred'}), 500 LOGGER.error(f"error related to response: {response}") return response #didnt work return jsonify(response) def get(self): service_list = self.client.ListServices(grpc_context_id(DEFAULT_CONTEXT_NAME)) #return context id as json qod_info = [service_2_qod(service) for service in service_list.services] #iterating over service list LOGGER.info(f"error related to qod_info: {qod_info}") return jsonify(qod_info), 200 return qod_info #didnt work return jsonify(qod_info) class QodInfoID(_Resource): def get(self, sessionId: str): try: service = self.client.GetService(grpc_service_id(DEFAULT_CONTEXT_NAME, sessionId)) Loading @@ -178,7 +180,6 @@ class QodInfoID(_Resource): if exc.code()==grpc.StatusCode.NOT_FOUND: LOGGER.warning(f"Qod Session not found: {sessionId}") return {"error": f"Qod Session {sessionId} not found"}, 404 def put(self, sessionId: str): try: request_data: Dict = request.get_json() Loading @@ -199,21 +200,18 @@ class QodInfoID(_Resource): updated_service = self.service_client.UpdateService(service) qod_response = service_2_qod(updated_service) return qod_response, 200 except KeyError as e: LOGGER.error(f"Missing required key: {e}") return {"error": f"Missing required key: {str(e)}"}, 400 except grpc._channel._InactiveRpcError as exc: if exc.code() == grpc.StatusCode.NOT_FOUND: LOGGER.warning(f"Qod Session not found: {sessionId}") return {"error": f"Qod Session {sessionId} not found"}, 404 LOGGER.error(f"gRPC error while updating Qod Session: {exc}") return {"error": "Internal Server Error"}, 500 except Exception as e: LOGGER.error(f"Error in PUT /sessions/{sessionId}: {e}") except: LOGGER.exception(f"Error in PUT /sessions/{sessionId}") return {"error": "Internal Server Error"}, 500 def delete(self, sessionId: str): self.service_client.DeleteService(grpc_service_id(DEFAULT_CONTEXT_NAME, sessionId)) return{"Session Deleted"} Loading src/nbi/tests/test_camara_qod_profile.py +1 −4 Original line number Diff line number Diff line Loading @@ -16,12 +16,10 @@ import logging from flask import jsonify import requests logging.basicConfig(level=logging.DEBUG) LOGGER = logging.getLogger() def test_create_profile(): BASE_URL = 'http://localhost/camara/qod/v0' BASE_URL = 'http://10.1.7.197/camara/qod/v0' qos_profile_data={ "name": "QCI_2_voice", "description": "QoS profile for video streaming", Loading Loading @@ -91,7 +89,6 @@ def test_create_profile(): #def test_update_profile(): # qos_profile_id = '0898e7e8-ef15-4522-8e93-623e31c92efa' # qos_profile_data = { Loading src/nbi/tests/test_camara_qos_service.py +16 −17 Original line number Diff line number Diff line Loading @@ -15,28 +15,27 @@ import logging from flask import jsonify import requests logging.basicConfig(level=logging.DEBUG) LOGGER = logging.getLogger() def test_create_SESSION(): BASE_URL = 'http://localhost/camara/qod/v0' service_data={ "device": {"ipv4Address":"84.75.11.12/25" }, "applicationServer": { "ipv4Address": "192.168.0.1/26", }, "duration":10000000.00, "qos_profile_id": "367d3e3f-96be-4391-af82-e21c042dd9bd", } post_response = requests.post(f'{BASE_URL}/sessions', json=service_data).json() #id=post_response['sessionID'] #get_response = requests.get(f'{BASE_URL}/sessions/{id}').json() get_response = requests.get(f'{BASE_URL}/sessions').json() BASE_URL = 'http://10.1.7.197/camara/qod/v0' #def test_create_SESSION(): # service_data={ # "device": # {"ipv4Address":"84.75.11.12/25" }, # "applicationServer": { # "ipv4Address": "192.168.0.1/26", # }, # "duration":10000000.00, # "qos_profile_id": "f46d563f-9f1a-44c8-9649-5fde673236d6", # } # post_response = requests.post(f'{BASE_URL}/sessions', json=service_data).json() # #id=post_response['sessionID'] # #get_response = requests.get(f'{BASE_URL}/sessions/{id}').json() # get_response = requests.get(f'{BASE_URL}/sessions').json() #def test_delete_session_by_id(): # session_id = '' # session_id = '83d4b75a-9b09-40f4-b9a9-f31d591fa319' # response = requests.delete(f'{BASE_URL}/sessions/{session_id}') #def test_update_session_by_id(): Loading Loading
my_deploy.sh +1 −1 Original line number Diff line number Diff line Loading @@ -134,7 +134,7 @@ export CRDB_PASSWORD="tfs123" export CRDB_DEPLOY_MODE="single" # Disable flag for dropping database, if it exists. export CRDB_DROP_DATABASE_IF_EXISTS="" export CRDB_DROP_DATABASE_IF_EXISTS="YES" # Disable flag for re-deploying CockroachDB from scratch. export CRDB_REDEPLOY="" Loading
src/nbi/service/rest_server/nbi_plugins/camara_qod/Resources.py +27 −29 Original line number Diff line number Diff line Loading @@ -48,15 +48,14 @@ class ProfileList(_Resource): # JSON TO GRPC to store the data in the grpc server try: qos_profile = create_qos_profile_from_json(request_data) except Exception as e: LOGGER.error(e) # track if there is an error raise e except: LOGGER.exception("Error happened while creating QoS profile from json") return {"message": "Failed to create QoS profile"}, 500 # Send to gRPC server using CreateQosProfile try: qos_profile_created = self.qos_profile_client.CreateQoSProfile(qos_profile) except Exception as e: LOGGER.error(e) raise e except: LOGGER.exception("error happened while creating QoS profile") #gRPC message back to JSON using the helper function qos_profile_data = grpc_message_to_qos_table_data(qos_profile_created) LOGGER.info(f'qos_profile_data{qos_profile_data}') Loading Loading @@ -92,8 +91,8 @@ class ProfileDetail(_Resource): return {"error": f"QoSProfile {qos_profile_id} not found"}, 404 LOGGER.error(f"gRPC error while fetching QoSProfile: {exc}") return {"error": "Internal Server Error"}, 500 except Exception as e: LOGGER.error(f"Error while fetching QoSProfile: {e}") except: LOGGER.exception(f"Error while fetching QoSProfile") return {"error": "Internal Server Error"}, 500 Loading @@ -114,8 +113,8 @@ class ProfileDetail(_Resource): return {"error": f"QoSProfile {qos_profile_id} not found"}, 404 LOGGER.error(f"gRPC error while updating QoSProfile: {exc}") return {"error": "Internal Server Error"}, 500 except Exception as e: LOGGER.error(f"Error in PUT /profiles/{qos_profile_id}: {e}") except: LOGGER.exception(f"Error in PUT /profiles/{qos_profile_id}") return {"error": "Internal Server Error"}, 500 def delete(self, qos_profile_id): Loading @@ -130,15 +129,15 @@ class ProfileDetail(_Resource): return {"error": f"QoSProfile {qos_profile_id} not found"}, 404 LOGGER.error(f"gRPC error while deleting QoSProfile: {exc}") return {"error": "Internal Server Error"}, 500 except Exception as e: LOGGER.error(f"Error in DELETE /profiles/{qos_profile_id}: {e}") except: LOGGER.exception(f"Error in DELETE /profiles/{qos_profile_id}") return {"error": "Internal Server Error"}, 500 ###SESSION########################################################## class QodInfo(_Resource): def post(self): if not request.is_json: return (jsonify({'error': 'Unsupported Media Type', 'message': 'JSON payload is required'}), 415) return jsonify({'error': 'Unsupported Media Type', 'message': 'JSON payload is required'}), 415 request_data: Dict = request.get_json() qos_profile_id = request_data.get('qos_profile_id') qos_session_id = request_data.get('qos_session_id') Loading @@ -154,22 +153,25 @@ class QodInfo(_Resource): stripped_service.ClearField('service_constraints') stripped_service.ClearField('service_config') try: response = format_grpc_to_json(self.service_client.CreateService(stripped_service)) response = format_grpc_to_json(self.service_client.UpdateService(service)) except Exception as e: # pylint: disable=broad-except create_response = format_grpc_to_json(self.service_client.CreateService(stripped_service)) update_response = format_grpc_to_json(self.service_client.UpdateService(service)) response = { "create_response": create_response, "update_response": update_response } except Exception as e: LOGGER.error(f"Unexpected error: {str(e)}", exc_info=True) return jsonify({'error': 'Internal Server Error', 'message': 'An unexpected error occurred'}), 500 LOGGER.error(f"error related to response: {response}") return response #didnt work return jsonify(response) def get(self): service_list = self.client.ListServices(grpc_context_id(DEFAULT_CONTEXT_NAME)) #return context id as json qod_info = [service_2_qod(service) for service in service_list.services] #iterating over service list LOGGER.info(f"error related to qod_info: {qod_info}") return jsonify(qod_info), 200 return qod_info #didnt work return jsonify(qod_info) class QodInfoID(_Resource): def get(self, sessionId: str): try: service = self.client.GetService(grpc_service_id(DEFAULT_CONTEXT_NAME, sessionId)) Loading @@ -178,7 +180,6 @@ class QodInfoID(_Resource): if exc.code()==grpc.StatusCode.NOT_FOUND: LOGGER.warning(f"Qod Session not found: {sessionId}") return {"error": f"Qod Session {sessionId} not found"}, 404 def put(self, sessionId: str): try: request_data: Dict = request.get_json() Loading @@ -199,21 +200,18 @@ class QodInfoID(_Resource): updated_service = self.service_client.UpdateService(service) qod_response = service_2_qod(updated_service) return qod_response, 200 except KeyError as e: LOGGER.error(f"Missing required key: {e}") return {"error": f"Missing required key: {str(e)}"}, 400 except grpc._channel._InactiveRpcError as exc: if exc.code() == grpc.StatusCode.NOT_FOUND: LOGGER.warning(f"Qod Session not found: {sessionId}") return {"error": f"Qod Session {sessionId} not found"}, 404 LOGGER.error(f"gRPC error while updating Qod Session: {exc}") return {"error": "Internal Server Error"}, 500 except Exception as e: LOGGER.error(f"Error in PUT /sessions/{sessionId}: {e}") except: LOGGER.exception(f"Error in PUT /sessions/{sessionId}") return {"error": "Internal Server Error"}, 500 def delete(self, sessionId: str): self.service_client.DeleteService(grpc_service_id(DEFAULT_CONTEXT_NAME, sessionId)) return{"Session Deleted"} Loading
src/nbi/tests/test_camara_qod_profile.py +1 −4 Original line number Diff line number Diff line Loading @@ -16,12 +16,10 @@ import logging from flask import jsonify import requests logging.basicConfig(level=logging.DEBUG) LOGGER = logging.getLogger() def test_create_profile(): BASE_URL = 'http://localhost/camara/qod/v0' BASE_URL = 'http://10.1.7.197/camara/qod/v0' qos_profile_data={ "name": "QCI_2_voice", "description": "QoS profile for video streaming", Loading Loading @@ -91,7 +89,6 @@ def test_create_profile(): #def test_update_profile(): # qos_profile_id = '0898e7e8-ef15-4522-8e93-623e31c92efa' # qos_profile_data = { Loading
src/nbi/tests/test_camara_qos_service.py +16 −17 Original line number Diff line number Diff line Loading @@ -15,28 +15,27 @@ import logging from flask import jsonify import requests logging.basicConfig(level=logging.DEBUG) LOGGER = logging.getLogger() def test_create_SESSION(): BASE_URL = 'http://localhost/camara/qod/v0' service_data={ "device": {"ipv4Address":"84.75.11.12/25" }, "applicationServer": { "ipv4Address": "192.168.0.1/26", }, "duration":10000000.00, "qos_profile_id": "367d3e3f-96be-4391-af82-e21c042dd9bd", } post_response = requests.post(f'{BASE_URL}/sessions', json=service_data).json() #id=post_response['sessionID'] #get_response = requests.get(f'{BASE_URL}/sessions/{id}').json() get_response = requests.get(f'{BASE_URL}/sessions').json() BASE_URL = 'http://10.1.7.197/camara/qod/v0' #def test_create_SESSION(): # service_data={ # "device": # {"ipv4Address":"84.75.11.12/25" }, # "applicationServer": { # "ipv4Address": "192.168.0.1/26", # }, # "duration":10000000.00, # "qos_profile_id": "f46d563f-9f1a-44c8-9649-5fde673236d6", # } # post_response = requests.post(f'{BASE_URL}/sessions', json=service_data).json() # #id=post_response['sessionID'] # #get_response = requests.get(f'{BASE_URL}/sessions/{id}').json() # get_response = requests.get(f'{BASE_URL}/sessions').json() #def test_delete_session_by_id(): # session_id = '' # session_id = '83d4b75a-9b09-40f4-b9a9-f31d591fa319' # response = requests.delete(f'{BASE_URL}/sessions/{session_id}') #def test_update_session_by_id(): Loading