当前位置: 首页>>代码示例>>Java>>正文


Java AdminUtils类代码示例

本文整理汇总了Java中kafka.admin.AdminUtils的典型用法代码示例。如果您正苦于以下问题:Java AdminUtils类的具体用法?Java AdminUtils怎么用?Java AdminUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AdminUtils类属于kafka.admin包,在下文中一共展示了AdminUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUpClass

import kafka.admin.AdminUtils; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException {
    // setup Zookeeper
    zkServer = new EmbeddedZookeeper();
    zkConnect = ZKHOST + ":" + zkServer.port();
    zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
    ZkUtils zkUtils = ZkUtils.apply(zkClient, false);

    // setup Broker
    Properties brokerProps = new Properties();
    brokerProps.setProperty("zookeeper.connect", zkConnect);
    brokerProps.setProperty("broker.id", "0");
    brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafkaUtils-").toAbsolutePath().toString());
    brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST + ":" + BROKERPORT);
    KafkaConfig config = new KafkaConfig(brokerProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);

    // create topics
    AdminUtils.createTopic(zkUtils, TOPIC_R, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);
    AdminUtils.createTopic(zkUtils, TOPIC_S, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);

}
 
开发者ID:apache,项目名称:incubator-samoa,代码行数:24,代码来源:KafkaUtilsTest.java

示例2: setUpClass

import kafka.admin.AdminUtils; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException {
    // setup Zookeeper
    zkServer = new EmbeddedZookeeper();
    zkConnect = ZKHOST + ":" + zkServer.port();
    zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
    ZkUtils zkUtils = ZkUtils.apply(zkClient, false);

    // setup Broker
    Properties brokerProps = new Properties();
    brokerProps.setProperty("zookeeper.connect", zkConnect);
    brokerProps.setProperty("broker.id", "0");
    brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString());
    brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST + ":" + BROKERPORT);
    KafkaConfig config = new KafkaConfig(brokerProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);

    // create topic
    AdminUtils.createTopic(zkUtils, TOPIC, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);

}
 
开发者ID:apache,项目名称:incubator-samoa,代码行数:23,代码来源:KafkaDestinationProcessorTest.java

示例3: setUpClass

import kafka.admin.AdminUtils; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws Exception {
  int zkConnectionTimeout = 6000;
  int zkSessionTimeout = 6000;

  zookeeper = new EmbeddedZookeeper();
  zkConnect = String.format("127.0.0.1:%d", zookeeper.port());
  zkUtils = ZkUtils.apply(
      zkConnect, zkSessionTimeout, zkConnectionTimeout,
      JaasUtils.isZkSecurityEnabled());

  port = NetworkUtils.getRandomPort();
  kafkaServer = TestUtil09.createKafkaServer(port, zkConnect);
  for (int i = 0; i < topics.length; i++) {
    topics[i] = UUID.randomUUID().toString();
    AdminUtils.createTopic(zkUtils, topics[i], 1, 1, new Properties());

    TestUtils.waitUntilMetadataIsPropagated(
        scala.collection.JavaConversions.asScalaBuffer(Arrays.asList(kafkaServer)),
        topics[i], 0, 5000);
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:23,代码来源:KafkaProducer09IT.java

示例4: setUpClass

import kafka.admin.AdminUtils; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException {
    // setup Zookeeper
    zkServer = new EmbeddedZookeeper();
    zkConnect = ZKHOST + ":" + zkServer.port();
    zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
    ZkUtils zkUtils = ZkUtils.apply(zkClient, false);

    // setup Broker
    Properties brokerProps = new Properties();
    brokerProps.setProperty("zookeeper.connect", zkConnect);
    brokerProps.setProperty("broker.id", "0");
    brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString());
    brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST + ":" + BROKERPORT);
    KafkaConfig config = new KafkaConfig(brokerProps);
    Time mock = new MockTime();
    kafkaServer = TestUtils.createServer(config, mock);

    // create topics        
    AdminUtils.createTopic(zkUtils, TOPIC_OOS, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);

}
 
开发者ID:apache,项目名称:incubator-samoa,代码行数:23,代码来源:KafkaEntranceProcessorTest.java

示例5: getTopicProperties

import kafka.admin.AdminUtils; //导入依赖的package包/类
/**
 * Get topic configuration
 *
 * @param connection connection
 * @param topicName  topic name
 * @return topic properties
 */
public Properties getTopicProperties(final ZkUtils connection, final String topicName) {
    try {
        return AdminUtils.fetchEntityConfig(connection, ConfigType.Topic(), topicName);
    } catch (IllegalArgumentException | KafkaException e) {
        throw new TopicOperationException(topicName, e.getMessage(), e, this.getClass());
    }
}
 
