private void ensureTopicCreated(ZkUtils zkUtils, Set<String> allTopics, String topic, long retentionMs, int replicationFactor, int partitionCount) { Properties props = new Properties(); props.setProperty(LogConfig.RetentionMsProp(), Long.toString(retentionMs)); props.setProperty(LogConfig.CleanupPolicyProp(), DEFAULT_CLEANUP_POLICY); if (!allTopics.contains(topic)) { AdminUtils.createTopic(zkUtils, topic, partitionCount, replicationFactor, props, RackAwareMode.Safe$.MODULE$); } else { try { AdminUtils.changeTopicConfig(zkUtils, topic, props); MetadataResponse.TopicMetadata topicMetadata = AdminUtils.fetchTopicMetadataFromZk(JavaConversions.asScalaSet(Collections.singleton(topic)), zkUtils, ListenerName.forSecurityProtocol(SecurityProtocol.PLAINTEXT)).head(); maybeIncreaseTopicReplicationFactor(zkUtils, topicMetadata, replicationFactor, topic); maybeIncreaseTopicPartitionCount(zkUtils, topic, topicMetadata, partitionCount); } catch (RuntimeException re) { LOG.error("Skip updating topic " + topic + " configuration due to failure:" + re.getMessage() + "."); } } }
private void updateTopic(ZkUtils zkUtils, String topic, Map<String, String> configMap) { Properties topicProperties = new Properties(); topicProperties.putAll(configMap); AdminUtils.changeTopicConfig(zkUtils, topic, topicProperties); }
/** * Updates the given topic's config with the {@link Properties} provided. This is not additive but a full * replacement * * @param topic * the topic to update config for * @param properties * the properties to assign to the topic * @throws IllegalArgumentException * if topic is null, empty or blank, or properties is {@code null} * @throws AdminOperationException * if there is an issue updating the topic config */ public void updateTopicConfig(String topic, Properties properties) { if (StringUtils.isBlank(topic)) throw new IllegalArgumentException("topic cannot be null, empty or blank"); if (properties == null) throw new IllegalArgumentException("properties cannot be null"); LOG.debug("Updating topic config for topic [{}] with config [{}]", topic, properties); try { AdminUtils.changeTopicConfig(zkUtils, topic, properties); } catch (ZkException e) { throw new AdminOperationException("Unable to update configuration for topic: " + topic, e); } }
public Properties deleteTopicConf(@TopicExistConstraint String topic, List<String> deleteProps) { // compile the final set of configs Properties configs = getTopicPropsFromZk(topic); deleteProps.stream().forEach(config -> configs.remove(config)); AdminUtils.changeTopicConfig(zkUtils, topic, configs); log.info("Delete config for topic: " + topic); return getTopicPropsFromZk(topic); }
public Properties createTopicConf(@TopicExistConstraint String topic, Properties prop) { Properties configs = getTopicPropsFromZk(topic); configs.putAll(prop); AdminUtils.changeTopicConfig(zkUtils, topic, configs); log.info("Create config for topic: " + topic + "Configs:" + configs); return getTopicPropsFromZk(topic); }
public boolean deleteTopicConfByKey(@TopicExistConstraint String topic, String key) { Properties configs = getTopicPropsFromZk(topic); configs.remove(key); AdminUtils.changeTopicConfig(zkUtils, topic, configs); return getTopicPropsFromZk(topic).get(key) == null; }
public Properties updateTopicConf(@TopicExistConstraint String topic, Properties prop) { AdminUtils.changeTopicConfig(zkUtils, topic, prop); return getTopicPropsFromZk(topic); }
@Override public void changeTopicConfig(String topicName, Map<String, String> topicConfig, Handler<AsyncResult<Void>> completionHandler) { Properties topicConfigProperties = new Properties(); topicConfigProperties.putAll(topicConfig); vertx.executeBlocking(future -> { try { kafka.admin.AdminUtils.changeTopicConfig(initZkClientAndGetZkUtils(), topicName, topicConfigProperties); completionHandler.handle(Future.succeededFuture()); } catch(Exception e) { completionHandler.handle(Future.failedFuture(e.getLocalizedMessage())); } finally { if(autoClose) { zkUtils.close(); } } }, r -> { }); }
public void updateTopic(String topic, Properties topicConfig) { AdminUtils.changeTopicConfig(kafkaServer.zkUtils(), topic, topicConfig); }