Search in sources :

Example 11 with KafkaServer

use of kafka.server.KafkaServer in project nd4j by deeplearning4j.

the class EmbeddedKafkaCluster method startup.

public void startup() {
    for (int i = 0; i < ports.size(); i++) {
        Integer port = ports.get(i);
        File logDir = TestUtils.constructTempDir("kafka-local");
        Properties properties = new Properties();
        properties.putAll(baseProperties);
        properties.setProperty("zookeeper.connect", zkConnection);
        properties.setProperty("broker.id", String.valueOf(i + 1));
        properties.setProperty("host.opName", "localhost");
        properties.setProperty("port", Integer.toString(port));
        properties.setProperty("log.dir", logDir.getAbsolutePath());
        properties.setProperty("num.partitions", String.valueOf(1));
        properties.setProperty("auto.create.topics.enable", String.valueOf(Boolean.TRUE));
        properties.setProperty("log.flush.interval.messages", String.valueOf(1));
        LOG.info("EmbeddedKafkaCluster: local directory: " + logDir.getAbsolutePath());
        KafkaServer broker = startBroker(properties);
        brokers.add(broker);
        logDirs.add(logDir);
    }
}
Also used : KafkaServer(kafka.server.KafkaServer) Properties(java.util.Properties) File(java.io.File)

Example 12 with KafkaServer

use of kafka.server.KafkaServer in project drill by apache.

the class EmbeddedKafkaCluster method getBroker.

private static KafkaServer getBroker(Properties properties) {
    KafkaServer broker = new KafkaServer(new KafkaConfig(properties), Time.SYSTEM, Option.<String>apply("kafka"), false);
    broker.startup();
    return broker;
}
Also used : KafkaServer(kafka.server.KafkaServer) KafkaConfig(kafka.server.KafkaConfig)

Example 13 with KafkaServer

use of kafka.server.KafkaServer in project kafka by apache.

the class IntegrationTestUtils method waitUntilMetadataIsPropagated.

private static void waitUntilMetadataIsPropagated(final List<KafkaServer> servers, final String topic, final int partition, final long timeout) throws InterruptedException {
    final String baseReason = String.format("Metadata for topic=%s partition=%d was not propagated to all brokers within %d ms. ", topic, partition, timeout);
    retryOnExceptionWithTimeout(timeout, () -> {
        final List<KafkaServer> emptyPartitionInfos = new ArrayList<>();
        final List<KafkaServer> invalidBrokerIds = new ArrayList<>();
        for (final KafkaServer server : servers) {
            final MetadataCache metadataCache = server.dataPlaneRequestProcessor().metadataCache();
            final Option<UpdateMetadataPartitionState> partitionInfo = metadataCache.getPartitionInfo(topic, partition);
            if (partitionInfo.isEmpty()) {
                emptyPartitionInfos.add(server);
                continue;
            }
            final UpdateMetadataPartitionState metadataPartitionState = partitionInfo.get();
            if (!Request.isValidBrokerId(metadataPartitionState.leader())) {
                invalidBrokerIds.add(server);
            }
        }
        final String reason = baseReason + ". Brokers without partition info: " + emptyPartitionInfos + ". Brokers with invalid broker id for partition leader: " + invalidBrokerIds;
        assertThat(reason, emptyPartitionInfos.isEmpty() && invalidBrokerIds.isEmpty());
    });
}
Also used : KafkaServer(kafka.server.KafkaServer) ArrayList(java.util.ArrayList) MetadataCache(kafka.server.MetadataCache) UpdateMetadataPartitionState(org.apache.kafka.common.message.UpdateMetadataRequestData.UpdateMetadataPartitionState)

Example 14 with KafkaServer

use of kafka.server.KafkaServer in project druid by druid-io.

the class TestKafkaExtractionCluster method setUp.