开发者ID:mcafee,项目名称:management-sdk-for-kafka,代码行数:15,代码来源:ClusterTools.java

示例6: createTopic

import kafka.admin.AdminUtils; //导入依赖的package包/类
/**
 * Create a topic
 *
 * @param connection        Connection
 * @param topicName         Topic name
 * @param partitions        The number of partitions for the topic being created
 * @param replicationFactor The replication factor for each partition in the topic being created
 * @param topicProperties   A topic configuration override for an existing topic
 * @throws TopicOperationException if topic was not created.
 */
public void createTopic(final ZkUtils connection, final String topicName,
                        final int partitions,
                        final int replicationFactor,
                        final Properties topicProperties) {

    try {
        AdminUtils.createTopic(connection,
                topicName,
                partitions,
                replicationFactor,
                topicProperties);

    } catch (IllegalArgumentException | KafkaException | AdminOperationException e) {
        throw new TopicOperationException(topicName, e.getMessage(), e, this.getClass());
    }
}
 
开发者ID:mcafee,项目名称:management-sdk-for-kafka,代码行数:27,代码来源:ClusterTools.java

示例7: ensureTopicCreated

import kafka.admin.AdminUtils; //导入依赖的package包/类
private void ensureTopicCreated(Map<String, ?> config) {
  ZkUtils zkUtils = createZkUtils(config);
  Map<String, List<PartitionInfo>> topics = _consumers.get(0).listTopics();
  long snapshotWindowMs = Long.parseLong((String) config.get(KafkaCruiseControlConfig.LOAD_SNAPSHOT_WINDOW_MS_CONFIG));
  int numSnapshotWindows = Integer.parseInt((String) config.get(KafkaCruiseControlConfig.NUM_LOAD_SNAPSHOTS_CONFIG));
  long retentionMs = (numSnapshotWindows * ADDITIONAL_SNAPSHOT_WINDOW_TO_RETAIN_FACTOR) * snapshotWindowMs;
  Properties props = new Properties();
  props.setProperty(LogConfig.RetentionMsProp(), Long.toString(retentionMs));
  props.setProperty(LogConfig.CleanupPolicyProp(), DEFAULT_CLEANUP_POLICY);
  int replicationFactor = Math.min(2, zkUtils.getAllBrokersInCluster().size());
  if (!topics.containsKey(_partitionMetricSampleStoreTopic)) {
    AdminUtils.createTopic(zkUtils, _partitionMetricSampleStoreTopic, 32, replicationFactor, props, RackAwareMode.Safe$.MODULE$);
  } else {
    AdminUtils.changeTopicConfig(zkUtils, _partitionMetricSampleStoreTopic, props);
  }

  if (!topics.containsKey(_brokerMetricSampleStoreTopic)) {
    AdminUtils.createTopic(zkUtils, _brokerMetricSampleStoreTopic, 32, replicationFactor, props, RackAwareMode.Safe$.MODULE$);
  } else {
    AdminUtils.changeTopicConfig(zkUtils, _brokerMetricSampleStoreTopic, props);
  }

  KafkaCruiseControlUtils.closeZkUtilsWithTimeout(zkUtils, 10000);
}
 
开发者ID:linkedin,项目名称:cruise-control,代码行数:25,代码来源:KafkaSampleStore.java

示例8: createTopic

import kafka.admin.AdminUtils; //导入依赖的package包/类
/**
 * 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);

    // Note: You must initialize the ZkClient with ZKStringSerializer.  If you don't, then
    // createTopic() will only seem to work (it will return without error).  The topic will exist in
    // only ZooKeeper and will be returned when listing topics, but Kafka itself does not create the
    // topic.
    final ZkClient zkClient = new ZkClient(
        zookeeperConnect(),
        DEFAULT_ZK_SESSION_TIMEOUT_MS,
        DEFAULT_ZK_CONNECTION_TIMEOUT_MS,
        ZKStringSerializer$.MODULE$);
    final boolean isSecure = false;
    final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperConnect()), isSecure);
    AdminUtils.createTopic(zkUtils, topic, partitions, replication, topicConfig, RackAwareMode.Enforced$.MODULE$);
    zkClient.close();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:30,代码来源:KafkaEmbedded.java

示例9: createTopic

import kafka.admin.AdminUtils; //导入依赖的package包/类
/**
 * 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(String topic,
                        int partitions,
                        int replication,
                        Properties topicConfig) {
  log.debug("Creating topic { name: {}, partitions: {}, replication: {}, config: {} }",
      topic, partitions, replication, topicConfig);
  // Note: You must initialize the ZkClient with ZKStringSerializer.  If you don't, then
  // createTopic() will only seem to work (it will return without error).  The topic will exist in
  // only ZooKeeper and will be returned when listing topics, but Kafka itself does not create the
  // topic.
  ZkClient zkClient = new ZkClient(
      zookeeperConnect(),
      DEFAULT_ZK_SESSION_TIMEOUT_MS,
      DEFAULT_ZK_CONNECTION_TIMEOUT_MS,
      ZKStringSerializer$.MODULE$);
  boolean isSecure = false;
  ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperConnect()), isSecure);
  AdminUtils.createTopic(zkUtils, topic, partitions, replication, topicConfig, RackAwareMode.Enforced$.MODULE$);
  zkClient.close();
}
 
开发者ID:kaiwaehner,项目名称:kafka-streams-machine-learning-examples,代码行数:29,代码来源:KafkaEmbedded.java

示例10: createTopic

import kafka.admin.AdminUtils; //导入依赖的package包/类
/**
 * Creates a Topic.
 *
 * @param topicName             Topic name.
 * @param partitions        Number of partitions for the topic.
 * @param replicationFactor Replication factor.
 * @param curatorFramework CuratorFramework.
 */
