public class LicenseManager extends Object
This manager is supplied configurations for an admin client to create the topic if necessary,
a consumer to read the contents of that topic, and a producer to store the updated license
information, if such is supplied when
registering and validating licenses.
Additional admin client configurations can be provided for Kafka clusters
that the license manager should consider when validating a license.
The next step is to read the license information from the component's configuration, or use a
blank string if the user did not provide a license, and call
registerOrValidateLicense(String) to register the new license or, if it is
blank, attempt to read a previously-stored license.
This method will thrown an InvalidLicenseException if the license is not valid or has
expired. Otherwise, a valid license exists and is returned for use by the application.
Note that the registerOrValidateLicense(String) logs information about the license,
either at WARN level if the license expires within 10 days, or at INFO level otherwise. The
message includes the type of license, the number of days until the license expires, and the
expiration date.
Finally, when the application stops, call stop() so the LicenseManager can release
any resources it might have created.
Here is an example:
// Read the license string from the application or component's configuration
String licenseStr = ...
// Start the license manager
String topicName = ...
Map<String, Object> producerConfig = ...
Map<String, Object> consumerConfig = ...
Map<String, Object> adminConfig = ...
LicenseManager licenseMgr = new LicenseManager(
producerConfig,
consumerConfig,
adminConfig);
License license = licenseMgr.registerOrValidateLicense(licenseStr);
// At some point stop the license manager
licenseMgr.stop();
| Modifier and Type | Class and Description |
|---|---|
protected static class |
LicenseManager.BasicClusterClient |
protected static interface |
LicenseManager.ClusterClient |
protected static class |
LicenseManager.LicenseChangedEvent |
static class |
LicenseManager.LicenseStatus
License status enumeration for license validation operations
|
| Modifier and Type | Field and Description |
|---|---|
protected static long |
WARN_THRESHOLD_DAYS |
| Modifier | Constructor and Description |
|---|---|
|
LicenseManager(ConfluentLicenseStore licenseStore,
String configuredLicenseStr) |
|
LicenseManager(ConfluentLicenseStore licenseStore,
String configuredLicenseStr,
LicenseAutoGenerationPolicy licenseAutoGenerationPolicy) |
|
LicenseManager(ConfluentLicenseStore licenseStore,
String configuredLicenseStr,
LicenseManagerPurpose licenseManagerPurpose) |
|
LicenseManager(ConfluentLicenseStore licenseStore,
String configuredLicenseStr,
LicenseManagerPurpose licenseManagerPurpose,
org.apache.kafka.common.utils.Time time) |
|
LicenseManager(ConfluentLicenseStore licenseStore,
String configuredLicenseStr,
LicenseManagerPurpose licenseManagerPurpose,
org.apache.kafka.common.utils.Time time,
LicenseAutoGenerationPolicy licenseAutoGenerationPolicy) |
protected |
LicenseManager(LicenseManager.ClusterClient primaryClusterClient,
LicenseStore licenseStore,
org.apache.kafka.common.utils.Time time) |
protected |
LicenseManager(LicenseManager.ClusterClient primaryClusterClient,
LicenseStore licenseStore,
org.apache.kafka.common.utils.Time time,
LicenseManagerPurpose licenseManagerPurpose) |
protected |
LicenseManager(LicenseManager.ClusterClient primaryClusterClient,
LicenseStore licenseStore,
org.apache.kafka.common.utils.Time time,
String configuredLicenseStr,
boolean startStore,
boolean allowInvalidLicenseToRun) |
protected |
LicenseManager(LicenseManager.ClusterClient primaryClusterClient,
LicenseStore licenseStore,
org.apache.kafka.common.utils.Time time,
String configuredLicenseStr,
boolean startStore,
boolean allowInvalidLicenseToRun,
LicenseManagerPurpose licenseManagerPurpose) |
|
LicenseManager(Map<String,Object> topicConfig,
LicenseStore licenseStore,
String configuredLicense,
boolean startStore) |
|
LicenseManager(Map<String,Object> topicConfig,
LicenseStore licenseStore,
String configuredLicense,
boolean startStore,
boolean allowInvalidLicenseToRun) |
|
LicenseManager(String topic,
Map<String,Object> producerConfig,
Map<String,Object> consumerConfig,
Map<String,Object> topicConfig)
Create a new license manager that uses the specified topic for licenses, configurations for an
admin client, producer, and consumer to create, write to, and read from that topic in a
primary Kafka cluster.
|
|
LicenseManager(String topic,
Map<String,Object> producerConfig,
Map<String,Object> consumerConfig,
Map<String,Object> topicConfig,
Duration topicCreateTimeout,
Duration retryBackoffMinMs,
Duration retryBackoffMaxMs) |
|
LicenseManager(String topic,
Map<String,Object> producerConfig,
Map<String,Object> consumerConfig,
Map<String,Object> topicConfig,
LicenseManagerPurpose licenseManagerPurpose) |
| Modifier and Type | Method and Description |
|---|---|
void |
addCluster(String key,
LicenseManager.ClusterClient client)
Add another Kafka cluster to be considered when validating a license.
|
void |
addCluster(String key,
Map<String,Object> adminConfig)
Add another Kafka cluster to be considered when validating a license.
|
boolean |
addListener(Consumer<LicenseChanged> listener)
Add a listener for subsequent license changes.
|
License |
configuredLicense() |
protected void |
doStart() |
protected void |
doStop() |
protected License |
generateLicense(long now) |
protected boolean |
hasOnlySingleNodeClusters() |
static PublicKey |
loadPublicKey() |
protected void |
notifyLicense(License newLicense,
License oldLicense,
List<License> finalInstalledLicense,
String reason) |
protected License |
readLicense(PublicKey publicKey,
String licenseStr,
boolean stored) |
License |
registerOrValidateAddOnLicense(String license)
Validate the supplied license, or if blank register a new trial license.
|
License |
registerOrValidateLicense(String license)
Validates a supplied CP or 'CP for CC' license and persists it in
LicenseStore. |
List<License> |
registerOrValidateMultiLicense(String license,
boolean skipTrialLicenseGeneration)
Validates a supplied CP or 'CP for CC' license, persists it in
LicenseStore. |
boolean |
removeCluster(String key)
Remove the Kafka cluster client with the specific name from being considered when validating a
license.
|
boolean |
removeListener(Consumer<LicenseChanged> listener)
Remove a previously registered license change listener.
|
void |
setSchedulingStrategy(Function<List<License>,License> selectionFunction) |
void |
start()
Begin running this license manager's check on a daily schedule, or more frequently if the
license is expired or has less than 1 day remaining.
|
void |
start(long initialDelay,
long period,
TimeUnit timeUnit)
Begin running this license manager's check with a configurable initial delay and period.
|
void |
stop()
Stop this license manager, close any resources, and remove any scheduled license checks.
|
long |
timeUntilLicenseExpirationMs() |
void |
timeUntilLicenseExpirationMs(long timeMs) |
protected static final long WARN_THRESHOLD_DAYS
public LicenseManager(String topic, Map<String,Object> producerConfig, Map<String,Object> consumerConfig, Map<String,Object> topicConfig)
topic - the name of the topic where licenses are persisted; may not be nullproducerConfig - the configuration for the producer used to write to the license topic;
may not be nullconsumerConfig - the configuration for the consumer used to read from the license topic;
may not be nulltopicConfig - the configuration for the admin client to create the license topic if
required; may not be nullpublic LicenseManager(String topic, Map<String,Object> producerConfig, Map<String,Object> consumerConfig, Map<String,Object> topicConfig, LicenseManagerPurpose licenseManagerPurpose)
public LicenseManager(String topic, Map<String,Object> producerConfig, Map<String,Object> consumerConfig, Map<String,Object> topicConfig, Duration topicCreateTimeout, Duration retryBackoffMinMs, Duration retryBackoffMaxMs)
public LicenseManager(Map<String,Object> topicConfig, LicenseStore licenseStore, String configuredLicense, boolean startStore)
public LicenseManager(Map<String,Object> topicConfig, LicenseStore licenseStore, String configuredLicense, boolean startStore, boolean allowInvalidLicenseToRun)
protected LicenseManager(LicenseManager.ClusterClient primaryClusterClient, LicenseStore licenseStore, org.apache.kafka.common.utils.Time time)
protected LicenseManager(LicenseManager.ClusterClient primaryClusterClient, LicenseStore licenseStore, org.apache.kafka.common.utils.Time time, LicenseManagerPurpose licenseManagerPurpose)
protected LicenseManager(LicenseManager.ClusterClient primaryClusterClient, LicenseStore licenseStore, org.apache.kafka.common.utils.Time time, String configuredLicenseStr, boolean startStore, boolean allowInvalidLicenseToRun)
protected LicenseManager(LicenseManager.ClusterClient primaryClusterClient, LicenseStore licenseStore, org.apache.kafka.common.utils.Time time, String configuredLicenseStr, boolean startStore, boolean allowInvalidLicenseToRun, LicenseManagerPurpose licenseManagerPurpose)
public LicenseManager(ConfluentLicenseStore licenseStore, String configuredLicenseStr)
public LicenseManager(ConfluentLicenseStore licenseStore, String configuredLicenseStr, LicenseAutoGenerationPolicy licenseAutoGenerationPolicy)
public LicenseManager(ConfluentLicenseStore licenseStore, String configuredLicenseStr, LicenseManagerPurpose licenseManagerPurpose)
public LicenseManager(ConfluentLicenseStore licenseStore, String configuredLicenseStr, LicenseManagerPurpose licenseManagerPurpose, org.apache.kafka.common.utils.Time time)
public LicenseManager(ConfluentLicenseStore licenseStore, String configuredLicenseStr, LicenseManagerPurpose licenseManagerPurpose, org.apache.kafka.common.utils.Time time, LicenseAutoGenerationPolicy licenseAutoGenerationPolicy)
public void addCluster(String key, Map<String,Object> adminConfig)
AdminClientConfig for the cluster, and the principal requires
privilege to read the cluster metadata.
This method is safe to be called whether or not the license manager is
running.
adminConfig - the admin client configurations for another Kafka clusters that should be
considered during license validation; may be null or emptypublic void addCluster(String key, LicenseManager.ClusterClient client)
LicenseManager.ClusterClient function, allowing callers to fully control
how the license manager determines the size of a cluster.
This method is safe to be called whether or not the license manager is
running.
key - the unique key for the cluster client; may not be nullclient - the cluster client function that should be used to determine the size of a
cluster during license validation; may be null or emptypublic boolean removeCluster(String key)
This method is safe to be called whether or not the license manager is
running.
public boolean addListener(Consumer<LicenseChanged> listener)
listener - the function that is to be called when license changes are detectedremoveListener(Consumer)public boolean removeListener(Consumer<LicenseChanged> listener)
listener - the function that is no longer to be called when license changes are detectedregisteredaddListener(Consumer)public void start()
This is useful for automatically detecting changes in the license and notifying the
listeners.
addListener(Consumer),
removeListener(Consumer)public void setSchedulingStrategy(Function<List<License>,License> selectionFunction)
public void start(long initialDelay,
long period,
TimeUnit timeUnit)
initialDelay - the initial delay period for the first checkperiod - the frequency of the following checkstimeUnit - the timeunit used for the initialDelay and the periodpublic void stop()
started.start()protected void doStart()
protected void doStop()
public License configuredLicense()
public License registerOrValidateAddOnLicense(String license) throws InvalidLicenseException
license - the new license string to be persisted in the topic; may be empty if there is
no updated licenseExpiredLicenseException - if the supplied or stored license has expiredInvalidLicenseException - if the supplied or stored license is not validpublic License registerOrValidateLicense(String license) throws InvalidLicenseException
LicenseStore.
If no input is provided, selects a valid stored license or generates a TRIAL/DEV CP license if allowed.
When input is provided:
- Valid CP → stored under CP if have greater expiry (does not overwrite 'CP for CC'); used as active.
- Valid 'CP for CC' → stored under 'CP for CC' if have greater expiry (does not overwrite CP); used as active.
- Invalid → throws InvalidLicenseException, which can occur due to:
- input JWT claims is invalid
- input signed JWT with invalid expiry format → falls back to stored licenses; if none active, throws InvalidLicenseException.
- Returns the valid stored CP license; otherwise the valid stored 'CP for CC' license.
When input is not provided:
- Returns the valid stored CP license; otherwise the valid stored 'CP for CC' license.
- If neither exists and no CP license was ever stored, generates and persists a TRIAL/DEV CP license, then returns it.license - CP or CP for CC license string; may be blankExpiredLicenseException - if the no active license provided and all stored licenses are expiredInvalidLicenseException - if the license is invalid or all stored licenses are invalidpublic List<License> registerOrValidateMultiLicense(String license, boolean skipTrialLicenseGeneration) throws InvalidLicenseException
LicenseStore.
and returns all active primary licenses. Optionally skips TRIAL/DEV license generation.
Verification and storage:
- Accepts CP or 'CP for CC' license; validates and stores under its scope.
- Invalid input → throws InvalidLicenseException.
- Signed JWT with invalid expiry format → falls back to stored licenses; if none active, throws InvalidLicenseException.
Trial/Dev generation:
- Generates and persists a TRIAL/DEV CP license only when skipTrialLicenseGeneration is false,
and no CP license was ever stored, and no active CP license is configured.
Return:
- Immutable list of active primary licenses: CP only, CP for CC only, or both. It will never be empty. It will throw an InvalidLicenseException if no active license found.license - CP or 'CP for CC' license; may be blankskipTrialLicenseGeneration - when true, never generates a TRIAL/DEV licenseExpiredLicenseException - if Stored CP license is expired and no other active license is available.InvalidLicenseException - if the configured license is invalid, or Stored CP license is invalid and no other active license is available.protected final License readLicense(PublicKey publicKey, String licenseStr, boolean stored) throws InvalidLicenseException
InvalidLicenseExceptionprotected License generateLicense(long now) throws InvalidLicenseException
InvalidLicenseExceptionprotected boolean hasOnlySingleNodeClusters()
protected final void notifyLicense(License newLicense, License oldLicense, List<License> finalInstalledLicense, String reason)
public static PublicKey loadPublicKey()
public void timeUntilLicenseExpirationMs(long timeMs)
public long timeUntilLicenseExpirationMs()