Package org.I0Itec.zkclient

Examples of org.I0Itec.zkclient.ZkClient


   * Creates a Kafka topic if needed, or try to increase its partition count to the desired number.
   */
  private void ensureTopicCreated(final String topicName, int numPartitions, int replicationFactor) {
    final int sessionTimeoutMs = 10000;
    final int connectionTimeoutMs = 10000;
    ZkClient zkClient = new ZkClient(zkAddress, sessionTimeoutMs, connectionTimeoutMs, utf8Serializer);

    // The following is basically copy/paste from AdminUtils.createTopic() with
    // createOrUpdateTopicPartitionAssignmentPathInZK(..., update=true)
    Properties topicConfig = new Properties();
    Seq<Object> brokerList = ZkUtils.getSortedBrokerList(zkClient);
    scala.collection.Map<Object, Seq<Object>> replicaAssignment = AdminUtils.assignReplicasToBrokers(brokerList,
        numPartitions, replicationFactor, -1, -1);
    AdminUtils.createOrUpdateTopicPartitionAssignmentPathInZK(zkClient, topicName, replicaAssignment, topicConfig,
        true);
    zkClient.close();

  }
View Full Code Here


    /**
     * See XD-2293. This is used to reproduce Kafka rebalance issues.
     */
    public static void main(String[] args) throws Exception {
        TestKafkaCluster cluster = new TestKafkaCluster();
        ZkClient client = new ZkClient(cluster.getZkConnectString(), 10000, 10000, KafkaMessageBus.utf8Serializer);
        int partitions = 5;
        int replication = 1;
        AdminUtils.createTopic(client, "mytopic", partitions, replication, new Properties());

        Properties props = new Properties();
View Full Code Here

            tryCleanupZookeeper();
        }

        void tryCleanupZookeeper() {
            try {
                ZkClient zk = new ZkClient(m_zkhost);
                String dir = "/consumers/" + m_groupId;
                zk.deleteRecursive(dir);
                dir = "/consumers/" + m_groupId + "-done";
                zk.deleteRecursive(dir);
                zk.close();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
View Full Code Here

  private volatile KeeperState state = KeeperState.SyncConnected;

  public ZkclientZookeeperClient(URL url) {
    super(url);
    client = new ZkClient(url.getBackupAddress());
    client.subscribeStateChanges(new IZkStateListener() {
      public void handleStateChanged(KeeperState state) throws Exception {
        ZkclientZookeeperClient.this.state = state;
        if (state == KeeperState.Disconnected) {
          stateChanged(StateListener.DISCONNECTED);
View Full Code Here

    private ZkClient zkClient;


    public ZkCmdLine(CommandLine cmdline) {
        this.cmdline = cmdline;
        this.zkClient = new ZkClient(cmdline.getOptionValue("zk") + "/" + cmdline.getOptionValue("chroot"),
                zkSessionTimeout, zkConnectionTimeout, new StringSerializer());
    }
View Full Code Here

        String toZnode = fromZnode;
        if (cmdline.hasOption("to-znode")) {
            toZnode = cmdline.getOptionValue("to-znode");
        }

        ZkClient toZkClient = new ZkClient((cmdline.hasOption("to-zk") ? cmdline.getOptionValue("to-zk") : cmdline.getOptionValue("zk")) +
                                           "/" +
                                           (cmdline.hasOption("to-chroot") ? cmdline.getOptionValue("to-chroot") : cmdline.getOptionValue("chroot")),
                zkSessionTimeout, zkConnectionTimeout, new StringSerializer());

        copyZnode(fromZnode, toZnode, this.zkClient, toZkClient);
View Full Code Here

        // use chroot for new root...
        // if (cmdline.hasOption("to-znode")) {
        //     toZnode = cmdline.getOptionValue("to-znode");
        // }

        ZkClient toZkClient = new ZkClient((cmdline.hasOption("to-zk") ? cmdline.getOptionValue("to-zk") : cmdline.getOptionValue("zk")) +
                                           "/" +
                                           (cmdline.hasOption("to-chroot") ? cmdline.getOptionValue("to-chroot") : cmdline.getOptionValue("chroot")),
                zkSessionTimeout, zkConnectionTimeout, new StringSerializer());

        List<String> znodes = flatten(getFamily(fromZnode));
View Full Code Here

    @Before
    public void startKeepers() throws Exception {
        myKeeper = new EmbeddedZookeeper(17023);
        String keeperPort = String.valueOf(myKeeper.getPort());
        System.setProperty("zk.servers", "localhost:" + keeperPort);
        myZkClient = new ZkClient("localhost:" + keeperPort, 10000, 60000, new StringSerializer());
        onAfterZKStart();
    }
View Full Code Here

    private static final int zkConnectionTimeout = Integer.parseInt(System.getProperty("zk.connectionTimeout", "600000"));


    // if the caller wants to close this later, that's their buisness.
    public static ZkClient makeStandardClient() {
        return new ZkClient(zkHosts + "/" + zkChroot, zkSessionTimeout, zkConnectionTimeout, new StringSerializer());
    }
View Full Code Here

        return new ZkClient(zkHosts + "/" + zkChroot, zkSessionTimeout, zkConnectionTimeout, new StringSerializer());
    }

    public static ZkClient makeStandardClient(String zkHosts, boolean useChroot) {
        String chroot = (useChroot) ? "/" + zkChroot : "";
        return new ZkClient(zkHosts + chroot, zkSessionTimeout, zkConnectionTimeout, new StringSerializer());
    }
View Full Code Here

TOP

Related Classes of org.I0Itec.zkclient.ZkClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.