public static void createTopic(String topicName, int partitions, int replicationFactor, CuratorFramework curatorFramework) {
    if (partitions <= 0)
        throw new AdminOperationException("number of partitions must be larger than 0");

    if (replicationFactor <= 0)
        throw new AdminOperationException("replication factor must be larger than 0");

    if (!topicExists(topicName, curatorFramework)) {
        m_logger.info(String.format("Topic %s not found, creating...", topicName));
        ZkClient zkClient = fromCurator(curatorFramework);
        try {
            AdminUtils.createTopic(zkClient, topicName, partitions, replicationFactor, new Properties());
            m_logger.info("Topic created. name: {}, partitions: {}, replicationFactor: {}", topicName,
                    partitions, replicationFactor);
        } catch (TopicExistsException ignore) {
            m_logger.info("Topic exists. name: {}", topicName);
        } finally {
            if (zkClient != null) {
                zkClient.close();
            }
        }
    } else {
        m_logger.info(String.format("Topic %s found!", topicName));
    }
}
 
开发者ID:Microsoft,项目名称:Availability-Monitor-for-Kafka,代码行数:34,代码来源:KafkaUtils.java

示例11: createTopic

import kafka.admin.AdminUtils; //导入依赖的package包/类
/**
 * 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);

  // Note: You must initialize the ZkClient with ZKStringSerializer.  If you don't, then
  // createTopic() will only seem to work (it will return without error).  The topic will exist in
  // only ZooKeeper and will be returned when listing topics, but Kafka itself does not create the
  // topic.
  final ZkClient zkClient = new ZkClient(
      zookeeperConnect(),
      DEFAULT_ZK_SESSION_TIMEOUT_MS,
      DEFAULT_ZK_CONNECTION_TIMEOUT_MS,
      ZKStringSerializer$.MODULE$);
  final boolean isSecure = false;
  final ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zookeeperConnect()), isSecure);
  AdminUtils.createTopic(zkUtils, topic, partitions, replication, topicConfig, RackAwareMode.Enforced$.MODULE$);
  zkClient.close();
}
 
开发者ID:Landoop,项目名称:kafka-testkit,代码行数:30,代码来源:KafkaEmbedded.java

示例12: reassignPartitions

import kafka.admin.AdminUtils; //导入依赖的package包/类
private static void reassignPartitions(ZkUtils zkUtils, Collection<Broker> brokers, String topic, int partitionCount, int replicationFactor) {
  scala.collection.mutable.ArrayBuffer<BrokerMetadata> brokersMetadata = new scala.collection.mutable.ArrayBuffer<>(brokers.size());
  for (Broker broker : brokers) {
    brokersMetadata.$plus$eq(new BrokerMetadata(broker.id(), broker.rack()));
  }
  scala.collection.Map<Object, Seq<Object>> newAssignment =
      AdminUtils.assignReplicasToBrokers(brokersMetadata, partitionCount, replicationFactor, 0, 0);

  scala.collection.mutable.ArrayBuffer<String> topicList = new scala.collection.mutable.ArrayBuffer<>();
  topicList.$plus$eq(topic);
  scala.collection.Map<Object, scala.collection.Seq<Object>> currentAssignment = zkUtils.getPartitionAssignmentForTopics(topicList).apply(topic);
  String currentAssignmentJson = formatAsReassignmentJson(topic, currentAssignment);
  String newAssignmentJson = formatAsReassignmentJson(topic, newAssignment);

  LOG.info("Reassign partitions for topic " + topic);
  LOG.info("Current partition replica assignment " + currentAssignmentJson);
  LOG.info("New partition replica assignment " + newAssignmentJson);
  zkUtils.createPersistentPath(ZkUtils.ReassignPartitionsPath(), newAssignmentJson, zkUtils.DefaultAcls());
}
 
开发者ID:linkedin,项目名称:kafka-monitor,代码行数:20,代码来源:MultiClusterTopicManagementService.java

示例13: createMonitoringTopicIfNotExists

import kafka.admin.AdminUtils; //导入依赖的package包/类
/**
 * Create the topic that the monitor uses to monitor the cluster.  This method attempts to create a topic so that all
 * the brokers in the cluster will have partitionToBrokerRatio partitions.  If the topic exists, but has different parameters
 * then this does nothing to update the parameters.
 *
 * TODO: Do we care about rack aware mode?  I would think no because we want to spread the topic over all brokers.
 * @param zkUrl zookeeper connection url
 * @param topic topic name
 * @param replicationFactor the replication factor for the topic
 * @param partitionToBrokerRatio This is multiplied by the number brokers to compute the number of partitions in the topic.
 * @param topicConfig additional parameters for the topic for example min.insync.replicas
 * @return the number of partitions created
 */
