2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
23 sdl "gerrit.o-ran-sc.org/r/ric-plt/sdlgo"
24 "gitlabe1.ext.net.nokia.com/ric_dev/ue-nib/api"
25 "gitlabe1.ext.net.nokia.com/ric_dev/ue-nib/pkg/uenibreader"
26 "gitlabe1.ext.net.nokia.com/ric_dev/ue-nib/pkg/uenibwriter"
31 // To be removed later
32 type SDLStatistics struct{}
34 var SDLCounterOpts = []CounterOpts{
35 {Name: "Stored", Help: "The total number of stored SDL transactions"},
36 {Name: "StoreError", Help: "The total number of SDL store errors"},
39 type SDLClient struct {
41 stat map[string]Counter
45 type UENIBClient struct {
46 reader *uenibreader.Reader
47 writer *uenibwriter.Writer
50 type RNIBClient struct {
54 // NewSDLClient returns a new SDLClient.
55 func NewSDLClient(ns string) *SDLClient {
57 db: sdl.NewSdlInstance(ns, sdl.NewDatabase()),
61 func (s *SDLClient) TestConnection() {
62 // Test DB connection, and wait until ready!
64 if _, err := s.db.GetAll(); err == nil {
67 Logger.Warn("Database connection not ready, waiting ...")
68 time.Sleep(time.Duration(5 * time.Second))
70 Logger.Info("Connection to database established!")
75 func (s *SDLClient) Store(key string, value interface{}) (err error) {
76 err = s.db.Set(key, value)
78 s.UpdateStatCounter("StoreError")
80 s.UpdateStatCounter("Stored")
85 func (s *SDLClient) Read(key string) (value map[string]interface{}, err error) {
86 value, err = s.db.Get([]string{key})
90 func (s *SDLClient) Subscribe(cb func(string, ...string), channel string) error {
91 return s.db.SubscribeChannel(cb, channel)
94 func (s *SDLClient) MSubscribe(cb func(string, ...string), channels ...string) error {
95 return s.db.SubscribeChannel(cb, channels...)
98 func (s *SDLClient) StoreAndPublish(channel string, event string, pairs ...interface{}) error {
99 return s.db.SetAndPublish([]string{channel, event}, pairs...)
102 func (s *SDLClient) MStoreAndPublish(channelsAndEvents []string, pairs ...interface{}) error {
103 return s.db.SetAndPublish(channelsAndEvents, pairs...)
106 func (s *SDLClient) Clear() {
110 func (s *SDLClient) RegisterMetrics() {
111 s.stat = Metric.RegisterCounterGroup(SDLCounterOpts, "SDL")
114 func (s *SDLClient) UpdateStatCounter(name string) {
120 func (c *SDLClient) GetStat() (t SDLStatistics) {
124 func NewUENIBClient() *UENIBClient {
126 reader: uenibreader.NewReader(),
127 writer: uenibwriter.NewWriter(),
131 func (u *UENIBClient) StoreUeMeasurement(gNbId string, gNbUeX2ApId string, data *api.MeasResults) error {
132 return u.writer.UpdateUeMeasurement(gNbId, gNbUeX2ApId, data)
135 func (u *UENIBClient) ReadUeMeasurement(gNbId string, gNbUeX2ApId string) (*api.MeasResults, error) {
136 return u.reader.GetUeMeasurement(gNbId, gNbUeX2ApId)
140 func NewRNIBClient(ns string) *RNIBClient {
142 db: sdl.NewSdlInstance(ns, sdl.NewDatabase()),
146 func (r *RNIBClient) GetgNBList() (values map[string]interface{}, err error) {
147 keys, err := r.db.GetAll()
149 values = make(map[string]interface{})
150 for _, key := range keys {
151 v, err := r.db.Get([]string{key})
160 func (r *RNIBClient) GetNRCellList(key string) (value map[string]interface{}, err error) {
161 return r.db.Get([]string{key})
164 func (r *RNIBClient) GetUE(key1, key2 string) (value map[string]interface{}, err error) {
165 return r.db.Get([]string{key1 + key2})
168 func (r *RNIBClient) Store(key string, value interface{}) (err error) {
169 return r.db.Set(key, value)
172 func (r *RNIBClient) Clear() {