Add TO client noCache option, change TM2 to use
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/ea5a0468 Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/ea5a0468 Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/ea5a0468 Branch: refs/heads/master Commit: ea5a04688d11caf4dd2239a94718011e74b0cbc4 Parents: 2ab63e0 Author: Robert Butts <robert.o.bu...@gmail.com> Authored: Thu Feb 16 13:06:50 2017 -0700 Committer: Dave Neuman <neu...@apache.org> Committed: Sun Feb 19 18:56:45 2017 -0700 ---------------------------------------------------------------------- .../traffic_monitor/manager/opsconfig.go | 3 ++- traffic_ops/client/traffic_ops.go | 15 ++++++++++----- traffic_stats/traffic_stats.go | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/ea5a0468/traffic_monitor_golang/traffic_monitor/manager/opsconfig.go ---------------------------------------------------------------------- diff --git a/traffic_monitor_golang/traffic_monitor/manager/opsconfig.go b/traffic_monitor_golang/traffic_monitor/manager/opsconfig.go index 111452c..dba64ca 100644 --- a/traffic_monitor_golang/traffic_monitor/manager/opsconfig.go +++ b/traffic_monitor_golang/traffic_monitor/manager/opsconfig.go @@ -159,7 +159,8 @@ func StartOpsConfigManager( continue } - realToSession, err := to.LoginWithAgent(newOpsConfig.Url, newOpsConfig.Username, newOpsConfig.Password, newOpsConfig.Insecure, staticAppData.UserAgent) + useCache := false // TODO add config + realToSession, err := to.LoginWithAgent(newOpsConfig.Url, newOpsConfig.Username, newOpsConfig.Password, newOpsConfig.Insecure, staticAppData.UserAgent, useCache) if err != nil { handleErr(fmt.Errorf("MonitorConfigPoller: error instantiating Session with traffic_ops: %s\n", err)) continue http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/ea5a0468/traffic_ops/client/traffic_ops.go ---------------------------------------------------------------------- diff --git a/traffic_ops/client/traffic_ops.go b/traffic_ops/client/traffic_ops.go index bfb5309..d02ffef 100644 --- a/traffic_ops/client/traffic_ops.go +++ b/traffic_ops/client/traffic_ops.go @@ -38,10 +38,11 @@ type Session struct { UserAgent *http.Client cache map[string]CacheEntry cacheMutex *sync.RWMutex + useCache bool UserAgentStr string } -func NewSession(user, password, url, userAgent string, client *http.Client) *Session { +func NewSession(user, password, url, userAgent string, client *http.Client, useCache bool) *Session { return &Session{ UserName: user, Password: password, @@ -49,6 +50,7 @@ func NewSession(user, password, url, userAgent string, client *http.Client) *Ses UserAgent: client, cache: map[string]CacheEntry{}, cacheMutex: &sync.RWMutex{}, + useCache: useCache, UserAgentStr: userAgent, } } @@ -122,7 +124,7 @@ func ResumeSession(toURL string, insecure bool) (*Session, error) { TLSClientConfig: &tls.Config{InsecureSkipVerify: insecure}, }, Jar: jar, - }) + }, false) resp, err := to.request("GET", "/api/1.2/user/current.json", nil) @@ -138,14 +140,14 @@ func ResumeSession(toURL string, insecure bool) (*Session, error) { // Deprecated: Login is deprecated, use LoginWithAgent instead. The `Login` function with its present signature will be removed in the next version and replaced with `Login(toURL string, toUser string, toPasswd string, insecure bool, userAgent string)`. The `LoginWithAgent` function will be removed the version after that. func Login(toURL string, toUser string, toPasswd string, insecure bool) (*Session, error) { - return LoginWithAgent(toURL, toUser, toPasswd, insecure, "traffic-ops-client") // TODO add version + return LoginWithAgent(toURL, toUser, toPasswd, insecure, "traffic-ops-client", false) // TODO add version } // Login to traffic_ops, the response should set the cookie for this session // automatically. Start with // to := traffic_ops.Login("user", "passwd", true) // subsequent calls like to.GetData("datadeliveryservice") will be authenticated. -func LoginWithAgent(toURL string, toUser string, toPasswd string, insecure bool, userAgent string) (*Session, error) { +func LoginWithAgent(toURL string, toUser string, toPasswd string, insecure bool, userAgent string, useCache bool) (*Session, error) { credentials, err := loginCreds(toUser, toPasswd) if err != nil { return nil, err @@ -165,7 +167,7 @@ func LoginWithAgent(toURL string, toUser string, toPasswd string, insecure bool, TLSClientConfig: &tls.Config{InsecureSkipVerify: insecure}, }, Jar: jar, - }) + }, useCache) path := "/api/1.2/user/login" resp, err := to.request("POST", path, credentials) @@ -262,6 +264,9 @@ func StringToCacheHitStatus(s string) CacheHitStatus { // setCache Sets the given cache key and value. This is threadsafe for multiple goroutines. func (to *Session) setCache(path string, entry CacheEntry) { + if !to.useCache { + return + } to.cacheMutex.Lock() defer to.cacheMutex.Unlock() to.cache[path] = entry http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/ea5a0468/traffic_stats/traffic_stats.go ---------------------------------------------------------------------- diff --git a/traffic_stats/traffic_stats.go b/traffic_stats/traffic_stats.go index 3d474c0..5bf9c44 100644 --- a/traffic_stats/traffic_stats.go +++ b/traffic_stats/traffic_stats.go @@ -414,7 +414,7 @@ func queryDB(con influx.Client, cmd string, database string) (res []influx.Resul } func writeSummaryStats(config StartupConfig, statsSummary traffic_ops.StatsSummary) { - to, err := traffic_ops.LoginWithAgent(config.ToURL, config.ToUser, config.ToPasswd, true, UserAgent) + to, err := traffic_ops.LoginWithAgent(config.ToURL, config.ToUser, config.ToPasswd, true, UserAgent, false) if err != nil { newErr := fmt.Errorf("Could not store summary stats! Error logging in to %v: %v", config.ToURL, err) log.Error(newErr) @@ -428,7 +428,7 @@ func writeSummaryStats(config StartupConfig, statsSummary traffic_ops.StatsSumma func getToData(config StartupConfig, init bool, configChan chan RunningConfig) { var runningConfig RunningConfig - to, err := traffic_ops.LoginWithAgent(config.ToURL, config.ToUser, config.ToPasswd, true, UserAgent) + to, err := traffic_ops.LoginWithAgent(config.ToURL, config.ToUser, config.ToPasswd, true, UserAgent, false) if err != nil { msg := fmt.Sprintf("Error logging in to %v: %v", config.ToURL, err) if init {