Example usage for org.apache.zookeeper.server.quorum.flexible QuorumVerifier getAllMembers

List of usage examples for org.apache.zookeeper.server.quorum.flexible QuorumVerifier getAllMembers

Introduction

In this page you can find the example usage for org.apache.zookeeper.server.quorum.flexible QuorumVerifier getAllMembers.

Prototype

Map<Long, QuorumServer> getAllMembers();

Source Link

Usage

From source file:org.apache.curator.framework.imps.EnsembleTracker.java

License:Apache License

@VisibleForTesting
public static String configToConnectionString(QuorumVerifier data) throws Exception {
    StringBuilder sb = new StringBuilder();
    for (QuorumPeer.QuorumServer server : data.getAllMembers().values()) {
        if (server.clientAddr == null) {
            // Invalid client address configuration in zoo.cfg
            continue;
        }/* w  w  w.  ja v  a2 s  .  c  om*/
        if (sb.length() != 0) {
            sb.append(",");
        }
        String hostAddress;
        if (server.clientAddr.getAddress().isAnyLocalAddress()) {
            hostAddress = server.addr.getAddress().getHostAddress();
        } else {
            hostAddress = server.clientAddr.getAddress().getHostAddress();
        }
        sb.append(hostAddress).append(":").append(server.clientAddr.getPort());
    }

    return sb.toString();
}

From source file:org.apache.curator.framework.imps.TestReconfiguration.java

License:Apache License

@Test(enabled = false) // it's what this test is inteded to do and it keeps failing - disable for now
public void testNewMembers() throws Exception {
    cluster.close();/*from   w  w w  .j a  v  a  2 s.c  o m*/
    cluster = null;

    TestingCluster smallCluster = null;
    TestingCluster localCluster = new TestingCluster(5);
    try {
        List<TestingZooKeeperServer> servers = localCluster.getServers();
        List<InstanceSpec> smallClusterInstances = Lists.newArrayList();
        for (int i = 0; i < 3; ++i) // only start 3 of the 5
        {
            TestingZooKeeperServer server = servers.get(i);
            server.start();
            smallClusterInstances.add(server.getInstanceSpec());
        }

        smallCluster = new TestingCluster(smallClusterInstances);
        try (CuratorFramework client = newClient(smallCluster.getConnectString())) {
            client.start();

            QuorumVerifier oldConfig = toQuorumVerifier(client.getConfig().forEnsemble());
            Assert.assertEquals(oldConfig.getAllMembers().size(), 5);
            assertConfig(oldConfig, localCluster.getInstances());

            CountDownLatch latch = setChangeWaiter(client);

            client.reconfig().withNewMembers(toReconfigSpec(smallClusterInstances)).forEnsemble();

            Assert.assertTrue(timing.awaitLatch(latch));
            byte[] newConfigData = client.getConfig().forEnsemble();
            QuorumVerifier newConfig = toQuorumVerifier(newConfigData);
            Assert.assertEquals(newConfig.getAllMembers().size(), 3);
            assertConfig(newConfig, smallClusterInstances);
            Assert.assertEquals(EnsembleTracker.configToConnectionString(newConfig),
                    ensembleProvider.getConnectionString());
        }
    } finally {
        CloseableUtils.closeQuietly(smallCluster);
        CloseableUtils.closeQuietly(localCluster);
    }
}

From source file:org.apache.curator.framework.imps.TestReconfiguration.java

License:Apache License

private void assertConfig(QuorumVerifier config, Collection<InstanceSpec> instances) {
    for (InstanceSpec instance : instances) {
        QuorumPeer.QuorumServer quorumServer = config.getAllMembers().get((long) instance.getServerId());
        Assert.assertNotNull(quorumServer,
                String.format("Looking for %s - found %s", instance.getServerId(), config.getAllMembers()));
        Assert.assertEquals(quorumServer.clientAddr.getPort(), instance.getPort());
    }//from  w w w  .  ja va 2  s . c  o m
}