Search in sources :

Example 1 with ZookeeperClientFactoryImpl

use of org.apache.pulsar.zookeeper.ZookeeperClientFactoryImpl in project incubator-pulsar by apache.

the class ZookeeperClientFactoryImplTest method testZKCreationRW.

@Test
void testZKCreationRW() throws Exception {
    ZooKeeperClientFactory zkf = new ZookeeperClientFactoryImpl();
    CompletableFuture<ZooKeeper> zkFuture = zkf.create("127.0.0.1:" + LOCAL_ZOOKEEPER_PORT, SessionType.ReadWrite, (int) ZOOKEEPER_SESSION_TIMEOUT_MILLIS);
    localZkc = zkFuture.get(ZOOKEEPER_SESSION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    assertTrue(localZkc.getState().isConnected());
    assertNotEquals(localZkc.getState(), States.CONNECTEDREADONLY);
    localZkc.close();
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ZookeeperClientFactoryImpl(org.apache.pulsar.zookeeper.ZookeeperClientFactoryImpl) ZooKeeperClientFactory(org.apache.pulsar.zookeeper.ZooKeeperClientFactory) Test(org.testng.annotations.Test)

Example 2 with ZookeeperClientFactoryImpl

use of org.apache.pulsar.zookeeper.ZookeeperClientFactoryImpl in project incubator-pulsar by apache.

the class ZookeeperClientFactoryImplTest method testZKCreationRO.

@Test
void testZKCreationRO() throws Exception {
    ZooKeeperClientFactory zkf = new ZookeeperClientFactoryImpl();
    CompletableFuture<ZooKeeper> zkFuture = zkf.create("127.0.0.1:" + LOCAL_ZOOKEEPER_PORT, SessionType.AllowReadOnly, (int) ZOOKEEPER_SESSION_TIMEOUT_MILLIS);
    localZkc = zkFuture.get(ZOOKEEPER_SESSION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    assertTrue(localZkc.getState().isConnected());
    localZkc.close();
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ZookeeperClientFactoryImpl(org.apache.pulsar.zookeeper.ZookeeperClientFactoryImpl) ZooKeeperClientFactory(org.apache.pulsar.zookeeper.ZooKeeperClientFactory) Test(org.testng.annotations.Test)

Example 3 with ZookeeperClientFactoryImpl

use of org.apache.pulsar.zookeeper.ZookeeperClientFactoryImpl in project incubator-pulsar by apache.

the class PulsarClusterMetadataSetup method main.

public static void main(String[] args) throws Exception {
    Arguments arguments = new Arguments();
    JCommander jcommander = new JCommander();
    try {
        jcommander.addObject(arguments);
        jcommander.parse(args);
        if (arguments.help) {
            jcommander.usage();
            return;
        }
    } catch (Exception e) {
        jcommander.usage();
        throw e;
    }
    log.info("Setting up cluster {} with zk={} global-zk={}", arguments.cluster, arguments.zookeeper, arguments.globalZookeeper);
    // Format BookKeeper metadata
    ServerConfiguration bkConf = new ServerConfiguration();
    bkConf.setLedgerManagerFactoryClass(HierarchicalLedgerManagerFactory.class);
    bkConf.setZkServers(arguments.zookeeper);
    if (!BookKeeperAdmin.format(bkConf, false, /* interactive */
    false)) {
        throw new IOException("Failed to initialize BookKeeper metadata");
    }
    ZooKeeperClientFactory zkfactory = new ZookeeperClientFactoryImpl();
    ZooKeeper localZk = zkfactory.create(arguments.zookeeper, SessionType.ReadWrite, 30000).get();
    ZooKeeper globalZk = zkfactory.create(arguments.globalZookeeper, SessionType.ReadWrite, 30000).get();
    localZk.create("/managed-ledgers", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    localZk.create("/namespace", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    try {
        ZkUtils.createFullPathOptimistic(globalZk, POLICIES_ROOT, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    } catch (NodeExistsException e) {
    // Ignore
    }
    try {
        ZkUtils.createFullPathOptimistic(globalZk, "/admin/clusters", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    } catch (NodeExistsException e) {
    // Ignore
    }
    ClusterData clusterData = new ClusterData(arguments.clusterWebServiceUrl, arguments.clusterWebServiceUrlTls, arguments.clusterBrokerServiceUrl, arguments.clusterBrokerServiceUrlTls);
    byte[] clusterDataJson = ObjectMapperFactory.getThreadLocal().writeValueAsBytes(clusterData);
    globalZk.create("/admin/clusters/" + arguments.cluster, clusterDataJson, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    // Create marker for "global" cluster
    ClusterData globalClusterData = new ClusterData(null, null);
    byte[] globalClusterDataJson = ObjectMapperFactory.getThreadLocal().writeValueAsBytes(globalClusterData);
    try {
        globalZk.create("/admin/clusters/global", globalClusterDataJson, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    } catch (NodeExistsException e) {
    // Ignore
    }
    log.info("Cluster metadata for '{}' setup correctly", arguments.cluster);
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) ZookeeperClientFactoryImpl(org.apache.pulsar.zookeeper.ZookeeperClientFactoryImpl) JCommander(com.beust.jcommander.JCommander) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) IOException(java.io.IOException) IOException(java.io.IOException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) ZooKeeperClientFactory(org.apache.pulsar.zookeeper.ZooKeeperClientFactory)

Example 4 with ZookeeperClientFactoryImpl

use of org.apache.pulsar.zookeeper.ZookeeperClientFactoryImpl in project incubator-pulsar by apache.

the class ZookeeperClientFactoryImplTest method testZKCreationFailure.

@Test
void testZKCreationFailure() throws Exception {
    ZooKeeperClientFactory zkf = new ZookeeperClientFactoryImpl();
    CompletableFuture<ZooKeeper> zkFuture = zkf.create("invalid", SessionType.ReadWrite, (int) ZOOKEEPER_SESSION_TIMEOUT_MILLIS);
    assertTrue(zkFuture.isCompletedExceptionally());
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ZookeeperClientFactoryImpl(org.apache.pulsar.zookeeper.ZookeeperClientFactoryImpl) ZooKeeperClientFactory(org.apache.pulsar.zookeeper.ZooKeeperClientFactory) Test(org.testng.annotations.Test)

Example 5 with ZookeeperClientFactoryImpl

use of org.apache.pulsar.zookeeper.ZookeeperClientFactoryImpl in project incubator-pulsar by apache.

the class LocalZooKeeperConnectionServiceTest method testSimpleZooKeeperConnectionFail.

@Test
void testSimpleZooKeeperConnectionFail() throws Exception {
    LocalZooKeeperConnectionService localZkConnectionService = new LocalZooKeeperConnectionService(new ZookeeperClientFactoryImpl(), "dummy", 1000);
    try {
        localZkConnectionService.start(null);
        fail("should fail");
    } catch (Exception e) {
        assertTrue(e.getMessage().contains("Failed to establish session with local ZK"));
    }
    localZkConnectionService.close();
}
Also used : LocalZooKeeperConnectionService(org.apache.pulsar.zookeeper.LocalZooKeeperConnectionService) ZookeeperClientFactoryImpl(org.apache.pulsar.zookeeper.ZookeeperClientFactoryImpl) Test(org.testng.annotations.Test)

Aggregations

ZookeeperClientFactoryImpl (org.apache.pulsar.zookeeper.ZookeeperClientFactoryImpl)5 ZooKeeperClientFactory (org.apache.pulsar.zookeeper.ZooKeeperClientFactory)4 ZooKeeper (org.apache.zookeeper.ZooKeeper)4 Test (org.testng.annotations.Test)4 JCommander (com.beust.jcommander.JCommander)1 IOException (java.io.IOException)1 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)1 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)1 LocalZooKeeperConnectionService (org.apache.pulsar.zookeeper.LocalZooKeeperConnectionService)1 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)1