rob05c commented on a change in pull request #2606: Updates 'grovetccfg' to to 
write a grove.cfg from the grove servers profile
URL: https://github.com/apache/trafficcontrol/pull/2606#discussion_r207919564
 
 

 ##########
 File path: grove/grovetccfg/grovetccfg.go
 ##########
 @@ -259,20 +328,162 @@ func main() {
        os.Exit(0)
 }
 
-func createRulesOldAPI(toc *to.Session, host string, certDir string) 
(remap.RemapRules, error) {
-       cachegroupsArr, err := toc.CacheGroups()
+func createGroveCfg(toc *to.Session, server tc.Server) (bool, config.Config, 
error) {
+       var new_cfg config.Config
+       var cur_cfg config.Config
+       var plugin_params = []string{}
+
+       // load the servers current config parameters.
+       if _, err := os.Stat(GroveConfigPath); err == nil {
+               cur_cfg, err = config.LoadConfig(GroveConfigPath)
+               if err != nil {
+                       fmt.Println(time.Now().Format(time.RFC3339Nano) + " 
Error loading current config from '" + GroveConfigPath + "' " + err.Error())
+                       return false, cur_cfg, err
+               } else {
+                       // make sure this array is sorted for later comparison
+                       sort.Strings(cur_cfg.Plugins)
+               }
+       }
+
+       serverParameters, err := toc.Parameters(server.Profile)
        if err != nil {
-               fmt.Println(time.Now().Format(time.RFC3339Nano) + " Error 
getting Traffic Ops Cachegroups: " + err.Error())
-               os.Exit(1)
+               fmt.Println(time.Now().Format(time.RFC3339Nano) + " Error 
getting Traffic Ops Parameters for host '" + server.HostName + "' profile '" + 
server.Profile + "': " + err.Error())
+               return false, cur_cfg, err
+       } else {
+               // load config parameters from the servers profile
+               for _, p := range serverParameters {
+                       if p.ConfigFile == "grove.cfg" {
+                               if p.Name == "plugins" {
+                                       plugin_params = append(plugin_params, 
p.Value)
+                               } else {
+                                       err := setConfigParameter(&new_cfg, 
p.Name, p.Value)
+                                       if err != nil {
+                                               
fmt.Println(time.Now().Format(time.RFC3339Nano) + " Error setting config 
parameter '" + p.Name + "' :" + err.Error())
+                                               return false, cur_cfg, err
+                                       }
+                               }
+                       }
+               }
+               sort.Strings(plugin_params)
+               new_cfg.Plugins = plugin_params
+       }
+       // no update is required if the configs are the same
+       areEqual := reflect.DeepEqual(new_cfg, cur_cfg)
+       if areEqual == true {
+               fmt.Println(time.Now().Format(time.RFC3339Nano) + " There are 
no changes needed to '" + GroveConfigPath + "'")
+               return false, cur_cfg, nil
+       } else { // updates are required, send the new config
+               fmt.Println(time.Now().Format(time.RFC3339Nano) + " Config 
updates are required to '" + GroveConfigPath + "'")
+               return true, new_cfg, nil
        }
-       cachegroups := makeCachegroupsNameMap(cachegroupsArr)
+}
+
+func setConfigParameter(cfg *config.Config, name string, value string) error {
+       var err error
+       err = nil
+       if name == "rfc_compliant" {
+               cfg.RFCCompliant, err = strconv.ParseBool(value)
+               return err
+       }
+       if name == "port" {
 
 Review comment:
   All these strings duplicating the JSON tags aren't great, but unfortunately, 
I don't think Go has a better way to do this

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to