X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=capifcore%2Finternal%2Finvokermanagement%2Finvokermanagement.go;fp=capifcore%2Finternal%2Finvokermanagement%2Finvokermanagement.go;h=ecf8de5d920867f21bea2884104dab516d99e638;hb=48a943de59afa094d586cee17b313f1de5ecbaf2;hp=c1ff264e72ddfd647f0832ccdbd5aa0599f98c7f;hpb=37b5fcbb802f06442a9c08c94e709080a747f7ad;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/internal/invokermanagement/invokermanagement.go b/capifcore/internal/invokermanagement/invokermanagement.go index c1ff264..ecf8de5 100644 --- a/capifcore/internal/invokermanagement/invokermanagement.go +++ b/capifcore/internal/invokermanagement/invokermanagement.go @@ -27,6 +27,7 @@ import ( "strings" "sync" + "oransc.org/nonrtric/capifcore/internal/eventsapi" publishapi "oransc.org/nonrtric/capifcore/internal/publishserviceapi" "oransc.org/nonrtric/capifcore/internal/common29122" @@ -54,15 +55,17 @@ type InvokerManager struct { onboardedInvokers map[string]invokerapi.APIInvokerEnrolmentDetails publishRegister publishservice.PublishRegister nextId int64 + eventChannel chan<- eventsapi.EventNotification lock sync.Mutex } // Creates a manager that implements both the InvokerRegister and the invokermanagementapi.ServerInterface interfaces. -func NewInvokerManager(publishRegister publishservice.PublishRegister) *InvokerManager { +func NewInvokerManager(publishRegister publishservice.PublishRegister, eventChannel chan<- eventsapi.EventNotification) *InvokerManager { return &InvokerManager{ onboardedInvokers: make(map[string]invokerapi.APIInvokerEnrolmentDetails), publishRegister: publishRegister, nextId: 1000, + eventChannel: eventChannel, } } @@ -126,6 +129,7 @@ func (im *InvokerManager) PostOnboardedInvokers(ctx echo.Context) error { newInvoker.ApiList = &apiList im.onboardedInvokers[*newInvoker.ApiInvokerId] = newInvoker + go im.sendEvent(*newInvoker.ApiInvokerId, eventsapi.CAPIFEventAPIINVOKERONBOARDED) uri := ctx.Request().Host + ctx.Request().URL.String() ctx.Response().Header().Set(echo.HeaderLocation, ctx.Scheme()+`://`+path.Join(uri, *newInvoker.ApiInvokerId)) @@ -144,6 +148,7 @@ func (im *InvokerManager) DeleteOnboardedInvokersOnboardingId(ctx echo.Context, defer im.lock.Unlock() delete(im.onboardedInvokers, onboardingId) + go im.sendEvent(onboardingId, eventsapi.CAPIFEventAPIINVOKEROFFBOARDED) return ctx.NoContent(http.StatusNoContent) } @@ -221,6 +226,17 @@ func (im *InvokerManager) getId(invokerInfo *string) *string { return &idAsString } +func (im *InvokerManager) sendEvent(invokerId string, eventType eventsapi.CAPIFEvent) { + invokerIds := []string{invokerId} + event := eventsapi.EventNotification{ + EventDetail: &eventsapi.CAPIFEventDetail{ + ApiInvokerIds: &invokerIds, + }, + Events: eventType, + } + im.eventChannel <- event +} + // This function wraps sending of an error in the Error format, and // handling the failure to marshal that. func sendCoreError(ctx echo.Context, code int, message string) error {