Commit 0ea56f78 authored by Pelayo Torres's avatar Pelayo Torres
Browse files

Merge branch 'OCF84-implementation-of-apistatusmonitoring-feature' into 'staging'

Ocf84 implementation of apistatusmonitoring feature

See merge request !72
parents c0a8e6dd 5c40c9d9
Loading
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ class InvokerManagementOperations(Resource):

        if res.status_code == 201:
            current_app.logger.info("Invoker Created")
            RedisEvent("API_INVOKER_ONBOARDED", "apiInvokerIds", [str(api_invoker_id)]).send_event()
            RedisEvent("API_INVOKER_ONBOARDED", ["apiInvokerIds"], [[str(api_invoker_id)]]).send_event()
        return res

    def update_apiinvokerenrolmentdetail(self, onboard_id, apiinvokerenrolmentdetail):
@@ -133,7 +133,7 @@ class InvokerManagementOperations(Resource):
            res = make_response(object=serialize_clean_camel_case(invoker_updated), status=200)
            if res.status_code == 200:
                current_app.logger.info("Invoker Updated")
                RedisEvent("API_INVOKER_UPDATED", "apiInvokerIds", [onboard_id]).send_event()
                RedisEvent("API_INVOKER_UPDATED", ["apiInvokerIds"], [[onboard_id]]).send_event()
            return res

        except Exception as e:
@@ -160,7 +160,7 @@ class InvokerManagementOperations(Resource):
            res = make_response(out, status=204)
            if res.status_code == 204:
                current_app.logger.info("Invoker Removed")
                RedisEvent("API_INVOKER_OFFBOARDED", "apiInvokerIds", [onboard_id]).send_event()
                RedisEvent("API_INVOKER_OFFBOARDED", ["apiInvokerIds"], [[onboard_id]]).send_event()
                publisher_ops.publish_message("internal-messages", f"invoker-removed:{onboard_id}")
            return res

+1 −1
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ class InternalServiceOps(Resource):
                "apiInvokerPolicies": inserted_service_acls_camel['apiInvokerPolicies']
            }
            RedisEvent("ACCESS_CONTROL_POLICY_UPDATE",
                       "accCtrlPolList", accCtrlPolListExt).send_event()
                       ["accCtrlPolList"], [accCtrlPolListExt]).send_event()

        current_app.logger.info(
            f"Invoker ACL added for invoker: {invoker_id} for service: {service_id}")
+16 −4
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@ from .internal_event_ops import InternalEventOperations
from models.event_notification import EventNotification
from models.access_control_policy_list_ext import AccessControlPolicyListExt
from models.capif_event_detail import CAPIFEventDetail
from models.event_subscription import EventSubscription
from models.service_api_description import ServiceAPIDescription
from encoder import CustomJSONEncoder
import sys
import json
@@ -29,11 +31,21 @@ class Notifications():
            for sub in subscriptions:
                url = sub["notification_destination"]
                current_app.logger.debug(url)
                event_detail=None
                data = EventNotification(sub["subscription_id"], events=redis_event.get('event'))
                if redis_event.get('key', None) != None and redis_event.get('information', None) != None:
                    event_detail={redis_event.get('key'):redis_event.get('information')}
                    event_detail={}
                    for pos, key in enumerate(redis_event.get('key', None)):

                        if sub["supported_features"] is None:
                            if not (key == "serviceAPIDescriptions" and redis_event.get('event', None) in ["SERVICE_API_AVAILABLE", "SERVICE_API_UNAVAILABLE"]):
                                event_detail[key]=redis_event.get('information', None)[pos]
                        else:
                            if not (redis_event.get('event', None) in ["SERVICE_API_AVAILABLE", "SERVICE_API_UNAVAILABLE"] and key == "serviceAPIDescriptions" and not EventSubscription.return_supp_feat_dict(sub["supported_features"])["ApiStatusMonitoring"]):
                                event_detail[key]=redis_event.get('information', None)[pos]

                    current_app.logger.debug(event_detail)
                data = EventNotification(sub["subscription_id"], events=redis_event.get('event'), event_detail=event_detail)
                    data.event_detail=event_detail

                current_app.logger.debug(json.dumps(data.to_dict(),cls=CustomJSONEncoder))

                asyncio.run(self.send(url, serialize_clean_camel_case(data)))
+13 −0
Original line number Diff line number Diff line
@@ -68,6 +68,19 @@ class EventSubscription(Model):
        self._websock_notif_config = websock_notif_config
        self._supported_features = supported_features

    @classmethod
    def return_supp_feat_dict(cls, supp_feat):
        TOTAL_FEATURES=4
        supp_feat_in_hex = int(supp_feat, 16)
        supp_feat_in_bin = bin(supp_feat_in_hex)[2:].zfill(TOTAL_FEATURES)[::-1]

        return {
            "NotificationTestEvent": True if supp_feat_in_bin[0] == "1" else False,
            "NotificationWebsocket": True if supp_feat_in_bin[1] == "1" else False,
            "EnhancedEventReport": True if supp_feat_in_bin[2] == "1" else False,
            "ApiStatusMonitoring": True if supp_feat_in_bin[3] == "1" else False
        }
    
    @classmethod
    def from_dict(cls, dikt) -> 'EventSubscription':
        """Returns the dict as a model
+15 −1
Original line number Diff line number Diff line
@@ -24,25 +24,39 @@ def clean_empty(d):


def dict_to_camel_case(my_dict):


        result = {}

        for attr, value in my_dict.items():

            if len(attr.split('_')) != 1:
                my_key = ''.join(word.title() for word in attr.split('_'))
                my_key = ''.join([my_key[0].lower(), my_key[1:]])
            else:
                my_key = attr

            if my_key == "serviceApiCategory":
                my_key = "serviceAPICategory"
            elif my_key == "serviceApiDescriptions":
                my_key = "serviceAPIDescriptions"

            if isinstance(value, list):
                result[my_key] = list(map(
                    lambda x: dict_to_camel_case(x) if isinstance(x, dict) else x, value ))

            elif hasattr(value, "to_dict"):
                result[my_key] = dict_to_camel_case(value)

            elif isinstance(value, dict):
                value = dict_to_camel_case(value)
                result[my_key] = value
            else:
                result[my_key] = value

        return result


def _deserialize(data, klass):
    """Deserializes dict, list, str into an object.

Loading