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"
28 // To be removed later
29 type SDLStatistics struct{}
31 var SDLCounterOpts = []CounterOpts{
32 {Name: "Stored", Help: "The total number of stored SDL transactions"},
33 {Name: "StoreError", Help: "The total number of SDL store errors"},
36 type SDLClient struct {
38 stat map[string]Counter
43 type RNIBClient struct {
47 // NewSDLClient returns a new SDLClient.
48 func NewSDLClient(ns string) *SDLClient {
50 db: sdl.NewSdlInstance(ns, sdl.NewDatabase()),
51 stat: Metric.RegisterCounterGroup(SDLCounterOpts, "SDL"),
56 func (s *SDLClient) TestConnection() {
57 // Test DB connection, and wait until ready!
59 if _, err := s.db.GetAll(); err == nil {
62 Logger.Warn("Database connection not ready, waiting ...")
63 time.Sleep(time.Duration(5 * time.Second))
66 Logger.Info("Connection to database established!")
69 func (s *SDLClient) IsReady() bool {
73 func (s *SDLClient) Store(key string, value interface{}) (err error) {
74 err = s.db.Set(key, value)
76 s.UpdateStatCounter("StoreError")
78 s.UpdateStatCounter("Stored")
83 func (s *SDLClient) Read(key string) (value map[string]interface{}, err error) {
84 value, err = s.db.Get([]string{key})
88 func (s *SDLClient) Subscribe(cb func(string, ...string), channel string) error {
89 return s.db.SubscribeChannel(cb, channel)
92 func (s *SDLClient) MSubscribe(cb func(string, ...string), channels ...string) error {
93 return s.db.SubscribeChannel(cb, channels...)
96 func (s *SDLClient) StoreAndPublish(channel string, event string, pairs ...interface{}) error {
97 return s.db.SetAndPublish([]string{channel, event}, pairs...)
100 func (s *SDLClient) MStoreAndPublish(channelsAndEvents []string, pairs ...interface{}) error {
101 return s.db.SetAndPublish(channelsAndEvents, pairs...)
104 func (s *SDLClient) Clear() {
108 func (s *SDLClient) RegisterMetrics() {
109 s.stat = Metric.RegisterCounterGroup(SDLCounterOpts, "SDL")
112 func (s *SDLClient) UpdateStatCounter(name string) {
118 func (c *SDLClient) GetStat() (t SDLStatistics) {
123 func NewRNIBClient(ns string) *RNIBClient {
125 db: sdl.NewSdlInstance(ns, sdl.NewDatabase()),
129 func (r *RNIBClient) GetgNBList() (values map[string]interface{}, err error) {
130 keys, err := r.db.GetAll()
132 values = make(map[string]interface{})
133 for _, key := range keys {
134 v, err := r.db.Get([]string{key})
143 func (r *RNIBClient) GetNRCellList(key string) (value map[string]interface{}, err error) {
144 return r.db.Get([]string{key})
147 func (r *RNIBClient) GetUE(key1, key2 string) (value map[string]interface{}, err error) {
148 return r.db.Get([]string{key1 + key2})
151 func (r *RNIBClient) Store(key string, value interface{}) (err error) {
152 return r.db.Set(key, value)
155 func (r *RNIBClient) Clear() {