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 rnibentities "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
24 rnibreader "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
25 sdl "gerrit.o-ran-sc.org/r/ric-plt/sdlgo"
26 rnibwriter "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/rnib"
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 SDLStorage struct {
41 stat map[string]Counter
46 //Deprecated: Will be removed in a future release, please use SDLStorage type
47 type SDLClient struct {
53 type RNIBNodeType = rnibentities.Node_Type
54 type RNIBGlobalNbId = rnibentities.GlobalNbId
55 type RNIBNodebInfo = rnibentities.NodebInfo
56 type RNIBIRNibError = error
57 type RNIBCells = rnibentities.Cells
58 type RNIBNbIdentity = rnibentities.NbIdentity
59 type RNIBCellType = rnibentities.Cell_Type
60 type RNIBCell = rnibentities.Cell
61 type RNIBEnb = rnibentities.Enb
62 type RNIBGnb = rnibentities.Gnb
64 const RNIBNodeENB = rnibentities.Node_ENB
65 const RNIBNodeGNB = rnibentities.Node_GNB
67 type RNIBServedCellInfo = rnibentities.ServedCellInfo
68 type RNIBNodebInfoEnb = rnibentities.NodebInfo_Enb
69 type RNIBNodebInfoGnb = rnibentities.NodebInfo_Gnb
70 type RNIBServedNRCell = rnibentities.ServedNRCell
71 type RNIBServedNRCellInformation = rnibentities.ServedNRCellInformation
72 type RNIBNrNeighbourInformation = rnibentities.NrNeighbourInformation
74 type RNIBClient struct {
76 reader rnibreader.RNibReader
77 writer rnibwriter.RNibWriter
80 // NewSdlStorage returns a new instance of SDLStorage type.
81 func NewSdlStorage() *SDLStorage {
83 db: sdl.NewSyncStorage(),
84 stat: Metric.RegisterCounterGroup(SDLCounterOpts, "SDL"),
89 func (s *SDLStorage) TestConnection(namespace string) {
90 // Test DB connection, and wait until ready!
92 if _, err := s.db.GetAll(namespace); err == nil {
95 Logger.Warn("Database connection not ready, waiting ...")
96 time.Sleep(time.Duration(5 * time.Second))
99 Logger.Info("Connection to database established!")
102 func (s *SDLStorage) IsReady() bool {
106 func (s *SDLStorage) doSet(namespace string, pairs ...interface{}) (err error) {
107 err = s.db.Set(namespace, pairs)
109 s.UpdateStatCounter("StoreError")
111 s.UpdateStatCounter("Stored")
116 func (s *SDLStorage) Store(namespace string, key string, value interface{}) (err error) {
117 return s.doSet(namespace, key, value)
120 func (s *SDLStorage) MStore(namespace string, pairs ...interface{}) (err error) {
121 return s.doSet(namespace, pairs)
124 func (s *SDLStorage) Read(namespace string, key string) (value map[string]interface{}, err error) {
125 return s.db.Get(namespace, []string{key})
128 func (s *SDLStorage) MRead(namespace string, key []string) (value map[string]interface{}, err error) {
129 return s.db.Get(namespace, key)
132 func (s *SDLStorage) ReadAllKeys(namespace string) (value []string, err error) {
133 return s.db.GetAll(namespace)
136 func (s *SDLStorage) Subscribe(namespace string, cb func(string, ...string), channel string) error {
137 return s.db.SubscribeChannel(namespace, cb, channel)
140 func (s *SDLStorage) MSubscribe(namespace string, cb func(string, ...string), channels ...string) error {
141 return s.db.SubscribeChannel(namespace, cb, channels...)
144 func (s *SDLStorage) StoreAndPublish(namespace string, channel string, event string, pairs ...interface{}) error {
145 return s.db.SetAndPublish(namespace, []string{channel, event}, pairs...)
148 func (s *SDLStorage) MStoreAndPublish(namespace string, channelsAndEvents []string, pairs ...interface{}) error {
149 return s.db.SetAndPublish(namespace, channelsAndEvents, pairs...)
152 func (s *SDLStorage) Delete(namespace string, keys []string) (err error) {
153 return s.db.Remove(namespace, keys)
156 func (s *SDLStorage) Clear(namespace string) {
157 s.db.RemoveAll(namespace)
160 func (s *SDLStorage) RegisterMetrics() {
161 s.stat = Metric.RegisterCounterGroup(SDLCounterOpts, "SDL")
164 func (s *SDLStorage) UpdateStatCounter(name string) {
170 func (s *SDLStorage) GetStat() (t SDLStatistics) {
174 //NewSDLClient returns a new SDLClient.
175 //Deprecated: Will be removed in a future release, please use NewSdlStorage
176 func NewSDLClient(ns string) *SDLClient {
186 //Deprecated: Will be removed in a future release, please use the TestConnection Receiver function of the SDLStorage type.
187 func (s *SDLClient) TestConnection() {
188 s.db.TestConnection(s.nameSpace)
191 func (s *SDLClient) IsReady() bool {
195 //Deprecated: Will be removed in a future release, please use the Store Receiver function of the SDLStorage type.
196 func (s *SDLClient) Store(key string, value interface{}) (err error) {
197 return s.db.Store(s.nameSpace, key, value)
200 //Deprecated: Will be removed in a future release, please use the MStore Receiver function of the SDLStorage type.
201 func (s *SDLClient) MStore(pairs ...interface{}) (err error) {
202 return s.db.MStore(s.nameSpace, pairs)
205 //Deprecated: Will be removed in a future release, please use the Read Receiver function of the SDLStorage type.
206 func (s *SDLClient) Read(key string) (value map[string]interface{}, err error) {
207 return s.db.Read(s.nameSpace, key)
210 //Deprecated: Will be removed in a future release, please use the MRead Receiver function of the SDLStorage type.
211 func (s *SDLClient) MRead(key []string) (value map[string]interface{}, err error) {
212 return s.db.MRead(s.nameSpace, key)
215 //Deprecated: Will be removed in a future release, please use the ReadAllKeys Receiver function of the SDLStorage type.
216 func (s *SDLClient) ReadAllKeys(key string) (value []string, err error) {
217 return s.db.ReadAllKeys(s.nameSpace)
220 //Deprecated: Will be removed in a future release, please use the Subscribe Receiver function of the SDLStorage type.
221 func (s *SDLClient) Subscribe(cb func(string, ...string), channel string) error {
222 return s.db.Subscribe(s.nameSpace, cb, channel)
225 //Deprecated: Will be removed in a future release, please use the MSubscribe Receiver function of the SDLStorage type.
226 func (s *SDLClient) MSubscribe(cb func(string, ...string), channels ...string) error {
227 return s.db.MSubscribe(s.nameSpace, cb, channels...)
230 //Deprecated: Will be removed in a future release, please use the StoreAndPublish Receiver function of the SDLStorage type.
231 func (s *SDLClient) StoreAndPublish(channel string, event string, pairs ...interface{}) error {
232 return s.db.StoreAndPublish(s.nameSpace, channel, event, pairs...)
235 //Deprecated: Will be removed in a future release, please use the MStoreAndPublish Receiver function of the SDLStorage type.
236 func (s *SDLClient) MStoreAndPublish(channelsAndEvents []string, pairs ...interface{}) error {
237 return s.db.MStoreAndPublish(s.nameSpace, channelsAndEvents, pairs...)
240 //Deprecated: Will be removed in a future release, please use the Delete Receiver function of the SDLStorage type.
241 func (s *SDLClient) Delete(keys []string) (err error) {
242 return s.db.Delete(s.nameSpace, keys)
245 //Deprecated: Will be removed in a future release, please use the Clear Receiver function of the SDLStorage type.
246 func (s *SDLClient) Clear() {
247 s.db.Clear(s.nameSpace)
250 //Deprecated: Will be removed in a future release, please use the RegisterMetrics Receiver function of the SDLStorage type.
251 func (s *SDLClient) RegisterMetrics() {
252 s.db.RegisterMetrics()
255 //Deprecated: Will be removed in a future release, please use the UpdateStatCounter Receiver function of the SDLStorage type.
256 func (s *SDLClient) UpdateStatCounter(name string) {
257 s.db.UpdateStatCounter(name)
260 //Deprecated: Will be removed in a future release, please use the GetStat Receiver function of the SDLStorage type.
261 func (c *SDLClient) GetStat() (t SDLStatistics) {
262 return c.db.GetStat()
265 func NewRNIBClient() *RNIBClient {
266 s := sdl.NewSdlInstance("e2Manager", sdl.NewDatabase())
274 func (r *RNIBClient) Subscribe(cb func(string, ...string), channel string) error {
275 return r.db.SubscribeChannel(cb, channel)
278 func (r *RNIBClient) StoreAndPublish(channel string, event string, pairs ...interface{}) error {
279 return r.db.SetAndPublish([]string{channel, event}, pairs...)
282 func (r *RNIBClient) GetNodeb(invName string) (*RNIBNodebInfo, RNIBIRNibError) {
283 return rnibreader.GetRNibReader(r.db).GetNodeb(invName)
286 func (r *RNIBClient) GetNodebByGlobalNbId(t RNIBNodeType, gid *RNIBGlobalNbId) (*RNIBNodebInfo, RNIBIRNibError) {
287 return rnibreader.GetRNibReader(r.db).GetNodebByGlobalNbId(t, gid)
290 func (r *RNIBClient) GetCellList(invName string) (*RNIBCells, RNIBIRNibError) {
291 return rnibreader.GetRNibReader(r.db).GetCellList(invName)
294 func (r *RNIBClient) GetListGnbIds() ([]*RNIBNbIdentity, RNIBIRNibError) {
295 return rnibreader.GetRNibReader(r.db).GetListGnbIds()
298 func (r *RNIBClient) GetListEnbIds() ([]*RNIBNbIdentity, RNIBIRNibError) {
299 return rnibreader.GetRNibReader(r.db).GetListEnbIds()
302 func (r *RNIBClient) GetCountGnbList() (int, RNIBIRNibError) {
303 return rnibreader.GetRNibReader(r.db).GetCountGnbList()
306 func (r *RNIBClient) GetCell(invName string, pci uint32) (*RNIBCell, RNIBIRNibError) {
307 return rnibreader.GetRNibReader(r.db).GetCell(invName, pci)
310 func (r *RNIBClient) GetCellById(cellType RNIBCellType, cellId string) (*RNIBCell, RNIBIRNibError) {
311 return rnibreader.GetRNibReader(r.db).GetCellById(cellType, cellId)
314 func (r *RNIBClient) SaveNodeb(nbIdentity *RNIBNbIdentity, entity *RNIBNodebInfo) RNIBIRNibError {
315 return rnibwriter.GetRNibWriter(r.db).SaveNodeb(nbIdentity, entity)