Search in sources :

Example 11 with StoreException

use of io.confluent.kafka.schemaregistry.storage.exceptions.StoreException in project schema-registry by confluentinc.

the class KafkaSchemaRegistry method getReferencedBy.

public List<Integer> getReferencedBy(String subject, VersionId versionId) throws SchemaRegistryException {
    try {
        int version = versionId.getVersionId();
        if (versionId.isLatest()) {
            version = getLatestVersion(subject).getVersion();
        }
        SchemaKey key = new SchemaKey(subject, version);
        List<Integer> ids = new ArrayList<>(lookupCache.referencesSchema(key));
        Collections.sort(ids);
        return ids;
    } catch (StoreException e) {
        throw new SchemaRegistryStoreException("Error from the backend Kafka store", e);
    }
}
Also used : ArrayList(java.util.ArrayList) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) StoreException(io.confluent.kafka.schemaregistry.storage.exceptions.StoreException)

Example 12 with StoreException

use of io.confluent.kafka.schemaregistry.storage.exceptions.StoreException in project schema-registry by confluentinc.

the class KafkaSchemaRegistry method deleteSchemaVersion.

@Override
public void deleteSchemaVersion(String subject, Schema schema, boolean permanentDelete) throws SchemaRegistryException {
    try {
        if (isReadOnlyMode(subject)) {
            throw new OperationNotPermittedException("Subject " + subject + " is in read-only mode");
        }
        SchemaKey key = new SchemaKey(subject, schema.getVersion());
        if (!lookupCache.referencesSchema(key).isEmpty()) {
            throw new ReferenceExistsException(key.toString());
        }
        SchemaValue schemaValue = (SchemaValue) lookupCache.get(key);
        if (permanentDelete && schemaValue != null && !schemaValue.isDeleted()) {
            throw new SchemaVersionNotSoftDeletedException(subject, schema.getVersion().toString());
        }
        // Ensure cache is up-to-date before any potential writes
        kafkaStore.waitUntilKafkaReaderReachesLastOffset(subject, kafkaStoreTimeoutMs);
        if (!permanentDelete) {
            schemaValue = new SchemaValue(schema);
            schemaValue.setDeleted(true);
            kafkaStore.put(key, schemaValue);
            if (!getAllVersions(subject, false).hasNext()) {
                if (getMode(subject) != null) {
                    deleteMode(subject);
                }
                if (getCompatibilityLevel(subject) != null) {
                    deleteCompatibility(subject);
                }
            }
        } else {
            kafkaStore.put(key, null);
        }
    } catch (StoreTimeoutException te) {
        throw new SchemaRegistryTimeoutException("Write to the Kafka store timed out while", te);
    } catch (StoreException e) {
        throw new SchemaRegistryStoreException("Error while deleting the schema for subject '" + subject + "' in the backend Kafka store", e);
    }
}
Also used : ReferenceExistsException(io.confluent.kafka.schemaregistry.exceptions.ReferenceExistsException) StoreTimeoutException(io.confluent.kafka.schemaregistry.storage.exceptions.StoreTimeoutException) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) OperationNotPermittedException(io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException) SchemaRegistryTimeoutException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryTimeoutException) SchemaVersionNotSoftDeletedException(io.confluent.kafka.schemaregistry.exceptions.SchemaVersionNotSoftDeletedException) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) StoreException(io.confluent.kafka.schemaregistry.storage.exceptions.StoreException)

Example 13 with StoreException

use of io.confluent.kafka.schemaregistry.storage.exceptions.StoreException in project schema-registry by confluentinc.

the class KafkaSchemaRegistry method deleteSubjectMode.

