Merge "Fix for DB read after VM restart and REST subscription query aded"
[ric-plt/submgr.git] / pkg / control / registry.go
index bd4e15a..72a2100 100644 (file)
@@ -20,6 +20,7 @@
 package control
 
 import (
+       "encoding/json"
        "fmt"
        "sync"
        "time"
@@ -40,12 +41,29 @@ type RESTSubscription struct {
        xAppIdToE2Id     map[int64]int64
        SubReqOngoing    bool
        SubDelReqOngoing bool
+       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:]
 }
@@ -62,8 +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
+       if err != nil {
+               r.lastReqMd5sum = ""
+       }
 }
 
 type Registry struct {
@@ -84,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()