Reading Rmr Configuration 56/11056/4
authornaman.gupta <naman.gupta@samsung.com>
Tue, 9 May 2023 10:01:52 +0000 (15:31 +0530)
committersubhash kumar singh <subh.singh@samsung.com>
Fri, 12 May 2023 07:22:00 +0000 (07:22 +0000)
Reading Rmr configuration.

Signed-off-by: naman.gupta <naman.gupta@samsung.com>
Change-Id: I18901dd232f35fdf81441dc415b5b714ced9ac82

config/configuration.go [new file with mode: 0644]
go.mod
pkg/rmr/rmr.go

diff --git a/config/configuration.go b/config/configuration.go
new file mode 100644 (file)
index 0000000..e67083a
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+==================================================================================
+  Copyright (c) 2023 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 (
+       "os"
+
+       "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/a1"
+       "github.com/spf13/viper"
+)
+
+type Configuration struct {
+       LogLevel          string
+       Name              string
+       MaxSize           int
+       ThreadType        int
+       LowLatency        bool
+       FastAck           bool
+       MaxRetryOnFailure int
+       Port              int
+}
+
+func ParseConfiguration() *Configuration {
+       viper.SetConfigType("yaml")
+       viper.SetConfigName("configuration")
+       configFile := os.Getenv("A1_CONFIG_FILE")
+       viper.SetConfigFile(configFile)
+       err := viper.ReadInConfig()
+       if err != nil {
+               a1.Logger.Info("#configuration.ParseConfiguration - failed to read configuration file: %s\n", err)
+       }
+
+       config := Configuration{}
+       config.LogLevel = viper.GetString("log-level")
+       viper.SetDefault("log-level", "info")
+       config.Name = viper.GetString("NAME")
+       viper.SetDefault("NAME", "")
+       config.MaxSize = viper.GetInt("MAX_SIZE")
+       viper.SetDefault("MAX_SIZE", 65534)
+       config.ThreadType = viper.GetInt("THREAD_TYPE")
+       viper.SetDefault("THREAD_TYPE", 0)
+       config.LowLatency = viper.GetBool("LOW_LATENCY")
+       viper.SetDefault("LOW_LATENCY", false)
+       config.FastAck = viper.GetBool("FAST_ACK")
+       viper.SetDefault("FAST_ACK", false)
+       config.MaxRetryOnFailure = viper.GetInt("MAX_RETRY_ON_FAILURE")
+       viper.SetDefault("MAX_RETRY_ON_FAILURE", 1)
+       config.Port = viper.GetInt("PORT")
+       viper.SetDefault("PORT", 4561)
+       return &config
+}
diff --git a/go.mod b/go.mod
index a78b02b..1f58f26 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -44,6 +44,7 @@ require (
        github.com/stretchr/testify v1.6.1
        golang.org/x/net v0.0.0-20210428140749-89ef3d95e781
        gopkg.in/yaml.v2 v2.4.0
+       github.com/spf13/viper v1.7.0
 )
 
 require (
index 4f4aa41..d9ec0f0 100644 (file)
@@ -29,6 +29,7 @@ import (
        "net/http"
        "strconv"
 
+       "gerrit.o-ran-sc.org/r/ric-plt/a1/config"
        "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/a1"
        "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/models"
        "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/policy"
@@ -57,17 +58,18 @@ type IRmrSender interface {
 }
 
 func NewRMRSender(policyManager *policy.PolicyManager) IRmrSender {
+       config := config.ParseConfiguration()
        RMRclient := xapp.NewRMRClientWithParams(&xapp.RMRClientParams{
                StatDesc: "",
                RmrData: xapp.PortData{
-                       //TODO: Read configuration from config file
-                       Name:              "",
-                       MaxSize:           65534,
-                       ThreadType:        0,
-                       LowLatency:        false,
-                       FastAck:           false,
-                       MaxRetryOnFailure: 1,
-                       Port:              4561,
+
+                       Name:              config.Name,
+                       MaxSize:           config.MaxSize,
+                       ThreadType:        config.ThreadType,
+                       LowLatency:        config.LowLatency,
+                       FastAck:           config.FastAck,
+                       MaxRetryOnFailure: config.MaxRetryOnFailure,
+                       Port:              config.Port,
                },
        })