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 rnibcommon "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
24 rnibentities "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
25 rnibreader "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
26 sdl "gerrit.o-ran-sc.org/r/ric-plt/sdlgo"
27 rnibwriter "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/rnib"
32 // To be removed later
33 type SDLStatistics struct{}
35 var SDLCounterOpts = []CounterOpts{
36 {Name: "Stored", Help: "The total number of stored SDL transactions"},
37 {Name: "StoreError", Help: "The total number of SDL store errors"},
40 type SDLStorage struct {
42 stat map[string]Counter
47 //Deprecated: Will be removed in a future release, please use SDLStorage type
48 type SDLClient struct {
54 type RNIBNodeType = rnibentities.Node_Type
55 type RNIBGlobalNbId = rnibentities.GlobalNbId
56 type RNIBNodebInfo = rnibentities.NodebInfo
57 type RNIBIRNibError = error
58 type RNIBCells = rnibentities.Cells
59 type RNIBNbIdentity = rnibentities.NbIdentity
60 type RNIBCellType = rnibentities.Cell_Type
61 type RNIBCell = rnibentities.Cell
62 type RNIBEnb = rnibentities.Enb
63 type RNIBGnb = rnibentities.Gnb
65 const RNIBNodeENB = rnibentities.Node_ENB
66 const RNIBNodeGNB = rnibentities.Node_GNB
68 type RNIBServedCellInfo = rnibentities.ServedCellInfo
69 type RNIBNodebInfoEnb = rnibentities.NodebInfo_Enb
70 type RNIBNodebInfoGnb = rnibentities.NodebInfo_Gnb
71 type RNIBServedNRCell = rnibentities.ServedNRCell
72 type RNIBServedNRCellInformation = rnibentities.ServedNRCellInformation
73 type RNIBNrNeighbourInformation = rnibentities.NrNeighbourInformation
75 type RNIBClient struct {
76 db rnibcommon.ISdlSyncStorage
77 reader rnibreader.RNibReader
78 writer rnibwriter.RNibWriter
81 // NewSdlStorage returns a new instance of SDLStorage type.
82 func NewSdlStorage() *SDLStorage {
84 db: sdl.NewSyncStorage(),
85 stat: Metric.RegisterCounterGroup(SDLCounterOpts, "SDL"),
90 func (s *SDLStorage) TestConnection(namespace string) {
91 // Test DB connection, and wait until ready!
93 if _, err := s.db.GetAll(namespace); err == nil {
96 Logger.Warn("Database connection not ready, waiting ...")
97 time.Sleep(time.Duration(5 * time.Second))
100 Logger.Info("Connection to database established!")
103 func (s *SDLStorage) IsReady() bool {
107 func (s *SDLStorage) doSet(namespace string, pairs ...interface{}) (err error) {
108 err = s.db.Set(namespace, pairs)
110 s.UpdateStatCounter("StoreError")
112 s.UpdateStatCounter("Stored")
117 func (s *SDLStorage) Store(namespace string, key string, value interface{}) (err error) {
118 return s.doSet(namespace, key, value)
121 func (s *SDLStorage) MStore(namespace string, pairs ...interface{}) (err error) {
122 return s.doSet(namespace, pairs)
125 func (s *SDLStorage) Read(namespace string, key string) (value map[string]interface{}, err error) {
126 return s.db.Get(namespace, []string{key})
129 func (s *SDLStorage) MRead(namespace string, key []string) (value map[string]interface{}, err error) {
130 return s.db.Get(namespace, key)
133 func (s *SDLStorage) ReadAllKeys(namespace string) (value []string, err error) {
134 return s.db.GetAll(namespace)
137 func (s *SDLStorage) Subscribe(namespace string, cb func(string, ...string), channel string) error {
138 return s.db.SubscribeChannel(namespace, cb, channel)
141 func (s *SDLStorage) MSubscribe(namespace string, cb func(string, ...string), channels ...string) error {
142 return s.db.SubscribeChannel(namespace, cb, channels...)
145 func (s *SDLStorage) StoreAndPublish(namespace string, channel string, event string, pairs ...interface{}) error {
146 return s.db.SetAndPublish(namespace, []string{channel, event}, pairs...)
149 func (s *SDLStorage) MStoreAndPublish(namespace string, channelsAndEvents []string, pairs ...interface{}) error {
150 return s.db.SetAndPublish(namespace, channelsAndEvents, pairs...)
153 func (s *SDLStorage) Delete(namespace string, keys []string) (err error) {
154 return s.db.Remove(namespace, keys)
157 func (s *SDLStorage) Clear(namespace string) {
158 s.db.RemoveAll(namespace)
161 func (s *SDLStorage) RegisterMetrics() {
162 s.stat = Metric.RegisterCounterGroup(SDLCounterOpts, "SDL")
165 func (s *SDLStorage) UpdateStatCounter(name string) {
171 func (s *SDLStorage) GetStat() (t SDLStatistics) {
175 //NewSDLClient returns a new SDLClient.
176 //Deprecated: Will be removed in a future release, please use NewSdlStorage
177 func NewSDLClient(ns string) *SDLClient {
187 //Deprecated: Will be removed in a future release, please use the TestConnection Receiver function of the SDLStorage type.
188 func (s *SDLClient) TestConnection() {
189 s.db.TestConnection(s.nameSpace)
192 func (s *SDLClient) IsReady() bool {
196 //Deprecated: Will be removed in a future release, please use the Store Receiver function of the SDLStorage type.
197 func (s *SDLClient) Store(key string, value interface{}) (err error) {
198 return s.db.Store(s.nameSpace, key, value)
201 //Deprecated: Will be removed in a future release, please use the MStore Receiver function of the SDLStorage type.
202 func (s *SDLClient) MStore(pairs ...interface{}) (err error) {
203 return s.db.MStore(s.nameSpace, pairs)
206 //Deprecated: Will be removed in a future release, please use the Read Receiver function of the SDLStorage type.
207 func (s *SDLClient) Read(key string) (value map[string]interface{}, err error) {
208 return s.db.Read(s.nameSpace, key)
211 //Deprecated: Will be removed in a future release, please use the MRead Receiver function of the SDLStorage type.
212 func (s *SDLClient) MRead(key []string) (value map[string]interface{}, err error) {
213 return s.db.MRead(s.nameSpace, key)
216 //Deprecated: Will be removed in a future release, please use the ReadAllKeys Receiver function of the SDLStorage type.
217 func (s *SDLClient) ReadAllKeys(key string) (value []string, err error) {
218 return s.db.ReadAllKeys(s.nameSpace)
221 //Deprecated: Will be removed in a future release, please use the Subscribe Receiver function of the SDLStorage type.
222 func (s *SDLClient) Subscribe(cb func(string, ...string), channel string) error {
223 return s.db.Subscribe(s.nameSpace, cb, channel)
226 //Deprecated: Will be removed in a future release, please use the MSubscribe Receiver function of the SDLStorage type.
227 func (s *SDLClient) MSubscribe(cb func(string, ...string), channels ...string) error {
228 return s.db.MSubscribe(s.nameSpace, cb, channels...)
231 //Deprecated: Will be removed in a future release, please use the StoreAndPublish Receiver function of the SDLStorage type.
232 func (s *SDLClient) StoreAndPublish(channel string, event string, pairs ...interface{}) error {
233 return s.db.StoreAndPublish(s.nameSpace, channel, event, pairs...)
236 //Deprecated: Will be removed in a future release, please use the MStoreAndPublish Receiver function of the SDLStorage type.
237 func (s *SDLClient) MStoreAndPublish(channelsAndEvents []string, pairs ...interface{}) error {
238 return s.db.MStoreAndPublish(s.nameSpace, channelsAndEvents, pairs...)
241 //Deprecated: Will be removed in a future release, please use the Delete Receiver function of the SDLStorage type.
242 func (s *SDLClient) Delete(keys []string) (err error) {
243 return s.db.Delete(s.nameSpace, keys)
246 //Deprecated: Will be removed in a future release, please use the Clear Receiver function of the SDLStorage type.
247 func (s *SDLClient) Clear() {
248 s.db.Clear(s.nameSpace)
251 //Deprecated: Will be removed in a future release, please use the RegisterMetrics Receiver function of the SDLStorage type.
252 func (s *SDLClient) RegisterMetrics() {
253 s.db.RegisterMetrics()
256 //Deprecated: Will be removed in a future release, please use the UpdateStatCounter Receiver function of the SDLStorage type.
257 func (s *SDLClient) UpdateStatCounter(name string) {
258 s.db.UpdateStatCounter(name)
261 //Deprecated: Will be removed in a future release, please use the GetStat Receiver function of the SDLStorage type.
262 func (c *SDLClient) GetStat() (t SDLStatistics) {
263 return c.db.GetStat()
266 func GetNewRnibClient(sdlStorage rnibcommon.ISdlSyncStorage) *RNIBClient {
269 reader: rnibreader.GetNewRNibReader(sdlStorage),
270 writer: rnibwriter.GetNewRNibWriter(sdlStorage),
274 //Deprecated: Will be removed in a future release, please use GetNewRnibClient instead.
275 func NewRNIBClient() *RNIBClient {
276 s := sdl.NewSyncStorage()
279 reader: rnibreader.GetNewRNibReader(s),
280 writer: rnibwriter.GetNewRNibWriter(s),
284 func (r *RNIBClient) Subscribe(cb func(string, ...string), channel string) error {
285 return r.db.SubscribeChannel(rnibcommon.GetRNibNamespace(), cb, channel)
288 func (r *RNIBClient) StoreAndPublish(channel string, event string, pairs ...interface{}) error {
289 return r.db.SetAndPublish(rnibcommon.GetRNibNamespace(), []string{channel, event}, pairs...)
292 func (r *RNIBClient) GetNodeb(invName string) (*RNIBNodebInfo, RNIBIRNibError) {
293 return r.reader.GetNodeb(invName)
296 func (r *RNIBClient) GetNodebByGlobalNbId(t RNIBNodeType, gid *RNIBGlobalNbId) (*RNIBNodebInfo, RNIBIRNibError) {
297 return r.reader.GetNodebByGlobalNbId(t, gid)
300 func (r *RNIBClient) GetCellList(invName string) (*RNIBCells, RNIBIRNibError) {
301 return r.reader.GetCellList(invName)
304 func (r *RNIBClient) GetListGnbIds() ([]*RNIBNbIdentity, RNIBIRNibError) {
305 return r.reader.GetListGnbIds()
308 func (r *RNIBClient) GetListEnbIds() ([]*RNIBNbIdentity, RNIBIRNibError) {
309 return r.reader.GetListEnbIds()
312 func (r *RNIBClient) GetCountGnbList() (int, RNIBIRNibError) {
313 return r.reader.GetCountGnbList()
316 func (r *RNIBClient) GetCell(invName string, pci uint32) (*RNIBCell, RNIBIRNibError) {
317 return r.reader.GetCell(invName, pci)
320 func (r *RNIBClient) GetCellById(cellType RNIBCellType, cellId string) (*RNIBCell, RNIBIRNibError) {
321 return r.reader.GetCellById(cellType, cellId)
324 func (r *RNIBClient) SaveNodeb(nbIdentity *RNIBNbIdentity, entity *RNIBNodebInfo) RNIBIRNibError {
325 return r.writer.SaveNodeb(nbIdentity, entity)