Search in sources :

Example 1 with LearnerType

use of org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType in project zookeeper by apache.

the class QuorumPeerConfig method setupPeerType.

private void setupPeerType() {
    // Warn about inconsistent peer type
    LearnerType roleByServersList = quorumVerifier.getObservingMembers().containsKey(serverId) ? LearnerType.OBSERVER : LearnerType.PARTICIPANT;
    if (roleByServersList != peerType) {
        LOG.warn("Peer type from servers list (" + roleByServersList + ") doesn't match peerType (" + peerType + "). Defaulting to servers list.");
        peerType = roleByServersList;
    }
}
Also used : LearnerType(org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType)

Example 2 with LearnerType

use of org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType in project coprhd-controller by CoprHD.

the class SpringQuorumPeerConfig method createQuorumServer.

/**
 * This logic is same as ZK 3.4.6 except splitting values with "," instead of ":"
 */
private void createQuorumServer(String key, String value) throws ConfigException {
    int dot = key.indexOf('.');
    long sid = Long.parseLong(key.substring(dot + 1));
    String[] parts = value.split(",");
    if ((parts.length != 2) && (parts.length != 3) && (parts.length != 4)) {
        log.error(value + " does not have the form host,port or host,port,port " + " or host,port,port,type");
    }
    InetSocketAddress addr = new InetSocketAddress(parts[0], Integer.parseInt(parts[1]));
    if (parts.length == 2) {
        servers.put(Long.valueOf(sid), new QuorumServer(sid, addr));
    } else if (parts.length == 3) {
        InetSocketAddress electionAddr = new InetSocketAddress(parts[0], Integer.parseInt(parts[2]));
        servers.put(Long.valueOf(sid), new QuorumServer(sid, addr, electionAddr));
    } else if (parts.length == 4) {
        InetSocketAddress electionAddr = new InetSocketAddress(parts[0], Integer.parseInt(parts[2]));
        LearnerType type = LearnerType.PARTICIPANT;
        if (parts[3].toLowerCase().equals("observer")) {
            type = LearnerType.OBSERVER;
            observers.put(Long.valueOf(sid), new QuorumServer(sid, addr, electionAddr, type));
        } else if (parts[3].toLowerCase().equals("participant")) {
            type = LearnerType.PARTICIPANT;
            servers.put(Long.valueOf(sid), new QuorumServer(sid, addr, electionAddr, type));
        } else {
            throw new ConfigException("Unrecognised peertype: " + value);
        }
    }
}
Also used : LearnerType(org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType) InetSocketAddress(java.net.InetSocketAddress) QuorumServer(org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer)

Aggregations

LearnerType (org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType)2 InetSocketAddress (java.net.InetSocketAddress)1 QuorumServer (org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer)1