Class AbstractSchemaRegistry
java.lang.Object
io.confluent.kafka.schemaregistry.storage.AbstractSchemaRegistry
- All Implemented Interfaces:
SchemaVersionFetcher,SslFactory.SslFactoryCreated,SchemaRegistry
- Direct Known Subclasses:
KafkaSchemaRegistry
public abstract class AbstractSchemaRegistry
extends Object
implements SchemaRegistry, SslFactory.SslFactoryCreated
Abstract base class for SchemaRegistry implementations that provides common state management
and shared functionality.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classInternal class representing a raw schema with parsing options.static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanprotected final SchemaRegistryConfigprotected final intprotected final intprotected final List<org.eclipse.jetty.server.Handler.Singleton>protected final CompatibilityLevelprotected final Modeprotected final booleanprotected final booleanprotected final AtomicBooleanprotected LookupCache<SchemaRegistryKey,SchemaRegistryValue> protected MetadataEncoderServiceprotected final MetricsContainerprotected final com.github.benmanes.caffeine.cache.LoadingCache<AbstractSchemaRegistry.RawSchema,ParsedSchema> protected final com.github.benmanes.caffeine.cache.LoadingCache<AbstractSchemaRegistry.RawSchema,ParsedSchema> protected final Map<String,SchemaProvider> protected final List<SchemaRegistryResourceExtension>protected RuleSetHandlerprotected final intprotected final intprotected final SslFactoryprotected Store<SchemaRegistryKey,SchemaRegistryValue> protected final intprotected final intprotected final intprotected final intprotected final org.apache.kafka.common.utils.Timeprotected final List<UpdateRequestHandler>Fields 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
ConstructorsModifierConstructorDescriptionprotectedAbstractSchemaRegistry(SchemaRegistryConfig config, MetricsContainer metricsContainer) Constructs an AbstractSchemaRegistry with the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCustomHandler(org.eclipse.jetty.server.Handler.Singleton handler) voidaddUpdateRequestHandler(UpdateRequestHandler updateRequestHandler) protected CloseableIterator<SchemaRegistryValue>allVersionsIncludingAliasesWithSubjectPrefix(String prefix, LookupFilter filter, boolean returnLatestOnly, Predicate<Schema> postFilter) protected ParsedSchemacanonicalizeSchema(Schema schema, Config config, boolean isNew, boolean normalize) voidcheckIfSchemaWithIdExist(int id, Schema schema) protected voidcheckRegisterMode(String subject, Schema schema) voidvoidconfig()voidextractSchemaTags(Schema schema, List<String> tags) getAllSchemaKeysDescending(String subject) getAllVersions(String subject, LookupFilter filter) getConfigInScope(String subject) List<org.eclipse.jetty.server.Handler.Singleton>static io.confluent.rest.NamedURIgetInterInstanceListener(List<io.confluent.rest.NamedURI> listeners, String interInstanceListenerName, String requestedScheme) This method returns a listener to be used for inter-instance communication.getLatestVersion(String subject) getLatestWithMetadata(String subject, Map<String, String> metadata, boolean lookupDeletedSchema) getModeInScope(String subject) getReferencedBy(SchemaKey key, boolean lookupDeletedSchema) getReferencedBy(String subject, VersionId versionId, boolean lookupDeletedSchema) getSchemaValue(SchemaKey key) getUsingContexts(String subject, int version, boolean returnDeletedSchema) getVersionsWithSubjectPrefix(String prefix, boolean includeAliases, LookupFilter filter, boolean returnLatestOnly, Predicate<Schema> postFilter) booleanhasSubjects(String subject, boolean lookupDeletedSubjects) protected Map<String,SchemaProvider> protected List<SchemaRegistryResourceExtension>voidinvalidateFromNewSchemaCache(Schema schemaKey) protected voidinvalidateFromOldSchemaCache(Schema schemaKey) isCompatible(String subject, Schema newSchema, List<SchemaKey> previousSchemas, boolean normalize) isCompatibleWithPrevious(Config config, ParsedSchema parsedSchema, List<ParsedSchemaHolder> previousSchemas) protected booleanisReadOnlyMode(String subject) protected booleanisSchemaFieldValidationEnabled(Config config) protected booleanprotected booleanisSubjectVersionDeleted(String subject, int version) listIdsForGuid(String guid) listSubjects(LookupFilter filter) listSubjectsForId(int id, String subject) listSubjectsForId(int id, String subject, boolean returnDeleted) listSubjectsWithPrefix(String prefix, LookupFilter filter) listVersionsForId(int id, String subject) listVersionsForId(int id, String subject, boolean lookupDeleted) protected ParsedSchemaloadSchema(Schema schema, boolean isNew, boolean normalize) Loads a schema from the cache or parses it if not cached.protected voidlogSchemaOp(Schema schema, String operation) protected SchemalookUpSchemaUnderSubject(Config config, String subject, Schema schema, boolean normalize, boolean lookupDeletedSchema, boolean lookupLatestOnly) lookUpSchemaUnderSubject(String subject, Schema schema, boolean normalize, boolean lookupDeletedSchema) Checks if given schema was ever registered under a subject.lookUpSchemaUnderSubjectUsingContexts(String subject, Schema schema, boolean normalize, boolean lookupDeletedSchema) protected booleanmaybePopulateFromPrevious(Config config, Schema schema, List<ParsedSchemaHolder> undeletedVersions, int newVersion, boolean propagateSchemaTags) protected booleanmaybeSetMetadataRuleSet(Config config, Schema schema, Schema previousSchema, Integer newVersion) modifySchemaTags(String subject, Schema schema, TagSchemaRequest request) intnormalizeContextLimit(int suppliedLimit) intnormalizeLimit(int suppliedLimit, int defaultLimit, int maxLimit) intnormalizeSchemaLimit(int suppliedLimit) intnormalizeSubjectLimit(int suppliedLimit) intnormalizeSubjectVersionLimit(int suppliedLimit) voidonKeystoreCreated(KeyStore keystore) voidonTruststoreCreated(KeyStore truststore) parseSchema(Schema schema) parseSchema(Schema schema, boolean isNew, boolean normalize) register(String subject, RegisterSchemaRequest request, boolean normalize) protected voidregisterProviders(Map<String, SchemaProvider> providerMap, List<SchemaProvider> schemaProviders) voidremoveCustomHandler(org.eclipse.jetty.server.Handler.Singleton handler) schemaProvider(String schemaType) booleanschemaVersionExists(String subject, VersionId versionId, boolean returnDeletedSchema) voidsetMode(String subject, ModeUpdateRequest mode) voidsetRuleSetHandler(RuleSetHandler ruleSetHandler) toSchemaEntity(SchemaValue schemaValue) Methods 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
addLeaderChangeListener, close, createAssociation, createAssociationOrForward, createOrUpdateAssociation, createOrUpdateAssociationOrForward, deleteAssociations, deleteAssociationsOrForward, deleteConfigOrForward, deleteContext, deleteContextOrForward, deleteSchemaVersion, deleteSchemaVersionOrForward, deleteSubject, deleteSubjectConfig, deleteSubjectMode, deleteSubjectMode, deleteSubjectModeOrForward, deleteSubjectOrForward, get, getAssociationByGuid, getAssociationsByResourceId, getAssociationsByResourceName, getAssociationsBySubject, getByVersion, getGroupId, getKafkaClusterId, getKafkaStore, healthy, init, initialized, isLeader, leaderIdentity, leaderRestService, listSubjects, lookUpSchemaUnderSubject, modifySchemaTagsOrForward, mutateAssociations, mutateAssociationsOrForward, myIdentity, postInit, register, register, register, registerOrForward, setLeader, setMode, setModeOrForward, setTenant, tenant, updateConfig, updateConfigOrForward
-
Field Details
-
store
-
config
-
props
-
metricsContainer
-
providers
-
resourceExtensions
-
customHandler
-
updateRequestHandlers
-
sslFactory
-
newSchemaCache
protected final com.github.benmanes.caffeine.cache.LoadingCache<AbstractSchemaRegistry.RawSchema,ParsedSchema> newSchemaCache -
oldSchemaCache
protected final com.github.benmanes.caffeine.cache.LoadingCache<AbstractSchemaRegistry.RawSchema,ParsedSchema> oldSchemaCache -
defaultCompatibilityLevel
-
defaultValidateFields
protected final boolean defaultValidateFields -
defaultValidateNewSchemas
protected final boolean defaultValidateNewSchemas -
defaultMode
-
schemaSearchDefaultLimit
protected final int schemaSearchDefaultLimit -
schemaSearchMaxLimit
protected final int schemaSearchMaxLimit -
subjectVersionSearchDefaultLimit
protected final int subjectVersionSearchDefaultLimit -
subjectVersionSearchMaxLimit
protected final int subjectVersionSearchMaxLimit -
subjectSearchDefaultLimit
protected final int subjectSearchDefaultLimit -
contextSearchMaxLimit
protected final int contextSearchMaxLimit -
contextSearchDefaultLimit
protected final int contextSearchDefaultLimit -
subjectSearchMaxLimit
protected final int subjectSearchMaxLimit -
allowModeChanges
protected final boolean allowModeChanges -
initialized
-
time
protected final org.apache.kafka.common.utils.Time time -
lookupCache
-
metadataEncoder
-
ruleSetHandler
-
-
Constructor Details
-
AbstractSchemaRegistry
protected AbstractSchemaRegistry(SchemaRegistryConfig config, MetricsContainer metricsContainer) throws SchemaRegistryException Constructs an AbstractSchemaRegistry with the given configuration.- Parameters:
config- the schema registry configurationmetricsContainer- the metrics container for tracking metrics- Throws:
SchemaRegistryException
-
-
Method Details
-
initResourceExtensions
-
getInterInstanceListener
public static io.confluent.rest.NamedURI getInterInstanceListener(List<io.confluent.rest.NamedURI> listeners, String interInstanceListenerName, String requestedScheme) throws SchemaRegistryException This method returns a listener to be used for inter-instance communication. It iterates through the list of listeners until it finds one whose name matches the inter.instance.listener.name config. If no such listener is found, it returns the last listener matching the requested scheme.
When there is no matching named listener, in theory, any port from any listener would be sufficient. Choosing the last, instead of say the first, is arbitrary. The port used by this listener also forms the identity of the schema registry instance along with the host name.
- Throws:
SchemaRegistryException
-
initProviders
-
registerProviders
protected void registerProviders(Map<String, SchemaProvider> providerMap, List<SchemaProvider> schemaProviders) -
loadSchema
protected ParsedSchema loadSchema(Schema schema, boolean isNew, boolean normalize) throws InvalidSchemaException Loads a schema from the cache or parses it if not cached.- Throws:
InvalidSchemaException
-
register
public Schema register(String subject, RegisterSchemaRequest request, boolean normalize) throws SchemaRegistryException - Throws:
SchemaRegistryException
-
isReadOnlyMode
- Throws:
SchemaRegistryStoreException
-
checkRegisterMode
protected void checkRegisterMode(String subject, Schema schema) throws OperationNotPermittedException, SchemaRegistryStoreException -
maybeSetMetadataRuleSet
-
maybePopulateFromPrevious
protected boolean maybePopulateFromPrevious(Config config, Schema schema, List<ParsedSchemaHolder> undeletedVersions, int newVersion, boolean propagateSchemaTags) throws SchemaRegistryException - Throws:
SchemaRegistryException
-
modifySchemaTags
public Schema modifySchemaTags(String subject, Schema schema, TagSchemaRequest request) throws SchemaRegistryException - Throws:
SchemaRegistryException
-
logSchemaOp
-
isSchemaFieldValidationEnabled
-
isSchemaNewSchemaValidationEnabled
-
canonicalizeSchema
protected ParsedSchema canonicalizeSchema(Schema schema, Config config, boolean isNew, boolean normalize) throws InvalidSchemaException - Throws:
InvalidSchemaException
-
isSubjectVersionDeleted
protected boolean isSubjectVersionDeleted(String subject, int version) throws SchemaRegistryException - Throws:
SchemaRegistryException
-
getAllSchemaKeysDescending
- Throws:
SchemaRegistryException
-
lookUpSchemaUnderSubject
protected Schema lookUpSchemaUnderSubject(Config config, String subject, Schema schema, boolean normalize, boolean lookupDeletedSchema, boolean lookupLatestOnly) throws SchemaRegistryException - Throws:
SchemaRegistryException
-
lookUpSchemaUnderSubject
public Schema lookUpSchemaUnderSubject(String subject, Schema schema, boolean normalize, boolean lookupDeletedSchema) throws SchemaRegistryException Checks if given schema was ever registered under a subject. If found, it returns the version of the schema under the subject. If not, returns -1- Specified by:
lookUpSchemaUnderSubjectin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
checkIfSchemaWithIdExist
public void checkIfSchemaWithIdExist(int id, Schema schema) throws SchemaRegistryException, StoreException -
allContexts
- Throws:
SchemaRegistryException
-
listVersionsForId
public List<SubjectVersion> listVersionsForId(int id, String subject) throws SchemaRegistryException - Throws:
SchemaRegistryException
-
listVersionsForId
public List<SubjectVersion> listVersionsForId(int id, String subject, boolean lookupDeleted) throws SchemaRegistryException - Specified by:
listVersionsForIdin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
allVersionsIncludingAliasesWithSubjectPrefix
public Iterator<ExtendedSchema> allVersionsIncludingAliasesWithSubjectPrefix(String prefix, LookupFilter filter, boolean returnLatestOnly, Predicate<Schema> postFilter) throws SchemaRegistryException - Throws:
SchemaRegistryException
-
isCompatibleWithPrevious
protected List<String> isCompatibleWithPrevious(Config config, ParsedSchema parsedSchema, List<ParsedSchemaHolder> previousSchemas) -
removeCustomHandler
public void removeCustomHandler(org.eclipse.jetty.server.Handler.Singleton handler) -
normalizeLimit
public int normalizeLimit(int suppliedLimit, int defaultLimit, int maxLimit) -
clearNewSchemaCache
public void clearNewSchemaCache()- Specified by:
clearNewSchemaCachein interfaceSchemaRegistry
-
clearOldSchemaCache
public void clearOldSchemaCache()- Specified by:
clearOldSchemaCachein interfaceSchemaRegistry
-
invalidateFromNewSchemaCache
- Specified by:
invalidateFromNewSchemaCachein interfaceSchemaRegistry
-
invalidateFromOldSchemaCache
-
normalizeSchemaLimit
public int normalizeSchemaLimit(int suppliedLimit) - Specified by:
normalizeSchemaLimitin interfaceSchemaRegistry
-
normalizeSubjectLimit
public int normalizeSubjectLimit(int suppliedLimit) - Specified by:
normalizeSubjectLimitin interfaceSchemaRegistry
-
normalizeContextLimit
public int normalizeContextLimit(int suppliedLimit) - Specified by:
normalizeContextLimitin interfaceSchemaRegistry
-
normalizeSubjectVersionLimit
public int normalizeSubjectVersionLimit(int suppliedLimit) - Specified by:
normalizeSubjectVersionLimitin interfaceSchemaRegistry
-
getHostnameVerifier
- Specified by:
getHostnameVerifierin interfaceSchemaRegistry- Throws:
SchemaRegistryStoreException
-
get
- Specified by:
getin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
get
public Schema get(String subject, int version, boolean returnDeletedSchema) throws SchemaRegistryException - Specified by:
getin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
setMode
- Specified by:
setModein interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
getModeInScope
- Specified by:
getModeInScopein interfaceSchemaRegistry- Throws:
SchemaRegistryStoreException
-
getMode
- Specified by:
getModein interfaceSchemaRegistry- Throws:
SchemaRegistryStoreException
-
isCompatible
public List<String> isCompatible(String subject, Schema newSchema, List<SchemaKey> previousSchemas, boolean normalize) throws SchemaRegistryException - Specified by:
isCompatiblein interfaceSchemaRegistry- Parameters:
previousSchemas- Full schema history in chronological order- Throws:
SchemaRegistryException
-
getConfigInScope
- Specified by:
getConfigInScopein interfaceSchemaRegistry- Throws:
SchemaRegistryStoreException
-
getConfig
- Specified by:
getConfigin interfaceSchemaRegistry- Throws:
SchemaRegistryStoreException
-
getLatestVersion
- Specified by:
getLatestVersionin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
getVersionsWithSubjectPrefix
public Iterator<ExtendedSchema> getVersionsWithSubjectPrefix(String prefix, boolean includeAliases, LookupFilter filter, boolean returnLatestOnly, Predicate<Schema> postFilter) throws SchemaRegistryException - Specified by:
getVersionsWithSubjectPrefixin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
getAllVersions
public Iterator<SchemaKey> getAllVersions(String subject, LookupFilter filter) throws SchemaRegistryException - Specified by:
getAllVersionsin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
hasSubjects
public boolean hasSubjects(String subject, boolean lookupDeletedSubjects) throws SchemaRegistryStoreException - Specified by:
hasSubjectsin interfaceSchemaRegistry- Throws:
SchemaRegistryStoreException
-
subjects
public Set<String> subjects(String subject, boolean lookupDeletedSubjects) throws SchemaRegistryStoreException - Specified by:
subjectsin interfaceSchemaRegistry- Throws:
SchemaRegistryStoreException
-
listSubjectsForId
public Set<String> listSubjectsForId(int id, String subject, boolean returnDeleted) throws SchemaRegistryException - Specified by:
listSubjectsForIdin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
listSubjectsForId
- Specified by:
listSubjectsForIdin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
listContexts
- Specified by:
listContextsin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
listSubjectsWithPrefix
public Set<String> listSubjectsWithPrefix(String prefix, LookupFilter filter) throws SchemaRegistryException - Specified by:
listSubjectsWithPrefixin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
listSubjects
- Specified by:
listSubjectsin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
getReferencedBy
public List<ContextId> getReferencedBy(String subject, VersionId versionId, boolean lookupDeletedSchema) throws SchemaRegistryException - Specified by:
getReferencedByin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
getReferencedBy
protected Set<ContextId> getReferencedBy(SchemaKey key, boolean lookupDeletedSchema) throws StoreException, SchemaRegistryException -
listIdsForGuid
- Specified by:
listIdsForGuidin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
getByGuid
- Specified by:
getByGuidin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
getSchemaValue
- Specified by:
getSchemaValuein interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
toSchemaEntity
- Specified by:
toSchemaEntityin interfaceSchemaRegistry- Throws:
SchemaRegistryStoreException
-
schemaVersionExists
public boolean schemaVersionExists(String subject, VersionId versionId, boolean returnDeletedSchema) throws SchemaRegistryException - Specified by:
schemaVersionExistsin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
getUsingContexts
public Schema getUsingContexts(String subject, int version, boolean returnDeletedSchema) throws SchemaRegistryException - Specified by:
getUsingContextsin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
parseSchema
public ParsedSchema parseSchema(Schema schema, boolean isNew, boolean normalize) throws InvalidSchemaException - Specified by:
parseSchemain interfaceSchemaRegistry- Throws:
InvalidSchemaException
-
parseSchema
- Specified by:
parseSchemain interfaceSchemaRegistry- Throws:
InvalidSchemaException
-
extractSchemaTags
- Specified by:
extractSchemaTagsin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
lookUpSchemaUnderSubjectUsingContexts
public Schema lookUpSchemaUnderSubjectUsingContexts(String subject, Schema schema, boolean normalize, boolean lookupDeletedSchema) throws SchemaRegistryException - Specified by:
lookUpSchemaUnderSubjectUsingContextsin interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
getLatestWithMetadata
public Schema getLatestWithMetadata(String subject, Map<String, String> metadata, boolean lookupDeletedSchema) throws SchemaRegistryException- Specified by:
getLatestWithMetadatain interfaceSchemaRegistry- Throws:
SchemaRegistryException
-
getLookupCache
- Specified by:
getLookupCachein interfaceSchemaRegistry
-
schemaTypes
- Specified by:
schemaTypesin interfaceSchemaRegistry
-
config
- Specified by:
configin interfaceSchemaRegistry
-
properties
- Specified by:
propertiesin interfaceSchemaRegistry
-
getMetadataEncoder
- Specified by:
getMetadataEncoderin interfaceSchemaRegistry
-
addUpdateRequestHandler
- Specified by:
addUpdateRequestHandlerin interfaceSchemaRegistry
-
getCompositeUpdateRequestHandler
- Specified by:
getCompositeUpdateRequestHandlerin interfaceSchemaRegistry
-
getCustomHandler
- Specified by:
getCustomHandlerin interfaceSchemaRegistry
-
addCustomHandler
public void addCustomHandler(org.eclipse.jetty.server.Handler.Singleton handler) - Specified by:
addCustomHandlerin interfaceSchemaRegistry
-
getMetricsContainer
- Specified by:
getMetricsContainerin interfaceSchemaRegistry
-
getResourceExtensions
- Specified by:
getResourceExtensionsin interfaceSchemaRegistry
-
schemaProvider
- Specified by:
schemaProviderin interfaceSchemaRegistry
-
getRuleSetHandler
- Specified by:
getRuleSetHandlerin interfaceSchemaRegistry
-
setRuleSetHandler
- Specified by:
setRuleSetHandlerin interfaceSchemaRegistry
-
getSslFactory
- Specified by:
getSslFactoryin interfaceSchemaRegistry
-
onKeystoreCreated
- Specified by:
onKeystoreCreatedin interfaceSslFactory.SslFactoryCreated
-
onTruststoreCreated
- Specified by:
onTruststoreCreatedin interfaceSslFactory.SslFactoryCreated
-