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


Java ZkUtils.apply方法代码示例

本文整理汇总了Java中kafka.utils.ZkUtils.apply方法的典型用法代码示例。如果您正苦于以下问题:Java ZkUtils.apply方法的具体用法?Java ZkUtils.apply怎么用?Java ZkUtils.apply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kafka.utils.ZkUtils的用法示例。


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

示例1: setUpClass

import kafka.utils.ZkUtils; //导入方法依赖的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

示例2: setUpClass

import kafka.utils.ZkUtils; //导入方法依赖的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

示例3: execute

import kafka.utils.ZkUtils; //导入方法依赖的package包/类
/**
 * Start the actual execution of the proposals.
 */
private void execute() {
  _zkUtils = ZkUtils.apply(_zkConnect, 30000, 30000, false);
  try {
    _state.set(ExecutorState.State.REPLICA_MOVEMENT_TASK_IN_PROGRESS);
    moveReplicas();
    // Start leader movements.
    _state.set(ExecutorState.State.LEADER_MOVEMENT_TASK_IN_PROGRESS);
    moveLeaders();
  } catch (Throwable t) {
    LOG.error("Executor got exception during execution", t);
  } finally {
    // Add the null pointer check for unit test.
    if (_loadMonitor != null) {
      _loadMonitor.resumeMetricSampling();
    }
    _stopRequested = false;
    _executionTaskManager.clear();
    KafkaCruiseControlUtils.closeZkUtilsWithTimeout(_zkUtils, 10000);
    _state.set(ExecutorState.State.NO_TASK_IN_PROGRESS);
  }
}
 
开发者ID:linkedin,项目名称:cruise-control,代码行数:25,代码来源:Executor.java

示例4: setOffsets

import kafka.utils.ZkUtils; //导入方法依赖的package包/类
/**
 * @param zkServers Zookeeper server string: host1:port1[,host2:port2,...]
 * @param groupID consumer group to update
 * @param offsets mapping of (topic and) partition to offset to push to Zookeeper
 */
