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.
22 "github.com/spf13/viper"
26 type Configuration struct {
39 MaxRnibConnectionAttempts int
40 RnibRetryIntervalMs int
42 ResourceStatusParams struct {
43 EnableResourceStatus bool
44 PartialSuccessAllowed bool
46 TnlLoadIndPeriodic bool
47 HwLoadIndPeriodic bool
48 AbsStatusPeriodic bool
49 RsrpMeasurementPeriodic bool
51 PeriodicityMs enums.ReportingPeriodicity
52 PeriodicityRsrpMeasurementMs enums.ReportingPeriodicityRSRPMR
53 PeriodicityCsiMs enums.ReportingPeriodicityCSIR
57 func ParseConfiguration() (*Configuration, error) {
58 viper.SetConfigType("yaml")
59 viper.SetConfigName("configuration")
60 viper.AddConfigPath("RSM/resources/")
61 viper.AddConfigPath("./resources/") //For production
62 viper.AddConfigPath("../resources/") //For test under Docker
63 viper.AddConfigPath("../../resources/") //For test under Docker
64 if err := viper.ReadInConfig(); err != nil {
65 return nil, fmt.Errorf("#configuration.parseConfiguration - failed to read configuration file: %s\n", err)
68 config := Configuration{}
69 if err := config.fillRmrConfig(viper.Sub("rmr")); err != nil {
72 if err := config.fillHttpConfig(viper.Sub("http")); err != nil {
75 if err := config.fillLoggingConfig(viper.Sub("logging")); err != nil {
78 if err := config.fillRnibConfig(viper.Sub("rnib")); err != nil {
81 if err := config.fillResourceStatusParamsConfig(viper.Sub("resourceStatusParams")); err != nil {
88 func (c *Configuration) fillLoggingConfig(logConfig *viper.Viper) error {
90 return fmt.Errorf("#configuration.fillLoggingConfig - failed to fill logging configuration: The entry 'logging' not found\n")
92 c.Logging.LogLevel = logConfig.GetString("logLevel")
96 func (c *Configuration) fillHttpConfig(httpConfig *viper.Viper) error {
97 if httpConfig == nil {
98 return fmt.Errorf("#configuration.fillHttpConfig - failed to fill HTTP configuration: The entry 'http' not found\n")
100 c.Http.Port = httpConfig.GetInt("port")
104 func (c *Configuration) fillRmrConfig(rmrConfig *viper.Viper) error {
105 if rmrConfig == nil {
106 return fmt.Errorf("#configuration.fillRmrConfig - failed to fill RMR configuration: The entry 'rmr' not found\n")
108 c.Rmr.Port = rmrConfig.GetInt("port")
109 c.Rmr.MaxMsgSize = rmrConfig.GetInt("maxMsgSize")
110 c.Rmr.ReadyIntervalSec = rmrConfig.GetInt("readyIntervalSec")
114 func (c *Configuration) fillRnibConfig(rnibConfig *viper.Viper) error {
115 if rnibConfig == nil {
116 return fmt.Errorf("#configuration.fillRnibConfig - failed to fill RNib configuration: The entry 'rnib' not found\n")
118 c.Rnib.MaxRnibConnectionAttempts = rnibConfig.GetInt("maxRnibConnectionAttempts")
119 c.Rnib.RnibRetryIntervalMs = rnibConfig.GetInt("rnibRetryIntervalMs")
123 func (c *Configuration) fillResourceStatusParamsConfig(chConfig *viper.Viper) error {
125 return fmt.Errorf("#configuration.fillResourceStatusParamsConfig - failed to fill resourceStatusParams configuration: The entry 'resourceStatusParams' not found\n")
127 c.ResourceStatusParams.EnableResourceStatus = chConfig.GetBool("enableResourceStatus")
128 c.ResourceStatusParams.PartialSuccessAllowed = chConfig.GetBool("partialSuccessAllowed")
129 c.ResourceStatusParams.PrbPeriodic = chConfig.GetBool("prbPeriodic")
130 c.ResourceStatusParams.TnlLoadIndPeriodic = chConfig.GetBool("tnlLoadIndPeriodic")
131 c.ResourceStatusParams.HwLoadIndPeriodic = chConfig.GetBool("hwLoadIndPeriodic")
132 c.ResourceStatusParams.AbsStatusPeriodic = chConfig.GetBool("absStatusPeriodic")
133 c.ResourceStatusParams.RsrpMeasurementPeriodic = chConfig.GetBool("rsrpMeasurementPeriodic")
134 c.ResourceStatusParams.CsiPeriodic = chConfig.GetBool("csiPeriodic")
135 if err := setPeriodicityMs(c, chConfig.GetInt("periodicityMs")); err != nil {
138 if err := setPeriodicityRsrpMeasurementMs(c, chConfig.GetInt("periodicityRsrpMeasurementMs")); err != nil {
141 if err := setPeriodicityCsiMs(c, chConfig.GetInt("periodicityCsiMs")); err != nil {
147 func setPeriodicityMs(c *Configuration, periodicityMs int) error {
148 v, ok := enums.ReportingPeriodicityValues[periodicityMs]
151 return fmt.Errorf("Invalid configuration value supplied for PeriodicityMs. Received: %d. Should be one of: %v\n", periodicityMs, enums.GetReportingPeriodicityValuesAsKeys())
154 c.ResourceStatusParams.PeriodicityMs = v
158 func setPeriodicityRsrpMeasurementMs(c *Configuration, periodicityRsrpMeasurementMs int) error {
159 v, ok := enums.ReportingPeriodicityRsrPmrValues[periodicityRsrpMeasurementMs]
162 return fmt.Errorf("Invalid configuration value supplied for PeriodicityRsrpMeasurementMs. Received: %d. Should be one of: %v\n", periodicityRsrpMeasurementMs, enums.GetReportingPeriodicityRsrPmrValuesAsKeys())
165 c.ResourceStatusParams.PeriodicityRsrpMeasurementMs = v
169 func setPeriodicityCsiMs(c *Configuration, periodicityCsiMs int) error {
170 v, ok := enums.ReportingPeriodicityCsirValues[periodicityCsiMs]
173 return fmt.Errorf("Invalid configuration value supplied for PeriodicityCsiMs. Received: %d. Should be one of: %v\n", periodicityCsiMs, enums.GetReportingPeriodicityCsirValuesAsKeys())
176 c.ResourceStatusParams.PeriodicityCsiMs = v
180 func (c *Configuration) String() string {
181 return fmt.Sprintf("{logging.logLevel: %s, http.port: %d, rmr.port: %d, rmr.maxMsgSize: %d, rmr.readyIntervalSec: %d, rnib.maxRnibConnectionAttempts: %d, rnib.rnibRetryIntervalMs: %d, "+
182 "resourceStatusParams.enableResourceStatus: %t, resourceStatusParams.partialSuccessAllowed: %t, resourceStatusParams.prbPeriodic: %t, "+
183 "resourceStatusParams.tnlLoadIndPeriodic: %t, resourceStatusParams.hwLoadIndPeriodic: %t, resourceStatusParams.absStatusPeriodic: %t,"+
184 "resourceStatusParams.rsrpMeasurementPeriodic: %t, resourceStatusParams.csiPeriodic: %t, resourceStatusParams.periodicityMs: %s, "+
185 "resourceStatusParams.periodicityRsrpMeasurementMs: %s, resourceStatusParams.periodicityCsiMs: %s}",
190 c.Rmr.ReadyIntervalSec,
191 c.Rnib.MaxRnibConnectionAttempts,
192 c.Rnib.RnibRetryIntervalMs,
193 c.ResourceStatusParams.EnableResourceStatus,
194 c.ResourceStatusParams.PartialSuccessAllowed,
195 c.ResourceStatusParams.PrbPeriodic,
196 c.ResourceStatusParams.TnlLoadIndPeriodic,
197 c.ResourceStatusParams.HwLoadIndPeriodic,
198 c.ResourceStatusParams.AbsStatusPeriodic,
199 c.ResourceStatusParams.RsrpMeasurementPeriodic,
200 c.ResourceStatusParams.CsiPeriodic,
202 c.ResourceStatusParams.PeriodicityMs,
203 c.ResourceStatusParams.PeriodicityRsrpMeasurementMs,
204 c.ResourceStatusParams.PeriodicityCsiMs,