public void deleteSubjectMode(String subject) throws SchemaRegistryStoreException, OperationNotPermittedException {
    if (!allowModeChanges) {
        throw new OperationNotPermittedException("Mode changes are not allowed");
    }
    try {
        kafkaStore.waitUntilKafkaReaderReachesLastOffset(subject, kafkaStoreTimeoutMs);
        deleteMode(subject);
    } catch (StoreException e) {
        throw new SchemaRegistryStoreException("Failed to delete subject config value from store", e);
    }
}
Also used : SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) OperationNotPermittedException(io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) StoreException(io.confluent.kafka.schemaregistry.storage.exceptions.StoreException)

Example 14 with StoreException

use of io.confluent.kafka.schemaregistry.storage.exceptions.StoreException in project schema-registry by confluentinc.

the class KafkaSchemaRegistry method setLeader.

/**
 * '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.
 *
 * @param newLeader Identity of the current leader. null means no leader is alive.
 */
@Override
public void setLeader(@Nullable SchemaRegistryIdentity newLeader) throws SchemaRegistryTimeoutException, SchemaRegistryStoreException, IdGenerationException {
    log.debug("Setting the leader to " + newLeader);
    // Only schema registry instances eligible for leader can be set to leader
    if (newLeader != null && !newLeader.getLeaderEligibility()) {
        throw new IllegalStateException("Tried to set an ineligible node to leader: " + newLeader);
    }
    kafkaStore.leaderLock().lock();
    try {
        SchemaRegistryIdentity previousLeader = leaderIdentity;
        leaderIdentity = newLeader;
        if (leaderIdentity == null) {
            leaderRestService = null;
        } else {
            leaderRestService = new RestService(leaderIdentity.getUrl());
            if (sslFactory != null && sslFactory.sslContext() != null) {
                leaderRestService.setSslSocketFactory(sslFactory.sslContext().getSocketFactory());
                leaderRestService.setHostnameVerifier(getHostnameVerifier());
            }
        }
        if (leaderIdentity != null && !leaderIdentity.equals(previousLeader) && isLeader()) {
            // The new leader may not know the exact last offset in the Kafka log. So, mark the
            // last offset invalid here
            kafkaStore.markLastWrittenOffsetInvalid();
            // leader
            try {
                kafkaStore.waitUntilKafkaReaderReachesLastOffset(initTimeout);
            } catch (StoreException e) {
                throw new SchemaRegistryStoreException("Exception getting latest offset ", e);
            }
            idGenerator.init();
        }
        metricsContainer.getLeaderNode().set(isLeader() ? 1 : 0);
    } finally {
        kafkaStore.leaderLock().unlock();
    }
}
Also used : SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) RestService(io.confluent.kafka.schemaregistry.client.rest.RestService) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) StoreException(io.confluent.kafka.schemaregistry.storage.exceptions.StoreException)

Example 15 with StoreException

use of io.confluent.kafka.schemaregistry.storage.exceptions.StoreException in project schema-registry by confluentinc.

the class KafkaSchemaRegistry method listVersionsForId.

