private Properties getTopicConfig(ZkUtils zkUtils, String topic) { return AdminUtils.fetchEntityConfig(zkUtils, ConfigType.Topic(), topic); } }
private Properties getTopicPropsFromZk(String topic) { return AdminUtils.fetchEntityConfig(zkUtils, ConfigType.Topic(), topic); }
public Properties getTopicConfByKey(@TopicExistConstraint String topic, String key) { String value = String.valueOf(AdminUtils.fetchEntityConfig(zkUtils, ConfigType.Topic(), topic).get(key)); Properties returnProps = new Properties(); if (!value.equals("null")) { returnProps.setProperty(key, value); return returnProps; } else return null; }
/** * Returns the {@link Properties} associated to the topic * * @param topic * a Kafka topic * @return the {@link Properties} associated to the topic * @throws IllegalArgumentException * if topic is null, empty or blank * @throws AdminOperationException * if there is an issue reading the topic config */ public Properties getTopicConfig(String topic) { if (StringUtils.isBlank(topic)) throw new IllegalArgumentException("topic cannot be null, empty or blank"); LOG.debug("Fetching topic config for topic [{}]", topic); try { return AdminUtils.fetchEntityConfig(zkUtils, ConfigType.Topic(), topic); } catch (ZkException | KafkaException | IllegalArgumentException e) { throw new AdminOperationException("Unable to retrieve configuration for topic: " + topic, e); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) private static void verifyTopic(ZkUtils zkUtils, String topic) { Set topics = new HashSet(); topics.add(topic); // check # partition and the replication factor scala.collection.mutable.Map partitionAssignmentForTopics = zkUtils .getPartitionAssignmentForTopics(JavaConversions.asScalaSet(topics).toSeq()); scala.collection.Map partitionAssignment = (scala.collection.Map) partitionAssignmentForTopics.get(topic).get(); if (partitionAssignment.size() != 1) { throw new RuntimeException(String.format("The schema topic %s should have only 1 partition.", topic)); } // check the retention policy Properties prop = AdminUtils.fetchEntityConfig(zkUtils, ConfigType.Topic(), topic); String retentionPolicy = prop.getProperty(LogConfig.CleanupPolicyProp()); if (retentionPolicy == null || "compact".compareTo(retentionPolicy) != 0) { throw new RuntimeException(String.format("The retention policy of the schema topic %s must be compact.", topic)); } } }
private void verifySchemaTopic() { Set<String> topics = new HashSet<String>(); topics.add(topic); // check # partition and the replication factor scala.collection.Map partitionAssignment = zkUtils.getPartitionAssignmentForTopics( JavaConversions.asScalaSet(topics).toSeq()) .get(topic).get(); if (partitionAssignment.size() != 1) { log.warn("The schema topic " + topic + " should have only 1 partition."); } if (((Seq) partitionAssignment.get(0).get()).size() < desiredReplicationFactor) { log.warn("The replication factor of the schema topic " + topic + " is less than the " + "desired one of " + desiredReplicationFactor + ". If this is a production " + "environment, it's crucial to add more brokers and increase the replication " + "factor of the topic."); } // check the retention policy Properties prop = AdminUtils.fetchEntityConfig(zkUtils, ConfigType.Topic(), topic); String retentionPolicy = prop.getProperty(LogConfig.CleanupPolicyProp()); if (retentionPolicy == null || "compact".compareTo(retentionPolicy) != 0) { log.warn("The retention policy of the schema topic " + topic + " may be incorrect. " + "Please configure it with compact."); } }