/** * @param zkServers Zookeeper server string: host1:port1[,host2:port2,...] * @param topic topic to check for existence * @return {@code true} if and only if the given topic exists */ public static boolean topicExists(String zkServers, String topic) { ZkUtils zkUtils = ZkUtils.apply(zkServers, ZK_TIMEOUT_MSEC, ZK_TIMEOUT_MSEC, false); try { return AdminUtils.topicExists(zkUtils, topic); } finally { zkUtils.close(); } }
/** * @param zkServers Zookeeper server string: host1:port1[,host2:port2,...] * @param topic topic to delete, if it exists */ public static void deleteTopic(String zkServers, String topic) { ZkUtils zkUtils = ZkUtils.apply(zkServers, ZK_TIMEOUT_MSEC, ZK_TIMEOUT_MSEC, false); try { if (AdminUtils.topicExists(zkUtils, topic)) { log.info("Deleting topic {}", topic); AdminUtils.deleteTopic(zkUtils, topic); log.info("Deleted Zookeeper topic {}", topic); } else { log.info("No need to delete topic {} as it does not exist", topic); } } finally { zkUtils.close(); } }
/** * @param zkServers Zookeeper server string: host1:port1[,host2:port2,...] * @param topic topic to create (if not already existing) * @param partitions number of topic partitions * @param topicProperties optional topic config properties */ public static void maybeCreateTopic(String zkServers, String topic, int partitions, Properties topicProperties) { ZkUtils zkUtils = ZkUtils.apply(zkServers, ZK_TIMEOUT_MSEC, ZK_TIMEOUT_MSEC, false); try { if (AdminUtils.topicExists(zkUtils, topic)) { log.info("No need to create topic {} as it already exists", topic); } else { log.info("Creating topic {} with {} partition(s)", topic, partitions); try { AdminUtils.createTopic( zkUtils, topic, partitions, 1, topicProperties, RackAwareMode.Enforced$.MODULE$); log.info("Created topic {}", topic); } catch (TopicExistsException re) { log.info("Topic {} already exists", topic); } } } finally { zkUtils.close(); } }
int replication = ConfigUtils.getInt(config, KafkaWriterConfigurationKeys.REPLICATION_COUNT, KafkaWriterConfigurationKeys.PARTITION_COUNT_DEFAULT); Properties topicConfig = new Properties(); if(AdminUtils.topicExists(zkUtils, topicName)) { log.debug("Topic"+topicName+" already Exists with replication: "+replication+" and partitions :"+partitions); return;
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);
public static boolean createKafkaTopicIfNecessary(String brokerUri, int replFactor, int numPartitions, String topic) throws IOException { URI zkUri = URI.create(brokerUri); Preconditions.checkArgument("zk".equals(zkUri.getScheme())); String zkServerList = zkUri.getAuthority() + zkUri.getPath(); ZkUtils zkUtils = ZkUtils.apply(zkServerList, ZK_SESSION_TIMEOUT_MS, ZK_CONNECTION_TIMEOUT_MS, JaasUtils.isZkSecurityEnabled()); try { if (AdminUtils.topicExists(zkUtils, topic)) { return false; } try { AdminUtils.createTopic(zkUtils, topic, numPartitions, replFactor, new Properties()); } catch (TopicExistsException ignored) { return false; } catch (RuntimeException e) { throw new IOException(e); } } finally { if (zkUtils != null) { zkUtils.close(); } } return true; } }
public Boolean existsTopic(String topic) { return AdminUtils.topicExists(zkClient, topic); }
public Boolean existsTopic(String topic) { return AdminUtils.topicExists(zkClient, topic); }
public boolean existTopic(String topicName) { return AdminUtils.topicExists(zkUtils, topicName); }
private boolean topicExists(ZkUtils zkUtils, String topic) { boolean topicExists = AdminUtils.topicExists(zkUtils, topic); log.debug("topic: {} exists={}", topic, topicExists); return topicExists; }
@VisibleForTesting protected boolean ifTopicExists(String topicName, ZkUtils zkUtils) { return AdminUtils.topicExists(zkUtils, topicName); }
@VisibleForTesting protected boolean ifTopicExists(String topicName, ZkUtils zkUtils) { return AdminUtils.topicExists(zkUtils, topicName); }
@Override public void createTopicIfNotExist(String topic, int replicationFactor, int partitions) { if (!AdminUtils.topicExists(zkClient, topic)) { createOrUpdateTopic(topic, replicationFactor, partitions); } else { logger.info("Topic {} already exists", topic); } }
@Override public void createTopicIfNotExist(String topic, int replicationFactor, int partitions) { if (!AdminUtils.topicExists(zkClient, topic)) { createOrUpdateTopic(topic, replicationFactor, partitions); } else { logger.info("Topic {} already exists", topic); } }
private void deleteTopic(String topic) { if (AdminUtils.topicExists(zkUtils, topic)) { AdminUtils.deleteTopic(zkUtils, topic); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } logger.info("deleted topic"); } }
@Override public boolean topicExists(String topic) throws Exception { LOGGER.debug("Checking if topic '" + topic + "' already exists."); return AdminUtils.topicExists(zookeeperClient, topic); } // topicExists
/** * @param zookeeperHosts * Zookeeper hosts e.g. localhost:2181. If multiple zookeeper * then host1:port1[,host2:port2,...] * @param topic * topic to check for existence * @return true if and only if the given topic exists */ public boolean topicExists(String zookeeperHosts, String topic) { try (SuperZkClient zkClient = new SuperZkClient(zookeeperHosts)) { return AdminUtils.topicExists(zkClient, topic); } }
/** * @param zkServers Zookeeper server string: host1:port1[,host2:port2,...] * @param topic topic to check for existence * @return {@code true} if and only if the given topic exists */ public static boolean topicExists(String zkServers, String topic) { ZkUtils zkUtils = ZkUtils.apply(zkServers, ZK_TIMEOUT_MSEC, ZK_TIMEOUT_MSEC, false); try { return AdminUtils.topicExists(zkUtils, topic); } finally { zkUtils.close(); } }
public static boolean topicExists(String topic, CuratorFramework curatorFramework) { ZkClient zkClient = fromCurator(curatorFramework); try { zkClient = fromCurator(curatorFramework); return AdminUtils.topicExists(zkClient, topic); } finally { if (zkClient != null) { zkClient.close(); } } } }
public static void checkAndCreateTopic(String zkConnect, String topic, int replicas) { ZkClient zkClient = new ZkClient(zkConnect, SESSION_TIMEOUT_MS, CONNECTION_TIMEOUT_MS, ZKStringSerializer$.MODULE$); ZkUtils zkUtils = new ZkUtils(zkClient, new ZkConnection(zkConnect), IS_SECURE_KAFKA_CLUSTER); if (AdminUtils.topicExists(zkUtils, topic)) { verifyTopic(zkUtils, topic); return; } int partitions = 1; Properties topicConfig = new Properties(); topicConfig.put(LogConfig.CleanupPolicyProp(), "compact"); AdminUtils.createTopic(zkUtils, topic, partitions, replicas, topicConfig, RackAwareMode.Enforced$.MODULE$); zkClient.close(); zkUtils.close(); }