Search in sources :

Example 1 with DescribeClusterResult

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);
    }
}
Also used : DescribeClusterResult(org.apache.kafka.clients.admin.DescribeClusterResult) Config(org.apache.kafka.clients.admin.Config) TopicConfig(org.apache.kafka.common.config.TopicConfig) Node(org.apache.kafka.common.Node) ConfigResource(org.apache.kafka.common.config.ConfigResource) KafkaTopicException(io.confluent.ksql.exception.KafkaTopicException) RetriableException(org.apache.kafka.common.errors.RetriableException) KafkaResponseGetFailedException(io.confluent.ksql.exception.KafkaResponseGetFailedException) ExecutionException(java.util.concurrent.ExecutionException) TopicExistsException(org.apache.kafka.common.errors.TopicExistsException)

Example 2 with DescribeClusterResult

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);
    }
}
Also used : DescribeClusterResult(org.apache.kafka.clients.admin.DescribeClusterResult) Node(org.apache.kafka.common.Node) Collection(java.util.Collection)

Example 3 with DescribeClusterResult

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;
}
Also used : DescribeClusterResult(org.apache.kafka.clients.admin.DescribeClusterResult) Node(org.apache.kafka.common.Node)

Aggregations

DescribeClusterResult (org.apache.kafka.clients.admin.DescribeClusterResult)3 Node (org.apache.kafka.common.Node)3 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)1 KafkaTopicException (io.confluent.ksql.exception.KafkaTopicException)1 Collection (java.util.Collection)1 ExecutionException (java.util.concurrent.ExecutionException)1 Config (org.apache.kafka.clients.admin.Config)1 ConfigResource (org.apache.kafka.common.config.ConfigResource)1 TopicConfig (org.apache.kafka.common.config.TopicConfig)1 RetriableException (org.apache.kafka.common.errors.RetriableException)1 TopicExistsException (org.apache.kafka.common.errors.TopicExistsException)1