Merge "[RICPLT-2503] Automation start and stop" into PI3
[ric-plt/e2mgr.git] / E2Manager / rNibWriter / rNibWriter.go
index 202a273..8cfb992 100644 (file)
 package rNibWriter
 
 import (
+       "encoding/json"
        "fmt"
        "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
        "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
        "github.com/golang/protobuf/proto"
 )
 
+const E2TAddressesKey = "E2TAddresses"
+
 type rNibWriterInstance struct {
        sdl common.ISdlInstance
 }
@@ -35,6 +38,8 @@ type RNibWriter interface {
        SaveNodeb(nbIdentity *entities.NbIdentity, nb *entities.NodebInfo) error
        UpdateNodebInfo(nodebInfo *entities.NodebInfo) error
        SaveRanLoadInformation(inventoryName string, ranLoadInformation *entities.RanLoadInformation) error
+       SaveE2TInstance(e2tInstance *entities.E2TInstance) error
+       SaveE2TAddresses(addresses []string) error
 }
 
 /*
@@ -180,6 +185,52 @@ func (w *rNibWriterInstance) SaveRanLoadInformation(inventoryName string, ranLoa
        return nil
 }
 
+func (w *rNibWriterInstance) SaveE2TInstance(e2tInstance *entities.E2TInstance) error {
+
+       key, rnibErr := common.ValidateAndBuildE2TInstanceKey(e2tInstance.Address)
+
+       if rnibErr != nil {
+               return rnibErr
+       }
+
+       data, err := json.Marshal(e2tInstance)
+
+       if err != nil {
+               return common.NewInternalError(err)
+       }
+
+       var pairs []interface{}
+       pairs = append(pairs, key, data)
+
+       err = w.sdl.Set(pairs)
+
+       if err != nil {
+               return common.NewInternalError(err)
+       }
+
+       return nil
+}
+
+func (w *rNibWriterInstance) SaveE2TAddresses(addresses []string) error {
+
+       data, err := json.Marshal(addresses)
+
+       if err != nil {
+               return common.NewInternalError(err)
+       }
+
+       var pairs []interface{}
+       pairs = append(pairs, E2TAddressesKey, data)
+
+       err = w.sdl.Set(pairs)
+
+       if err != nil {
+               return common.NewInternalError(err)
+       }
+
+       return nil
+}
+
 /*
 Close the writer
 */