Beispiel #1
0
func (s *Sentinel) GetSentinels(podname string) (sentinels []*Sentinel, err error) {
	conn, err := client.Dial(s.Host, s.Port)
	if err != nil {
		return
	}
	defer conn.ClosePool()
	sinfos, err := conn.SentinelSentinels(podname)
	if err != nil {
		return sentinels, err
	}
	stracker := make(map[string]*Sentinel)
	for _, sent := range sinfos {
		sentinel := Sentinel{Name: sent.Name, Host: sent.IP, Port: sent.Port}
		conn, err := client.Dial(sent.IP, sent.Port)
		if err != nil {
			//log.Printf("Unable to connect to sentinel %s. Error reported as '%s'", sent.Name, err.Error())
			continue
		}
		defer conn.ClosePool()
		sentinel.Connection = conn
		pm, err := sentinel.Connection.SentinelGetMaster(podname)
		if err != nil || pm.Port == 0 {
			//log.Printf("S:GS -> %s said %s had pod %s but it didn't.", s.Name, sentinel.Name, podname)
		} else {
			stracker[sentinel.Name] = &sentinel
		}
	}
	for _, v := range stracker {
		sentinels = append(sentinels, v)
	}
	sentinels = append(sentinels, s)
	return sentinels, nil
}
Beispiel #2
0
func init() {
	client, err := rclient.Dial("127.0.0.1", 6379)
	if err != nil {
		panic(err)
	}
	r = client
}
Beispiel #3
0
func (s *Sentinel) GetPod(podname string) (rp RedisPod, err error) {
	//log.Printf("Sentinel.Getpod called for pod '%s'", podname)
	conn, err := client.Dial(s.Host, s.Port)
	if err != nil {
		return
	}
	mi, err := conn.SentinelMasterInfo(podname)
	if err != nil {
		log.Print("S:GetPod failed to get master info. Err:", err)
		return rp, err
	}
	if mi.Port == 0 {
		err = fmt.Errorf("WTF?! Got nothing back from SentinelMasterInfo, not even an error")
		return rp, err
	}
	auth, _ := s.GetPodAuthFromConfig(podname)
	//log.Printf("%s :: s.GetPodAuthFromConfig = '%s'", s.Name, auth)
	rp, err = NewMasterFromMasterInfo(mi, auth)
	if auth == "" {
		err = fmt.Errorf("NO AUTH FOR POD '%s'!", mi.Name)
		return rp, err
	}
	if err != nil {
		log.Print("S:GetPod failed to get pod from master info. Err:", err)
		return rp, err
	}
	if s.PodMap == nil {
		s.PodMap = make(map[string]RedisPod)
	}
	s.PodMap[podname] = rp
	return rp, nil
}
Beispiel #4
0
func (s *Sentinel) MonitorPod(podname, address string, port, quorum int, auth string) (rp RedisPod, err error) {
	// TODO: Update to new common and error packages
	//log.Printf("S:MP-> add called for %s-> %s:%d", podname, address, port)
	conn, err := client.Dial(s.Host, s.Port)
	if err != nil {
		return
	}
	_, err = conn.SentinelMonitor(podname, address, port, quorum)
	if err != nil {
		return rp, err
	}
	if auth > "" {
		conn.SentinelSetString(podname, "auth-pass", auth)
	}
	s.LoadPods()
	rp, err = s.GetPod(podname)
	if err != nil {
		log.Printf("S:MP Error on s.GetPod: %s", err.Error())
	}
	_, err = LoadNodeFromHostPort(address, port, auth)
	if err != nil {
		return rp, fmt.Errorf("S:MP-> unable to load new pod's master node: Error: %s", err)
	}
	//log.Printf("A:S:MP-> Loaded master node")
	return rp, nil
}
Beispiel #5
0
func (s *Sentinel) GetMasters() (master []structures.MasterInfo, err error) {
	conn, err := client.Dial(s.Host, s.Port)
	if err != nil {
		return
	}
	defer conn.ClosePool()
	return conn.SentinelMasters()
}
Beispiel #6
0
func SetRedisConnection(ip string, port int, auth string) (err error) {
	if auth > "" {
		redisconn, err = client.DialWithConfig(&client.DialConfig{Address: fmt.Sprintf("%s:%d", ip, port), Password: auth})
	} else {
		redisconn, err = client.Dial(ip, port)
	}
	return err
}
Beispiel #7
0
func main() {
	rc, _ := client.Dial("127.0.0.1", 30001)
	slots, err := rc.ClusterSlots()
	if err != nil {
		log.Print(err)
	}
	log.Printf("Slots: %+v", slots)
}
func getPodListFromSentinel(ip string) (pods []structures.MasterInfo, conn *client.Redis, err error) {
	conn, err = client.Dial(ip, 26379)
	if err != nil {
		log.Printf("Unable to connect to %s. Error='%v'", ip, err)
		return
	}
	pods, err = conn.SentinelMasters()
	return
}
Beispiel #9
0
func (s *Sentinel) DoFailover(podname string) (ok bool, err error) {
	// Q: Move error handling/reporting to constellation?
	conn, err := client.Dial(s.Host, s.Port)
	if err != nil {
		return
	}
	didFailover, err := conn.SentinelFailover(podname)
	return didFailover, err
}
Beispiel #10
0
func (s *Sentinel) GetSlaves(podname string) (slaves []structures.SlaveInfo, err error) {
	// TODO: Bubble errors to out custom error package
	// See DoFailover for an example
	conn, err := client.Dial(s.Host, s.Port)
	if err != nil {
		return
	}
	defer conn.ClosePool()
	return conn.SentinelSlaves(podname)
}
Beispiel #11
0
func (s *Sentinel) ResetPod(podname string) {
	conn, err := client.Dial(s.Host, s.Port)
	if err != nil {
		return
	}
	defer conn.ClosePool()
	err = conn.SentinelReset(podname)
	if err != nil {
		log.Print("Error on reset call for " + podname + " Err=" + err.Error())
	}
}
Beispiel #12
0
func (s *Sentinel) GetMaster(podname string) (master structures.MasterAddress, err error) {
	if s.Connection == nil {
		log.Fatal("s.Connection is nil, connection not initialzed!")
	}
	conn, err := client.Dial(s.Host, s.Port)
	if err != nil {
		return
	}
	master, err = conn.SentinelGetMaster(podname)
	// TODO: THis needs changed to our custom errors package
	return
}
func (s *Sentinel) RemovePod(podname string) (ok bool, err error) {
	conn, err := client.Dial(s.Host, s.Port)
	if err != nil {
		return
	}
	_, err = conn.SentinelRemove(podname)
	if err != nil {
		// convert to custom errors package
		return false, err
	}
	return true, err
}
Beispiel #14
0
// AddNodeHTMLProcessor is the target for the AddNode form's action
func AddNodeHTMLProcessor(c web.C, w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	// initially this will require a node to already be available on the network
	// will also need to add auth for node. Free nodes' auth string common
	// among the nodes on bootup, but then changed to a constellation-specific
	// one. This will help ensure only the constellation which manages the
	// instance can do so
	//
	// Once I've got a Redis Anywhere API built/figured out it will call that
	// to provision the node then add it into this system
	nodename := c.URLParams["nodeName"]
	node := NodeMaster.GetNode(nodename)
	context, err := NewPageContext()
	checkContextError(err, &w)
	context.Title = "Node Node Result"
	context.ViewTemplate = "slave-added"
	context.NodeMaster = NodeMaster
	address := r.FormValue("host")
	portstr := r.FormValue("port")
	port, _ := strconv.Atoi(portstr)
	log.Printf("Name: %s. Address: %s, Port: %d", nodename, address, port)
	_ = node
	type results struct {
		Name     string
		Address  string
		Port     int
		Error    string
		HasError bool
		NodeURL  string
	}
	res := results{Name: nodename, Address: address, Port: port}
	nodeconn, err := client.Dial(address, port)
	if err != nil {
		log.Print("ERR: Dialing node -", err)
		//context.Data = err
		render(w, context)
		return
	}
	defer nodeconn.ClosePool()
	_ = nodeconn
	context.Data = res // wtf, why is this insisting it needs to be a comparison?!
	render(w, context)

}
Beispiel #15
0
func (s *Sentinel) GetConnection() (conn *client.Redis, err error) {
	conn, err = client.Dial(s.Host, s.Port)
	return
}