X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Fregistry.go;h=72a210056efaf6f97d04f9cc779261ffad13ba12;hb=ff383bb22dcf671c68c543294556fe303feb27ff;hp=671cf5197a832d6cebfd7475a6ef8bec6d8c9912;hpb=268d715e3bceab8f7955d89945141efdb2c3b368;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/registry.go b/pkg/control/registry.go index 671cf51..72a2100 100644 --- a/pkg/control/registry.go +++ b/pkg/control/registry.go @@ -20,6 +20,7 @@ package control import ( + "encoding/json" "fmt" "sync" "time" @@ -40,13 +41,29 @@ type RESTSubscription struct { xAppIdToE2Id map[int64]int64 SubReqOngoing bool SubDelReqOngoing bool - Md5sum string + lastReqMd5sum string } func (r *RESTSubscription) AddE2InstanceId(instanceId uint32) { + + for _, v := range r.InstanceIds { + if v == instanceId { + return + } + + } + r.InstanceIds = append(r.InstanceIds, instanceId) } +func (r *RESTSubscription) AddMd5Sum(md5sum string) { + if md5sum != "" { + r.lastReqMd5sum = md5sum + } else { + xapp.Logger.Error("EMPTY md5sum attempted to be add to subscrition") + } +} + func (r *RESTSubscription) DeleteE2InstanceId(instanceId uint32) { r.InstanceIds = r.InstanceIds[1:] } @@ -63,9 +80,11 @@ func (r *RESTSubscription) DeleteXappIdToE2Id(xAppEventInstanceID int64) { delete(r.xAppIdToE2Id, xAppEventInstanceID) } -func (r *RESTSubscription) SetProcessed() { +func (r *RESTSubscription) SetProcessed(err error) { r.SubReqOngoing = false - r.Md5sum = "" + if err != nil { + r.lastReqMd5sum = "" + } } type Registry struct { @@ -86,6 +105,16 @@ func (r *Registry) Initialize() { } } +func (r *Registry) GetAllRestSubscriptions() []byte { + r.mutex.Lock() + defer r.mutex.Unlock() + restSubscriptionsJson, err := json.Marshal(r.restSubscriptions) + if err != nil { + xapp.Logger.Error("GetAllRestSubscriptions(): %v", err) + } + return restSubscriptionsJson +} + func (r *Registry) CreateRESTSubscription(restSubId *string, xAppRmrEndPoint *string, maid *string) (*RESTSubscription, error) { r.mutex.Lock() defer r.mutex.Unlock()