Skip to content

Commit

Permalink
MOSIP-29320 (#239)
Browse files Browse the repository at this point in the history
* Build check

Signed-off-by: HimajaDhanyamraju2 <[email protected]>

* MOSIP-29320: Fixed build failure

Signed-off-by: HimajaDhanyamraju2 <[email protected]>

* MOSIP-29320: Fixed build error

Signed-off-by: HimajaDhanyamraju2 <[email protected]>

---------

Signed-off-by: HimajaDhanyamraju2 <[email protected]>
  • Loading branch information
HimajaDhanyamraju2 authored Feb 5, 2024
1 parent 05b9403 commit 58d7f7b
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package io.mosip.kafkaadminclient;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;

import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.admin.CreateTopicsResult;
import org.apache.kafka.clients.admin.DescribeTopicsResult;
import org.apache.kafka.clients.admin.ListTopicsOptions;
import org.apache.kafka.clients.admin.NewTopic;
import org.apache.kafka.clients.admin.TopicDescription;
import org.apache.kafka.common.KafkaFuture;
import org.apache.kafka.common.errors.TopicExistsException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -35,4 +41,25 @@ public void createTopic(String topicName) throws Exception {
future.get();
}
}

public boolean isTopicsPresent(String topics) throws Exception {
List<String> topicsList = Arrays.asList(topics.split(","));
Set<String> kafkaTopics = getAllTopics();
return topicsList.stream().allMatch(kafkaTopics::contains);
}

public Set<String> getAllTopics() throws Exception {
try (Admin admin = Admin.create(properties)) {
ListTopicsOptions listTopicsOptions = new ListTopicsOptions();
listTopicsOptions.listInternal(true);
return admin.listTopics(listTopicsOptions).names().get();
}
}

public Map<String, TopicDescription> describeTopic(String topic) throws Exception {
try (Admin admin = Admin.create(properties)) {
DescribeTopicsResult result = admin.describeTopics(Collections.singleton(topic));
return result.all().get();
}
}
}

0 comments on commit 58d7f7b

Please sign in to comment.