Exemplo n.º 1
0
// Get the relative nodes
func (ct *ClusterTopology) GetRelatives() (nodes []*ClusterTopologyNode) {
	nodemap := make(map[string]*ClusterTopologyNode, 0)
	nodes = make([]*ClusterTopologyNode, 0)
	mux.RLock()
	defer mux.RUnlock()
	for _, nd := range ct.Nodes {
		if util.ContainsString(currentNode.Twins, nd.Node.Name) || util.ContainsString(currentNode.Stepbrothers, nd.Node.Name) {
			if Active == nd.Node.State {
				nodemap[nd.Node.Name] = nd
			}
		}
	}
	for _, nd := range nodemap {
		nodes = append(nodes, nd)
	}
	return nodes
}
Exemplo n.º 2
0
func (srv *Server) registerServer() {
	// update topology
	if len(srv.config.Topology.Nodes) > 0 {
		// connect first node
		for _, node := range srv.config.Topology.Nodes {
			if node.Node.Name != srv.config.ServerNode.Node.Name {
				if topology, err := srv.outcmdproc.Caller.GetTopology(srv.config.ServerNode.Node.Name, node.Node); err == nil {
					srv.config.Topology.Merge(topology)
					break
				}
			}
		}
		topologies := make([]*cluster.ClusterTopology, 0)
		failedNodes := make([]*cluster.ClusterTopologyNode, 0)
		for _, node := range srv.config.Topology.Nodes {
			if node.Node.Name != srv.config.ServerNode.Node.Name {
				if util.ContainsString(srv.config.ServerNode.Stepbrothers, node.Node.Name) && util.ContainsString(srv.config.ServerNode.Twins, node.Node.Name) {
					// register this node as twin and stepbrother
					if topology, err := srv.outcmdproc.Caller.RegisterTwinAndStepbrother(srv.config.ServerNode, node.Node); err == nil && topology != nil {
						log.Printf("Registration was successful on twin and stepbrother node %s\r\n", node.Node.Name)
						topologies = append(topologies, topology)
					} else {
						log.Printf("Registration failed on twin and stepbrother node %s\r\n", node.Node.Name)
						failedNodes = append(failedNodes, node)
					}
				} else if util.ContainsString(srv.config.ServerNode.Stepbrothers, node.Node.Name) {
					// register this node on a stepbrother node: the current node became the twin of the stepbrother node
					if topology, err := srv.outcmdproc.Caller.RegisterTwin(srv.config.ServerNode, node.Node); err == nil && topology != nil {
						log.Printf("Registration was successful on stepbrother node %s\r\n", node.Node.Name)
						topologies = append(topologies, topology)
					} else {
						log.Printf("Registration failed on stepbrother node %s\r\n", node.Node.Name)
						failedNodes = append(failedNodes, node)
					}
				} else if util.ContainsString(srv.config.ServerNode.Twins, node.Node.Name) {
					// register this node as a twin node: the node became the stepbrother of the current node
					if topology, err := srv.outcmdproc.Caller.RegisterStepbrother(srv.config.ServerNode, node.Node); err == nil && topology != nil {
						log.Printf("Registration was successful on twin node %s\r\n", node.Node.Name)
						topologies = append(topologies, topology)
					} else {
						log.Printf("Registration failed on twin node %s\r\n", node.Node.Name)
						failedNodes = append(failedNodes, node)
					}
				} else {
					// register node on the cluster
					if topology, err := srv.outcmdproc.Caller.RegisterNode(srv.config.ServerNode, node.Node); err == nil && topology != nil {
						log.Printf("Registration was successful on node %s\r\n", node.Node.Name)
						topologies = append(topologies, topology)
					} else {
						log.Printf("Registration failed on node %s\r\n", node.Node.Name)
						failedNodes = append(failedNodes, node)
					}
				}
			}
		}
		// remove failed nodes
		for _, node := range failedNodes {
			srv.config.Topology.RemoveNode(node.Node.Name)
		}
		// merge
		for _, topology := range topologies {
			srv.config.Topology.Merge(topology)
		}
	}
	srv.config.WriteTmp()
}