github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/pkg/sink/kafka/cluster_admin_client.go (about) 1 // Copyright 2021 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package kafka 15 16 import ( 17 "context" 18 ) 19 20 // TopicDetail represent a topic's detail information. 21 type TopicDetail struct { 22 Name string 23 NumPartitions int32 24 ReplicationFactor int16 25 } 26 27 // Broker represents a Kafka broker. 28 type Broker struct { 29 ID int32 30 } 31 32 // ClusterAdminClient is the administrative client for Kafka, 33 // which supports managing and inspecting topics, brokers, configurations and ACLs. 34 type ClusterAdminClient interface { 35 // GetAllBrokers return all brokers among the cluster 36 GetAllBrokers(ctx context.Context) ([]Broker, error) 37 38 // GetBrokerConfig return the broker level configuration with the `configName` 39 GetBrokerConfig(ctx context.Context, configName string) (string, error) 40 41 // GetTopicConfig return the topic level configuration with the `configName` 42 GetTopicConfig(ctx context.Context, topicName string, configName string) (string, error) 43 44 // GetTopicsMeta return all target topics' metadata 45 // if `ignoreTopicError` is true, ignore the topic error and return the metadata of valid topics 46 GetTopicsMeta(ctx context.Context, 47 topics []string, ignoreTopicError bool) (map[string]TopicDetail, error) 48 49 // GetTopicsPartitionsNum return the number of partitions of each topic. 50 GetTopicsPartitionsNum(ctx context.Context, topics []string) (map[string]int32, error) 51 52 // CreateTopic creates a new topic. 53 CreateTopic(ctx context.Context, detail *TopicDetail, validateOnly bool) error 54 55 // Close shuts down the admin client. 56 Close() 57 }