diff --git a/cache-config/t3c-apply/torequest/torequest.go b/cache-config/t3c-apply/torequest/torequest.go index 10fefd6836..7a93499615 100644 --- a/cache-config/t3c-apply/torequest/torequest.go +++ b/cache-config/t3c-apply/torequest/torequest.go @@ -61,21 +61,21 @@ type TrafficOpsReq struct { pluginPkgs map[string]struct{} // map of packages changedFiles []string // list of config files which were changed - configFiles map[string]*ConfigFile - TrafficCtlReload bool // a traffic_ctl_reload is required - SysCtlReload bool // a reload of the sysctl.conf is required - NtpdRestart bool // ntpd needs restarting - TeakdRestart bool // a restart of teakd is required - TrafficServerRestart bool // a trafficserver restart is required - RemapConfigReload bool // remap.config should be reloaded - unixTimeStr string // unix time string at program startup. + configFiles map[string]*ConfigFile + + RestartData } type ShouldReloadRestart struct { - ReloadRestart []RestartData + ReloadRestart []FileRestartData +} + +type FileRestartData struct { + Name string + RestartData } + type RestartData struct { - Name string TrafficCtlReload bool // a traffic_ctl_reload is required SysCtlReload bool // a reload of the sysctl.conf is required NtpdRestart bool // ntpd needs restarting @@ -180,8 +180,6 @@ func (r *TrafficOpsReq) DumpConfigFiles() { // NewTrafficOpsReq returns a new TrafficOpsReq object. func NewTrafficOpsReq(cfg config.Cfg) *TrafficOpsReq { - unixTimeString := strconv.FormatInt(time.Now().Unix(), 10) - return &TrafficOpsReq{ Cfg: cfg, pkgs: map[string]bool{}, @@ -189,7 +187,6 @@ func NewTrafficOpsReq(cfg config.Cfg) *TrafficOpsReq { configFiles: map[string]*ConfigFile{}, installedPkgs: map[string]struct{}{}, pluginPkgs: map[string]struct{}{}, - unixTimeStr: unixTimeString, } } @@ -475,12 +472,12 @@ func (r *TrafficOpsReq) readCfgFile(cfg *ConfigFile, dir string) ([]byte, error) const configFileTempSuffix = `.tmp` // replaceCfgFile replaces an ATS configuration file with one from Traffic Ops. -func (r *TrafficOpsReq) replaceCfgFile(cfg *ConfigFile) (*RestartData, error) { +func (r *TrafficOpsReq) replaceCfgFile(cfg *ConfigFile) (*FileRestartData, error) { if r.Cfg.ReportOnly || (r.Cfg.Files != t3cutil.ApplyFilesFlagAll && r.Cfg.Files != t3cutil.ApplyFilesFlagReval) { log.Infof("You elected not to replace %s with the version from Traffic Ops.\n", cfg.Name) cfg.ChangeApplied = false - return &RestartData{Name: cfg.Name}, nil + return &FileRestartData{Name: cfg.Name}, nil } tmpFileName := cfg.Path + configFileTempSuffix @@ -492,12 +489,12 @@ func (r *TrafficOpsReq) replaceCfgFile(cfg *ConfigFile) (*RestartData, error) { // we'd end up with malformed files. if _, err := util.WriteFileWithOwner(tmpFileName, cfg.Body, &cfg.Uid, &cfg.Gid, cfg.Perm); err != nil { - return &RestartData{Name: cfg.Name}, errors.New("Failed to write temp config file '" + tmpFileName + "': " + err.Error()) + return &FileRestartData{Name: cfg.Name}, errors.New("Failed to write temp config file '" + tmpFileName + "': " + err.Error()) } log.Infof("Copying temp file '%s' to real '%s'\n", tmpFileName, cfg.Path) if err := os.Rename(tmpFileName, cfg.Path); err != nil { - return &RestartData{Name: cfg.Name}, errors.New("Failed to move temp '" + tmpFileName + "' to real '" + cfg.Path + "': " + err.Error()) + return &FileRestartData{Name: cfg.Name}, errors.New("Failed to move temp '" + tmpFileName + "' to real '" + cfg.Path + "': " + err.Error()) } cfg.ChangeApplied = true r.changedFiles = append(r.changedFiles, cfg.Path) @@ -526,13 +523,15 @@ func (r *TrafficOpsReq) replaceCfgFile(cfg *ConfigFile) (*RestartData, error) { log.Debugf("Reload state after %s: remap.config: %t reload: %t restart: %t ntpd: %t sysctl: %t", cfg.Name, remapConfigReload, trafficCtlReload, trafficServerRestart, ntpdRestart, sysCtlReload) log.Debugf("Setting change applied for '%s'\n", cfg.Name) - return &RestartData{ - Name: cfg.Name, - TrafficCtlReload: trafficCtlReload, - SysCtlReload: sysCtlReload, - NtpdRestart: ntpdRestart, - TrafficServerRestart: trafficServerRestart, - RemapConfigReload: remapConfigReload, + return &FileRestartData{ + Name: cfg.Name, + RestartData: RestartData{ + TrafficCtlReload: trafficCtlReload, + SysCtlReload: sysCtlReload, + NtpdRestart: ntpdRestart, + TrafficServerRestart: trafficServerRestart, + RemapConfigReload: remapConfigReload, + }, }, nil } @@ -793,24 +792,17 @@ func (r *TrafficOpsReq) CheckSyncDSState() (UpdateStatus, error) { } // CheckReloadRestart determines the final reload/restart state after all config files are processed. -func (r *TrafficOpsReq) CheckReloadRestart(data []RestartData) (bool, bool, bool, bool, bool, bool) { - trafficCtlReload := false - sysCtlReload := false - ntpdRestart := false - teakdRestart := false - trafficServerRestart := false - remapConfigReload := false - +func (r *TrafficOpsReq) CheckReloadRestart(data []FileRestartData) RestartData { + rd := RestartData{} for _, changedFile := range data { - trafficCtlReload = trafficCtlReload || changedFile.TrafficCtlReload - sysCtlReload = sysCtlReload || changedFile.SysCtlReload - ntpdRestart = ntpdRestart || changedFile.NtpdRestart - teakdRestart = teakdRestart || changedFile.TeakdRestart - trafficServerRestart = trafficServerRestart || changedFile.TrafficServerRestart - remapConfigReload = remapConfigReload || changedFile.RemapConfigReload - } - - return trafficCtlReload, sysCtlReload, ntpdRestart, teakdRestart, trafficServerRestart, remapConfigReload + rd.TrafficCtlReload = rd.TrafficCtlReload || changedFile.TrafficCtlReload + rd.SysCtlReload = rd.SysCtlReload || changedFile.SysCtlReload + rd.NtpdRestart = rd.NtpdRestart || changedFile.NtpdRestart + rd.TeakdRestart = rd.TeakdRestart || changedFile.TeakdRestart + rd.TrafficServerRestart = rd.TrafficServerRestart || changedFile.TrafficServerRestart + rd.RemapConfigReload = rd.RemapConfigReload || changedFile.RemapConfigReload + } + return rd } // ProcessConfigFiles processes all config files retrieved from Traffic Ops. @@ -850,7 +842,7 @@ func (r *TrafficOpsReq) ProcessConfigFiles() (UpdateStatus, error) { } changesRequired := 0 - shouldRestartReload := ShouldReloadRestart{[]RestartData{}} + shouldRestartReload := ShouldReloadRestart{[]FileRestartData{}} for _, cfg := range r.configFiles { if cfg.ChangeNeeded && @@ -882,7 +874,7 @@ func (r *TrafficOpsReq) ProcessConfigFiles() (UpdateStatus, error) { } } - r.TrafficCtlReload, r.SysCtlReload, r.NtpdRestart, r.TeakdRestart, r.TrafficServerRestart, r.RemapConfigReload = r.CheckReloadRestart(shouldRestartReload.ReloadRestart) + r.RestartData = r.CheckReloadRestart(shouldRestartReload.ReloadRestart) if 0 < len(r.changedFiles) { log.Infof("Final state: remap.config: %t reload: %t restart: %t ntpd: %t sysctl: %t", r.RemapConfigReload, r.TrafficCtlReload, r.TrafficServerRestart, r.NtpdRestart, r.SysCtlReload)