use of org.apache.kafka.clients.admin.DescribeClusterResult in project ksql by confluentinc.
the class KafkaTopicClientImpl method isTopicDeleteEnabled.
private static boolean isTopicDeleteEnabled(final AdminClient adminClient) {
try {
DescribeClusterResult describeClusterResult = adminClient.describeCluster();
Collection<Node> nodes = describeClusterResult.nodes().get();
if (nodes.isEmpty()) {
log.warn("No available broker found to fetch config info.");
throw new KsqlException("Could not fetch broker information. KSQL cannot initialize");
}
ConfigResource resource = new ConfigResource(ConfigResource.Type.BROKER, String.valueOf(nodes.iterator().next().id()));
Map<ConfigResource, Config> config = executeWithRetries(() -> adminClient.describeConfigs(Collections.singleton(resource)).all());
return config.get(resource).entries().stream().anyMatch(configEntry -> configEntry.name().equalsIgnoreCase("delete.topic.enable") && configEntry.value().equalsIgnoreCase("true"));
} catch (final Exception e) {
log.error("Failed to initialize TopicClient: {}", e.getMessage());
throw new KsqlException("Could not fetch broker information. KSQL cannot initialize", e);
}
}
use of org.apache.kafka.clients.admin.DescribeClusterResult in project strimzi by strimzi.
the class MockAdminClient method describeCluster.
@Override
public DescribeClusterResult describeCluster(DescribeClusterOptions describeClusterOptions) {
try {
Constructor<DescribeClusterResult> ctor = DescribeClusterResult.class.getDeclaredConstructor(KafkaFuture.class, KafkaFuture.class, KafkaFuture.class);
ctor.setAccessible(true);
final List<Node> nodes = asList(new Node(0, "localhost", -2), new Node(1, "localhost", -2), new Node(2, "localhost", -2));
KafkaFuture<Collection<Node>> nodesFuture = KafkaFutureImpl.completedFuture(nodes);
KafkaFuture<Node> controllerFuture = KafkaFutureImpl.completedFuture(nodes.get(0));
KafkaFuture<String> clusterIdFuture = KafkaFutureImpl.completedFuture("mock-cluster");
return ctor.newInstance(nodesFuture, controllerFuture, clusterIdFuture);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
use of org.apache.kafka.clients.admin.DescribeClusterResult in project ksql by confluentinc.
the class KafkaTopicClientImplTest method describeClusterResult.
private DescribeClusterResult describeClusterResult() {
Collection<Node> nodes = Collections.singletonList(node);
DescribeClusterResult describeClusterResult = mock(DescribeClusterResult.class);
expect(describeClusterResult.nodes()).andReturn(KafkaFuture.completedFuture(nodes));
replay(describeClusterResult);
return describeClusterResult;
}
Aggregations