public static int createMonitoringTopicIfNotExists(String zkUrl, String topic, int replicationFactor,
    double partitionToBrokerRatio, Properties topicConfig) {
  ZkUtils zkUtils = ZkUtils.apply(zkUrl, ZK_SESSION_TIMEOUT_MS, ZK_CONNECTION_TIMEOUT_MS, JaasUtils.isZkSecurityEnabled());
  try {
    if (AdminUtils.topicExists(zkUtils, topic)) {
      return getPartitionNumForTopic(zkUrl, topic);
    }
    int brokerCount = zkUtils.getAllBrokersInCluster().size();
    int partitionCount = (int) Math.ceil(brokerCount * partitionToBrokerRatio);

    try {
      AdminUtils.createTopic(zkUtils, topic, partitionCount, replicationFactor, topicConfig, RackAwareMode.Enforced$.MODULE$);
    } catch (TopicExistsException e) {
      //There is a race condition with the consumer.
      LOG.debug("Monitoring topic " + topic + " already exists in cluster " + zkUrl, e);
      return getPartitionNumForTopic(zkUrl, topic);
    }
    LOG.info("Created monitoring topic " + topic + " in cluster " + zkUrl + " with " + partitionCount + " partitions, min ISR of "
      + topicConfig.get(KafkaConfig.MinInSyncReplicasProp()) + " and replication factor of " + replicationFactor + ".");

    return partitionCount;
  } finally {
    zkUtils.close();
  }
}
 
开发者ID:linkedin,项目名称:kafka-monitor,代码行数:39,代码来源:Utils.java

示例14: deleteTopics

import kafka.admin.AdminUtils; //导入依赖的package包/类
/**
 * Deletes the named topics
 * @param topicNames The names of the topics to delete
 * @return A set of the names of the topics that were successfully deleted
 */
public String[] deleteTopics(final String...topicNames) {
	if(!connected.get()) throw new IllegalStateException("The KafkaTestServer is not running");
	if(topicNames==null || topicNames.length==0) return new String[0];
	final Set<String> deleted = new LinkedHashSet<String>();
	for(String topicName: topicNames) {
		if(topicName==null || topicName.trim().isEmpty()) {
			try {
				AdminUtils.deleteTopic(zkUtils, topicName.trim());
				deleted.add(topicName.trim());
			} catch (Exception ex) {
				log.warn("Failed to delete topic [" + topicName.trim() + "]", ex);
			}
		}
	}
	return deleted.toArray(new String[deleted.size()]);
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:22,代码来源:KafkaAdminClient.java

示例15: deleteTopics

import kafka.admin.AdminUtils; //导入依赖的package包/类
/**
 * Deletes the named topics
 * @param topicNames The names of the topics to delete
 * @return A set of the names of the topics that were successfully deleted
 */
public String[] deleteTopics(final String...topicNames) {
	if(!running.get()) throw new IllegalStateException("The KafkaTestServer is not running");
	if(topicNames==null || topicNames.length==0) return new String[0];
	final Set<String> deleted = new LinkedHashSet<String>();
	final ZkUtils z = getZkUtils();
	for(String topicName: topicNames) {
		if(topicName==null || topicName.trim().isEmpty()) {
			try {
				AdminUtils.deleteTopic(z, topicName.trim());
				deleted.add(topicName.trim());
			} catch (Exception ex) {
				log.warn("Failed to delete topic [" + topicName.trim() + "]", ex);
			}
		}
	}
	return deleted.toArray(new String[deleted.size()]);
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:23,代码来源:KafkaTestServer.java


注:本文中的kafka.admin.AdminUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。