func (s *XLSuite) makeALocalEndPoint(c *C, node *xn.Node) { addr := fmt.Sprintf("127.0.0.1:0") ep, err := xt.NewTcpEndPoint(addr) c.Assert(err, IsNil) c.Assert(ep, Not(IsNil)) ndx, err := node.AddEndPoint(ep) c.Assert(err, IsNil) c.Assert(ndx, Equals, 0) // it's the only one }
// Given contact information for a registry and the name of a cluster, // the client joins the cluster, collects information on the other members, // and terminates when it has info on the entire membership. func NewMemberMaker( node *xn.Node, attrs uint64, regName string, regID *xi.NodeID, regEnd xt.EndPointI, regCK, regSK *rsa.PublicKey, clusterName string, clusterAttrs uint64, clusterID *xi.NodeID, size, epCount uint32, endPoints []xt.EndPointI) ( mm *MemberMaker, err error) { var ( cm *xcl.ClusterMember isAdmin = (attrs & xcl.ATTR_ADMIN) != 0 regPeer *xn.Peer ) // sanity checks on parameter list if node == nil { err = MissingNode } else { if regName == "" || regID == nil || regEnd == nil || regCK == nil { err = MissingServerInfo } if err == nil { // DEBUG fmt.Printf("NemMemberMaker: regEnd is %s\n", regEnd.String()) // END if (attrs & xcl.ATTR_SOLO) == uint64(0) { if clusterName == "" { err = MissingClusterNameOrID if err == nil && size < uint32(1) { // err = ClusterMustHaveTwo err = ClusterMustHaveMember } } if err == nil { // if the client is an admin client epCount applies // to the cluster if epCount < uint32(1) { epCount = uint32(1) } if !isAdmin { // XXX There is some confusion here: we don't require // that all members have the same number of endpoints actualEPCount := uint32(len(endPoints)) if actualEPCount == 0 { err = MemberMustHaveEndPoint } else if epCount > actualEPCount { epCount = actualEPCount } for i := 0; i < int(epCount); i++ { _, err = node.AddEndPoint(endPoints[i]) } } } } } } if err == nil { var ctor xt.ConnectorI var ctors []xt.ConnectorI ctor, err = xt.NewTcpConnector(regEnd) if err == nil { ctors = append(ctors, ctor) regPeer, err = xn.NewPeer(regName, regID, regCK, regSK, nil, ctors) if err == nil { _, err = node.AddPeer(regPeer) } } } if err == nil { cm = &xcl.ClusterMember{ // Attrs gets negotiated ClusterName: clusterName, ClusterAttrs: clusterAttrs, ClusterID: clusterID, ClusterMaxSize: size, EPCount: epCount, // Members added on the fly Members: make([]*xcl.MemberInfo, size), Node: *node, } mm = &MemberMaker{ ProposedAttrs: attrs, DoneCh: make(chan error, 1), RegPeer: regPeer, ClusterMember: *cm, } } return }