Example #1
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
}
Example #2
0
func TestLoadNonExistingTempate(t *testing.T) {

	path := "does_not_exist_template.cfg"
	collection := types.NewMasterDetailsCollection()

	_, err := RenderTemplate(path, &collection)

	if err == nil {
		t.Error("Template doesn't exist - this should error")
	}
}
Example #3
0
func TestLoadTempate(t *testing.T) {

	path := "../../build/configs/redis-haproxy/haproxy_template.cfg"
	collection := types.NewMasterDetailsCollection()
	collection.AddOrReplace(&types.MasterDetails{Name: "one", Ip: "10.0.0.1", Port: 2345, ExternalPort: 5432})
	collection.AddOrReplace(&types.MasterDetails{Name: "two", Ip: "10.0.1.1", Port: 5432, ExternalPort: 2345})

	renderedTemplate, err := RenderTemplate(path, &collection)

	if err != nil {
		t.Error("Error rendering test file")
	}

	fmt.Printf("%s", renderedTemplate)
}
func NewHAProxyFlipper(configuration *configuration.ConfigurationManager) *HAProxyFlipperClient {
	state := types.NewMasterDetailsCollection()
	return &HAProxyFlipperClient{configurationManager: configuration, lock: &sync.Mutex{}, state: &state}
}