Search in sources :

Example 1 with KafkaZkClient

use of kafka.zk.KafkaZkClient 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 KafkaZkClient

use of kafka.zk.KafkaZkClient 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 KafkaZkClient

use of kafka.zk.KafkaZkClient 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)

Example 4 with KafkaZkClient

use of kafka.zk.KafkaZkClient in project kafka by apache.

the class PartitionCreationBench method setup.

@SuppressWarnings("deprecation")
@Setup(Level.Invocation)
public void setup() {
    if (useTopicIds)
        topicId = Option.apply(Uuid.randomUuid());
    else
        topicId = Option.empty();
    this.scheduler = new KafkaScheduler(1, "scheduler-thread", true);
    this.brokerProperties = KafkaConfig.fromProps(TestUtils.createBrokerConfig(0, TestUtils.MockZkConnect(), true, true, 9092, Option.empty(), Option.empty(), Option.empty(), true, false, 0, false, 0, false, 0, Option.empty(), 1, true, 1, (short) 1));
    this.metrics = new Metrics();
    this.time = Time.SYSTEM;
    this.failureChannel = new LogDirFailureChannel(brokerProperties.logDirs().size());
    final BrokerTopicStats brokerTopicStats = new BrokerTopicStats();
    final List<File> files = JavaConverters.seqAsJavaList(brokerProperties.logDirs()).stream().map(File::new).collect(Collectors.toList());
    CleanerConfig cleanerConfig = CleanerConfig.apply(1, 4 * 1024 * 1024L, 0.9d, 1024 * 1024, 32 * 1024 * 1024, Double.MAX_VALUE, 15 * 1000, true, "MD5");
    ConfigRepository configRepository = new MockConfigRepository();
    this.logManager = new LogManagerBuilder().setLogDirs(files).setInitialOfflineDirs(Collections.emptyList()).setConfigRepository(configRepository).setInitialDefaultConfig(createLogConfig()).setCleanerConfig(cleanerConfig).setRecoveryThreadsPerDataDir(1).setFlushCheckMs(1000L).setFlushRecoveryOffsetCheckpointMs(10000L).setFlushStartOffsetCheckpointMs(10000L).setRetentionCheckMs(1000L).setMaxPidExpirationMs(60000).setInterBrokerProtocolVersion(ApiVersion.latestVersion()).setScheduler(scheduler).setBrokerTopicStats(brokerTopicStats).setLogDirFailureChannel(failureChannel).setTime(Time.SYSTEM).setKeepPartitionMetadataFile(true).build();
    scheduler.startup();
    this.quotaManagers = QuotaFactory.instantiate(this.brokerProperties, this.metrics, this.time, "");
    this.zkClient = new KafkaZkClient(null, false, Time.SYSTEM) {

        @Override
        public Properties getEntityConfigs(String rootEntityType, String sanitizedEntityName) {
            return new Properties();
        }
    };
    this.alterIsrManager = TestUtils.createAlterIsrManager();
    this.replicaManager = new ReplicaManagerBuilder().setConfig(brokerProperties).setMetrics(metrics).setTime(time).setZkClient(zkClient).setScheduler(scheduler).setLogManager(logManager).setQuotaManagers(quotaManagers).setBrokerTopicStats(brokerTopicStats).setMetadataCache(new ZkMetadataCache(this.brokerProperties.brokerId())).setLogDirFailureChannel(failureChannel).setAlterIsrManager(alterIsrManager).build();
    replicaManager.startup();
    replicaManager.checkpointHighWatermarks();
}
Also used : ConfigRepository(kafka.server.metadata.ConfigRepository) MockConfigRepository(kafka.server.metadata.MockConfigRepository) LogManagerBuilder(kafka.server.builders.LogManagerBuilder) ReplicaManagerBuilder(kafka.server.builders.ReplicaManagerBuilder) LogDirFailureChannel(kafka.server.LogDirFailureChannel) CleanerConfig(kafka.log.CleanerConfig) KafkaZkClient(kafka.zk.KafkaZkClient) Properties(java.util.Properties) ZkMetadataCache(kafka.server.metadata.ZkMetadataCache) Metrics(org.apache.kafka.common.metrics.Metrics) BrokerTopicStats(kafka.server.BrokerTopicStats) MockConfigRepository(kafka.server.metadata.MockConfigRepository) KafkaScheduler(kafka.utils.KafkaScheduler) File(java.io.File) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

KafkaZkClient (kafka.zk.KafkaZkClient)4 AdminZkClient (kafka.zk.AdminZkClient)3 Properties (java.util.Properties)2 File (java.io.File)1 Map (java.util.Map)1 CleanerConfig (kafka.log.CleanerConfig)1 BrokerTopicStats (kafka.server.BrokerTopicStats)1 LogDirFailureChannel (kafka.server.LogDirFailureChannel)1 LogManagerBuilder (kafka.server.builders.LogManagerBuilder)1 ReplicaManagerBuilder (kafka.server.builders.ReplicaManagerBuilder)1 ConfigRepository (kafka.server.metadata.ConfigRepository)1 MockConfigRepository (kafka.server.metadata.MockConfigRepository)1 ZkMetadataCache (kafka.server.metadata.ZkMetadataCache)1 KafkaScheduler (kafka.utils.KafkaScheduler)1 Metrics (org.apache.kafka.common.metrics.Metrics)1 Setup (org.openjdk.jmh.annotations.Setup)1