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;
}
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;
}
Aggregations