Move TO Golang DBMaxConns from db.conf to cdn.conf

As requested by @dewrich


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/9987fb9a
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/9987fb9a
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/9987fb9a

Branch: refs/heads/master
Commit: 9987fb9ae3442048914fead01ed0337227de695d
Parents: 57c1a13
Author: Robert Butts <robert.o.bu...@gmail.com>
Authored: Sun Aug 6 10:30:17 2017 -0600
Committer: Dewayne Richardson <dewr...@apache.org>
Committed: Thu Aug 10 09:46:03 2017 -0600

----------------------------------------------------------------------
 traffic_ops/traffic_ops_golang/perlconfig.go | 40 +++++++++++++++--------
 1 file changed, 26 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/9987fb9a/traffic_ops/traffic_ops_golang/perlconfig.go
----------------------------------------------------------------------
diff --git a/traffic_ops/traffic_ops_golang/perlconfig.go 
b/traffic_ops/traffic_ops_golang/perlconfig.go
index d088fb3..ff118b3 100644
--- a/traffic_ops/traffic_ops_golang/perlconfig.go
+++ b/traffic_ops/traffic_ops_golang/perlconfig.go
@@ -72,12 +72,6 @@ func getPerlConfigsFromStrs(cdnConfBytes string, dbConfBytes 
string) (Config, er
        cfg.LogLocationEvent = OldAccessLogPath
        cfg.LogLocationDebug = log.LogLocationNull
 
-       if dbconf.MaxConnections != nil {
-               cfg.MaxDBConnections = *dbconf.MaxConnections
-       } else {
-               cfg.MaxDBConnections = DefaultMaxDBConnections
-       }
-
        return cfg, nil
 }
 
@@ -115,6 +109,13 @@ func getCDNConf(s string) (Config, error) {
                return Config{}, err
        }
 
+       if dbMaxConns, err := getDBMaxConns(obj); err != nil {
+               log.Warnf("failed to get Max DB Connections from cdn.conf (%v), 
using default %v\n", err, DefaultMaxDBConnections)
+               cfg.MaxDBConnections = DefaultMaxDBConnections
+       } else {
+               cfg.MaxDBConnections = dbMaxConns
+       }
+
        return cfg, nil
 }
 
@@ -135,6 +136,18 @@ func getPort(obj map[string]interface{}) (string, error) {
        return strconv.Itoa(port), nil
 }
 
+func getDBMaxConns(obj map[string]interface{}) (int, error) {
+       inum, ok := obj["traffic_ops_golang_max_db_connections"]
+       if !ok {
+               return 0, fmt.Errorf("missing 
traffic_ops_golang_max_db_connections key")
+       }
+       num, ok := inum.(float64)
+       if !ok {
+               return 0, fmt.Errorf("traffic_ops_golang_max_db_connections key 
'%v' type %T not a number", inum, inum)
+       }
+       return int(num), nil
+}
+
 func getOldPort(obj map[string]interface{}) (string, error) {
        hypnotoadI, ok := obj["hypnotoad"]
        if !ok {
@@ -279,14 +292,13 @@ func getSecret(obj map[string]interface{}) (string, 
error) {
 }
 
 type DatabaseConf struct {
-       Description    string `json:"description"`
-       DBName         string `json:"dbname"`
-       Hostname       string `json:"hostname"`
-       User           string `json:"user"`
-       Password       string `json:"password"`
-       Port           string `json:"port"`
-       Type           string `json:"type"`
-       MaxConnections *int   `json:"max_connections"`
+       Description string `json:"description"`
+       DBName      string `json:"dbname"`
+       Hostname    string `json:"hostname"`
+       User        string `json:"user"`
+       Password    string `json:"password"`
+       Port        string `json:"port"`
+       Type        string `json:"type"`
 }
 
 func getDbConf(s string) (DatabaseConf, error) {

Reply via email to