Search in sources :

Example 16 with ZkUtils

use of kafka.utils.ZkUtils in project incubator-rya by apache.

the class KafkaTestInstanceRule method deleteTopic.

/**
 * Marks a topic for deletion. You may have to wait some time for the delete to actually complete.
 *
 * @param topicName - The topic that will be deleted. (not null)
 */
public void deleteTopic(final String topicName) {
    ZkUtils zkUtils = null;
    try {
        logger.info("Deleting Kafka Topic: '{}'", topicName);
        zkUtils = ZkUtils.apply(new ZkClient(kafkaInstance.getZookeeperConnect(), 30000, 30000, ZKStringSerializer$.MODULE$), false);
        AdminUtils.deleteTopic(zkUtils, topicName);
    } finally {
        if (zkUtils != null) {
            zkUtils.close();
        }
    }
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) ZkUtils(kafka.utils.ZkUtils)

Example 17 with ZkUtils

use of kafka.utils.ZkUtils in project nakadi by zalando.

the class KafkaTopicRepository method doWithZkUtils.

private void doWithZkUtils(final ZkUtilsAction action) throws Exception {
    ZkUtils zkUtils = null;
    try {
        final String connectionString = zkFactory.get().getZookeeperClient().getCurrentConnectionString();
        zkUtils = ZkUtils.apply(connectionString, zookeeperSettings.getZkSessionTimeoutMs(), zookeeperSettings.getZkConnectionTimeoutMs(), false);
        action.execute(zkUtils);
    } finally {
        if (zkUtils != null) {
            zkUtils.close();
        }
    }
}
Also used : ZkUtils(kafka.utils.ZkUtils)

Example 18 with ZkUtils

use of kafka.utils.ZkUtils in project nakadi by zalando.

the class KafkaTestHelper method createTopic.

public void createTopic(final String topic, final String zkUrl) {
    ZkUtils zkUtils = null;
    try {
        zkUtils = ZkUtils.apply(zkUrl, 30000, 10000, false);
        AdminUtils.createTopic(zkUtils, topic, 1, 1, new Properties(), RackAwareMode.Safe$.MODULE$);
    } finally {
        if (zkUtils != null) {
            zkUtils.close();
        }
    }
}
Also used : ZkUtils(kafka.utils.ZkUtils) Properties(java.util.Properties)

Example 19 with ZkUtils

use of kafka.utils.ZkUtils in project drill by axbaretto.

the class TestKafkaSuit method initKafka.

@BeforeClass
public static void initKafka() throws Exception {
    synchronized (TestKafkaSuit.class) {
        if (initCount.get() == 0) {
            ZookeeperTestUtil.setZookeeperSaslTestConfigProps();
            System.setProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM, ClassLoader.getSystemResource(LOGIN_CONF_RESOURCE_PATHNAME).getFile());
            embeddedKafkaCluster = new EmbeddedKafkaCluster();
            Properties topicProps = new Properties();
            zkClient = new ZkClient(embeddedKafkaCluster.getZkServer().getConnectionString(), SESSION_TIMEOUT, CONN_TIMEOUT, ZKStringSerializer$.MODULE$);
            ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(embeddedKafkaCluster.getZkServer().getConnectionString()), false);
            AdminUtils.createTopic(zkUtils, TestQueryConstants.JSON_TOPIC, 1, 1, topicProps, RackAwareMode.Disabled$.MODULE$);
            org.apache.kafka.common.requests.MetadataResponse.TopicMetadata fetchTopicMetadataFromZk = AdminUtils.fetchTopicMetadataFromZk(TestQueryConstants.JSON_TOPIC, zkUtils);
            logger.info("Topic Metadata: " + fetchTopicMetadataFromZk);
            KafkaMessageGenerator generator = new KafkaMessageGenerator(embeddedKafkaCluster.getKafkaBrokerList(), StringSerializer.class);
            generator.populateJsonMsgIntoKafka(TestQueryConstants.JSON_TOPIC, NUM_JSON_MSG);
        }
        initCount.incrementAndGet();
        runningSuite = true;
    }
    logger.info("Initialized Embedded Zookeeper and Kafka");
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) EmbeddedKafkaCluster(org.apache.drill.exec.store.kafka.cluster.EmbeddedKafkaCluster) ZkUtils(kafka.utils.ZkUtils) Properties(java.util.Properties) ZkConnection(org.I0Itec.zkclient.ZkConnection) BeforeClass(org.junit.BeforeClass)

Example 20 with ZkUtils

use of kafka.utils.ZkUtils in project atlas by apache.

the class AtlasTopicCreatorTest method shouldCloseResources.

@Test
public void shouldCloseResources() {
    Configuration configuration = mock(Configuration.class);
    when(configuration.getBoolean(AtlasTopicCreator.ATLAS_NOTIFICATION_CREATE_TOPICS_KEY, true)).thenReturn(true);
    when(configuration.getString("atlas.authentication.method.kerberos")).thenReturn("false");
    final ZkUtils zookeeperUtils = mock(ZkUtils.class);
    AtlasTopicCreator atlasTopicCreator = new AtlasTopicCreator() {

        @Override
        protected boolean ifTopicExists(String topicName, ZkUtils zkUtils) {
            return false;
        }

        @Override
        protected ZkUtils createZkUtils(Configuration atlasProperties) {
            return zookeeperUtils;
        }

        @Override
        protected void createTopic(Configuration atlasProperties, String topicName, ZkUtils zkUtils) {
        }
    };
    atlasTopicCreator.createAtlasTopic(configuration, "ATLAS_HOOK", "ATLAS_ENTITIES");
    verify(zookeeperUtils, times(1)).close();
}
Also used : Configuration(org.apache.commons.configuration.Configuration) ZkUtils(kafka.utils.ZkUtils) Test(org.testng.annotations.Test)

Aggregations

ZkUtils (kafka.utils.ZkUtils)61 ZkClient (org.I0Itec.zkclient.ZkClient)26 Properties (java.util.Properties)25 ZkConnection (org.I0Itec.zkclient.ZkConnection)22 Test (org.testng.annotations.Test)18 Configuration (org.apache.commons.configuration.Configuration)16 HashMap (java.util.HashMap)8 KafkaConfig (kafka.server.KafkaConfig)8 TestingServer (org.apache.curator.test.TestingServer)8 KafkaServerStartable (kafka.server.KafkaServerStartable)7 ServerSocket (java.net.ServerSocket)6 Test (org.junit.Test)4 File (java.io.File)3 Path (java.nio.file.Path)2 Level (java.util.logging.Level)2 TopicMetadata (kafka.api.TopicMetadata)2 TopicExistsException (kafka.common.TopicExistsException)2 InstanceSpec (org.apache.curator.test.InstanceSpec)2 TopicDescription (org.apache.kafka.clients.admin.TopicDescription)2 Before (org.junit.Before)2