diff options
author | Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> | 2023-11-13 17:39:31 +0530 |
---|---|---|
committer | Herbert Eiselt <herbert.eiselt@highstreet-technologies.com> | 2023-12-06 17:30:59 +0000 |
commit | 6a805bdb781a1be4806542cb38da08a32ebcca8b (patch) | |
tree | 7921ad866d67b7777ef2ab50ea146cb79834e809 /sdnr/wt/mountpoint-registrar | |
parent | 89ebab617ae3808f63a4306d05cf93d6868f6060 (diff) |
Prohibit kafka client library from generating WARN message burst
Query for topic existence before polling
Issue-ID: CCSDK-3962
Change-Id: I579f9133b01caf5ba9268d9e25d455778d5efcc4
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/mountpoint-registrar')
3 files changed, 31 insertions, 12 deletions
diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/MessageConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/MessageConfig.java index 3b3394454..92367e660 100644 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/MessageConfig.java +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/MessageConfig.java @@ -17,7 +17,6 @@ * ============LICENSE_END========================================================================== */ - package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config; import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration; @@ -36,10 +35,10 @@ public abstract class MessageConfig implements Configuration { private static final String DEFAULT_VALUE_CONSUMER_ID = "C1"; public static final String PROPERTY_KEY_CONSUMER_TIMEOUT = "timeout"; - private static final String DEFAULT_VALUE_CONSUMER_TIMEOUT = "20000"; + private static final String DEFAULT_VALUE_CONSUMER_TIMEOUT = "2000"; public static final String PROPERTY_KEY_CONSUMER_LIMIT = "limit"; - private static final String DEFAULT_VALUE_CONSUMER_LIMIT = "10000"; + private static final String DEFAULT_VALUE_CONSUMER_LIMIT = "1000"; public static final String PROPERTY_KEY_CONSUMER_FETCHPAUSE = "fetchPause"; private static final String DEFAULT_VALUE_CONSUMER_FETCHPAUSE = "5000"; diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgConsumerImpl.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgConsumerImpl.java index 249eb612e..76870271d 100644 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgConsumerImpl.java +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgConsumerImpl.java @@ -24,6 +24,9 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.List; import java.util.Properties; +import java.util.concurrent.ExecutionException; +import org.apache.kafka.clients.CommonClientConfigs; +import org.apache.kafka.clients.admin.Admin; import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.GeneralConfig; import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.kafka.VESMsgKafkaConsumer; import org.slf4j.Logger; @@ -42,6 +45,7 @@ public abstract class StrimziKafkaVESMsgConsumerImpl private boolean ready = false; private int fetchPause = 5000; // Default pause between fetch - 5 seconds protected final GeneralConfig generalConfig; + Admin kafkaAdminClient = null; protected StrimziKafkaVESMsgConsumerImpl(GeneralConfig generalConfig) { this.generalConfig = generalConfig; @@ -54,22 +58,22 @@ public abstract class StrimziKafkaVESMsgConsumerImpl */ @Override public void run() { - if (ready) { running = true; while (running) { try { boolean noData = true; List<String> consumerResponse = null; - consumerResponse = consumer.poll(); - for (String msg : consumerResponse) { - noData = false; - LOG.debug("{} received ActualMessage from Kafka VES Message topic {}", name, msg); - if (isMessageValid(msg)) { - processMsg(msg); + if (isTopicExists(consumer.getTopicName())) { + consumerResponse = consumer.poll(); + for (String msg : consumerResponse) { + noData = false; + LOG.debug("{} received ActualMessage from Kafka VES Message topic {}", name, msg); + if (isMessageValid(msg)) { + processMsg(msg); + } } } - if (noData) { pauseThread(); } @@ -103,6 +107,9 @@ public abstract class StrimziKafkaVESMsgConsumerImpl */ @Override public void init(Properties strimziKafkaProperties, Properties consumerProperties) { + Properties props = new Properties(); + props.put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, strimziKafkaProperties.getProperty("bootstrapServers")); + kafkaAdminClient = Admin.create(props); try { this.consumer = new VESMsgKafkaConsumer(strimziKafkaProperties, consumerProperties); @@ -122,6 +129,19 @@ public abstract class StrimziKafkaVESMsgConsumerImpl } } + private boolean isTopicExists(String topicName) { + LOG.trace("Checking for existence of topic - {}", topicName); + try { + for (String kafkaTopic : kafkaAdminClient.listTopics().names().get()) { + if (kafkaTopic.equals(topicName)) + return true; + } + } catch (InterruptedException | ExecutionException e) { + LOG.error("Exception in isTopicExists method - ", e); + } + return false; + } + @Override public boolean isReady() { return ready; diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/kafka/VESMsgKafkaConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/kafka/VESMsgKafkaConsumer.java index 352db03f2..80e232a15 100644 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/kafka/VESMsgKafkaConsumer.java +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/kafka/VESMsgKafkaConsumer.java @@ -68,7 +68,7 @@ public class VESMsgKafkaConsumer { */ public List<String> poll() { List<String> msgs = new ArrayList<>(); - ConsumerRecords<String, String> records = consumer.poll(Duration.ofSeconds(pollTimeout)); + ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(pollTimeout)); for (ConsumerRecord<String, String> rec : records) { msgs.add(rec.value()); } |