Search in sources :

Example 1 with RaftCluster

use of tezc.core.cluster.RaftCluster in project tezcRaft by tezc.

the class Core method openCluster.

/**
 * Open cluster, if does not exist, a new one will be created
 * @param name         cluster name
 * @param states       state map of the cluster
 * @return             cluster object
 * @throws IOException on any IO error
 */
public RaftCluster openCluster(String name, List<State> states) throws IOException {
    Cluster cluster;
    synchronized (lock) {
        cluster = clusters.get(name);
        if (cluster == null) {
            ClusterWorker worker = getClusterWorker();
            ClusterWorker snapshotWorker = getSnapshotWorker();
            cluster = new Cluster(this, name, workingDir, worker, snapshotWorker, states);
            clusters.put(name, cluster);
        }
    }
    return cluster;
}
Also used : RaftCluster(tezc.core.cluster.RaftCluster) Cluster(tezc.core.cluster.Cluster) ClusterWorker(tezc.core.worker.clusterworker.ClusterWorker)

Example 2 with RaftCluster

use of tezc.core.cluster.RaftCluster in project tezcRaft by tezc.

the class App method start.

public void start(List<State> states, String name) throws IOException {
    TlsConfig tlsConfig = new TlsConfig(null, null, null, null, null, null, null, null, null, null);
    Config config = new Config();
    config.setLogLevel("DEBUG");
    config.setTlsConfig(tlsConfig);
    Tezc tezc = new Tezc("./cluster1/" + name, this, config);
    RaftCluster cluster = tezc.openCluster("cluster1", states);
    if (!cluster.isStarted()) {
        NodeRecord nodeRecord1 = new NodeRecord("node0", "group0");
        nodeRecord1.addTransport(new TransportRecord("tcp", "127.0.0.1", 9090));
        /*NodeRecord nodeRecord2 = new NodeRecord("node1", "group0");
            nodeRecord2.addTransport(new TransportRecord("tcp", "127.0.0.1", 9091));

            NodeRecord nodeRecord3 = new NodeRecord("node2", "group1");
            nodeRecord3.addTransport(new TransportRecord("tcp", "127.0.0.1", 9092));*/
        cluster.setLocal(Integer.parseInt(name));
        cluster.addNode(nodeRecord1);
    // cluster.addNode(nodeRecord2);
    // cluster.addNode(nodeRecord3);
    }
    cluster.run();
}
Also used : NodeRecord(tezc.core.record.NodeRecord) TransportRecord(tezc.core.record.TransportRecord) Config(tezc.core.Config) TlsConfig(tezc.base.transport.TlsConfig) RaftCluster(tezc.core.cluster.RaftCluster) TlsConfig(tezc.base.transport.TlsConfig) Tezc(tezc.Tezc)

Aggregations

RaftCluster (tezc.core.cluster.RaftCluster)2 Tezc (tezc.Tezc)1 TlsConfig (tezc.base.transport.TlsConfig)1 Config (tezc.core.Config)1 Cluster (tezc.core.cluster.Cluster)1 NodeRecord (tezc.core.record.NodeRecord)1 TransportRecord (tezc.core.record.TransportRecord)1 ClusterWorker (tezc.core.worker.clusterworker.ClusterWorker)1