Java Code Examples for kafka.utils.ZkUtils#createZkClient()

The following examples show how to use kafka.utils.ZkUtils#createZkClient() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestUtils.java    From uReplicator with Apache License 2.0 6 votes vote down vote up
public static ZKHelixAdmin initHelixClustersForWorkerTest(Properties properties, String route1,
    String route2) throws InterruptedException {
  String zkRoot = properties.getProperty("zkServer");
  Thread.sleep(500);
  ZkClient zkClient = ZkUtils.createZkClient(ZkStarter.DEFAULT_ZK_STR, 1000, 1000);
  zkClient.createPersistent("/ureplicator");
  zkClient.close();
  ZKHelixAdmin helixAdmin = new ZKHelixAdmin(zkRoot);
  String deployment = properties.getProperty("federated.deployment.name");
  String managerHelixClusterName = WorkerUtils.getManagerWorkerHelixClusterName(deployment);
  String controllerHelixClusterName = WorkerUtils.getControllerWorkerHelixClusterName(route1);
  if (StringUtils.isNotBlank(route2)) {
    String controllerHelixClusterName2 = WorkerUtils.getControllerWorkerHelixClusterName(route2);
    HelixSetupUtils.setup(controllerHelixClusterName2, zkRoot, "0");
  }

  HelixSetupUtils.setup(managerHelixClusterName, zkRoot, "0");
  HelixSetupUtils.setup(controllerHelixClusterName, zkRoot, "0");

  return helixAdmin;
}
 
Example 2
Source File: ZookeeperUtils.java    From kafka-workers with Apache License 2.0 5 votes vote down vote up
public static void createTopics(String zookeeperUrl, int partitions, int replicas, String... topicNames) throws InterruptedException {

        ZkClient zkClient = ZkUtils.createZkClient(zookeeperUrl, SESSION_TIMEOUT_MS, CONNECTION_TIMEOUT_MS);
        ZkConnection zkConnection = new ZkConnection(zookeeperUrl);
        ZkUtils zkUtils = new ZkUtils(zkClient, zkConnection, false);

        for (String topicName : topicNames) {
            AdminUtils.createTopic(zkUtils, topicName, partitions, replicas, new Properties(), RackAwareMode.Enforced$.MODULE$);
        }

        zkUtils.close();
        zkConnection.close();
        zkClient.close();
    }
 
Example 3
Source File: ZookeeperCheckpointManager.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
public ZookeeperCheckpointManager(CustomizedConsumerConfig config, String groupId) {
  this.commitZkClient = ZkUtils.createZkClient(
      config.getProperty(Constants.COMMIT_ZOOKEEPER_SERVER_CONFIG),
      config.getInt(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, 10000),
      config.getInt(ConsumerConfig.REQUEST_TIMEOUT_MS_CONFIG, 10000));
  this.groupId = groupId;
  this.commitExecutor = Executors.newFixedThreadPool(10);
  KafkaUReplicatorMetricsReporter.get().registerMetric(COMMIT_FAILURE_METER_NAME, commitFailure);
}
 
Example 4
Source File: ZookeeperCheckpointManagerTest.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
@BeforeTest
public void setup() {
  ZkStarter.startLocalZkServer();
  ZkClient zkClient = ZkUtils.createZkClient(ZkStarter.DEFAULT_ZK_STR, 1000, 1000);
  zkClient.createPersistent("/" + TestUtils.SRC_CLUSTER);
  zkClient.close();
  KafkaUReplicatorMetricsReporter
      .init(new MetricsReporterConf("dca1", new ArrayList<>(), "localhost", null, null));

  for (int i = 0; i < 50; i++) {
    offsetCommitMap
        .put(new TopicPartition(TEST_TOPIC_PREFIX + String.valueOf(i / 10), i % 10), i * 10l);
  }
}