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) doSet(pairs ...interface{}) (err error) {
76 s.UpdateStatCounter("StoreError")
78 s.UpdateStatCounter("Stored")
83 func (s *SDLClient) Store(key string, value interface{}) (err error) {
84 return s.doSet(key, value)
87 func (s *SDLClient) MStore(pairs ...interface{}) (err error) {
91 func (s *SDLClient) Read(key string) (value map[string]interface{}, err error) {
92 return s.db.Get([]string{key})
95 func (s *SDLClient) MRead(key []string) (value map[string]interface{}, err error) {
99 func (s *SDLClient) ReadAllKeys(key string) (value []string, err error) {
103 func (s *SDLClient) Subscribe(cb func(string, ...string), channel string) error {
104 return s.db.SubscribeChannel(cb, channel)
107 func (s *SDLClient) MSubscribe(cb func(string, ...string), channels ...string) error {
108 return s.db.SubscribeChannel(cb, channels...)
111 func (s *SDLClient) StoreAndPublish(channel string, event string, pairs ...interface{}) error {
112 return s.db.SetAndPublish([]string{channel, event}, pairs...)
115 func (s *SDLClient) MStoreAndPublish(channelsAndEvents []string, pairs ...interface{}) error {
116 return s.db.SetAndPublish(channelsAndEvents, pairs...)
119 func (s *SDLClient) Clear() {
123 func (s *SDLClient) RegisterMetrics() {
124 s.stat = Metric.RegisterCounterGroup(SDLCounterOpts, "SDL")
127 func (s *SDLClient) UpdateStatCounter(name string) {
133 func (c *SDLClient) GetStat() (t SDLStatistics) {
138 func NewRNIBClient(ns string) *RNIBClient {
140 db: sdl.NewSdlInstance(ns, sdl.NewDatabase()),
144 func (r *RNIBClient) GetgNBList() (values map[string]interface{}, err error) {
145 keys, err := r.db.GetAll()
147 values = make(map[string]interface{})
148 for _, key := range keys {
149 v, err := r.db.Get([]string{key})
158 func (r *RNIBClient) GetNRCellList(key string) (value map[string]interface{}, err error) {
159 return r.db.Get([]string{key})
162 func (r *RNIBClient) GetUE(key1, key2 string) (value map[string]interface{}, err error) {
163 return r.db.Get([]string{key1 + key2})
166 func (r *RNIBClient) Store(key string, value interface{}) (err error) {
167 return r.db.Set(key, value)
170 func (r *RNIBClient) Clear() {