@Before
public void setUp() throws Exception {
    zkServer = new TestingCluster(1);
    zkServer.start();
    closer.register(() -> {
        zkServer.stop();
    });
    kafkaServer = new KafkaServer(getBrokerProperties(), Time.SYSTEM, Some.apply(StringUtils.format("TestingBroker[%d]-", 1)), false);
    kafkaServer.startup();
    closer.register(() -> {
        kafkaServer.shutdown();
        kafkaServer.awaitShutdown();
    });
    log.info("---------------------------Started Kafka Broker ---------------------------");
    log.info("---------------------------Publish Messages to topic-----------------------");
    publishRecordsToKafka();
    System.setProperty("druid.extensions.searchCurrentClassloader", "false");
    injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bindConstant().annotatedWith(Names.named("serviceName")).to("test");
            binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
            binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(-1);
        }
    }, // These injections fail under IntelliJ but are required for maven
    new NamespaceExtractionModule(), new KafkaExtractionNamespaceModule()));
    mapper = injector.getInstance(ObjectMapper.class);
    log.info("--------------------------- placed default item via producer ---------------------------");
    final Map<String, String> consumerProperties = getConsumerProperties();
    final KafkaLookupExtractorFactory kafkaLookupExtractorFactory = new KafkaLookupExtractorFactory(null, TOPIC_NAME, consumerProperties);
    factory = (KafkaLookupExtractorFactory) mapper.readValue(mapper.writeValueAsString(kafkaLookupExtractorFactory), LookupExtractorFactory.class);
    Assert.assertEquals(kafkaLookupExtractorFactory.getKafkaTopic(), factory.getKafkaTopic());
    Assert.assertEquals(kafkaLookupExtractorFactory.getKafkaProperties(), factory.getKafkaProperties());
    factory.start();
    closer.register(() -> factory.close());
    log.info("--------------------------- started rename manager ---------------------------");
}
Also used : KafkaServer(kafka.server.KafkaServer) NamespaceExtractionModule(org.apache.druid.server.lookup.namespace.NamespaceExtractionModule) Binder(com.google.inject.Binder) TestingCluster(org.apache.curator.test.TestingCluster) Module(com.google.inject.Module) NamespaceExtractionModule(org.apache.druid.server.lookup.namespace.NamespaceExtractionModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 15 with KafkaServer

use of kafka.server.KafkaServer in project bagheera by mozilla-metrics.

the class ProducerTest method startServer.

private void startServer() {
    stopServer();
    Properties props = new Properties();
    props.setProperty("hostname", "localhost");
    props.setProperty("port", String.valueOf(KAFKA_BROKER_PORT));
    props.setProperty("brokerid", String.valueOf(KAFKA_BROKER_ID));
    props.setProperty("log.dir", KAFKA_DIR);
    props.setProperty("enable.zookeeper", "false");
    // flush every message.
    props.setProperty("log.flush.interval", "1");
    // flush every 1ms
    props.setProperty("log.default.flush.scheduler.interval.ms", "1");
    server = new KafkaServer(new KafkaConfig(props));
    server.startup();
}
Also used : KafkaServer(kafka.server.KafkaServer) Properties(java.util.Properties) KafkaConfig(kafka.server.KafkaConfig)

Aggregations

KafkaServer (kafka.server.KafkaServer)28 Properties (java.util.Properties)16 KafkaConfig (kafka.server.KafkaConfig)13 ArrayList (java.util.ArrayList)9 File (java.io.File)5 KafkaMetricsReporter (kafka.metrics.KafkaMetricsReporter)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Binder (com.google.inject.Binder)2 Module (com.google.inject.Module)2 IOException (java.io.IOException)2 BindException (java.net.BindException)2 URL (java.net.URL)2 KafkaException (kafka.common.KafkaException)2 Time (kafka.utils.Time)2 ZkClient (org.I0Itec.zkclient.ZkClient)2 ApplicationProperties (org.apache.atlas.ApplicationProperties)2 TestingServer (org.apache.curator.test.TestingServer)2 Before (org.junit.Before)2 NamespaceExtractionModule (io.druid.server.lookup.namespace.NamespaceExtractionModule)1 Closeable (java.io.Closeable)1