@SuppressWarnings("deprecation")
public static void setOffsets(String zkServers,
                              String groupID,
                              Map<Pair<String,Integer>,Long> offsets) {
  ZkUtils zkUtils = ZkUtils.apply(zkServers, ZK_TIMEOUT_MSEC, ZK_TIMEOUT_MSEC, false);
  try {
    offsets.forEach((topicAndPartition, offset) -> {
      ZKGroupTopicDirs topicDirs = new ZKGroupTopicDirs(groupID, topicAndPartition.getFirst());
      int partition = topicAndPartition.getSecond();
      String partitionOffsetPath = topicDirs.consumerOffsetDir() + "/" + partition;
      // TODO replace call below with defaultAcls(false, "") when < 0.10.2 is supported
      zkUtils.updatePersistentPath(partitionOffsetPath,
                                   Long.toString(offset),
                                   ZkUtils$.MODULE$.DefaultAcls(false));
    });
  } finally {
    zkUtils.close();
  }
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:25,代码来源:KafkaUtils.java

示例5: lookupBootstrap

import kafka.utils.ZkUtils; //导入方法依赖的package包/类
/**
 * Generates the Kafka bootstrap connection string from the metadata stored in Zookeeper.
 * Allows for backwards compatibility of the zookeeperConnect configuration.
 */
private String lookupBootstrap(String zookeeperConnect, SecurityProtocol securityProtocol) {
  ZkUtils zkUtils = ZkUtils.apply(zookeeperConnect, ZK_SESSION_TIMEOUT, ZK_CONNECTION_TIMEOUT,
      JaasUtils.isZkSecurityEnabled());
  try {
    List<BrokerEndPoint> endPoints =
        asJavaListConverter(zkUtils.getAllBrokerEndPointsForChannel(securityProtocol)).asJava();
    List<String> connections = new ArrayList<>();
    for (BrokerEndPoint endPoint : endPoints) {
      connections.add(endPoint.connectionString());
    }
    return StringUtils.join(connections, ',');
  } finally {
    zkUtils.close();
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:20,代码来源:KafkaSource.java

示例6: AutoTopicWhitelistingManager

import kafka.utils.ZkUtils; //导入方法依赖的package包/类
public AutoTopicWhitelistingManager(KafkaBrokerTopicObserver srcKafkaTopicObserver,
    KafkaBrokerTopicObserver destKafkaTopicObserver,
    HelixMirrorMakerManager helixMirrorMakerManager,
    String patternToExcludeTopics,
    int refreshTimeInSec,
    int initWaitTimeInSec) {
  _srcKafkaTopicObserver = srcKafkaTopicObserver;
  _destKafkaTopicObserver = destKafkaTopicObserver;
  _helixMirrorMakerManager = helixMirrorMakerManager;
  _patternToExcludeTopics = patternToExcludeTopics;
  _refreshTimeInSec = refreshTimeInSec;
  _initWaitTimeInSec = initWaitTimeInSec;
  _zkClient = new ZkClient(_helixMirrorMakerManager.getHelixZkURL(), 30000, 30000, ZKStringSerializer$.MODULE$);
  _zkUtils = ZkUtils.apply(_zkClient, false);
  _blacklistedTopicsZPath = String.format("/%s/BLACKLISTED_TOPICS", _helixMirrorMakerManager.getHelixClusterName());
}
 
开发者ID:uber,项目名称:uReplicator,代码行数:17,代码来源:AutoTopicWhitelistingManager.java

示例7: KafkaBrokerTopicObserver

import kafka.utils.ZkUtils; //导入方法依赖的package包/类
public KafkaBrokerTopicObserver(String brokerClusterName, String zkString, long refreshTimeIntervalInMillis) {
  LOGGER.info("Trying to init KafkaBrokerTopicObserver {} with ZK: {}", brokerClusterName,
          zkString);
  _kakfaClusterName = brokerClusterName;
  _refreshTimeIntervalInMillis = refreshTimeIntervalInMillis;
  _zkClient = new ZkClient(zkString, 30000, 30000, ZKStringSerializer$.MODULE$);
  _zkClient.subscribeChildChanges(KAFKA_TOPICS_PATH, this);
  _zkUtils = ZkUtils.apply(_zkClient, false);
  registerMetric();
  executorService.scheduleAtFixedRate(new Runnable() {
    @Override
    public void run() {
      tryToRefreshCache();
    }
  }, 0, _refreshTimeIntervalInMillis, TimeUnit.SECONDS);
}
 
开发者ID:uber,项目名称:uReplicator,代码行数:17,代码来源:KafkaBrokerTopicObserver.java

示例8: createMonitoringTopicIfNotExists

import kafka.utils.ZkUtils; //导入方法依赖的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

示例9: AutoTopicWhitelistingManager

import kafka.utils.ZkUtils; //导入方法依赖的package包/类
public AutoTopicWhitelistingManager(KafkaBrokerTopicObserver srcKafkaTopicObserver,
                                    KafkaBrokerTopicObserver destKafkaTopicObserver,
                                    HelixMirrorMakerManager helixMirrorMakerManager,
                                    String patternToExcludeTopics,
                                    int refreshTimeInSec,
                                    int initWaitTimeInSec) {
  _srcKafkaTopicObserver = srcKafkaTopicObserver;
  _destKafkaTopicObserver = destKafkaTopicObserver;
  _helixMirrorMakerManager = helixMirrorMakerManager;
  _patternToExcludeTopics = patternToExcludeTopics;
  _refreshTimeInSec = refreshTimeInSec;
  _initWaitTimeInSec = initWaitTimeInSec;
  _zkUtils = ZkUtils.apply(_helixMirrorMakerManager.getHelixZkURL(), 30000, 30000, false);
  _zkClient = ZkUtils.createZkClient(_helixMirrorMakerManager.getHelixZkURL(), 30000, 30000);
  _blacklistedTopicsZPath =
          String.format("/%s/BLACKLISTED_TOPICS", _helixMirrorMakerManager.getHelixClusterName());
}
 
开发者ID:uber,项目名称:chaperone,代码行数:18,代码来源:AutoTopicWhitelistingManager.java

示例10: putOffsetInfoIntoZk

import kafka.utils.ZkUtils; //导入方法依赖的package包/类
private static void putOffsetInfoIntoZk(String groupId, Map<String, Map<Integer, Long>> topicOffsetsMap) {
  ZkUtils zkUtils =
      ZkUtils.apply(AuditConfig.INGESTER_ZK_CONNECT, Integer.valueOf(AuditConfig.INGESTER_ZK_SESSION_TIMEOUT_MS),
          Integer.valueOf(AuditConfig.INGESTER_ZK_SESSION_TIMEOUT_MS), false);
  try {
    for (Map.Entry<String, Map<Integer, Long>> topicEntry : topicOffsetsMap.entrySet()) {
      String zkPath = String.format("%s/%s/offsets/%s/", ZkUtils.ConsumersPath(), groupId, topicEntry.getKey());
      for (Map.Entry<Integer, Long> offsetEntry : topicEntry.getValue().entrySet()) {
        logger.info("Put offset={} to partition={} with znode path={}", offsetEntry.getValue(), offsetEntry.getKey(),
            zkPath + offsetEntry.getKey());
        zkUtils.updatePersistentPath(zkPath + offsetEntry.getKey(), offsetEntry.getValue().toString(),
            zkUtils.DefaultAcls());
      }
    }
  } catch (Exception e) {
    logger.error("Got exception to put offset, with zkPathPrefix={}",
        String.format("%s/%s/offsets", ZkUtils.ConsumersPath(), groupId));
    throw e;
  } finally {
    zkUtils.close();
  }
}
 
开发者ID:uber,项目名称:chaperone,代码行数:23,代码来源:KafkaIngester.java

示例11: removeOffsetInfoFromZk

import kafka.utils.ZkUtils; //导入方法依赖的package包/类
private static void removeOffsetInfoFromZk(final String groupId) {
  ZkUtils zkUtils =
      ZkUtils.apply(AuditConfig.INGESTER_ZK_CONNECT, Integer.valueOf(AuditConfig.INGESTER_ZK_SESSION_TIMEOUT_MS),
          Integer.valueOf(AuditConfig.INGESTER_ZK_SESSION_TIMEOUT_MS), false);
  try {
    String[] targets = new String[] {"offsets", "owners"};
    for (String target : targets) {
      String zkPath = String.format("%s/%s/%s", ZkUtils.ConsumersPath(), groupId, target);
      logger.info("Remove {} with znode path={}", target, zkPath);
      zkUtils.deletePathRecursive(zkPath);
    }
  } catch (Exception e) {
    logger.error("Got exception to remove offsets or owners from zookeeper, with zkPathPrefix={}",
        String.format("%s/%s/", ZkUtils.ConsumersPath(), groupId));
    throw e;
  } finally {
    zkUtils.close();
  }
}
 
开发者ID:uber,项目名称:chaperone,代码行数:20,代码来源:KafkaIngester.java

示例12: createTopic

import kafka.utils.ZkUtils; //导入方法依赖的package包/类
public void createTopic(int clusterid, String topicName)
{
  String[] args = new String[9];
  args[0] = "--zookeeper";
  args[1] = "localhost:" + TEST_ZOOKEEPER_PORT[clusterid];
  args[2] = "--replication-factor";
  args[3] = "1";
  args[4] = "--partitions";
  if (hasMultiPartition) {
    args[5] = "2";
  } else {
    args[5] = "1";
  }
  args[6] = "--topic";
  args[7] = topicName;
  args[8] = "--create";

  ZkUtils zu = ZkUtils.apply("localhost:" + TEST_ZOOKEEPER_PORT[clusterid], 30000, 30000, false);
  TopicCommand.createTopic(zu, new TopicCommand.TopicCommandOptions(args));

}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:22,代码来源:KafkaOperatorTestBase.java

示例13: createTopic

import kafka.utils.ZkUtils; //导入方法依赖的package包/类
public void createTopic(String name, int numPartitions, boolean waitUntilMetadataIsPropagated) throws InterruptedException {
  ZkUtils zkUtils = null;
  Level oldLevel = UnitTestHelper.getJavaLoggingLevel();
  try {
    UnitTestHelper.setJavaLoggingLevel(Level.OFF);
    zkUtils = ZkUtils.apply(zookeeperConnectString, 30000, 30000, false);
    AdminUtilsWrapper.createTopic(zkUtils, name, numPartitions, 1, new Properties());
    if (waitUntilMetadataIsPropagated) {
      waitUntilMetadataIsPropagated(name, numPartitions);
    }
  }catch(TopicExistsException tee) {
  }finally {
    if(zkUtils != null){
      zkUtils.close();
    }
    UnitTestHelper.setJavaLoggingLevel(oldLevel);
  }
}
 
开发者ID:apache,项目名称:metron,代码行数:19,代码来源:KafkaComponent.java

示例14: LocalKafkaServer

import kafka.utils.ZkUtils; //导入方法依赖的package包/类
public LocalKafkaServer() throws IOException {

		while (new File(logDir).exists()) {
			FileUtils.deleteDirectory(new File(logDir));
		}

		Properties props = new Properties();
		props.put("broker.id", nodeId);
		props.put("port", port);
		props.put("log.dir", logDir);
		props.put("zookeeper.connect", zkConnect);
		props.put("host.name", "127.0.0.1");
		KafkaConfig conf = new KafkaConfig(props);

                zkUtils = ZkUtils.apply(props.getProperty("zookeeper.connect"),
                          30000,
                          30000,
                          JaasUtils.isZkSecurityEnabled());


		server = new KafkaServerStartable(conf);
		server.startup();
	}
 
开发者ID:blackberry,项目名称:Krackle,代码行数:24,代码来源:LocalKafkaServer.java

示例15: createTopic

import kafka.utils.ZkUtils; //导入方法依赖的package包/类
public static void createTopic(String topicName, int numPartitions, int zkPort) {
    // setup
    String[] arguments = new String[9];
    arguments[0] = "--create";
    arguments[1] = "--zookeeper";
    arguments[2] = "127.0.0.1:" + zkPort;
    arguments[3] = "--replication-factor";
    arguments[4] = "1";
    arguments[5] = "--partitions";
    arguments[6] = "" + Integer.valueOf(numPartitions);
    arguments[7] = "--topic";
    arguments[8] = topicName;
    TopicCommand.TopicCommandOptions opts = new TopicCommand.TopicCommandOptions(arguments);

    ZkUtils zkUtils = ZkUtils.apply(opts.options().valueOf(opts.zkConnectOpt()), 30000, 30000,
            JaasUtils.isZkSecurityEnabled());
    TopicCommand.createTopic(zkUtils, opts);
}
 
开发者ID:DDTH,项目名称:ddth-kafka,代码行数:19,代码来源:QndEmbeddedServer.java


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