Class KafkaSchemaRegistry
java.lang.Object
io.confluent.kafka.schemaregistry.storage.AbstractSchemaRegistry
io.confluent.kafka.schemaregistry.storage.KafkaSchemaRegistry
- All Implemented Interfaces:
SchemaVersionFetcher,SslFactory.SslFactoryCreated,LeaderAwareSchemaRegistry,SchemaRegistry
public class KafkaSchemaRegistry
extends AbstractSchemaRegistry
implements LeaderAwareSchemaRegistry
-
Nested Class Summary
Nested classes/interfaces inherited from class io.confluent.kafka.schemaregistry.storage.AbstractSchemaRegistry
AbstractSchemaRegistry.RawSchema, AbstractSchemaRegistry.SchemeAndPort -
Field Summary
Fields inherited from class io.confluent.kafka.schemaregistry.storage.AbstractSchemaRegistry
allowModeChanges, config, contextSearchDefaultLimit, contextSearchMaxLimit, customHandler, defaultCompatibilityLevel, defaultMode, defaultValidateFields, defaultValidateNewSchemas, initialized, lookupCache, metadataEncoder, metricsContainer, newSchemaCache, oldSchemaCache, props, providers, resourceExtensions, ruleSetHandler, schemaSearchDefaultLimit, schemaSearchMaxLimit, sslFactory, store, subjectSearchDefaultLimit, subjectSearchMaxLimit, subjectVersionSearchDefaultLimit, subjectVersionSearchMaxLimit, time, updateRequestHandlersFields inherited from interface io.confluent.kafka.schemaregistry.storage.SchemaRegistry
DEFAULT_TENANT, FIELD_CONFLICTS_WITH_RESERVED_FIELD, MAX_VERSION, MIN_VERSION, RESERVED_FIELD_REMOVED, RESOURCE_WILDCARD -
Constructor Summary
ConstructorsConstructorDescriptionKafkaSchemaRegistry(SchemaRegistryConfig config, Serializer<SchemaRegistryKey, SchemaRegistryValue> serializer) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLeaderChangeListener(Consumer<Boolean> listener) Add a leader change listener.voidclose()createAssociation(String context, boolean dryRun, AssociationCreateOrUpdateRequest request) createAssociationOrForward(String context, boolean dryRun, AssociationCreateOrUpdateRequest request, Map<String, String> headerProperties) createOrUpdateAssociation(String context, boolean dryRun, AssociationCreateOrUpdateRequest request) createOrUpdateAssociation(String context, boolean dryRun, AssociationCreateOrUpdateRequest request, boolean isCreateOnly) createOrUpdateAssociationOrForward(String context, boolean dryRun, AssociationCreateOrUpdateRequest request, Map<String, String> headerProperties) voiddeleteAssociations(String resourceId, String resourceType, List<String> associationTypes, boolean cascadeLifecycle, boolean dryRun) voiddeleteAssociationsOrForward(String subject, String resourceId, String resourceType, List<String> associationTypes, boolean cascadeLifecycle, boolean dryRun, Map<String, String> headerProperties) voiddeleteConfigOrForward(String subject, Map<String, String> headerProperties) voiddeleteContext(String delimitedContext) voiddeleteContextOrForward(Map<String, String> requestProperties, String delimitedContext) voiddeleteSchemaVersion(String subject, Schema schema, boolean permanentDelete) voiddeleteSchemaVersionOrForward(Map<String, String> headerProperties, String subject, Schema schema, boolean permanentDelete) deleteSubject(String subject, boolean permanentDelete) voiddeleteSubjectConfig(String subject) voiddeleteSubjectMode(String subject) voiddeleteSubjectMode(String subject, boolean recursive) voiddeleteSubjectModeOrForward(String subject, boolean recursive, Map<String, String> headerProperties) deleteSubjectOrForward(Map<String, String> requestProperties, String subject, boolean permanentDelete) forwardModifySchemaTagsRequestToLeader(String subject, Schema schema, TagSchemaRequest request, Map<String, String> headerProperties) getAssociationByGuid(String guid) getAssociationsByResourceId(String resourceId, String resourceType, List<String> associationTypes, LifecyclePolicy lifecycle) getAssociationsByResourceName(String resourceName, String resourceNamespace, String resourceType, List<String> associationTypes, LifecyclePolicy lifecycle) getAssociationsBySubject(String subject, String resourceType, List<String> associationTypes, LifecyclePolicy lifecycle) protected StringgetContextPrefixForDeleteMode(String context) Returns the context prefix to use for listing subjects under a given context.protected SchemaUpdateHandlerbooleanhealthy()protected IdGeneratorvoidinit()booleanbooleanisLeader()protected KafkaStore<SchemaRegistryKey,SchemaRegistryValue> kafkaStore(SchemaRegistryConfig config) Return the identity of the SchemaRegistry that this instance thinks is current leader.protected LookupCache<SchemaRegistryKey,SchemaRegistryValue> modifySchemaTagsOrForward(String subject, Schema schema, TagSchemaRequest request, Map<String, String> headerProperties) mutateAssociations(String context, boolean dryRun, AssociationBatchRequest request) mutateAssociationsOrForward(String context, boolean dryRun, AssociationBatchRequest request, Map<String, String> headerProperties) Return json data encoding basic information about this SchemaRegistry instance, such as host, port, etc.voidpostInit()Register the given schema under the given subject.registerOrForward(String subject, RegisterSchemaRequest request, boolean normalize, Map<String, String> headerProperties) voidsetLeader(SchemaRegistryIdentity newLeader) 'Inform' this SchemaRegistry instance which SchemaRegistry is the current leader.voidsetMode(String subject, ModeUpdateRequest request, boolean force) voidsetModeOrForward(String subject, ModeUpdateRequest mode, boolean force, Map<String, String> headerProperties) updateConfig(String subject, ConfigUpdateRequest config) updateConfigOrForward(String subject, ConfigUpdateRequest newConfig, Map<String, String> headerProperties) voidMethods inherited from class io.confluent.kafka.schemaregistry.storage.AbstractSchemaRegistry
addCustomHandler, addUpdateRequestHandler, allContexts, allVersionsIncludingAliasesWithSubjectPrefix, canonicalizeSchema, checkIfSchemaWithIdExist, checkRegisterMode, clearNewSchemaCache, clearOldSchemaCache, config, extractSchemaTags, get, get, getAllSchemaKeysDescending, getAllVersions, getByGuid, getCompositeUpdateRequestHandler, getConfig, getConfigInScope, getCustomHandler, getHostnameVerifier, getInterInstanceListener, getLatestVersion, getLatestWithMetadata, getLookupCache, getMetadataEncoder, getMetricsContainer, getMode, getModeInScope, getReferencedBy, getReferencedBy, getResourceExtensions, getRuleSetHandler, getSchemaValue, getSslFactory, getUsingContexts, getVersionsWithSubjectPrefix, hasSubjects, initProviders, initResourceExtensions, invalidateFromNewSchemaCache, invalidateFromOldSchemaCache, isCompatible, isCompatibleWithPrevious, isReadOnlyMode, isSchemaFieldValidationEnabled, isSchemaNewSchemaValidationEnabled, isSubjectVersionDeleted, listContexts, listIdsForGuid, listSubjects, listSubjectsForId, listSubjectsForId, listSubjectsWithPrefix, listVersionsForId, listVersionsForId, loadSchema, logSchemaOp, lookUpSchemaUnderSubject, lookUpSchemaUnderSubject, lookUpSchemaUnderSubjectUsingContexts, maybePopulateFromPrevious, maybeSetMetadataRuleSet, modifySchemaTags, normalizeContextLimit, normalizeLimit, normalizeSchemaLimit, normalizeSubjectLimit, normalizeSubjectVersionLimit, onKeystoreCreated, onTruststoreCreated, parseSchema, parseSchema, properties, register, registerProviders, removeCustomHandler, schemaProvider, schemaTypes, schemaVersionExists, setMode, setRuleSetHandler, subjects, toSchemaEntityMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.confluent.kafka.schemaregistry.storage.SchemaRegistry
deleteAssociations, getByVersion, listSubjects, lookUpSchemaUnderSubject, register, register, setTenant, tenant
-
Constructor Details
-
KafkaSchemaRegistry
public KafkaSchemaRegistry(SchemaRegistryConfig config, Serializer<SchemaRegistryKey, SchemaRegistryValue> serializer) throws SchemaRegistryException- Throws:
SchemaRegistryException
-
-
Method Details
-
kafkaStore
protected KafkaStore<SchemaRegistryKey,SchemaRegistryValue> kafkaStore(SchemaRegistryConfig config) throws SchemaRegistryException - Throws:
SchemaRegistryException
-
getSchemaUpdateHandler
-
lookupCache
-
getSerializer
-
identityGenerator
-
getIdentityGenerator
-
init
- Specified by:
initin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
postInit
- Specified by:
postInitin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
waitForInit
- Throws:
InterruptedException
-
initialized
public boolean initialized()- Specified by:
initializedin interfaceSchemaRegistry
-
healthy
public boolean healthy()- Specified by:
healthyin interfaceSchemaRegistry
-
addLeaderChangeListener
Add a leader change listener.- Specified by:
addLeaderChangeListenerin interfaceSchemaRegistry- Parameters:
listener- a function that takes whether this node is a leader
-
isLeader
public boolean isLeader()- Specified by:
isLeaderin interfaceSchemaRegistry
-
setLeader
public void setLeader(@Nullable SchemaRegistryIdentity newLeader) throws SchemaRegistryTimeoutException, SchemaRegistryStoreException, IdGenerationException 'Inform' this SchemaRegistry instance which SchemaRegistry is the current leader. If this instance is set as the new leader, ensure it is up-to-date with data in the kafka store.- Specified by:
setLeaderin interfaceLeaderAwareSchemaRegistry- Specified by:
setLeaderin interfaceSchemaRegistry- Parameters:
newLeader- Identity of the current leader. null means no leader is alive.- Throws:
SchemaRegistryTimeoutExceptionSchemaRegistryStoreExceptionIdGenerationException
-
myIdentity
Return json data encoding basic information about this SchemaRegistry instance, such as host, port, etc.- Specified by:
myIdentityin interfaceSchemaRegistry
-
leaderIdentity
Return the identity of the SchemaRegistry that this instance thinks is current leader. Any request that requires writing new data gets forwarded to the leader.- Specified by:
leaderIdentityin interfaceSchemaRegistry
-
leaderRestService
- Specified by:
leaderRestServicein interfaceSchemaRegistry
-
register
public Schema register(String subject, Schema schema, boolean normalize, boolean propagateSchemaTags) throws SchemaRegistryException Register the given schema under the given subject.If the schema already exists, it is returned. During registration, the metadata and ruleSet may be populated by the config that is in scope.
- Specified by:
registerin interfaceSchemaRegistry- Parameters:
subject- The subjectschema- The schemanormalize- Whether to normalize the schema before registration- Returns:
- A schema containing the id. If the schema is different from the input parameter, it is set in the return object.
- Throws:
SchemaRegistryException
-
registerOrForward
public Schema registerOrForward(String subject, RegisterSchemaRequest request, boolean normalize, Map<String, String> headerProperties) throws SchemaRegistryException- Specified by:
registerOrForwardin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
modifySchemaTagsOrForward
public Schema modifySchemaTagsOrForward(String subject, Schema schema, TagSchemaRequest request, Map<String, String> headerProperties) throws SchemaRegistryException- Specified by:
modifySchemaTagsOrForwardin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
deleteSchemaVersion
public void deleteSchemaVersion(String subject, Schema schema, boolean permanentDelete) throws SchemaRegistryException - Specified by:
deleteSchemaVersionin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
deleteSchemaVersionOrForward
public void deleteSchemaVersionOrForward(Map<String, String> headerProperties, String subject, Schema schema, boolean permanentDelete) throws SchemaRegistryException- Specified by:
deleteSchemaVersionOrForwardin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
deleteSubject
public List<Integer> deleteSubject(String subject, boolean permanentDelete) throws SchemaRegistryException - Specified by:
deleteSubjectin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
deleteSubjectOrForward
public List<Integer> deleteSubjectOrForward(Map<String, String> requestProperties, String subject, boolean permanentDelete) throws SchemaRegistryException- Specified by:
deleteSubjectOrForwardin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
deleteContext
- Specified by:
deleteContextin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
deleteContextOrForward
public void deleteContextOrForward(Map<String, String> requestProperties, String delimitedContext) throws SchemaRegistryException- Specified by:
deleteContextOrForwardin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
createAssociation
public AssociationResponse createAssociation(String context, boolean dryRun, AssociationCreateOrUpdateRequest request) throws SchemaRegistryException - Specified by:
createAssociationin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
createAssociationOrForward
public AssociationResponse createAssociationOrForward(String context, boolean dryRun, AssociationCreateOrUpdateRequest request, Map<String, String> headerProperties) throws SchemaRegistryException- Specified by:
createAssociationOrForwardin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
mutateAssociations
public AssociationBatchResponse mutateAssociations(String context, boolean dryRun, AssociationBatchRequest request) - Specified by:
mutateAssociationsin interfaceSchemaRegistry
-
mutateAssociationsOrForward
public AssociationBatchResponse mutateAssociationsOrForward(String context, boolean dryRun, AssociationBatchRequest request, Map<String, String> headerProperties) throws SchemaRegistryException- Specified by:
mutateAssociationsOrForwardin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
createOrUpdateAssociation
public AssociationResponse createOrUpdateAssociation(String context, boolean dryRun, AssociationCreateOrUpdateRequest request) throws SchemaRegistryException - Specified by:
createOrUpdateAssociationin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
createOrUpdateAssociation
public AssociationResponse createOrUpdateAssociation(String context, boolean dryRun, AssociationCreateOrUpdateRequest request, boolean isCreateOnly) throws SchemaRegistryException - Throws:
SchemaRegistryException
-
createOrUpdateAssociationOrForward
public AssociationResponse createOrUpdateAssociationOrForward(String context, boolean dryRun, AssociationCreateOrUpdateRequest request, Map<String, String> headerProperties) throws SchemaRegistryException- Specified by:
createOrUpdateAssociationOrForwardin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
getAssociationByGuid
- Specified by:
getAssociationByGuidin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
getAssociationsBySubject
public List<Association> getAssociationsBySubject(String subject, String resourceType, List<String> associationTypes, LifecyclePolicy lifecycle) throws SchemaRegistryException - Specified by:
getAssociationsBySubjectin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
getAssociationsByResourceId
public List<Association> getAssociationsByResourceId(String resourceId, String resourceType, List<String> associationTypes, LifecyclePolicy lifecycle) throws SchemaRegistryException - Specified by:
getAssociationsByResourceIdin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
getAssociationsByResourceName
public List<Association> getAssociationsByResourceName(String resourceName, String resourceNamespace, String resourceType, List<String> associationTypes, LifecyclePolicy lifecycle) throws SchemaRegistryException - Specified by:
getAssociationsByResourceNamein interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
deleteAssociations
public void deleteAssociations(String resourceId, String resourceType, List<String> associationTypes, boolean cascadeLifecycle, boolean dryRun) throws SchemaRegistryException - Throws:
SchemaRegistryException
-
deleteAssociationsOrForward
public void deleteAssociationsOrForward(String subject, String resourceId, String resourceType, List<String> associationTypes, boolean cascadeLifecycle, boolean dryRun, Map<String, String> headerProperties) throws SchemaRegistryException- Specified by:
deleteAssociationsOrForwardin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
forwardModifySchemaTagsRequestToLeader
public Schema forwardModifySchemaTagsRequestToLeader(String subject, Schema schema, TagSchemaRequest request, Map<String, String> headerProperties) throws SchemaRegistryRequestForwardingException -
get
public SchemaString get(int id, String subject, String format, boolean fetchMaxId) throws SchemaRegistryException - Specified by:
getin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
close
- Specified by:
closein interfaceSchemaRegistry- Throws:
IOException
-
updateConfig
public Config updateConfig(String subject, ConfigUpdateRequest config) throws SchemaRegistryStoreException, OperationNotPermittedException, UnknownLeaderException - Specified by:
updateConfigin interfaceSchemaRegistry- Throws:
SchemaRegistryStoreExceptionOperationNotPermittedExceptionUnknownLeaderException
-
updateConfigOrForward
public Config updateConfigOrForward(String subject, ConfigUpdateRequest newConfig, Map<String, String> headerProperties) throws SchemaRegistryStoreException, SchemaRegistryRequestForwardingException, UnknownLeaderException, OperationNotPermittedException- Specified by:
updateConfigOrForwardin interfaceSchemaRegistry- Throws:
SchemaRegistryStoreExceptionSchemaRegistryRequestForwardingExceptionUnknownLeaderExceptionOperationNotPermittedException
-
deleteSubjectConfig
public void deleteSubjectConfig(String subject) throws SchemaRegistryStoreException, OperationNotPermittedException - Specified by:
deleteSubjectConfigin interfaceSchemaRegistry- Throws:
SchemaRegistryStoreExceptionOperationNotPermittedException
-
deleteConfigOrForward
public void deleteConfigOrForward(String subject, Map<String, String> headerProperties) throws SchemaRegistryStoreException, SchemaRegistryRequestForwardingException, OperationNotPermittedException, UnknownLeaderException- Specified by:
deleteConfigOrForwardin interfaceSchemaRegistry- Throws:
SchemaRegistryStoreExceptionSchemaRegistryRequestForwardingExceptionOperationNotPermittedExceptionUnknownLeaderException
-
getKafkaClusterId
- Specified by:
getKafkaClusterIdin interfaceSchemaRegistry
-
getGroupId
- Specified by:
getGroupIdin interfaceSchemaRegistry
-
setMode
public void setMode(String subject, ModeUpdateRequest request, boolean force) throws SchemaRegistryException - Specified by:
setModein interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
setModeOrForward
public void setModeOrForward(String subject, ModeUpdateRequest mode, boolean force, Map<String, String> headerProperties) throws SchemaRegistryException- Specified by:
setModeOrForwardin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
deleteSubjectMode
public void deleteSubjectMode(String subject) throws SchemaRegistryStoreException, OperationNotPermittedException - Specified by:
deleteSubjectModein interfaceSchemaRegistry- Throws:
SchemaRegistryStoreExceptionOperationNotPermittedException
-
deleteSubjectMode
public void deleteSubjectMode(String subject, boolean recursive) throws SchemaRegistryStoreException, OperationNotPermittedException - Specified by:
deleteSubjectModein interfaceSchemaRegistry- Throws:
SchemaRegistryStoreExceptionOperationNotPermittedException
-
deleteSubjectModeOrForward
public void deleteSubjectModeOrForward(String subject, boolean recursive, Map<String, String> headerProperties) throws SchemaRegistryStoreException, SchemaRegistryRequestForwardingException, OperationNotPermittedException, UnknownLeaderException- Specified by:
deleteSubjectModeOrForwardin interfaceSchemaRegistry- Throws:
SchemaRegistryStoreExceptionSchemaRegistryRequestForwardingExceptionOperationNotPermittedExceptionUnknownLeaderException
-
getContextPrefixForDeleteMode
Returns the context prefix to use for listing subjects under a given context. This method can be overridden in subclasses to customize prefix computation.- Parameters:
context- The normalized context string, or null for default context- Returns:
- The subject prefix to use for matching subjects
-
getKafkaStore
- Specified by:
getKafkaStorein interfaceSchemaRegistry
-