public List<SubjectVersion> listVersionsForId(int id, String subject, boolean lookupDeleted) throws SchemaRegistryException {
    SchemaValue schema = null;
    try {
        SchemaKey subjectVersionKey = getSchemaKeyUsingContexts(id, subject);
        if (subjectVersionKey == null) {
            return null;
        }
        schema = (SchemaValue) kafkaStore.get(subjectVersionKey);
        if (schema == null) {
            return null;
        }
        return lookupCache.schemaIdAndSubjects(new Schema(schema.getSubject(), schema.getVersion(), schema.getId(), schema.getSchemaType(), schema.getReferences().stream().map(ref -> new io.confluent.kafka.schemaregistry.client.rest.entities.SchemaReference(ref.getName(), ref.getSubject(), ref.getVersion())).collect(Collectors.toList()), schema.getSchema())).allSubjectVersions().entrySet().stream().flatMap(e -> {
            try {
                SchemaValue schemaValue = (SchemaValue) kafkaStore.get(new SchemaKey(e.getKey(), e.getValue()));
                if ((schemaValue != null && !schemaValue.isDeleted()) || lookupDeleted) {
                    return Stream.of(new SubjectVersion(e.getKey(), e.getValue()));
                } else {
                    return Stream.empty();
                }
            } catch (StoreException ex) {
                return Stream.empty();
            }
        }).collect(Collectors.toList());
    } catch (StoreException e) {
        throw new SchemaRegistryStoreException("Error while retrieving schema with id " + id + " from the backend Kafka store", e);
    }
}
Also used : IncompatibleSchemaException(io.confluent.kafka.schemaregistry.exceptions.IncompatibleSchemaException) Arrays(java.util.Arrays) LoadingCache(com.google.common.cache.LoadingCache) DEFAULT_CONTEXT(io.confluent.kafka.schemaregistry.utils.QualifiedSubject.DEFAULT_CONTEXT) IdGenerator(io.confluent.kafka.schemaregistry.id.IdGenerator) RestException(io.confluent.rest.exceptions.RestException) LoggerFactory(org.slf4j.LoggerFactory) SchemaRegistryException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryException) TimeoutException(java.util.concurrent.TimeoutException) ReferenceExistsException(io.confluent.kafka.schemaregistry.exceptions.ReferenceExistsException) AdminClient(org.apache.kafka.clients.admin.AdminClient) InvalidSchemaException(io.confluent.kafka.schemaregistry.exceptions.InvalidSchemaException) Map(java.util.Map) RestClientException(io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException) RegisterSchemaRequest(io.confluent.kafka.schemaregistry.client.rest.entities.requests.RegisterSchemaRequest) QualifiedSubject(io.confluent.kafka.schemaregistry.utils.QualifiedSubject) URI(java.net.URI) IncrementalIdGenerator(io.confluent.kafka.schemaregistry.id.IncrementalIdGenerator) KafkaGroupLeaderElector(io.confluent.kafka.schemaregistry.leaderelector.kafka.KafkaGroupLeaderElector) SchemaRegistryConfig(io.confluent.kafka.schemaregistry.rest.SchemaRegistryConfig) HostnameVerifier(javax.net.ssl.HostnameVerifier) ConfigDef(org.apache.kafka.common.config.ConfigDef) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) ModeUpdateRequest(io.confluent.kafka.schemaregistry.client.rest.entities.requests.ModeUpdateRequest) StoreTimeoutException(io.confluent.kafka.schemaregistry.storage.exceptions.StoreTimeoutException) UnknownLeaderException(io.confluent.kafka.schemaregistry.exceptions.UnknownLeaderException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MetricsContainer(io.confluent.kafka.schemaregistry.metrics.MetricsContainer) Set(java.util.Set) SubjectVersion(io.confluent.kafka.schemaregistry.client.rest.entities.SubjectVersion) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) Serializer(io.confluent.kafka.schemaregistry.storage.serialization.Serializer) Collectors(java.util.stream.Collectors) CONTEXT_WILDCARD(io.confluent.kafka.schemaregistry.utils.QualifiedSubject.CONTEXT_WILDCARD) CacheLoader(com.google.common.cache.CacheLoader) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) StoreException(io.confluent.kafka.schemaregistry.storage.exceptions.StoreException) ConfigUpdateRequest(io.confluent.kafka.schemaregistry.client.rest.entities.requests.ConfigUpdateRequest) CacheBuilder(com.google.common.cache.CacheBuilder) RestService(io.confluent.kafka.schemaregistry.client.rest.RestService) ProtobufSchemaProvider(io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider) SchemaString(io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString) HashMap(java.util.HashMap) Application(io.confluent.rest.Application) Schema(io.confluent.kafka.schemaregistry.client.rest.entities.Schema) AvroSchema(io.confluent.kafka.schemaregistry.avro.AvroSchema) OperationNotPermittedException(io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException) ArrayList(java.util.ArrayList) SchemaVersionNotSoftDeletedException(io.confluent.kafka.schemaregistry.exceptions.SchemaVersionNotSoftDeletedException) CompatibilityLevel(io.confluent.kafka.schemaregistry.CompatibilityLevel) SchemaProvider(io.confluent.kafka.schemaregistry.SchemaProvider) CONTEXT_DELIMITER(io.confluent.kafka.schemaregistry.utils.QualifiedSubject.CONTEXT_DELIMITER) RestConfig(io.confluent.rest.RestConfig) JsonSchemaProvider(io.confluent.kafka.schemaregistry.json.JsonSchemaProvider) LinkedHashSet(java.util.LinkedHashSet) IdGenerationException(io.confluent.kafka.schemaregistry.exceptions.IdGenerationException) VersionId(io.confluent.kafka.schemaregistry.rest.VersionId) CONTEXT_PREFIX(io.confluent.kafka.schemaregistry.utils.QualifiedSubject.CONTEXT_PREFIX) SchemaRegistryTimeoutException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryTimeoutException) SubjectNotSoftDeletedException(io.confluent.kafka.schemaregistry.exceptions.SubjectNotSoftDeletedException) UrlList(io.confluent.kafka.schemaregistry.client.rest.utils.UrlList) Logger(org.slf4j.Logger) Properties(java.util.Properties) Iterator(java.util.Iterator) AdminClientConfig(org.apache.kafka.clients.admin.AdminClientConfig) AvroSchemaProvider(io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider) IOException(java.io.IOException) IdDoesNotMatchException(io.confluent.kafka.schemaregistry.exceptions.IdDoesNotMatchException) SchemaRegistryInitializationException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryInitializationException) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Nullable(org.apache.avro.reflect.Nullable) StoreInitializationException(io.confluent.kafka.schemaregistry.storage.exceptions.StoreInitializationException) SchemaRegistryRequestForwardingException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException) Collections(java.util.Collections) SslFactory(io.confluent.kafka.schemaregistry.client.security.SslFactory) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) Schema(io.confluent.kafka.schemaregistry.client.rest.entities.Schema) AvroSchema(io.confluent.kafka.schemaregistry.avro.AvroSchema) SubjectVersion(io.confluent.kafka.schemaregistry.client.rest.entities.SubjectVersion) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) StoreException(io.confluent.kafka.schemaregistry.storage.exceptions.StoreException)

