Search in sources :

Example 1 with ZkClient

use of org.I0Itec.zkclient.ZkClient in project kafka by apache.

the class InternalTopicIntegrationTest method getTopicConfigProperties.

private Properties getTopicConfigProperties(final String changelog) {
    // Note: You must initialize the ZkClient with ZKStringSerializer.  If you don't, then
    // createTopics() will only seem to work (it will return without error).  The topic will exist in
    // only ZooKeeper and will be returned when listing topics, but Kafka itself does not create the
    // topic.
    final ZkClient zkClient = new ZkClient(CLUSTER.zKConnectString(), DEFAULT_ZK_SESSION_TIMEOUT_MS, DEFAULT_ZK_CONNECTION_TIMEOUT_MS, ZKStringSerializer$.MODULE$);
    try {
        final boolean isSecure = false;
        final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(CLUSTER.zKConnectString()), isSecure);
        final Map<String, Properties> topicConfigs = AdminUtils.fetchAllTopicConfigs(zkUtils);
        final Iterator it = topicConfigs.iterator();
        while (it.hasNext()) {
            final Tuple2<String, Properties> topicConfig = (Tuple2<String, Properties>) it.next();
            final String topic = topicConfig._1;
            final Properties prop = topicConfig._2;
            if (topic.equals(changelog)) {
                return prop;
            }
        }
        return new Properties();
    } finally {
        zkClient.close();
    }
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) Tuple2(scala.Tuple2) Iterator(scala.collection.Iterator) ZkUtils(kafka.utils.ZkUtils) Properties(java.util.Properties) ZkConnection(org.I0Itec.zkclient.ZkConnection)

Example 2 with ZkClient

use of org.I0Itec.zkclient.ZkClient in project kafka by apache.

the class KafkaEmbedded method deleteTopic.

public void deleteTopic(final String topic) {
    log.debug("Deleting topic { name: {} }", topic);
    final ZkClient zkClient = new ZkClient(zookeeperConnect(), DEFAULT_ZK_SESSION_TIMEOUT_MS, DEFAULT_ZK_CONNECTION_TIMEOUT_MS, ZKStringSerializer$.MODULE$);
    final boolean isSecure = false;
    final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperConnect()), isSecure);
    AdminUtils.deleteTopic(zkUtils, topic);
    zkClient.close();
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) ZkUtils(kafka.utils.ZkUtils) ZkConnection(org.I0Itec.zkclient.ZkConnection)

Example 3 with ZkClient

use of org.I0Itec.zkclient.ZkClient in project kafka by apache.

the class KafkaEmbedded method createTopic.

/**
     * Create a Kafka topic with the given parameters.
     *
     * @param topic       The name of the topic.
     * @param partitions  The number of partitions for this topic.
     * @param replication The replication factor for (partitions of) this topic.
     * @param topicConfig Additional topic-level configuration settings.
     */
public void createTopic(final String topic, final int partitions, final int replication, final Properties topicConfig) {
    log.debug("Creating topic { name: {}, partitions: {}, replication: {}, config: {} }", topic, partitions, replication, topicConfig);
    // Note: You must initialize the ZkClient with ZKStringSerializer.  If you don't, then
    // createTopic() will only seem to work (it will return without error).  The topic will exist in
    // only ZooKeeper and will be returned when listing topics, but Kafka itself does not create the
    // topic.
    final ZkClient zkClient = new ZkClient(zookeeperConnect(), DEFAULT_ZK_SESSION_TIMEOUT_MS, DEFAULT_ZK_CONNECTION_TIMEOUT_MS, ZKStringSerializer$.MODULE$);
    final boolean isSecure = false;
    final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperConnect()), isSecure);
    AdminUtils.createTopic(zkUtils, topic, partitions, replication, topicConfig, RackAwareMode.Enforced$.MODULE$);
    zkClient.close();
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) ZkUtils(kafka.utils.ZkUtils) ZkConnection(org.I0Itec.zkclient.ZkConnection)

Example 4 with ZkClient

use of org.I0Itec.zkclient.ZkClient in project storm by apache.

the class KafkaUnit method setUp.

public void setUp() throws IOException {
    // setup ZK
    zkServer = new EmbeddedZookeeper();
    String zkConnect = ZK_HOST + ":" + zkServer.port();
    ZkClient zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
    zkUtils = ZkUtils.apply(zkClient, false);
    // setup Broker
    Properties brokerProps = new Properties();
    brokerProps.setProperty("zookeeper.connect", zkConnect);
    brokerProps.setProperty("broker.id", "0");
    brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString());
    brokerProps.setProperty("listeners", String.format("PLAINTEXT://%s:%d", KAFKA_HOST, KAFKA_PORT));
    KafkaConfig config = new KafkaConfig(brokerProps);
    MockTime mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);
    // setup default Producer
    createProducer();
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) EmbeddedZookeeper(kafka.zk.EmbeddedZookeeper) Properties(java.util.Properties) MockTime(kafka.utils.MockTime) KafkaConfig(kafka.server.KafkaConfig)

Example 5 with ZkClient

use of org.I0Itec.zkclient.ZkClient in project databus by linkedin.

the class RemovePaths method main.

/**
   * main
   */
public static void main(String[] args) {
    String pathsToDeleteStr = ExampleUtils.getRequiredStringProperty("paths", LOG);
    String[] pathsToDelete = pathsToDeleteStr.split(",");
    LOG.info("Deleting paths: " + Arrays.toString(pathsToDelete));
    ZkClient zkClient = new ZkClient(ExampleUtils.getRequiredStringProperty("zkServerList", LOG), ExampleUtils.getRequiredIntProperty("sessionTimeoutMillis", LOG), ExampleUtils.getRequiredIntProperty("connectTimeoutMillis", LOG));
    for (String pathToDelete : pathsToDelete) {
        zkClient.deleteRecursive(pathToDelete);
    }
    zkClient.close();
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient)

Aggregations

ZkClient (org.I0Itec.zkclient.ZkClient)28 Properties (java.util.Properties)8 ZkUtils (kafka.utils.ZkUtils)7 ZkConnection (org.I0Itec.zkclient.ZkConnection)6 Before (org.junit.Before)6 File (java.io.File)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 KafkaConfig (kafka.server.KafkaConfig)4 DateTime (org.joda.time.DateTime)3 PinotHelixResourceManager (com.linkedin.pinot.controller.helix.core.PinotHelixResourceManager)2 URL (com.weibo.api.motan.rpc.URL)2 ISE (io.druid.java.util.common.ISE)2 TopicExistsException (kafka.common.TopicExistsException)2 MockTime (kafka.utils.MockTime)2 Time (kafka.utils.Time)2 EmbeddedZookeeper (kafka.zk.EmbeddedZookeeper)2 IDefaultNameSpace (org.I0Itec.zkclient.IDefaultNameSpace)2 ZkServer (org.I0Itec.zkclient.ZkServer)2 TestingServer (org.apache.curator.test.TestingServer)2