From 38eeef2b92456bc6a7a8ae54805f7ef305f637ec Mon Sep 17 00:00:00 2001 From: Ikram Ul Haq Date: Fri, 30 Aug 2024 10:10:22 +0500 Subject: [PATCH] Implement logic to send the sotification when the subscription created --- .../server/capif-mgmt/convert.go | 19 ++ .../capif-mgmt/model_event_notification.go | 15 ++ .../server/capif-mgmt/service-mgmt.go | 165 ++++++++++-------- 3 files changed, 127 insertions(+), 72 deletions(-) create mode 100644 go-apps/meep-app-enablement/server/capif-mgmt/model_event_notification.go diff --git a/go-apps/meep-app-enablement/server/capif-mgmt/convert.go b/go-apps/meep-app-enablement/server/capif-mgmt/convert.go index 5da1e2737..73bd9fc98 100644 --- a/go-apps/meep-app-enablement/server/capif-mgmt/convert.go +++ b/go-apps/meep-app-enablement/server/capif-mgmt/convert.go @@ -87,6 +87,16 @@ func convertJsonToSerAvailabilityNotifSub(jsonData string) *SerAvailabilityNotif return &obj } +func convertJsonToSerAvailabilityNotifSub_1(jsonData string) *EventSubscription { + var obj EventSubscription + err := json.Unmarshal([]byte(jsonData), &obj) + if err != nil { + log.Error(err.Error()) + return nil + } + return &obj +} + func convertServiceAvailabilityNotifToJson(obj *ServiceAvailabilityNotification) string { jsonInfo, err := json.Marshal(*obj) if err != nil { @@ -96,6 +106,15 @@ func convertServiceAvailabilityNotifToJson(obj *ServiceAvailabilityNotification) return string(jsonInfo) } +func convertServiceAvailabilityNotifToJson_1(obj *EventNotification) string { + jsonInfo, err := json.Marshal(*obj) + if err != nil { + log.Error(err.Error()) + return "" + } + return string(jsonInfo) +} + func convertProblemDetailsToJson(obj *ProblemDetails) string { jsonInfo, err := json.Marshal(*obj) if err != nil { diff --git a/go-apps/meep-app-enablement/server/capif-mgmt/model_event_notification.go b/go-apps/meep-app-enablement/server/capif-mgmt/model_event_notification.go new file mode 100644 index 000000000..2c1c22e1d --- /dev/null +++ b/go-apps/meep-app-enablement/server/capif-mgmt/model_event_notification.go @@ -0,0 +1,15 @@ +/* + * MEC service management realized by CAPIF APIs + * + * The ETSI MEC ISG MEC011 MEC Service Management realized by CAPIF APIs described using OpenAPI + * + * API version: 3.2.1 + * Contact: cti_support@etsi.org + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ +package server + +type EventNotification struct { + // The values SERVICE_API_AVAILABLE, SERVICE_API_UNAVAILABLE, and SERVICE_API_UPDATE defined in the type \"CAPIFEvent\" shall be supported. The remaining values of that type need not be supported. + Events []CapifEvent `json:"events,omitempty"` +} diff --git a/go-apps/meep-app-enablement/server/capif-mgmt/service-mgmt.go b/go-apps/meep-app-enablement/server/capif-mgmt/service-mgmt.go index 47de735f3..c98599d6c 100644 --- a/go-apps/meep-app-enablement/server/capif-mgmt/service-mgmt.go +++ b/go-apps/meep-app-enablement/server/capif-mgmt/service-mgmt.go @@ -1835,21 +1835,23 @@ func checkSerAvailNotification(sInfo *ServiceInfo, mep string, changeType CapifE for _, sub := range subList { // Unmarshal original JSON subscription - origSub := convertJsonToSerAvailabilityNotifSub(sub.JsonSubOrig) + origSub := convertJsonToSerAvailabilityNotifSub_1(sub.JsonSubOrig) if origSub == nil { continue } // Check subscription filter criteria - if origSub.FilteringCriteria != nil { - + if len(origSub.EventFilters) > 0 { + found := false // Service Instance IDs - if origSub.FilteringCriteria.SerInstanceIds != nil && len(origSub.FilteringCriteria.SerInstanceIds) > 0 { - found := false - for _, serInstanceId := range origSub.FilteringCriteria.SerInstanceIds { - if serInstanceId == sInfo.SerInstanceId { - found = true - break + for _, eventFilter := range origSub.EventFilters { + // Check if ApiIds (replacing SerInstanceIds) match + if len(eventFilter.ApiIds) > 0 { + for _, apiId := range eventFilter.ApiIds { + if apiId == sInfo.SerInstanceId { // Compare with the current Service Instance ID (now ApiId) + found = true + break + } } } if !found { @@ -1858,80 +1860,99 @@ func checkSerAvailNotification(sInfo *ServiceInfo, mep string, changeType CapifE } // Service Names - if origSub.FilteringCriteria.SerNames != nil && len(origSub.FilteringCriteria.SerNames) > 0 { - found := false - for _, serName := range origSub.FilteringCriteria.SerNames { - if serName == sInfo.SerName { - found = true - break - } - } - if !found { - continue - } - } + // if origSub.FilteringCriteria.SerNames != nil && len(origSub.FilteringCriteria.SerNames) > 0 { + // found := false + // for _, serName := range origSub.FilteringCriteria.SerNames { + // if serName == sInfo.SerName { + // found = true + // break + // } + // } + // if !found { + // continue + // } + // } // Service Categories - if origSub.FilteringCriteria.SerCategories != nil && len(origSub.FilteringCriteria.SerCategories) > 0 { - found := false - for _, serCategory := range origSub.FilteringCriteria.SerCategories { - if serCategory.Href == sInfo.SerCategory.Href && - serCategory.Id == sInfo.SerCategory.Id && - serCategory.Name == sInfo.SerCategory.Name && - serCategory.Version == sInfo.SerCategory.Version { - found = true - break - } - } - if !found { - continue - } - } + // if origSub.FilteringCriteria.SerCategories != nil && len(origSub.FilteringCriteria.SerCategories) > 0 { + // found := false + // for _, serCategory := range origSub.FilteringCriteria.SerCategories { + // if serCategory.Href == sInfo.SerCategory.Href && + // serCategory.Id == sInfo.SerCategory.Id && + // serCategory.Name == sInfo.SerCategory.Name && + // serCategory.Version == sInfo.SerCategory.Version { + // found = true + // break + // } + // } + // if !found { + // continue + // } + // } // Service states - if origSub.FilteringCriteria.States != nil && len(origSub.FilteringCriteria.States) > 0 { - found := false - for _, serState := range origSub.FilteringCriteria.States { - if serState == *sInfo.State { - found = true - break - } - } - if !found { - continue - } - } - - // Service locality - if origSub.FilteringCriteria.IsLocal && !sInfo.IsLocal { - continue - } + // if origSub.FilteringCriteria.States != nil && len(origSub.FilteringCriteria.States) > 0 { + // found := false + // for _, serState := range origSub.FilteringCriteria.States { + // if serState == *sInfo.State { + // found = true + // break + // } + // } + // if !found { + // continue + // } + // } + + // // Service locality + // if origSub.FilteringCriteria.IsLocal && !sInfo.IsLocal { + // continue + // } } - - // Create notification payload - notif := &ServiceAvailabilityNotification{ - NotificationType: SER_AVAILABILITY_NOTIF_TYPE, - Links: &Subscription{ - Subscription: &LinkType{ - Href: sub.Cfg.Self, - }, - }, + // Create a new EventNotification instance + notif := &EventNotification{} + + // Set the event type based on changeType + var eventType CapifEvent + switch changeType { + case "SERVICE_API_AVAILABLE": + eventType = AVAILABLE + case "SERVICE_API_UNAVAILABLE": + eventType = UNAVAILABLE + case "SERVICE_API_UPDATE": + eventType = UPDATE + default: + // Handle any default case or errors } - serAvailabilityRef := ServiceAvailabilityNotificationServiceReferences{ - Link: &LinkType{ - Href: hostUrl.String() + basePath + "services/" + sInfo.SerInstanceId, - }, - SerName: sInfo.SerName, - SerInstanceId: sInfo.SerInstanceId, - State: sInfo.State, - ChangeType: &changeType, + + // If eventType is set, append it to the Events slice + if eventType != "" { + notif.Events = append(notif.Events, eventType) } - notif.ServiceReferences = append(notif.ServiceReferences, serAvailabilityRef) + // // Create notification payload + // notif := &ServiceAvailabilityNotification{ + // NotificationType: SER_AVAILABILITY_NOTIF_TYPE, + // Links: &Subscription{ + // Subscription: &LinkType{ + // Href: sub.Cfg.Self, + // }, + // }, + // } + // serAvailabilityRef := ServiceAvailabilityNotificationServiceReferences{ + // Link: &LinkType{ + // Href: hostUrl.String() + basePath + "services/" + sInfo.SerInstanceId, + // }, + // SerName: sInfo.SerName, + // SerInstanceId: sInfo.SerInstanceId, + // State: sInfo.State, + // ChangeType: &changeType, + // } + // notif.ServiceReferences = append(notif.ServiceReferences, serAvailabilityRef) // Send notification go func(sub *subs.Subscription) { log.Info("Sending Service Availability notification (" + sub.Cfg.Id + ") for " + string(changeType)) - err := subMgr.SendNotification(sub, []byte(convertServiceAvailabilityNotifToJson(notif))) + err := subMgr.SendNotification(sub, []byte(convertServiceAvailabilityNotifToJson_1(notif))) if err != nil { log.Error("Failed to send Service Availability notif with err: ", err.Error()) } -- GitLab