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"
25 type Configuration struct {
36 RoutingManager struct {
39 NotificationResponseBuffer int
40 BigRedButtonTimeoutSec int
41 MaxConnectionAttempts int
42 MaxRnibConnectionAttempts int
43 RnibRetryIntervalMs int
44 KeepAliveResponseTimeoutMs int
48 func ParseConfiguration() *Configuration {
49 viper.SetConfigType("yaml")
50 viper.SetConfigName("configuration")
51 viper.AddConfigPath("E2Manager/resources/")
52 viper.AddConfigPath("./resources/") //For production
53 viper.AddConfigPath("../resources/") //For test under Docker
54 viper.AddConfigPath("../../resources/") //For test under Docker
55 err := viper.ReadInConfig()
57 panic(fmt.Sprintf("#configuration.ParseConfiguration - failed to read configuration file: %s\n", err))
60 config := Configuration{}
61 config.populateRmrConfig(viper.Sub("rmr"))
62 config.populateHttpConfig(viper.Sub("http"))
63 config.populateLoggingConfig(viper.Sub("logging"))
64 config.populateRoutingManagerConfig(viper.Sub("routingManager"))
65 config.NotificationResponseBuffer = viper.GetInt("notificationResponseBuffer")
66 config.BigRedButtonTimeoutSec = viper.GetInt("bigRedButtonTimeoutSec")
67 config.MaxConnectionAttempts = viper.GetInt("maxConnectionAttempts")
68 config.MaxRnibConnectionAttempts = viper.GetInt("maxRnibConnectionAttempts")
69 config.RnibRetryIntervalMs = viper.GetInt("rnibRetryIntervalMs")
70 config.KeepAliveResponseTimeoutMs = viper.GetInt("keepAliveResponseTimeoutMs")
71 config.KeepAliveDelayMs = viper.GetInt("KeepAliveDelayMs")
75 func (c *Configuration) populateLoggingConfig(logConfig *viper.Viper) {
77 panic(fmt.Sprintf("#configuration.populateLoggingConfig - failed to populate logging configuration: The entry 'logging' not found\n"))
79 c.Logging.LogLevel = logConfig.GetString("logLevel")
82 func (c *Configuration) populateHttpConfig(httpConfig *viper.Viper) {
83 if httpConfig == nil {
84 panic(fmt.Sprintf("#configuration.populateHttpConfig - failed to populate HTTP configuration: The entry 'http' not found\n"))
86 c.Http.Port = httpConfig.GetInt("port")
89 func (c *Configuration) populateRmrConfig(rmrConfig *viper.Viper) {
91 panic(fmt.Sprintf("#configuration.populateRmrConfig - failed to populate RMR configuration: The entry 'rmr' not found\n"))
93 c.Rmr.Port = rmrConfig.GetInt("port")
94 c.Rmr.MaxMsgSize = rmrConfig.GetInt("maxMsgSize")
97 func (c *Configuration) populateRoutingManagerConfig(rmConfig *viper.Viper) {
99 panic(fmt.Sprintf("#configuration.populateRoutingManagerConfig - failed to populate Routing Manager configuration: The entry 'routingManager' not found\n"))
101 c.RoutingManager.BaseUrl = rmConfig.GetString("baseUrl")