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.
18 This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 platform project (RICP).
21 ==================================================================================
25 Abstract: File SDL implementation. Only for testing purpose.
34 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
37 "routing-manager/pkg/rtmgr"
41 Reads the content of the rt.json file
42 Parses the JSON content and loads each xApp entry into an xApp object
43 Returns an array os xApp object
50 func NewFile() *File {
55 func (f *File) ReadAll(file string) (*rtmgr.RicComponents, error) {
56 xapp.Logger.Debug("Invoked sdl.ReadAll(" + file + ")")
57 var rcs *rtmgr.RicComponents
58 jsonFile, err := os.Open(file)
60 return nil, errors.New("cannot open the file due to: " + err.Error())
62 defer jsonFile.Close()
64 byteValue, err := ioutil.ReadAll(jsonFile)
66 return nil, errors.New("cannot read the file due to: " + err.Error())
68 err = json.Unmarshal(byteValue, &rcs)
70 return nil, errors.New("cannot parse data due to: " + err.Error())
72 xapp.Logger.Debug("file.fileReadAll returns: %v", rcs)
76 func (f *File) WriteAll(file string, rcs *rtmgr.RicComponents) error {
77 xapp.Logger.Debug("Invoked sdl.WriteAll")
78 xapp.Logger.Debug("file.fileWriteAll writes into file: " + file)
79 xapp.Logger.Debug("file.fileWriteAll writes data: %v", *rcs)
80 byteValue, err := json.Marshal(rcs)
82 return errors.New("cannot convert data due to: " + err.Error())
84 err = ioutil.WriteFile(file, byteValue, 0644)
86 return errors.New("cannot write file due to: " + err.Error())
91 func (f *File) WriteXApps(file string, xApps *[]rtmgr.XApp) error {
92 xapp.Logger.Debug("Invoked sdl.WriteXApps")
93 xapp.Logger.Debug("file.fileWriteXApps writes into file: " + file)
94 xapp.Logger.Debug("file.fileWriteXApps writes data: %v", *xApps)
96 ricData, err := NewFile().ReadAll(file)
98 xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
99 return errors.New("cannot read full ric data to modify xApps data, due to: " + err.Error())
101 ricData.XApps = *xApps
103 byteValue, err := json.Marshal(ricData)
105 return errors.New("cannot convert data due to: " + err.Error())
107 err = ioutil.WriteFile(file, byteValue, 0644)
109 return errors.New("cannot write file due to: " + err.Error())
114 func (f *File) WriteNewE2TInstance(file string, E2TInst *rtmgr.E2TInstance) error {
115 xapp.Logger.Debug("Invoked sdl.WriteNewE2TInstance")
116 xapp.Logger.Debug("file.WriteNewE2TInstance writes into file: " + file)
117 xapp.Logger.Debug("file.WriteNewE2TInstance writes data: %v", *E2TInst)
119 ricData, err := NewFile().ReadAll(file)
121 xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
122 return errors.New("cannot read full ric data to modify xApps data, due to: " + err.Error())
124 ricData.E2Ts[E2TInst.Fqdn] = *E2TInst
126 byteValue, err := json.Marshal(ricData)
128 return errors.New("cannot convert data due to: " + err.Error())
130 err = ioutil.WriteFile(file, byteValue, 0644)
132 return errors.New("cannot write file due to: " + err.Error())