Search in sources :

Example 36 with ZkUtils

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

the class AtlasTopicCreatorTest method shouldNotCreateTopicIfItAlreadyExists.

@Test
public void shouldNotCreateTopicIfItAlreadyExists() {
    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);
    final boolean[] topicExistsCalled = new boolean[] { false };
    final boolean[] createTopicCalled = new boolean[] { false };
    AtlasTopicCreator atlasTopicCreator = new AtlasTopicCreator() {

        @Override
        protected boolean ifTopicExists(String topicName, ZkUtils zkUtils) {
            topicExistsCalled[0] = true;
            return true;
        }

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

        @Override
        protected void createTopic(Configuration atlasProperties, String topicName, ZkUtils zkUtils) {
            createTopicCalled[0] = true;
        }
    };
    atlasTopicCreator.createAtlasTopic(configuration, "ATLAS_HOOK");
    assertTrue(topicExistsCalled[0]);
    assertFalse(createTopicCalled[0]);
}
Also used : Configuration(org.apache.commons.configuration.Configuration) ZkUtils(kafka.utils.ZkUtils) Test(org.testng.annotations.Test)

Example 37 with ZkUtils

use of kafka.utils.ZkUtils 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 38 with ZkUtils

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

the class KafkaTestEnvironmentImpl method getLeaderToShutDown.

@Override
public int getLeaderToShutDown(String topic) throws Exception {
    ZkUtils zkUtils = getZkUtils();
    try {
        PartitionMetadata firstPart = null;
        do {
            if (firstPart != null) {
                LOG.info("Unable to find leader. error code {}", firstPart.errorCode());
                // not the first try. Sleep a bit
                Thread.sleep(150);
            }
            Seq<PartitionMetadata> partitionMetadata = AdminUtils.fetchTopicMetadataFromZk(topic, zkUtils).partitionsMetadata();
            firstPart = partitionMetadata.head();
        } while (firstPart.errorCode() != 0);
        return firstPart.leader().get().id();
    } finally {
        zkUtils.close();
    }
}
Also used : PartitionMetadata(kafka.api.PartitionMetadata) ZkUtils(kafka.utils.ZkUtils)

Example 39 with ZkUtils

use of kafka.utils.ZkUtils 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)

Example 40 with ZkUtils

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

the class KafkaTestInstanceRule method createTopic.

/**
 * Utility method to provide additional unique topics if they are required.
 * @param topicName - The Kafka topic to create.
 */
public void createTopic(final String topicName) {
    // Setup Kafka.
    ZkUtils zkUtils = null;
    try {
        logger.info("Creating Kafka Topic: '{}'", topicName);
        zkUtils = ZkUtils.apply(new ZkClient(kafkaInstance.getZookeeperConnect(), 30000, 30000, ZKStringSerializer$.MODULE$), false);
        AdminUtils.createTopic(zkUtils, topicName, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);
    } finally {
        if (zkUtils != null) {
            zkUtils.close();
        }
    }
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) ZkUtils(kafka.utils.ZkUtils) Properties(java.util.Properties)

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