Search in sources :

Example 1 with ZkConnection

use of org.I0Itec.zkclient.ZkConnection 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 ZkConnection

use of org.I0Itec.zkclient.ZkConnection 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 ZkConnection

use of org.I0Itec.zkclient.ZkConnection 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 ZkConnection

use of org.I0Itec.zkclient.ZkConnection in project opennms by OpenNMS.

the class JUnitKafkaServer method getBrokerMetadatas.

private List<BrokerMetadata> getBrokerMetadatas() {
    ZkClient zkClient = new ZkClient(getZookeeperConnectString(), 1000, 1000, ZKStringSerializer$.MODULE$);
    ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(getZookeeperConnectString()), false);
    return JavaConversions.asJavaList(AdminUtils.getBrokerMetadatas(zkUtils, Enforced$.MODULE$, Option.empty()));
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) ZkUtils(kafka.utils.ZkUtils) ZkConnection(org.I0Itec.zkclient.ZkConnection)

Example 5 with ZkConnection

use of org.I0Itec.zkclient.ZkConnection in project ignite by apache.

the class TestKafkaBroker method setupZooKeeper.

/**
     * Sets up ZooKeeper test server.
     *
     * @throws Exception If failed.
     */
private void setupZooKeeper() throws Exception {
    zkServer = new TestingServer(ZK_PORT, true);
    Tuple2<ZkClient, ZkConnection> zkTuple = ZkUtils.createZkClientAndConnection(zkServer.getConnectString(), ZK_SESSION_TIMEOUT, ZK_CONNECTION_TIMEOUT);
    zkUtils = new ZkUtils(zkTuple._1(), zkTuple._2(), false);
}
Also used : TestingServer(org.apache.curator.test.TestingServer) ZkClient(org.I0Itec.zkclient.ZkClient) ZkUtils(kafka.utils.ZkUtils) ZkConnection(org.I0Itec.zkclient.ZkConnection)

Aggregations

ZkClient (org.I0Itec.zkclient.ZkClient)6 ZkConnection (org.I0Itec.zkclient.ZkConnection)6 ZkUtils (kafka.utils.ZkUtils)5 Properties (java.util.Properties)1 ZkNodeExistsException (org.I0Itec.zkclient.exception.ZkNodeExistsException)1 TestingServer (org.apache.curator.test.TestingServer)1 SamzaException (org.apache.samza.SamzaException)1 Before (org.junit.Before)1 Tuple2 (scala.Tuple2)1 Iterator (scala.collection.Iterator)1