Ejemplo n.º 1
0
Archivo: ipc.go Proyecto: robyoung/serf
func (i *AgentIPC) handleMembers(client *IPCClient, seq uint64) error {
	serf := i.agent.Serf()
	raw := serf.Members()

	members := make([]Member, 0, len(raw))
	for _, m := range raw {
		sm := Member{
			Name:        m.Name,
			Addr:        m.Addr,
			Port:        m.Port,
			Role:        m.Role,
			Status:      m.Status.String(),
			ProtocolMin: m.ProtocolMin,
			ProtocolMax: m.ProtocolMax,
			ProtocolCur: m.ProtocolCur,
			DelegateMin: m.DelegateMin,
			DelegateMax: m.DelegateMax,
			DelegateCur: m.DelegateCur,
		}
		members = append(members, sm)
	}

	header := responseHeader{
		Seq:   seq,
		Error: "",
	}
	resp := membersResponse{
		Members: members,
	}
	return client.Send(&header, &resp)
}
Ejemplo n.º 2
0
Archivo: ipc.go Proyecto: paha/serf
func (i *AgentIPC) handleMembers(client *IPCClient, command string, seq uint64) error {
	serf := i.agent.Serf()
	raw := serf.Members()
	members := make([]Member, 0, len(raw))

	if command == membersFilteredCommand {
		var req membersFilteredRequest
		err := client.dec.Decode(&req)
		if err != nil {
			return fmt.Errorf("decode failed: %v", err)
		}
		raw, err = i.filterMembers(raw, req.Tags, req.Status, req.Name)
		if err != nil {
			return err
		}
	}

	for _, m := range raw {
		sm := Member{
			Name:        m.Name,
			Addr:        m.Addr,
			Port:        m.Port,
			Tags:        m.Tags,
			Status:      m.Status.String(),
			ProtocolMin: m.ProtocolMin,
			ProtocolMax: m.ProtocolMax,
			ProtocolCur: m.ProtocolCur,
			DelegateMin: m.DelegateMin,
			DelegateMax: m.DelegateMax,
			DelegateCur: m.DelegateCur,
		}
		members = append(members, sm)
	}

	header := responseHeader{
		Seq:   seq,
		Error: "",
	}
	resp := membersResponse{
		Members: members,
	}
	return client.Send(&header, &resp)
}