func initConnPools() { cfg := g.Config() judgeInstances := nset.NewStringSet() for _, instance := range cfg.Judge.Cluster { judgeInstances.Add(instance) } JudgeConnPools = cpool.CreateSafeRpcConnPools(cfg.Judge.MaxConns, cfg.Judge.MaxIdle, cfg.Judge.ConnTimeout, cfg.Judge.CallTimeout, judgeInstances.ToSlice()) // graph graphInstances := nset.NewSafeSet() for _, nitem := range cfg.Graph.Cluster2 { for _, addr := range nitem.Addrs { graphInstances.Add(addr) } } GraphConnPools = cpool.CreateSafeRpcConnPools(cfg.Graph.MaxConns, cfg.Graph.MaxIdle, cfg.Graph.ConnTimeout, cfg.Graph.CallTimeout, graphInstances.ToSlice()) // graph migrating if cfg.Graph.Migrating && cfg.Graph.ClusterMigrating != nil { graphMigratingInstances := nset.NewSafeSet() for _, cnode := range cfg.Graph.ClusterMigrating2 { for _, addr := range cnode.Addrs { graphMigratingInstances.Add(addr) } } GraphMigratingConnPools = cpool.CreateSafeRpcConnPools(cfg.Graph.MaxConns, cfg.Graph.MaxIdle, cfg.Graph.ConnTimeout, cfg.Graph.CallTimeout, graphMigratingInstances.ToSlice()) } }
func refreshDesiredAgent() { pageInfo := &models.PageInfo{PageIndex: 1, PageSize: math.MaxInt32} agentList, _ := models.QueryAgentList(models.QueryAgentDto{}, pageInfo) if nil == agentList || 0 == len(agentList) { return } refreshAgentsMap(agentList) hostGroupAgentMap := make(map[int64]*set.SafeSet) usedHostGroupIds := set.NewSafeInt64Set() //获取Agent关联到的HostGroupId for _, agent := range agentList { relAgentGroups, _ := models.QueryRelAgentGroupList(agent.Id) if nil == relAgentGroups || 0 == len(relAgentGroups) { continue } for _, rag := range relAgentGroups { usedHostGroupIds.Add(rag.HostGroupId) nameSet, exists := hostGroupAgentMap[rag.HostGroupId] if !exists { nameSet = set.NewSafeSet() } nameSet.Add(agent.Name) hostGroupAgentMap[rag.HostGroupId] = nameSet } } //获取每个HostGroup下属Endpoint endpointList, _ := models.QueryEndpointList(models.QueryEndpointDto{}, pageInfo) if nil == endpointList || 0 == len(endpointList) { return } for _, hostGroupId := range usedHostGroupIds.Slice() { relEndpointGroupList, _ := models.QueryRelEndpointGroupList(models.QueryRelEndpointGroupDto{HostGroupId: hostGroupId}, pageInfo) if nil == relEndpointGroupList || 0 == len(relEndpointGroupList) { continue } for _, reg := range relEndpointGroupList { if "fixed" == reg.RelType && "hostname" == reg.PropName { HostAgents.Put(reg.PropValue, hostGroupAgentMap[hostGroupId].ToSlice()) } else { pattern := regexp.MustCompile(reg.PropValue) for _, endpoint := range endpointList { if "hostname" == reg.PropName { if pattern.MatchString(endpoint.Hostname) { HostAgents.Put(endpoint.Hostname, hostGroupAgentMap[hostGroupId].ToSlice()) } } else if "ip" == reg.PropValue { if pattern.MatchString(endpoint.Ip) { HostAgents.Put(endpoint.Hostname, hostGroupAgentMap[hostGroupId].ToSlice()) } } } } } } }
// internal functions func initConnPools() { cfg := g.Config() // TODO 为了得到Slice,这里做的太复杂了 graphInstances := nset.NewSafeSet() for _, address := range cfg.Graph.Cluster { graphInstances.Add(address) } GraphConnPools = spool.CreateSafeRpcConnPools(cfg.Graph.MaxConns, cfg.Graph.MaxIdle, cfg.Graph.ConnTimeout, cfg.Graph.CallTimeout, graphInstances.ToSlice()) }
func (this *HostAgentsMap) Put(hostname string, agentNames []string) { this.Lock() defer this.Unlock() has, exists := this.M[hostname] if !exists { has = &HostAgentSet{Timestamp: time.Now().Unix(), AgentNameSet: set.NewSafeSet()} } for _, name := range agentNames { has.AgentNameSet.Add(name) } this.M[hostname] = has }