Esempio n. 1
0
func NewMonitor(sentinel types.Sentinel, manager Manager, redisConnection redis.RedisConnection) (*Monitor, error) {

	uri := sentinel.GetLocation()

	channel := make(chan redis.RedisPubSubReply)
	pubSubClient, err := redis.NewPubSubClient(uri, channel, redisConnection)

	if err != nil {
		return nil, err
	}

	client, err := redis.NewSentinelClient(sentinel, redisConnection)

	if err != nil {
		return nil, err
	}

	monitor := &Monitor{pubSubClient: pubSubClient,
		client:          client,
		channel:         channel,
		manager:         manager,
		sentinel:        sentinel,
		redisConnection: redisConnection}
	return monitor, nil
}
Esempio n. 2
0
func (m *SentinelManager) getTopology(stateChannel chan types.MasterDetailsCollection) {

	topology := types.NewMasterDetailsCollection()
	configuration := m.configurationManager.GetCurrentConfiguration()

	for _, sentinel := range configuration.Sentinels {
		client, err := redis.NewSentinelClient(sentinel, m.redisConnection)

		if err != nil {
			logger.Info.Printf("Error starting sentinel (%s) client : %s", sentinel.GetLocation(), err.Error())
			continue
		}
		defer client.Close()

		for _, clusterDetails := range configuration.Clusters {

			details, err := client.DiscoverMasterForCluster(clusterDetails.Name)

			if err != nil {
				continue
			}

			details.ExternalPort = clusterDetails.ExternalPort
			// TODO : last one wins?
			topology.AddOrReplace(details)
		}
	}
	stateChannel <- topology
}