use of io.confluent.kafka.schemaregistry.client.rest.entities.SubjectVersion in project schema-registry by confluentinc.
the class RestService method getAllVersionsById.
public List<SubjectVersion> getAllVersionsById(Map<String, String> requestProperties, int id, String subject, boolean lookupDeleted) throws IOException, RestClientException {
UriBuilder builder = UriBuilder.fromPath("/schemas/ids/{id}/versions");
builder.queryParam("deleted", lookupDeleted);
if (subject != null) {
builder.queryParam("subject", subject);
}
String path = builder.build(id).toString();
List<SubjectVersion> response = httpRequest(path, "GET", null, requestProperties, GET_VERSIONS_RESPONSE_TYPE);
return response;
}
use of io.confluent.kafka.schemaregistry.client.rest.entities.SubjectVersion in project schema-registry by confluentinc.
the class RestApiTest method testGetVersionsAssociatedWithSchemaId.
@Test
public void testGetVersionsAssociatedWithSchemaId() throws Exception {
String subject1 = "testTopic1";
String subject2 = "testTopic2";
String schema = TestUtils.getRandomCanonicalAvroString(1).get(0);
TestUtils.registerAndVerifySchema(restApp.restClient, schema, 1, subject1);
TestUtils.registerAndVerifySchema(restApp.restClient, schema, 1, subject2);
List<SubjectVersion> associatedSubjects = restApp.restClient.getAllVersionsById(1);
assertEquals(associatedSubjects.size(), 2);
assertTrue(associatedSubjects.contains(new SubjectVersion(subject1, 1)));
assertTrue(associatedSubjects.contains(new SubjectVersion(subject2, 1)));
assertEquals("Deleting Schema Version Success", (Integer) 1, restApp.restClient.deleteSchemaVersion(RestService.DEFAULT_REQUEST_PROPERTIES, subject2, "1"));
associatedSubjects = restApp.restClient.getAllVersionsById(1);
assertEquals(associatedSubjects.size(), 1);
assertTrue(associatedSubjects.contains(new SubjectVersion(subject1, 1)));
associatedSubjects = restApp.restClient.getAllVersionsById(RestService.DEFAULT_REQUEST_PROPERTIES, 1, null, true);
assertEquals(associatedSubjects.size(), 2);
assertTrue(associatedSubjects.contains(new SubjectVersion(subject1, 1)));
assertTrue(associatedSubjects.contains(new SubjectVersion(subject2, 1)));
}
use of io.confluent.kafka.schemaregistry.client.rest.entities.SubjectVersion 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);
}
}
use of io.confluent.kafka.schemaregistry.client.rest.entities.SubjectVersion in project schema-registry by confluentinc.
the class SchemasResource method getVersions.
@GET
@Path("/ids/{id}/versions")
@DocumentedName("getAllVersionsById")
@Operation(summary = "List subject-versions associated to schema ID", description = "Get all the subject-version pairs associated with the input ID.", responses = { @ApiResponse(responseCode = "200", description = "The subject versions matching the specified parameters", content = @Content(array = @ArraySchema(schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = SubjectVersion.class)))), @ApiResponse(responseCode = "404", description = "Error code 40403 -- Schema not " + "found\n"), @ApiResponse(responseCode = "500", description = "Error code 50001 -- Error in the " + "backend data store\n") })
public List<SubjectVersion> getVersions(@Parameter(description = "Globally unique identifier of the schema", required = true) @PathParam("id") Integer id, @Parameter(description = "Filters results by the respective subject") @QueryParam("subject") String subject, @Parameter(description = "Whether to include subject versions where the schema was deleted") @QueryParam("deleted") boolean lookupDeletedSchema) {
List<SubjectVersion> versions;
String errorMessage = "Error while retrieving all subjects associated with schema id " + id + " from the schema registry";
try {
versions = schemaRegistry.listVersionsForId(id, subject, lookupDeletedSchema);
} catch (SchemaRegistryStoreException e) {
log.debug(errorMessage, e);
throw Errors.storeException(errorMessage, e);
} catch (SchemaRegistryException e) {
throw Errors.schemaRegistryException(errorMessage, e);
}
if (versions == null) {
throw Errors.schemaNotFoundException();
}
return versions;
}
Aggregations