Search in sources :

Example 1 with AdminZkClient

use of kafka.zk.AdminZkClient in project apache-kafka-on-k8s by banzaicloud.

the class InternalTopicIntegrationTest method getTopicProperties.

private Properties getTopicProperties(final String changelog) {
    try (KafkaZkClient kafkaZkClient = KafkaZkClient.apply(CLUSTER.zKConnectString(), false, DEFAULT_ZK_SESSION_TIMEOUT_MS, DEFAULT_ZK_CONNECTION_TIMEOUT_MS, Integer.MAX_VALUE, Time.SYSTEM, "testMetricGroup", "testMetricType")) {
        final AdminZkClient adminZkClient = new AdminZkClient(kafkaZkClient);
        final Map<String, Properties> topicConfigs = scala.collection.JavaConversions.mapAsJavaMap(adminZkClient.getAllTopicConfigs());
        for (Map.Entry<String, Properties> topicConfig : topicConfigs.entrySet()) {
            if (topicConfig.getKey().equals(changelog))
                return topicConfig.getValue();
        }
        return new Properties();
    }
}
Also used : AdminZkClient(kafka.zk.AdminZkClient) KafkaZkClient(kafka.zk.KafkaZkClient) Properties(java.util.Properties) Map(java.util.Map)

Example 2 with AdminZkClient

use of kafka.zk.AdminZkClient in project apache-kafka-on-k8s by banzaicloud.

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);
    try (KafkaZkClient kafkaZkClient = createZkClient()) {
        final AdminZkClient adminZkClient = new AdminZkClient(kafkaZkClient);
        adminZkClient.createTopic(topic, partitions, replication, topicConfig, RackAwareMode.Enforced$.MODULE$);
    }
}
Also used : AdminZkClient(kafka.zk.AdminZkClient) KafkaZkClient(kafka.zk.KafkaZkClient)

Example 3 with AdminZkClient

use of kafka.zk.AdminZkClient in project hive by apache.

the class KafkaBrokerResource method before.

/**
 * Override to set up your specific external resource.
 *
 * @throws Throwable if setup fails (which will disable {@code after}
 */
@Override
protected void before() throws Throwable {
    // Start the ZK and the Broker
    LOG.info("init embedded Zookeeper");
    tmpLogDir = Files.createTempDirectory("kafka-log-dir-").toAbsolutePath();
    zkServer = new EmbeddedZookeeper();
    String zkConnect = "127.0.0.1:" + zkServer.port();
    LOG.info("init kafka broker");
    Properties brokerProps = new Properties();
    brokerProps.setProperty("zookeeper.connect", zkConnect);
    brokerProps.setProperty("broker.id", "0");
    brokerProps.setProperty("log.dir", tmpLogDir.toString());
    brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKER_IP_PORT);
    brokerProps.setProperty("offsets.topic.replication.factor", "1");
    brokerProps.setProperty("transaction.state.log.replication.factor", "1");
    brokerProps.setProperty("transaction.state.log.min.isr", "1");
    KafkaConfig config = new KafkaConfig(brokerProps);
    kafkaServer = TestUtils.createServer(config, Time.SYSTEM);
    kafkaServer.startup();
    kafkaServer.zkClient();
    adminZkClient = new AdminZkClient(kafkaServer.zkClient());
    LOG.info("Creating kafka TOPIC [{}]", TOPIC);
    adminZkClient.createTopic(TOPIC, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);
}
Also used : AdminZkClient(kafka.zk.AdminZkClient) EmbeddedZookeeper(kafka.zk.EmbeddedZookeeper) Properties(java.util.Properties) KafkaConfig(kafka.server.KafkaConfig)

Example 4 with AdminZkClient

use of kafka.zk.AdminZkClient in project apache-kafka-on-k8s by banzaicloud.

the class KafkaEmbedded method deleteTopic.

public void deleteTopic(final String topic) {
    log.debug("Deleting topic { name: {} }", topic);
    try (KafkaZkClient kafkaZkClient = createZkClient()) {
        final AdminZkClient adminZkClient = new AdminZkClient(kafkaZkClient);
        adminZkClient.deleteTopic(topic);
        kafkaZkClient.close();
    }
}
Also used : AdminZkClient(kafka.zk.AdminZkClient) KafkaZkClient(kafka.zk.KafkaZkClient)

Aggregations

AdminZkClient (kafka.zk.AdminZkClient)4 KafkaZkClient (kafka.zk.KafkaZkClient)3 Properties (java.util.Properties)2 Map (java.util.Map)1 KafkaConfig (kafka.server.KafkaConfig)1 EmbeddedZookeeper (kafka.zk.EmbeddedZookeeper)1