Aggregations

StoreException (io.confluent.kafka.schemaregistry.storage.exceptions.StoreException)22 SchemaRegistryStoreException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException)16 OperationNotPermittedException (io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException)7 StoreTimeoutException (io.confluent.kafka.schemaregistry.storage.exceptions.StoreTimeoutException)7 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)5 SchemaString (io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString)4 SchemaRegistryTimeoutException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryTimeoutException)4 ArrayList (java.util.ArrayList)4 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)3 Schema (io.confluent.kafka.schemaregistry.client.rest.entities.Schema)3 ReferenceExistsException (io.confluent.kafka.schemaregistry.exceptions.ReferenceExistsException)3 StoreInitializationException (io.confluent.kafka.schemaregistry.storage.exceptions.StoreInitializationException)3 ExecutionException (java.util.concurrent.ExecutionException)3 TimeoutException (java.util.concurrent.TimeoutException)3 SchemaProvider (io.confluent.kafka.schemaregistry.SchemaProvider)2 RestService (io.confluent.kafka.schemaregistry.client.rest.RestService)2 IdDoesNotMatchException (io.confluent.kafka.schemaregistry.exceptions.IdDoesNotMatchException)2 IncompatibleSchemaException (io.confluent.kafka.schemaregistry.exceptions.IncompatibleSchemaException)2 SchemaRegistryException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryException)2 SchemaVersionNotSoftDeletedException (io.confluent.kafka.schemaregistry.exceptions.SchemaVersionNotSoftDeletedException)2