From a84cb754f14cffea594825cf32afaded891d9998 Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Mon, 16 Dec 2024 10:52:25 +0100 Subject: [PATCH 01/18] Setting logic for events sent by publisher according to monitoring status. --- .../core/serviceapidescriptions.py | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index 83d5f7b..0ba6df0 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -132,28 +132,27 @@ class PublishServiceOperations(Resource): if res.status_code == 201: current_app.logger.info("Service published") - if serviceapidescription.api_status is None or len(serviceapidescription.api_status.aef_ids) > 0: - if serviceapidescription.return_supp_feat_dict(serviceapidescription.supported_features)["ApiStatusMonitoring"]: - current_app.logger.info(f"Service available") + if serviceapidescription.return_supp_feat_dict(serviceapidescription.supported_features)["ApiStatusMonitoring"]: + if serviceapidescription.api_status is None or len(serviceapidescription.api_status.aef_ids) > 0: + current_app.logger.info( + "Service available, at least one AEF is available") RedisEvent("SERVICE_API_AVAILABLE", service_api_descriptions=[clean_n_camel_case( serviceapidescription.to_dict())], api_ids=[str(api_id)]).send_event() else: - current_app.logger.info("Service available") - RedisEvent("SERVICE_API_AVAILABLE", - api_ids=[str(api_id)]).send_event() - else: - if serviceapidescription.return_supp_feat_dict(serviceapidescription.supported_features)["ApiStatusMonitoring"]: - current_app.logger.info(f"Service unavailable") + current_app.logger.info( + "Service unavailable, all AEFs are unavailable") RedisEvent("SERVICE_API_UNAVAILABLE", service_api_descriptions=[clean_n_camel_case( serviceapidescription.to_dict())], api_ids=[str(api_id)]).send_event() - else: - current_app.logger.info("Service available") - RedisEvent("SERVICE_API_UNAVAILABLE", - api_ids=[str(api_id)]).send_event() + else: + current_app.logger.info(f"Service available") + RedisEvent("SERVICE_API_AVAILABLE", + service_api_descriptions=[clean_n_camel_case( + serviceapidescription.to_dict())], + api_ids=[str(api_id)]).send_event() return res -- GitLab From 865ec9ef0242a06953549ecc48679f1aa3034bbd Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Mon, 16 Dec 2024 11:01:29 +0100 Subject: [PATCH 02/18] Delete publish send only SERVICE_API_UNAVAILABLE --- .../core/serviceapidescriptions.py | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index 0ba6df0..dd3b8ed 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -228,25 +228,12 @@ class PublishServiceOperations(Resource): serviceapidescription = clean_empty( dict_to_camel_case(serviceapidescription_dict)) if res.status_code == 204: - is_supported = serviceapidescription.get("supportedFeatures") and \ - ServiceAPIDescription.return_supp_feat_dict( - serviceapidescription["supportedFeatures"]).get("ApiStatusMonitoring") - - if is_supported: - current_app.logger.info("Service unavailable") - RedisEvent( - "SERVICE_API_UNAVAILABLE", - service_api_descriptions=[serviceapidescription], - api_ids=[str(service_api_id)] - ).send_event() - - else: - status_message = "Service available" if serviceapidescription.get( - "supportedFeatures") is None else "Service unavailable" - current_app.logger.info(status_message) - RedisEvent( - "SERVICE_API_UNAVAILABLE", api_ids=[str(service_api_id)] - ).send_event() + current_app.logger.info("Service unavailable") + RedisEvent( + "SERVICE_API_UNAVAILABLE", + service_api_descriptions=[serviceapidescription], + api_ids=[str(service_api_id)] + ).send_event() return res -- GitLab From 3990bdeb81cf206cfe03fe4686b56544ad426e2b Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Mon, 16 Dec 2024 12:01:18 +0100 Subject: [PATCH 03/18] Update on publish upgraded to support send of event SERVICE_API_AVAILABLE/UNAVAILABLE only on change --- .../core/serviceapidescriptions.py | 86 +++++++++++-------- 1 file changed, 50 insertions(+), 36 deletions(-) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index dd3b8ed..fd6c9c3 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -254,17 +254,20 @@ class PublishServiceOperations(Resource): "Updating service api with id: " + service_api_id) my_query = {'apf_id': apf_id, 'api_id': service_api_id} - serviceapidescription = mycol.find_one(my_query) + serviceapidescription_old = mycol.find_one(my_query) - if serviceapidescription is None: + if serviceapidescription_old is None: current_app.logger.error(service_api_not_found_message) return not_found_error(detail="Service API not existing", cause="Service API id not found") service_api_description = service_api_description.to_dict() service_api_description = clean_empty(service_api_description) + service_api_description_old = ServiceAPIDescription.from_dict( + json.dumps(serviceapidescription_old, cls=CustomJSONEncoder)) + result = mycol.find_one_and_update( - serviceapidescription, + serviceapidescription_old, {"$set": service_api_description}, projection={"_id": 0, "api_name": 1, @@ -293,39 +296,10 @@ class PublishServiceOperations(Resource): if response.status_code == 200: RedisEvent("SERVICE_API_UPDATE", service_api_descriptions=[service_api_description_updated]).send_event() - if service_api_description.api_status is None or len(service_api_description.api_status.aef_ids) > 0: - if service_api_description.supported_features is not None: - if service_api_description.return_supp_feat_dict(service_api_description.supported_features)["ApiStatusMonitoring"]: - current_app.logger.info(f"Service available") - RedisEvent("SERVICE_API_AVAILABLE", - service_api_descriptions=[ - service_api_description], - api_ids=[str(service_api_id)] - ).send_event() - else: - current_app.logger.info("Service available") - RedisEvent("SERVICE_API_AVAILABLE", - api_ids=[str(service_api_id)]).send_event() - else: - current_app.logger.info("Service available") - RedisEvent("SERVICE_API_AVAILABLE", - api_ids=[str(service_api_id)]).send_event() - else: - if service_api_description.supported_features is not None: - if service_api_description.return_supp_feat_dict(service_api_description.supported_features)["ApiStatusMonitoring"]: - current_app.logger.info(f"Service unavailable") - RedisEvent("SERVICE_API_UNAVAILABLE", - service_api_descriptions=[ - service_api_description], - api_ids=[str(service_api_id)]).send_event() - else: - current_app.logger.info("Service available") - RedisEvent("SERVICE_API_UNAVAILABLE", - api_ids=[str(service_api_id)]).send_event() - else: - current_app.logger.info("Service available") - RedisEvent("SERVICE_API_UNAVAILABLE", - api_ids=[str(service_api_id)]).send_event() + self.send_events_on_update( + service_api_id, + service_api_description_old, + service_api_description_updated) return response @@ -333,3 +307,43 @@ class PublishServiceOperations(Resource): exception = "An exception occurred in update service" current_app.logger.error(exception + "::" + str(e)) return internal_server_error(detail=exception, cause=str(e)) + + def send_events_on_update(self, + service_api_id, + service_api_decription_old, + service_api_description_new): + + service_api_status_event_old = self.service_api_status_event( + service_api_decription_old) + service_api_status_event_new = self.service_api_status_event( + service_api_decription_old) + + if service_api_status_event_old == service_api_status_event_new: + current_app.logger.info( + "service_api_status not changed, it remains " + + service_api_status_event_new + + " Then no event will be sent") + else: + current_app.logger.info("service_api_status changed, event " + + service_api_status_event_new + + " Event will be sent") + RedisEvent(service_api_status_event_new, + service_api_descriptions=[ + service_api_description_new], + api_ids=[str(service_api_id)]).send_event() + + def service_api_status_event(service_api_description): + service_api_status = "" + if ServiceAPIDescription.return_supp_feat_dict(service_api_description.supported_features)["ApiStatusMonitoring"]: + if service_api_description.api_status is None or len(service_api_description.api_status.aef_ids) > 0: + current_app.logger.info( + "Service available, at least one AEF is available") + service_api_status = "SERVICE_API_AVAILABLE" + else: + current_app.logger.info( + "Service unavailable, all AEFs are unavailable") + service_api_status = "SERVICE_API_UNAVAILABLE" + else: + current_app.logger.info("Service available") + service_api_status = "SERVICE_API_AVAILABLE" + return service_api_status -- GitLab From 05d50bb29a85299264dcf2d7846bb2c407d15012 Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Mon, 16 Dec 2024 12:08:12 +0100 Subject: [PATCH 04/18] Code refactor con publish events --- .../core/serviceapidescriptions.py | 33 +++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index fd6c9c3..d27f5c3 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -132,27 +132,12 @@ class PublishServiceOperations(Resource): if res.status_code == 201: current_app.logger.info("Service published") - if serviceapidescription.return_supp_feat_dict(serviceapidescription.supported_features)["ApiStatusMonitoring"]: - if serviceapidescription.api_status is None or len(serviceapidescription.api_status.aef_ids) > 0: - current_app.logger.info( - "Service available, at least one AEF is available") - RedisEvent("SERVICE_API_AVAILABLE", - service_api_descriptions=[clean_n_camel_case( - serviceapidescription.to_dict())], - api_ids=[str(api_id)]).send_event() - else: - current_app.logger.info( - "Service unavailable, all AEFs are unavailable") - RedisEvent("SERVICE_API_UNAVAILABLE", - service_api_descriptions=[clean_n_camel_case( - serviceapidescription.to_dict())], - api_ids=[str(api_id)]).send_event() - else: - current_app.logger.info(f"Service available") - RedisEvent("SERVICE_API_AVAILABLE", - service_api_descriptions=[clean_n_camel_case( - serviceapidescription.to_dict())], - api_ids=[str(api_id)]).send_event() + event_to_send = self.service_api_availability_event( + serviceapidescription) + RedisEvent(event_to_send, + service_api_descriptions=[clean_n_camel_case( + serviceapidescription.to_dict())], + api_ids=[str(api_id)]).send_event() return res @@ -313,9 +298,9 @@ class PublishServiceOperations(Resource): service_api_decription_old, service_api_description_new): - service_api_status_event_old = self.service_api_status_event( + service_api_status_event_old = self.service_api_availability_event( service_api_decription_old) - service_api_status_event_new = self.service_api_status_event( + service_api_status_event_new = self.service_api_availability_event( service_api_decription_old) if service_api_status_event_old == service_api_status_event_new: @@ -332,7 +317,7 @@ class PublishServiceOperations(Resource): service_api_description_new], api_ids=[str(service_api_id)]).send_event() - def service_api_status_event(service_api_description): + def service_api_availability_event(service_api_description): service_api_status = "" if ServiceAPIDescription.return_supp_feat_dict(service_api_description.supported_features)["ApiStatusMonitoring"]: if service_api_description.api_status is None or len(service_api_description.api_status.aef_ids) > 0: -- GitLab From 347670cf53380f8c9bd4ef55b8ade960bd97f21f Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Mon, 16 Dec 2024 12:14:03 +0100 Subject: [PATCH 05/18] Fix code --- .../published_apis/core/serviceapidescriptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index d27f5c3..bab85a6 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -317,7 +317,7 @@ class PublishServiceOperations(Resource): service_api_description_new], api_ids=[str(service_api_id)]).send_event() - def service_api_availability_event(service_api_description): + def service_api_availability_event(self, service_api_description): service_api_status = "" if ServiceAPIDescription.return_supp_feat_dict(service_api_description.supported_features)["ApiStatusMonitoring"]: if service_api_description.api_status is None or len(service_api_description.api_status.aef_ids) > 0: -- GitLab From 4db3eb183377be2a9effcb69f029aa0c151fa23b Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Mon, 16 Dec 2024 12:36:04 +0100 Subject: [PATCH 06/18] Fix code --- .../published_apis/core/serviceapidescriptions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index bab85a6..70c059f 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -248,8 +248,8 @@ class PublishServiceOperations(Resource): service_api_description = service_api_description.to_dict() service_api_description = clean_empty(service_api_description) - service_api_description_old = ServiceAPIDescription.from_dict( - json.dumps(serviceapidescription_old, cls=CustomJSONEncoder)) + # service_api_description_old = ServiceAPIDescription.from_dict( + # json.dumps(serviceapidescription_old, cls=CustomJSONEncoder)) result = mycol.find_one_and_update( serviceapidescription_old, @@ -283,7 +283,7 @@ class PublishServiceOperations(Resource): service_api_descriptions=[service_api_description_updated]).send_event() self.send_events_on_update( service_api_id, - service_api_description_old, + serviceapidescription_old, service_api_description_updated) return response -- GitLab From 86d93c0406c36a34f62951f05c3840c47d611f25 Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Mon, 16 Dec 2024 12:49:25 +0100 Subject: [PATCH 07/18] Fix Code, adding check on Publish PUT to check supportedFeatures are present --- .../published_apis/controllers/default_controller.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/controllers/default_controller.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/controllers/default_controller.py index 3e2ddb9..b5bed44 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/controllers/default_controller.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/controllers/default_controller.py @@ -173,6 +173,13 @@ def apf_id_service_apis_service_api_id_put(service_api_id, apf_id, body): # noq current_app.logger.info( "Updating service api id with id: " + service_api_id) + if 'supportedFeatures' not in body: + return bad_request_error( + detail="supportedFeatures not present in request", + cause="supportedFeatures not present", + invalid_params=[{"param": "supportedFeatures", "reason": "not defined"}] + ) + if request.is_json: body = ServiceAPIDescription.from_dict(request.get_json()) # noqa: E501 -- GitLab From 4dcdb54effe3a32ab5ad2a35bfbc49069b791a25 Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Mon, 16 Dec 2024 13:05:32 +0100 Subject: [PATCH 08/18] Fix Code, adding check on Publish PUT to check supportedFeatures are present --- .../published_apis/core/serviceapidescriptions.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index 70c059f..0baf4ad 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -248,9 +248,6 @@ class PublishServiceOperations(Resource): service_api_description = service_api_description.to_dict() service_api_description = clean_empty(service_api_description) - # service_api_description_old = ServiceAPIDescription.from_dict( - # json.dumps(serviceapidescription_old, cls=CustomJSONEncoder)) - result = mycol.find_one_and_update( serviceapidescription_old, {"$set": service_api_description}, @@ -284,7 +281,7 @@ class PublishServiceOperations(Resource): self.send_events_on_update( service_api_id, serviceapidescription_old, - service_api_description_updated) + result) return response @@ -297,7 +294,6 @@ class PublishServiceOperations(Resource): service_api_id, service_api_decription_old, service_api_description_new): - service_api_status_event_old = self.service_api_availability_event( service_api_decription_old) service_api_status_event_new = self.service_api_availability_event( -- GitLab From 97d1642b7c3d1acd2703ce19746f5e229808f87d Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Mon, 16 Dec 2024 13:16:00 +0100 Subject: [PATCH 09/18] log service_api_descriptions --- .../published_apis/core/serviceapidescriptions.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index 0baf4ad..8d1a63f 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -294,8 +294,10 @@ class PublishServiceOperations(Resource): service_api_id, service_api_decription_old, service_api_description_new): + current_app.logger.debug(json.dumps(service_api_status_event_old, indent=4)) service_api_status_event_old = self.service_api_availability_event( service_api_decription_old) + current_app.logger.debug(json.dumps(service_api_status_event_new, indent=4)) service_api_status_event_new = self.service_api_availability_event( service_api_decription_old) -- GitLab From 91dcd8998e064c545841dbcf2fc7c4a039375c78 Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Mon, 16 Dec 2024 13:24:34 +0100 Subject: [PATCH 10/18] log service_api_descriptions --- .../published_apis/core/serviceapidescriptions.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index 8d1a63f..0a21ade 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -292,14 +292,14 @@ class PublishServiceOperations(Resource): def send_events_on_update(self, service_api_id, - service_api_decription_old, + service_api_description_old, service_api_description_new): - current_app.logger.debug(json.dumps(service_api_status_event_old, indent=4)) + current_app.logger.debug(json.dumps(service_api_description_old, indent=4)) service_api_status_event_old = self.service_api_availability_event( - service_api_decription_old) + service_api_description_old) current_app.logger.debug(json.dumps(service_api_status_event_new, indent=4)) service_api_status_event_new = self.service_api_availability_event( - service_api_decription_old) + service_api_description_old) if service_api_status_event_old == service_api_status_event_new: current_app.logger.info( -- GitLab From eb8a0f6164e77a53d45323c3ce527eab5b4e2806 Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Mon, 16 Dec 2024 13:43:58 +0100 Subject: [PATCH 11/18] debug log added to publish --- .../published_apis/core/serviceapidescriptions.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index 0a21ade..73067df 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -278,9 +278,12 @@ class PublishServiceOperations(Resource): if response.status_code == 200: RedisEvent("SERVICE_API_UPDATE", service_api_descriptions=[service_api_description_updated]).send_event() + my_service_api = dict_to_camel_case(serviceapidescription_old) + my_service_api = clean_empty(my_service_api) + my_service_api_old = ServiceAPIDescription.from_dict(my_service_api) self.send_events_on_update( service_api_id, - serviceapidescription_old, + my_service_api_old, result) return response @@ -294,10 +297,11 @@ class PublishServiceOperations(Resource): service_api_id, service_api_description_old, service_api_description_new): - current_app.logger.debug(json.dumps(service_api_description_old, indent=4)) + current_app.logger.debug("send Events if needed") + # current_app.logger.debug(json.dumps(service_api_description_old, indent=4)) service_api_status_event_old = self.service_api_availability_event( service_api_description_old) - current_app.logger.debug(json.dumps(service_api_status_event_new, indent=4)) + # current_app.logger.debug(json.dumps(service_api_status_event_new, indent=4)) service_api_status_event_new = self.service_api_availability_event( service_api_description_old) -- GitLab From 12c0e8dc791ea5c62037648c8e1eb2506a406ff5 Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Mon, 16 Dec 2024 14:25:40 +0100 Subject: [PATCH 12/18] Fix on publish service --- .../published_apis/core/serviceapidescriptions.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index 73067df..adc7873 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -239,7 +239,17 @@ class PublishServiceOperations(Resource): "Updating service api with id: " + service_api_id) my_query = {'apf_id': apf_id, 'api_id': service_api_id} - serviceapidescription_old = mycol.find_one(my_query) + serviceapidescription_old = mycol.find_one(my_query, {"_id": 0, + "api_name": 1, + "api_id": 1, + "aef_profiles": 1, + "description": 1, + "supported_features": 1, + "shareable_info": 1, + "service_api_category": 1, + "api_supp_feats": 1, + "pub_api_path": 1, + "ccf_id": 1}) if serviceapidescription_old is None: current_app.logger.error(service_api_not_found_message) @@ -280,7 +290,8 @@ class PublishServiceOperations(Resource): service_api_descriptions=[service_api_description_updated]).send_event() my_service_api = dict_to_camel_case(serviceapidescription_old) my_service_api = clean_empty(my_service_api) - my_service_api_old = ServiceAPIDescription.from_dict(my_service_api) + my_service_api_old = ServiceAPIDescription.from_dict( + my_service_api) self.send_events_on_update( service_api_id, my_service_api_old, -- GitLab From e0223e8185a3e080c89c36e8328e4f1c3dd4c62b Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Mon, 16 Dec 2024 14:36:36 +0100 Subject: [PATCH 13/18] Fix on publish service --- .../published_apis/core/serviceapidescriptions.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index adc7873..70f0001 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -250,7 +250,6 @@ class PublishServiceOperations(Resource): "api_supp_feats": 1, "pub_api_path": 1, "ccf_id": 1}) - if serviceapidescription_old is None: current_app.logger.error(service_api_not_found_message) return not_found_error(detail="Service API not existing", cause="Service API id not found") @@ -288,10 +287,18 @@ class PublishServiceOperations(Resource): if response.status_code == 200: RedisEvent("SERVICE_API_UPDATE", service_api_descriptions=[service_api_description_updated]).send_event() + current_app.logger.debug("1") + current_app.logger.debug(serviceapidescription_old) my_service_api = dict_to_camel_case(serviceapidescription_old) + current_app.logger.debug("2") + current_app.logger.debug(my_service_api) my_service_api = clean_empty(my_service_api) + current_app.logger.debug("3") + current_app.logger.debug(my_service_api) my_service_api_old = ServiceAPIDescription.from_dict( my_service_api) + current_app.logger.debug("4") + current_app.logger.debug(my_service_api) self.send_events_on_update( service_api_id, my_service_api_old, -- GitLab From 2b5d318fbfbb9fd637e47af6050f1526d342bc78 Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Mon, 16 Dec 2024 14:44:03 +0100 Subject: [PATCH 14/18] Fix on publish service --- .../core/serviceapidescriptions.py | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index 70f0001..83ad7a4 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -289,19 +289,19 @@ class PublishServiceOperations(Resource): service_api_descriptions=[service_api_description_updated]).send_event() current_app.logger.debug("1") current_app.logger.debug(serviceapidescription_old) - my_service_api = dict_to_camel_case(serviceapidescription_old) - current_app.logger.debug("2") - current_app.logger.debug(my_service_api) - my_service_api = clean_empty(my_service_api) - current_app.logger.debug("3") - current_app.logger.debug(my_service_api) - my_service_api_old = ServiceAPIDescription.from_dict( - my_service_api) - current_app.logger.debug("4") - current_app.logger.debug(my_service_api) + # my_service_api = dict_to_camel_case(serviceapidescription_old) + # current_app.logger.debug("2") + # current_app.logger.debug(my_service_api) + # my_service_api = clean_empty(my_service_api) + # current_app.logger.debug("3") + # current_app.logger.debug(my_service_api) + # my_service_api_old = ServiceAPIDescription.from_dict( + # my_service_api) + # current_app.logger.debug("4") + # current_app.logger.debug(my_service_api) self.send_events_on_update( service_api_id, - my_service_api_old, + serviceapidescription_old, result) return response @@ -319,9 +319,13 @@ class PublishServiceOperations(Resource): # current_app.logger.debug(json.dumps(service_api_description_old, indent=4)) service_api_status_event_old = self.service_api_availability_event( service_api_description_old) + current_app.logger.debug("A1") # current_app.logger.debug(json.dumps(service_api_status_event_new, indent=4)) service_api_status_event_new = self.service_api_availability_event( service_api_description_old) + current_app.logger.debug("A2") + current_app.logger.debug(service_api_status_event_old) + current_app.logger.debug(service_api_status_event_new) if service_api_status_event_old == service_api_status_event_new: current_app.logger.info( -- GitLab From 5cc4ed815dac82faa29995bba68e0696525a19f4 Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Mon, 16 Dec 2024 14:49:23 +0100 Subject: [PATCH 15/18] Fix on publish service --- .../published_apis/core/serviceapidescriptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index 83ad7a4..b6452cc 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -343,7 +343,7 @@ class PublishServiceOperations(Resource): def service_api_availability_event(self, service_api_description): service_api_status = "" - if ServiceAPIDescription.return_supp_feat_dict(service_api_description.supported_features)["ApiStatusMonitoring"]: + if ServiceAPIDescription.return_supp_feat_dict(service_api_description.get("supported_features", None))["ApiStatusMonitoring"]: if service_api_description.api_status is None or len(service_api_description.api_status.aef_ids) > 0: current_app.logger.info( "Service available, at least one AEF is available") -- GitLab From cda6097dbc87a3deffef57851a6429ba889b7810 Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Mon, 16 Dec 2024 15:00:25 +0100 Subject: [PATCH 16/18] Fix on publish service --- .../published_apis/core/serviceapidescriptions.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index b6452cc..0519e9c 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -289,6 +289,13 @@ class PublishServiceOperations(Resource): service_api_descriptions=[service_api_description_updated]).send_event() current_app.logger.debug("1") current_app.logger.debug(serviceapidescription_old) + my_service_api = dict_to_camel_case(serviceapidescription_old) + current_app.logger.debug("2") + current_app.logger.debug(my_service_api) + my_service_api = clean_empty(my_service_api) + current_app.logger.debug("3") + current_app.logger.debug(my_service_api) + my_service_old = ServiceAPIDescription.from_dict(json.dumps(my_service_api, cls=CustomJSONEncoder)) # my_service_api = dict_to_camel_case(serviceapidescription_old) # current_app.logger.debug("2") # current_app.logger.debug(my_service_api) @@ -301,7 +308,7 @@ class PublishServiceOperations(Resource): # current_app.logger.debug(my_service_api) self.send_events_on_update( service_api_id, - serviceapidescription_old, + my_service_old, result) return response @@ -316,11 +323,9 @@ class PublishServiceOperations(Resource): service_api_description_old, service_api_description_new): current_app.logger.debug("send Events if needed") - # current_app.logger.debug(json.dumps(service_api_description_old, indent=4)) service_api_status_event_old = self.service_api_availability_event( service_api_description_old) current_app.logger.debug("A1") - # current_app.logger.debug(json.dumps(service_api_status_event_new, indent=4)) service_api_status_event_new = self.service_api_availability_event( service_api_description_old) current_app.logger.debug("A2") @@ -343,7 +348,7 @@ class PublishServiceOperations(Resource): def service_api_availability_event(self, service_api_description): service_api_status = "" - if ServiceAPIDescription.return_supp_feat_dict(service_api_description.get("supported_features", None))["ApiStatusMonitoring"]: + if ServiceAPIDescription.return_supp_feat_dict(service_api_description.supported_features)["ApiStatusMonitoring"]: if service_api_description.api_status is None or len(service_api_description.api_status.aef_ids) > 0: current_app.logger.info( "Service available, at least one AEF is available") -- GitLab From ff1751d30970c703d0d14912968f126e6ec57f1b Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Mon, 16 Dec 2024 15:20:31 +0100 Subject: [PATCH 17/18] Fix on publish service --- .../published_apis/core/serviceapidescriptions.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index 0519e9c..ad070f0 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -296,6 +296,7 @@ class PublishServiceOperations(Resource): current_app.logger.debug("3") current_app.logger.debug(my_service_api) my_service_old = ServiceAPIDescription.from_dict(json.dumps(my_service_api, cls=CustomJSONEncoder)) + current_app.logger.debug(my_service_old.to_dict()) # my_service_api = dict_to_camel_case(serviceapidescription_old) # current_app.logger.debug("2") # current_app.logger.debug(my_service_api) @@ -349,6 +350,8 @@ class PublishServiceOperations(Resource): def service_api_availability_event(self, service_api_description): service_api_status = "" if ServiceAPIDescription.return_supp_feat_dict(service_api_description.supported_features)["ApiStatusMonitoring"]: + current_app.logger.info( + "ApiStatusMonitoring active") if service_api_description.api_status is None or len(service_api_description.api_status.aef_ids) > 0: current_app.logger.info( "Service available, at least one AEF is available") -- GitLab From 3319604bb502e116198b4c1a96e97088b31830d6 Mon Sep 17 00:00:00 2001 From: Jorge Moratinos Salcines Date: Mon, 16 Dec 2024 15:44:27 +0100 Subject: [PATCH 18/18] Fix problem with event checked on publish --- .../core/serviceapidescriptions.py | 40 +++++-------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py index ad070f0..ffc31e5 100644 --- a/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py +++ b/services/TS29222_CAPIF_Publish_Service_API/published_apis/core/serviceapidescriptions.py @@ -133,7 +133,8 @@ class PublishServiceOperations(Resource): if res.status_code == 201: current_app.logger.info("Service published") event_to_send = self.service_api_availability_event( - serviceapidescription) + clean_n_camel_case( + serviceapidescription_dict)) RedisEvent(event_to_send, service_api_descriptions=[clean_n_camel_case( serviceapidescription.to_dict())], @@ -287,30 +288,12 @@ class PublishServiceOperations(Resource): if response.status_code == 200: RedisEvent("SERVICE_API_UPDATE", service_api_descriptions=[service_api_description_updated]).send_event() - current_app.logger.debug("1") - current_app.logger.debug(serviceapidescription_old) - my_service_api = dict_to_camel_case(serviceapidescription_old) - current_app.logger.debug("2") - current_app.logger.debug(my_service_api) - my_service_api = clean_empty(my_service_api) - current_app.logger.debug("3") - current_app.logger.debug(my_service_api) - my_service_old = ServiceAPIDescription.from_dict(json.dumps(my_service_api, cls=CustomJSONEncoder)) - current_app.logger.debug(my_service_old.to_dict()) - # my_service_api = dict_to_camel_case(serviceapidescription_old) - # current_app.logger.debug("2") - # current_app.logger.debug(my_service_api) - # my_service_api = clean_empty(my_service_api) - # current_app.logger.debug("3") - # current_app.logger.debug(my_service_api) - # my_service_api_old = ServiceAPIDescription.from_dict( - # my_service_api) - # current_app.logger.debug("4") - # current_app.logger.debug(my_service_api) + + my_service_api = clean_n_camel_case(serviceapidescription_old) self.send_events_on_update( service_api_id, - my_service_old, - result) + my_service_api, + service_api_description_updated) return response @@ -326,12 +309,8 @@ class PublishServiceOperations(Resource): current_app.logger.debug("send Events if needed") service_api_status_event_old = self.service_api_availability_event( service_api_description_old) - current_app.logger.debug("A1") service_api_status_event_new = self.service_api_availability_event( service_api_description_old) - current_app.logger.debug("A2") - current_app.logger.debug(service_api_status_event_old) - current_app.logger.debug(service_api_status_event_new) if service_api_status_event_old == service_api_status_event_new: current_app.logger.info( @@ -349,10 +328,10 @@ class PublishServiceOperations(Resource): def service_api_availability_event(self, service_api_description): service_api_status = "" - if ServiceAPIDescription.return_supp_feat_dict(service_api_description.supported_features)["ApiStatusMonitoring"]: + if ServiceAPIDescription.return_supp_feat_dict(service_api_description.get("supportedFeatures"))["ApiStatusMonitoring"]: current_app.logger.info( - "ApiStatusMonitoring active") - if service_api_description.api_status is None or len(service_api_description.api_status.aef_ids) > 0: + "ApiStatusMonitoring active") + if service_api_description.get("apiStatus") is None or len(service_api_description.get("apiStatus").get("aefIds")) > 0: current_app.logger.info( "Service available, at least one AEF is available") service_api_status = "SERVICE_API_AVAILABLE" @@ -361,6 +340,7 @@ class PublishServiceOperations(Resource): "Service unavailable, all AEFs are unavailable") service_api_status = "SERVICE_API_UNAVAILABLE" else: + current_app.logger.info("ApiStatusMonitoring") current_app.logger.info("Service available") service_api_status = "SERVICE_API_AVAILABLE" return service_api_status -- GitLab