2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 // platform project (RICP).
24 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
29 type rsmReaderInstance struct {
30 sdl common.ISdlInstance
33 // RsmReader interface allows retrieving data from redis BD by various keys
34 type RsmReader interface {
35 GetRsmGeneralConfiguration() (*models.RsmGeneralConfiguration, error)
36 GetRsmRanInfo(ranName string) (*models.RsmRanInfo, error)
39 // GetRsmReader returns reference to RsmReader
40 func GetRsmReader(sdl common.ISdlInstance) RsmReader {
41 return &rsmReaderInstance{sdl: sdl}
44 // GetRsmRanInfo returns the rsm data associated with ran 'ranName'
45 func (r *rsmReaderInstance) GetRsmRanInfo(ranName string) (*models.RsmRanInfo, error) {
47 key, err := common.ValidateAndBuildNodeBNameKey(ranName)
52 rsmRanInfo := &models.RsmRanInfo{}
54 err = r.getByKeyAndUnmarshal(key, rsmRanInfo)
60 return rsmRanInfo, nil
63 // GetRsmGeneralConfiguration returns resource status request related configuration
64 func (r *rsmReaderInstance) GetRsmGeneralConfiguration() (*models.RsmGeneralConfiguration, error) {
65 cfg := &models.RsmGeneralConfiguration{}
66 err := r.getByKeyAndUnmarshal(buildRsmGeneralConfigurationKey(), cfg)
70 // getByKeyAndUnmarshal returns the value that is associated with key 'key' as a Go structure
71 func (r *rsmReaderInstance) getByKeyAndUnmarshal(key string, entity interface{}) error {
72 data, err := r.sdl.Get([]string{key})
74 return common.NewInternalError(err)
76 if data != nil && data[key] != nil {
77 err = json.Unmarshal([]byte(data[key].(string)), entity)
79 return common.NewInternalError(err)
83 return common.NewResourceNotFoundErrorf("#rsmReader.getByKeyAndUnmarshal - entity of type %s not found. Key: %s", reflect.TypeOf(entity).String(), key)
86 func buildRsmGeneralConfigurationKey() string {
87 return "CFG:GENERAL:v1.0.0"