From ad876453a050280c51ca4b275cbfec4c43f11d20 Mon Sep 17 00:00:00 2001 From: "naman.gupta" Date: Tue, 9 May 2023 15:31:52 +0530 Subject: [PATCH] Reading Rmr Configuration Reading Rmr configuration. Signed-off-by: naman.gupta Change-Id: I18901dd232f35fdf81441dc415b5b714ced9ac82 --- config/configuration.go | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 1 + pkg/rmr/rmr.go | 18 +++++++------ 3 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 config/configuration.go diff --git a/config/configuration.go b/config/configuration.go new file mode 100644 index 0000000..e67083a --- /dev/null +++ b/config/configuration.go @@ -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 --- 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 ( diff --git a/pkg/rmr/rmr.go b/pkg/rmr/rmr.go index 4f4aa41..d9ec0f0 100644 --- a/pkg/rmr/rmr.go +++ b/pkg/rmr/rmr.go @@ -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, }, }) -- 2.16.6