本文整理汇总了Golang中github.com/Comcast/traffic_control/traffic_ops/client.Session.CRConfigRaw方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.CRConfigRaw方法的具体用法?Golang Session.CRConfigRaw怎么用?Golang Session.CRConfigRaw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Comcast/traffic_control/traffic_ops/client.Session
的用法示例。
在下文中一共展示了Session.CRConfigRaw方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getServerTypes
func getServerTypes(to *traffic_ops.Session, cdn string) (map[string]string, error) {
// This is efficient (with getDeliveryServiceServers) because the traffic_ops client caches its result.
// Were that not the case, these functions could be refactored to only call traffic_ops.Session.CRConfigRaw() once.
crcData, err := to.CRConfigRaw(cdn)
if err != nil {
return nil, err
}
type CrConfig struct {
ContentServers map[string]struct {
Type string `json:"type"`
} `json:"contentServers"`
}
var crc CrConfig
if err := json.Unmarshal(crcData, &crc); err != nil {
return nil, err
}
serverTypes := map[string]string{}
for serverName, serverData := range crc.ContentServers {
serverTypes[serverName] = serverData.Type
}
return serverTypes, nil
}
示例2: getDeliveryServiceTypes
func getDeliveryServiceTypes(to *traffic_ops.Session, cdn string) (map[string]deliveryservicestats.DsStatType, error) {
dsTypes := map[string]deliveryservicestats.DsStatType{}
crcData, err := to.CRConfigRaw(cdn)
if err != nil {
return nil, err
}
type CrConfig struct {
DeliveryServices map[string]struct {
Matchsets []struct {
Protocol string `json:"protocol"`
} `json:"matchsets"`
} `json:"deliveryServices"`
}
var crc CrConfig
if err := json.Unmarshal(crcData, &crc); err != nil {
return nil, fmt.Errorf("Error unmarshalling CRConfig: %v", err)
}
for dsName, dsData := range crc.DeliveryServices {
if len(dsData.Matchsets) < 1 {
return nil, fmt.Errorf("CRConfig missing protocol for '%s'", dsName)
}
dsTypeStr := dsData.Matchsets[0].Protocol
dsType := deliveryservicestats.DsStatTypeFromString(dsTypeStr)
if dsType == deliveryservicestats.DsStatTypeInvalid {
return nil, fmt.Errorf("CRConfig unknowng protocol for '%s': '%s'", dsName, dsTypeStr)
}
dsTypes[dsName] = dsType
}
return dsTypes, nil
}
示例3: getServerTypes
// getServerTypes gets the cache type of each ATS Edge+Mid Cache server, for the given CDN, from Traffic Ops.
func getServerTypes(to *traffic_ops.Session, cdn string) (map[string]deliveryservicestats.DsStatCacheType, error) {
serverTypes := map[string]deliveryservicestats.DsStatCacheType{}
crcData, err := to.CRConfigRaw(cdn)
if err != nil {
return nil, err
}
type CrConfig struct {
ContentServers map[string]struct {
Type string `json:"type"`
} `json:"contentServers"`
}
var crc CrConfig
if err := json.Unmarshal(crcData, &crc); err != nil {
return nil, err
}
for server, serverData := range crc.ContentServers {
t := deliveryservicestats.DsStatCacheTypeFromString(serverData.Type)
if t == deliveryservicestats.DsStatCacheTypeInvalid {
return nil, fmt.Errorf("getServerTypes CRConfig unknown type for '%s': '%s'", server, serverData.Type)
}
serverTypes[server] = t
}
return serverTypes, nil
}
示例4: getDeliveryServiceRegexes
// getDeliveryServiceRegexes gets the regexes of each delivery service, for the given CDN, from Traffic Ops.
// Returns a map[deliveryService][]regex.
func getDeliveryServiceRegexes(to *traffic_ops.Session, cdn string) (map[string][]string, error) {
dsRegexes := map[string][]string{}
crcData, err := to.CRConfigRaw(cdn)
if err != nil {
return nil, err
}
type CrConfig struct {
DeliveryServices map[string]struct {
Matchsets []struct {
MatchList []struct {
Regex string `json:"regex"`
} `json:"matchlist"`
} `json:"matchsets"`
} `json:"deliveryServices"`
}
var crc CrConfig
if err := json.Unmarshal(crcData, &crc); err != nil {
return nil, err
}
for dsName, dsData := range crc.DeliveryServices {
if len(dsData.Matchsets) < 1 {
return nil, fmt.Errorf("CRConfig missing regex for '%s'", dsName)
}
for _, matchset := range dsData.Matchsets {
if len(matchset.MatchList) < 1 {
return nil, fmt.Errorf("CRConfig missing Regex for '%s'", dsName)
}
dsRegexes[dsName] = append(dsRegexes[dsName], matchset.MatchList[0].Regex)
}
}
return dsRegexes, nil
}
示例5: getDeliveryServiceServers
// getDeliveryServiceServers gets the servers on each delivery services, for the given CDN, from Traffic Ops.
// Returns a map[deliveryService][]server, and a map[server]deliveryService
func getDeliveryServiceServers(to *traffic_ops.Session, cdn string) (map[string][]string, map[string]string, error) {
dsServers := map[string][]string{}
serverDs := map[string]string{}
crcData, err := to.CRConfigRaw(cdn)
if err != nil {
return nil, nil, err
}
type CrConfig struct {
ContentServers map[string]struct {
DeliveryServices map[string][]string `json:"deliveryServices"`
} `json:"contentServers"`
}
var crc CrConfig
if err := json.Unmarshal(crcData, &crc); err != nil {
return nil, nil, err
}
for serverName, serverData := range crc.ContentServers {
for deliveryServiceName, _ := range serverData.DeliveryServices {
dsServers[deliveryServiceName] = append(dsServers[deliveryServiceName], serverName)
serverDs[serverName] = deliveryServiceName
}
}
return dsServers, serverDs, nil
}
示例6: getServerCachegroups
// getServerCachegroups gets the cachegroup of each ATS Edge+Mid Cache server, for the given CDN, from Traffic Ops.
// Returns a map[server]cachegroup.
func getServerCachegroups(to *traffic_ops.Session, cdn string) (map[string]string, error) {
serverCachegroups := map[string]string{}
crcData, err := to.CRConfigRaw(cdn)
if err != nil {
return nil, err
}
type CrConfig struct {
ContentServers map[string]struct {
CacheGroup string `json:"cacheGroup"`
} `json:"contentServers"`
}
var crc CrConfig
if err := json.Unmarshal(crcData, &crc); err != nil {
return nil, err
}
for server, serverData := range crc.ContentServers {
serverCachegroups[server] = serverData.CacheGroup
}
return serverCachegroups, nil
}
示例7: Start
//.........这里部分代码省略.........
dr := make(chan http_server.DataRequest)
healthHistory := make(map[string][]interface{})
statHistory := make(map[string][]interface{})
var opsConfig handler.OpsConfig
var monitorConfig traffic_ops.TrafficMonitorConfigMap
localStates := peer.Crstates{Caches: make(map[string]peer.IsAvailable), Deliveryservice: make(map[string]peer.Deliveryservice)} // this is the local state as discoverer by this traffic_monitor
peerStates := make(map[string]peer.Crstates) // each peer's last state is saved in this map
combinedStates := peer.Crstates{Caches: make(map[string]peer.IsAvailable), Deliveryservice: make(map[string]peer.Deliveryservice)} // this is the result of combining the localStates and all the peerStates using the var ??
deliveryServiceServers := map[string][]string{}
serverTypes := map[string]string{}
// TODO put stat data in a struct, for brevity
lastHealthEndTimes := map[string]time.Time{}
lastHealthDurations := map[string]time.Duration{}
fetchCount := uint64(0) // note this is the number of individual caches fetched from, not the number of times all the caches were polled.
healthIteration := uint64(0)
errorCount := uint64(0)
events := []Event{}
eventIndex := uint64(0)
for {
select {
case req := <-dr:
defer close(req.C)
var body []byte
var err error
switch req.T {
case http_server.TR_CONFIG:
if toSession != nil && opsConfig.CdnName != "" {
body, err = toSession.CRConfigRaw(opsConfig.CdnName)
}
case http_server.TR_STATE_DERIVED:
body, err = peer.CrStatesMarshall(combinedStates)
case http_server.TR_STATE_SELF:
body, err = peer.CrStatesMarshall(localStates)
case http_server.CACHE_STATS:
// TODO: add support for ?hc=N query param, stats=, wildcard, individual caches
// add pp and date to the json:
/*
pp: "0=[my-ats-edge-cache-1], hc=[1]",
date: "Thu Oct 09 20:28:36 UTC 2014"
*/
params := req.Parameters
hc := 1
if _, exists := params["hc"]; exists {
v, err := strconv.Atoi(params["hc"][0])
if err == nil {
hc = v
}
}
body, err = cache.StatsMarshall(statHistory, hc)
case http_server.DS_STATS:
body = []byte("TODO implement")
case http_server.EVENT_LOG:
body, err = json.Marshal(JSONEvents{Events: events})
case http_server.PEER_STATES:
body = []byte("TODO implement")
case http_server.STAT_SUMMARY:
body = []byte("TODO implement")
case http_server.STATS:
body, err = getStats(staticAppData, cacheHealthPoller.Config.Interval, lastHealthDurations, fetchCount, healthIteration, errorCount)
if err != nil {