Esempio n. 1
0
        // Creates and returns a configured array of raftnodes using the test cluster
        static internal RaftNode[] ConfigureRaftCluster(int numberOfNodes, SM sm)
        {
            RaftNode[] nodes = new RaftNode[numberOfNodes];

            // Create nodes
            for (uint i = 0; i < numberOfNodes; i++)
            {
                if (sm == SM.Numeral)
                {
                    nodes[i] = new RaftNode(i, new NumeralStateMachine());
                }
                else
                {
                    nodes[i] = new RaftNode(i, new DictionaryStateMachine());
                }
            }

            // Adding them to a cluster and configuring them
            foreach (RaftNode node in nodes)
            {
                var c = new RaftCluster();
                Array.ForEach(nodes, x => c.AddNode(new ObjectRaftConnector(x.NodeId, x)));
                node.Configure(c);
            }

            return(nodes);
        }
        public ClusterService()
        {
            var numberOfNodes = 5;
            var _nodes        = new List <RaftNode>();

            // Create nodes
            for (uint i = 0; i < numberOfNodes; i++)
            {
                var node = new RaftNode(i, new NumeralStateMachine());
                _nodes.Add(node);
            }

            // Adding them to a cluster and configuring them
            foreach (RaftNode node in _nodes)
            {
                var c = new RaftCluster();
                _nodes.ForEach(x => c.AddNode(new ObjectRaftConnector(x.NodeId, x)));
                node.Configure(c);
            }

            this.cluster = _nodes[0].Cluster;

            _nodes.ForEach(node => node.Run());

            this.nodes = _nodes;
        }
Esempio n. 3
0
        // Creates a single-node cluster with a numeral state machine and returns the node
        static internal RaftNode CreateNode()
        {
            RaftNode node = new RaftNode(1, new NumeralStateMachine());
            var      c    = new RaftCluster();

            c.AddNode(new ObjectRaftConnector(node.NodeId, node));
            node.Configure(c);
            return(node);
        }
Esempio n. 4
0
        private static RaftNode StartNode(Configuration conf)
        {
            var id   = conf.CurrentNode.Id;
            var node = new RaftNode(id, new RaftCore.StateMachine.Implementations.NumeralStateMachine());
            var clusterConfiguration = new RaftCluster();

            foreach (var anotherNode in conf.Nodes)
            {
                clusterConfiguration.AddNode(new APIRaftConnector(anotherNode.Id, anotherNode.BaseUrl + "/RaftApi"));
            }
            node.Configure(clusterConfiguration);
            node.Run();
            return(node);
        }