Simplify the reading configuration 22/9122/2
authorsubhash kumar singh <subh.singh@samsung.com>
Wed, 28 Sep 2022 10:08:33 +0000 (10:08 +0000)
committersubhash kumar singh <subh.singh@samsung.com>
Wed, 28 Sep 2022 10:17:30 +0000 (10:17 +0000)
Simplify reading configuration by creating model for config.

Signed-off-by: subhash kumar singh <subh.singh@samsung.com>
Change-Id: I2a4b527c36e83dabafe6f32b3f1f1c100cb24215

config/config-test.yaml
config/config.yaml
pkg/config/conf.go [new file with mode: 0644]
pkg/ricdms/ricdms.go

index de9d2ad..5e37c1c 100644 (file)
@@ -12,4 +12,6 @@
 #   See the License for the specific language governing permissions and
 #   limitations under the License.
 #
-log-level: debug
\ No newline at end of file
+log-level: debug
+onborder-url: "http://127.0.0.1:9191"
+mock-server: "127.0.0.1:9191"
\ No newline at end of file
index de9d2ad..e47eaca 100644 (file)
@@ -12,4 +12,5 @@
 #   See the License for the specific language governing permissions and
 #   limitations under the License.
 #
-log-level: debug
\ No newline at end of file
+log-level: debug
+onborder-url: "http://service-ricplt-xapp-onboarder-http.ricplt:8888/api/v1/onboard"
\ No newline at end of file
diff --git a/pkg/config/conf.go b/pkg/config/conf.go
new file mode 100644 (file)
index 0000000..1eff109
--- /dev/null
@@ -0,0 +1,50 @@
+//==================================================================================
+//  Copyright (c) 2022 Samsung
+//
+//   Licensed under the Apache License, Version 2.0 (the "License");
+//   you may not use this file except in compliance with the License.
+//   You may obtain a copy of the License at
+//
+//       http://www.apache.org/licenses/LICENSE-2.0
+//
+//   Unless required by applicable law or agreed to in writing, software
+//   distributed under the License is distributed on an "AS IS" BASIS,
+//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//   See the License for the specific language governing permissions and
+//   limitations under the License.
+//
+//   This source code is part of the near-RT RIC (RAN Intelligent Controller)
+//   platform project (RICP).
+//==================================================================================
+//
+
+package config
+
+import (
+       "fmt"
+       "io/ioutil"
+
+       "gopkg.in/yaml.v3"
+)
+
+type Conf struct {
+       LogLevel   string `yaml:"log-level"`
+       OnboardURL string `yaml:"onborder-url"`
+       MockServer string `yaml:"mock-server"`
+}
+
+func ReadConfiguration(configFile string) (c *Conf, err error) {
+       yamlFile, err := ioutil.ReadFile(configFile)
+       if err != nil {
+               fmt.Printf("error in resolving config file : %+v\n", err)
+               return nil, err
+       }
+
+       err = yaml.Unmarshal(yamlFile, &c)
+       if err != nil {
+               fmt.Printf("Unmarshal error : %+v\n", err)
+               return nil, err
+       }
+
+       return c, err
+}
index 40c2f9d..b15bf01 100644 (file)
@@ -25,12 +25,14 @@ import (
        "os"
 
        mdclog "gerrit.o-ran-sc.org/r/com/golog"
+       "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/config"
 )
 
 type ricdms struct {
 }
 
 var Logger *mdclog.MdcLogger
+var Config *config.Conf
 
 func Init() {
        var err error
@@ -44,9 +46,13 @@ func Init() {
 
        if configFile != "" {
                Logger.ParseFileContent(configFile)
+               Config, err = config.ReadConfiguration(configFile)
+               if err != nil {
+                       Logger.Error("Error in parsing config file: %v", err)
+               }
                Logger.Info("Logger is initialized with config file : %s", configFile)
        } else {
                Logger.LevelSet(mdclog.INFO)
-               Logger.Info("Logger is initialized without config file.")
+               Logger.Info("Logger is initialized without config file(%s).", configFile)
        }
 }