Search in sources :

Example 36 with SchemaRegistryStoreException

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

the class SubjectVersionsResource method getSchemaByVersion.

@GET
@Path("/{version}")
@PerformanceMetric("subjects.versions.get-schema")
@Operation(summary = "Get a specific version of the schema registered under this subject.", responses = { @ApiResponse(responseCode = "404", description = "Error code 40401 -- Subject not found\n" + "Error code 40402 -- Version not found"), @ApiResponse(responseCode = "422", description = "Error code 42202 -- Invalid version"), @ApiResponse(responseCode = "500", description = "Error code 50001 -- Error in the " + "backend data store") })
public Schema getSchemaByVersion(@Parameter(description = "Name of the subject", required = true) @PathParam("subject") String subject, @Parameter(description = VERSION_PARAM_DESC, required = true) @PathParam("version") String version, @Parameter(description = "Whether to include deleted schema") @QueryParam("deleted") boolean lookupDeletedSchema) {
    subject = QualifiedSubject.normalize(schemaRegistry.tenant(), subject);
    VersionId versionId;
    try {
        versionId = new VersionId(version);
    } catch (InvalidVersionException e) {
        throw Errors.invalidVersionException(e.getMessage());
    }
    Schema schema;
    String errorMessage = "Error while retrieving schema for subject " + subject + " with version " + version + " from the schema registry";
    try {
        schema = schemaRegistry.getUsingContexts(subject, versionId.getVersionId(), lookupDeletedSchema);
        if (schema == null) {
            if (!schemaRegistry.hasSubjects(subject, lookupDeletedSchema)) {
                throw Errors.subjectNotFoundException(subject);
            } else {
                throw Errors.versionNotFoundException(versionId.getVersionId());
            }
        }
    } catch (SchemaRegistryStoreException e) {
        log.debug(errorMessage, e);
        throw Errors.storeException(errorMessage, e);
    } catch (InvalidVersionException e) {
        throw Errors.invalidVersionException(e.getMessage());
    } catch (SchemaRegistryException e) {
        throw Errors.schemaRegistryException(errorMessage, e);
    }
    return schema;
}
Also used : VersionId(io.confluent.kafka.schemaregistry.rest.VersionId) InvalidVersionException(io.confluent.kafka.schemaregistry.exceptions.InvalidVersionException) Schema(io.confluent.kafka.schemaregistry.client.rest.entities.Schema) AvroSchema(io.confluent.kafka.schemaregistry.avro.AvroSchema) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) SchemaRegistryException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryException) Path(javax.ws.rs.Path) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Example 37 with SchemaRegistryStoreException

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

the class SubjectVersionsResource method listVersions.

@GET
@PerformanceMetric("subjects.versions.list")
@Operation(summary = "Get a list of versions registered under the specified subject.", responses = { @ApiResponse(responseCode = "404", description = "Error code 40401 -- Subject not found"), @ApiResponse(responseCode = "500", description = "Error code 50001 -- Error in the backend data store") })
public List<Integer> listVersions(@Parameter(description = "Name of the subject", required = true) @PathParam("subject") String subject, @Parameter(description = "Whether to include deleted schemas") @QueryParam("deleted") boolean lookupDeletedSchema) {
    subject = QualifiedSubject.normalize(schemaRegistry.tenant(), subject);
    // check if subject exists. If not, throw 404
    Iterator<Schema> allSchemasForThisTopic;
    List<Integer> allVersions = new ArrayList<>();
    String errorMessage = "Error while validating that subject " + subject + " exists in the registry";
    try {
        if (!schemaRegistry.hasSubjects(subject, lookupDeletedSchema)) {
            throw Errors.subjectNotFoundException(subject);
        }
    } catch (SchemaRegistryStoreException e) {
        throw Errors.storeException(errorMessage, e);
    } catch (SchemaRegistryException e) {
        throw Errors.schemaRegistryException(errorMessage, e);
    }
    errorMessage = "Error while listing all versions for subject " + subject;
    try {
        allSchemasForThisTopic = schemaRegistry.getAllVersions(subject, lookupDeletedSchema);
    } catch (SchemaRegistryStoreException e) {
        throw Errors.storeException(errorMessage, e);
    } catch (SchemaRegistryException e) {
        throw Errors.schemaRegistryException(errorMessage, e);
    }
    while (allSchemasForThisTopic.hasNext()) {
        Schema schema = allSchemasForThisTopic.next();
        allVersions.add(schema.getVersion());
    }
    return allVersions;
}
Also used : Schema(io.confluent.kafka.schemaregistry.client.rest.entities.Schema) AvroSchema(io.confluent.kafka.schemaregistry.avro.AvroSchema) ArrayList(java.util.ArrayList) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) SchemaRegistryException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryException) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

SchemaRegistryStoreException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException)37 Operation (io.swagger.v3.oas.annotations.Operation)19 StoreException (io.confluent.kafka.schemaregistry.storage.exceptions.StoreException)16 OperationNotPermittedException (io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException)14 Path (javax.ws.rs.Path)13 SchemaRegistryException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryException)12 Schema (io.confluent.kafka.schemaregistry.client.rest.entities.Schema)11 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)10 SchemaRegistryRequestForwardingException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException)9 UnknownLeaderException (io.confluent.kafka.schemaregistry.exceptions.UnknownLeaderException)9 GET (javax.ws.rs.GET)9 SchemaString (io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString)8 SchemaRegistryTimeoutException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryTimeoutException)8 PerformanceMetric (io.confluent.rest.annotations.PerformanceMetric)8 ArrayList (java.util.ArrayList)8 CompatibilityLevel (io.confluent.kafka.schemaregistry.CompatibilityLevel)7 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)5 VersionId (io.confluent.kafka.schemaregistry.rest.VersionId)5 Config (io.confluent.kafka.schemaregistry.client.rest.entities.Config)4 ReferenceExistsException (io.confluent.kafka.schemaregistry.exceptions.ReferenceExistsException)4