本文整理汇总了Golang中github.com/Comcast/traffic_control/traffic_monitor/experimental/traffic_monitor/peer.CRStatesThreadsafe.SetDeliveryService方法的典型用法代码示例。如果您正苦于以下问题:Golang CRStatesThreadsafe.SetDeliveryService方法的具体用法?Golang CRStatesThreadsafe.SetDeliveryService怎么用?Golang CRStatesThreadsafe.SetDeliveryService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Comcast/traffic_control/traffic_monitor/experimental/traffic_monitor/peer.CRStatesThreadsafe
的用法示例。
在下文中一共展示了CRStatesThreadsafe.SetDeliveryService方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: monitorConfigListen
// TODO timing, and determine if the case, or its internal `for`, should be put in a goroutine
// TODO determine if subscribers take action on change, and change to mutexed objects if not.
func monitorConfigListen(monitorConfigTS TrafficMonitorConfigMapThreadsafe, monitorConfigPollChan <-chan to.TrafficMonitorConfigMap, localStates peer.CRStatesThreadsafe, statUrlSubscriber chan<- poller.HttpPollerConfig, healthUrlSubscriber chan<- poller.HttpPollerConfig, peerUrlSubscriber chan<- poller.HttpPollerConfig, cfg config.Config, staticAppData StaticAppData) {
for {
select {
case monitorConfig := <-monitorConfigPollChan:
monitorConfigTS.Set(monitorConfig)
healthUrls := map[string]string{}
statUrls := map[string]string{}
peerUrls := map[string]string{}
caches := map[string]string{}
for _, srv := range monitorConfig.TrafficServer {
caches[srv.HostName] = srv.Status
cacheName := enum.CacheName(srv.HostName)
if srv.Status == "ONLINE" {
localStates.SetCache(cacheName, peer.IsAvailable{IsAvailable: true})
continue
}
if srv.Status == "OFFLINE" {
localStates.SetCache(cacheName, peer.IsAvailable{IsAvailable: false})
continue
}
// seed states with available = false until our polling cycle picks up a result
if _, exists := localStates.Get().Caches[cacheName]; !exists {
localStates.SetCache(cacheName, peer.IsAvailable{IsAvailable: false})
}
url := monitorConfig.Profile[srv.Profile].Parameters.HealthPollingURL
r := strings.NewReplacer(
"${hostname}", srv.FQDN,
"${interface_name}", srv.InterfaceName,
"application=system", "application=plugin.remap",
"application=", "application=plugin.remap",
)
url = r.Replace(url)
healthUrls[srv.HostName] = url
r = strings.NewReplacer("application=plugin.remap", "application=")
url = r.Replace(url)
statUrls[srv.HostName] = url
}
for _, srv := range monitorConfig.TrafficMonitor {
if srv.HostName == staticAppData.Hostname {
continue
}
if srv.Status != "ONLINE" {
continue
}
// TODO: the URL should be config driven. -jse
url := fmt.Sprintf("http://%s:%d/publish/CrStates?raw", srv.IP, srv.Port)
peerUrls[srv.HostName] = url
}
statUrlSubscriber <- poller.HttpPollerConfig{Urls: statUrls, Interval: cfg.CacheStatPollingInterval}
healthUrlSubscriber <- poller.HttpPollerConfig{Urls: healthUrls, Interval: cfg.CacheHealthPollingInterval}
peerUrlSubscriber <- poller.HttpPollerConfig{Urls: peerUrls, Interval: cfg.PeerPollingInterval}
for cacheName := range localStates.GetCaches() {
if _, exists := monitorConfig.TrafficServer[string(cacheName)]; !exists {
log.Warnf("Removing %s from localStates", cacheName)
localStates.DeleteCache(cacheName)
}
}
// TODO because there are multiple writers to localStates.DeliveryService, there is a race condition, where MonitorConfig (this func) and HealthResultManager could write at the same time, and the HealthResultManager could overwrite a delivery service addition or deletion here. Probably the simplest and most performant fix would be a lock-free algorithm using atomic compare-and-swaps.
for _, ds := range monitorConfig.DeliveryService {
// since caches default to unavailable, also default DS false
if _, exists := localStates.Get().Deliveryservice[enum.DeliveryServiceName(ds.XMLID)]; !exists {
localStates.SetDeliveryService(enum.DeliveryServiceName(ds.XMLID), peer.Deliveryservice{IsAvailable: false, DisabledLocations: []enum.CacheName{}}) // important to initialize DisabledLocations, so JSON is `[]` not `null`
}
}
for ds, _ := range localStates.Get().Deliveryservice {
if _, exists := monitorConfig.DeliveryService[string(ds)]; !exists {
localStates.DeleteDeliveryService(ds)
}
}
}
}
}