Search in sources :

Example 1 with Cluster

use of tezc.core.cluster.Cluster 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 Cluster

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

the class Core method removeCluster.

/**
 * Remove cluster, if running, will be stopped first, than will be deleted,
 * this a non blocking call, it may take a while to stop working gracefully
 * @param name         cluster name
 * @throws IOException on any IO error
 */
public void removeCluster(String name) throws IOException {
    Cluster cluster = clusters.get(name);
    if (cluster == null) {
        throw new RaftException("Cannot find cluster with name : " + name);
    }
    cluster.remove();
}
Also used : RaftException(tezc.base.exception.RaftException) RaftCluster(tezc.core.cluster.RaftCluster) Cluster(tezc.core.cluster.Cluster)

Example 3 with Cluster

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

the class IOWorker method handleConnectReqMsg.

/**
 * Received connect request, pass it to related cluster worker
 * @param conn connection
 * @param req  connect request
 */
public void handleConnectReqMsg(Connection conn, ConnectReq req) {
    pendings.remove(conn);
    conn.unregister();
    Cluster cluster = core.getCluster(req.getClusterName());
    if (cluster != null) {
        core.getIOWorker().sendAddConnectionEvent(conn);
        cluster.sendIncomingConnEvent(conn, req);
    } else {
        logInfo("Cannot find cluster for ", req.getClusterName());
        conn.disconnect(false);
    }
}
Also used : Cluster(tezc.core.cluster.Cluster)

Example 4 with Cluster

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

the class ClusterWorker method eventsDrained.

/**
 * All events are processed
 */
@Override
public void eventsDrained() {
    try {
        for (PeerNode node : readyNodes) {
            node.handleMsgs();
        }
        readyNodes.clear();
        for (Cluster cluster : readyClusters) {
            cluster.flush();
        }
        readyClusters.clear();
    } catch (Exception e) {
        logError(e);
    }
}
Also used : Cluster(tezc.core.cluster.Cluster) PeerNode(tezc.core.node.PeerNode)

Aggregations

Cluster (tezc.core.cluster.Cluster)4 RaftCluster (tezc.core.cluster.RaftCluster)2 RaftException (tezc.base.exception.RaftException)1 PeerNode (tezc.core.node.PeerNode)1 ClusterWorker (tezc.core.worker.clusterworker.ClusterWorker)1