use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer 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);
}
}
}
use of org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer in project coprhd-controller by CoprHD.
the class SpringQuorumPeerConfigTest method testInitWithCustomizedSeperator.
@Test
public void testInitWithCustomizedSeperator() throws Exception {
springQuorumPeerConfig.setProperties(properties);
springQuorumPeerConfig.init();
assertTrue(springQuorumPeerConfig.getServers().size() == 3);
QuorumServer server1 = springQuorumPeerConfig.getServers().get(new Long(1));
assertTrue(server1.addr.toString().equals("/192.168.1.1:2888"));
assertTrue(server1.electionAddr.toString().equals("/192.168.1.1:3888"));
assertTrue(server1.type == LearnerType.PARTICIPANT);
QuorumServer server2 = springQuorumPeerConfig.getServers().get(new Long(2));
assertTrue(server2.addr.toString().equals("hostname:2888"));
assertTrue(server2.electionAddr.toString().equals("hostname:3888"));
assertTrue(server2.type == LearnerType.PARTICIPANT);
QuorumServer server3 = springQuorumPeerConfig.getServers().get(new Long(3));
assertTrue(server3.addr.toString().equals("/fe80:0:0:0:81fe:4fd:95b1:8bbf:2888"));
assertTrue(server3.electionAddr.toString().equals("/fe80:0:0:0:81fe:4fd:95b1:8bbf:3888"));
assertTrue(server3.type == LearnerType.PARTICIPANT);
}
Aggregations