Class LicenseTopicAdmin
- All Implemented Interfaces:
AutoCloseable
Admin.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA builder ofNewTopicinstances.static class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final LicenseTopicAdmin.TopicCreationResponsestatic final intstatic final short -
Constructor Summary
ConstructorsConstructorDescriptionLicenseTopicAdmin(Map<String, Object> adminConfig) Create a new topic admin component with the given configuration.LicenseTopicAdmin(Map<String, Object> adminConfig, org.apache.kafka.clients.admin.Admin adminClient) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidbooleancreateOrFindTopic(org.apache.kafka.clients.admin.NewTopic topic) Attempt to find or create the topic described by the given definition, returning true if the topic was created or had already existed, or false if the topic did not exist and could not be created.createOrFindTopics(org.apache.kafka.clients.admin.NewTopic... topics) Attempt to create the topics described by the given definitions, returning all of the names of those topics that were created by this request.booleancreateTopic(org.apache.kafka.clients.admin.NewTopic topic) Attempt to create the topic described by the given definition, returning true if the topic was created or false if the topic already existed.createTopics(org.apache.kafka.clients.admin.NewTopic... topics) Attempt to create the topics described by the given definitions, returning all of the names of those topics that were created by this request.createTopicsWithRetry(org.apache.kafka.clients.admin.NewTopic topicDescription, long timeoutMs, long backOffMs, org.apache.kafka.common.utils.Time time) Implements a retry logic around creating topic(s) in case it'd fail due to specific type of exceptions, seeretryableTopicCreationException(ConnectException)defineTopic(String topicName) Obtain abuilderto define aNewTopic.org.apache.kafka.clients.admin.ConfigdescribeTopicConfig(String topic) Attempt to fetch the topic configuration for the given topic.describeTopicConfigs(String... topicNames) Attempt to fetch the topic configurations for the given topics.describeTopics(String... topics) Attempt to fetch the descriptions of the given topics Apache Kafka added support for describing topics in 0.10.0.0, so this method works as expected with that and later versions.endOffsets(Set<org.apache.kafka.common.TopicPartition> partitions) Fetch the most recent offset for each of the suppliedTopicPartitionobjects.static org.apache.kafka.connect.errors.ConnectExceptionretryEndOffsets(Set<org.apache.kafka.common.TopicPartition> partitions, Duration timeoutDuration, long retryBackoffMs) Fetch the most recent offset for each of the suppliedTopicPartitionobjects, and performs retry whenRetriableExceptionis thrown.topicCleanupPolicy(String topic) Get the cleanup policy for a topic.booleanverifyTopicCleanupPolicyOnlyCompact(String topic, String workerTopicConfig, String topicPurpose) Verify the named topic uses only compaction for the cleanup policy.
-
Field Details
-
EMPTY_CREATION
-
NO_PARTITIONS
public static final int NO_PARTITIONS- See Also:
-
NO_REPLICATION_FACTOR
public static final short NO_REPLICATION_FACTOR- See Also:
-
-
Constructor Details
-
LicenseTopicAdmin
Create a new topic admin component with the given configuration.Note that this will create an underlying
Admininstance which must be freed when this topic admin is no longer needed by callingclose()orclose(Duration).- Parameters:
adminConfig- the configuration for theAdmin
-
LicenseTopicAdmin
-
-
Method Details
-
defineTopic
Obtain abuilderto define aNewTopic.- Parameters:
topicName- the name of the topic- Returns:
- the
NewTopicdescription of the topic; never null
-
createTopic
public boolean createTopic(org.apache.kafka.clients.admin.NewTopic topic) Attempt to create the topic described by the given definition, returning true if the topic was created or false if the topic already existed.- Parameters:
topic- the specification of the topic- Returns:
- true if the topic was created or false if the topic already existed.
- Throws:
org.apache.kafka.connect.errors.ConnectException- if an error occurs, the operation takes too long, or the thread is interrupted while attempting to perform this operationorg.apache.kafka.common.errors.UnsupportedVersionException- if the broker does not support the necessary APIs to perform this request
-
createTopics
Attempt to create the topics described by the given definitions, returning all of the names of those topics that were created by this request. Any existing topics with the same name are unchanged, and the names of such topics are excluded from the result.If multiple topic definitions have the same topic name, the last one with that name will be used.
Apache Kafka added support for creating topics in 0.10.1.0, so this method works as expected with that and later versions. With brokers older than 0.10.1.0, this method is unable to create topics and always returns an empty set.
- Parameters:
topics- the specifications of the topics- Returns:
- the names of the topics that were created by this operation; never null but possibly empty
- Throws:
org.apache.kafka.connect.errors.ConnectException- if an error occurs, the operation takes too long, or the thread is interrupted while attempting to perform this operation
-
createTopicsWithRetry
public Set<String> createTopicsWithRetry(org.apache.kafka.clients.admin.NewTopic topicDescription, long timeoutMs, long backOffMs, org.apache.kafka.common.utils.Time time) Implements a retry logic around creating topic(s) in case it'd fail due to specific type of exceptions, seeretryableTopicCreationException(ConnectException)- Parameters:
topicDescription- the specifications of the topictimeoutMs- Timeout in millisecondsbackOffMs- Time for delay after initial failed attempt in millisecondstime-Timeinstance- Returns:
- the names of the topics that were created by this operation; never null but possibly empty,
the same as
createTopics(NewTopic...)
-
createOrFindTopic
public boolean createOrFindTopic(org.apache.kafka.clients.admin.NewTopic topic) Attempt to find or create the topic described by the given definition, returning true if the topic was created or had already existed, or false if the topic did not exist and could not be created.- Parameters:
topic- the specification of the topic- Returns:
- true if the topic was created or existed, or false if the topic could not already existed.
- Throws:
org.apache.kafka.connect.errors.ConnectException- if an error occurs, the operation takes too long, or the thread is interrupted while attempting to perform this operationorg.apache.kafka.common.errors.UnsupportedVersionException- if the broker does not support the necessary APIs to perform this request
-
createOrFindTopics
public LicenseTopicAdmin.TopicCreationResponse createOrFindTopics(org.apache.kafka.clients.admin.NewTopic... topics) Attempt to create the topics described by the given definitions, returning all of the names of those topics that were created by this request. Any existing topics with the same name are unchanged, and the names of such topics are excluded from the result.If multiple topic definitions have the same topic name, the last one with that name will be used.
Apache Kafka added support for creating topics in 0.10.1.0, so this method works as expected with that and later versions. With brokers older than 0.10.1.0, this method is unable to create topics and always returns an empty set.
- Parameters:
topics- the specifications of the topics- Returns:
- the
LicenseTopicAdmin.TopicCreationResponsewith the names of the newly created and existing topics; never null but possibly empty - Throws:
org.apache.kafka.connect.errors.ConnectException- if an error occurs, the operation takes too long, or the thread is interrupted while attempting to perform this operation
-
describeTopics
Attempt to fetch the descriptions of the given topics Apache Kafka added support for describing topics in 0.10.0.0, so this method works as expected with that and later versions. With brokers older than 0.10.0.0, this method is unable to describe topics and always returns an empty set.- Parameters:
topics- the topics to describe- Returns:
- a map of topic names to topic descriptions of the topics that were requested; never null but possibly empty
- Throws:
org.apache.kafka.connect.errors.RetriableException- if a retriable error occurs, the operation takes too long, or the thread is interrupted while attempting to perform this operationorg.apache.kafka.connect.errors.ConnectException- if a non retriable error occurs
-
verifyTopicCleanupPolicyOnlyCompact
public boolean verifyTopicCleanupPolicyOnlyCompact(String topic, String workerTopicConfig, String topicPurpose) Verify the named topic uses only compaction for the cleanup policy.- Parameters:
topic- the name of the topicworkerTopicConfig- the name of the worker configuration that specifies the topic name- Returns:
- true if the admin client could be used to verify the topic setting, or false if the verification could not be performed, likely because the admin client principal did not have the required permissions or because the broker was older than 0.11.0.0
- Throws:
org.apache.kafka.common.config.ConfigException- if the actual topic setting did not match the required setting
-
topicCleanupPolicy
Get the cleanup policy for a topic.- Parameters:
topic- the name of the topic- Returns:
- the set of cleanup policies set for the topic; may be empty if the topic does not exist or the topic's cleanup policy could not be retrieved
-
describeTopicConfig
Attempt to fetch the topic configuration for the given topic. Apache Kafka added support for describing topic configurations in 0.11.0.0, so this method works as expected with that and later versions. With brokers older than 0.11.0.0, this method is unable get the topic configurations and always returns a null value.If the topic does not exist, a null value is returned.
- Parameters:
topic- the name of the topic for which the topic configuration should be obtained- Returns:
- the topic configuration if the topic exists, or null if the topic did not exist
- Throws:
org.apache.kafka.connect.errors.RetriableException- if a retriable error occurs, the operation takes too long, or the thread is interrupted while attempting to perform this operationorg.apache.kafka.connect.errors.ConnectException- if a non retriable error occurs
-
describeTopicConfigs
Attempt to fetch the topic configurations for the given topics. Apache Kafka added support for describing topic configurations in 0.11.0.0, so this method works as expected with that and later versions. With brokers older than 0.11.0.0, this method is unable get the topic configurations and always returns an empty set.An entry with a null Config is placed into the resulting map for any topic that does not exist on the brokers.
- Parameters:
topicNames- the topics to obtain configurations- Returns:
- the map of topic configurations for each existing topic, or an empty map if none of the topics exist
- Throws:
org.apache.kafka.connect.errors.RetriableException- if a retriable error occurs, the operation takes too long, or the thread is interrupted while attempting to perform this operationorg.apache.kafka.connect.errors.ConnectException- if a non retriable error occurs
-
endOffsets
public Map<org.apache.kafka.common.TopicPartition,Long> endOffsets(Set<org.apache.kafka.common.TopicPartition> partitions) Fetch the most recent offset for each of the suppliedTopicPartitionobjects.- Parameters:
partitions- the topic partitions- Returns:
- the map of offset for each topic partition, or an empty map if the supplied partitions are null or empty
- Throws:
org.apache.kafka.common.errors.UnsupportedVersionException- if the admin client cannot read end offsetsorg.apache.kafka.common.errors.TimeoutException- if the offset metadata could not be fetched before the amount of time allocated byrequest.timeout.msexpires, and this call can be retriedorg.apache.kafka.common.errors.LeaderNotAvailableException- if the leader was not available and this call can be retriedorg.apache.kafka.connect.errors.RetriableException- if a retriable error occurs, or the thread is interrupted while attempting to perform this operationorg.apache.kafka.connect.errors.ConnectException- if a non retriable error occurs
-
retryEndOffsets
public Map<org.apache.kafka.common.TopicPartition,Long> retryEndOffsets(Set<org.apache.kafka.common.TopicPartition> partitions, Duration timeoutDuration, long retryBackoffMs) Fetch the most recent offset for each of the suppliedTopicPartitionobjects, and performs retry whenRetriableExceptionis thrown.- Parameters:
partitions- the topic partitionstimeoutDuration- timeout duration; may not be nullretryBackoffMs- the number of milliseconds to delay upon receiving aRetriableExceptionbefore retrying again; must be 0 or more- Returns:
- the map of offset for each topic partition, or an empty map if the supplied partitions are null or empty
- Throws:
org.apache.kafka.common.errors.UnsupportedVersionException- if the broker is too old to support the admin client API to read end offsetsorg.apache.kafka.connect.errors.ConnectException- iftimeoutDurationis exhausted- See Also:
-
maybeWrap
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
close
-