@Override public List<SchemaVersion> getVersions(TopicName topic) { Response response = target.path("subjects") .path(topic.qualifiedName()) .path("versions") .request() .get(); return extractSchemaVersions(topic.qualifiedName(), response); }
@Override public List<SchemaVersion> getVersions(TopicName topic) { Response response = target.path("subjects") .path(topic.qualifiedName()) .path("versions") .request() .get(); return extractSchemaVersions(topic.qualifiedName(), response); }
@Override public Optional<RawSchema> getLatestSchema(TopicName topic) { final String version = "latest"; Response response = target.path("subjects") .path(topic.qualifiedName()) .path("versions") .path(version) .request() .get(); return extractSchema(topic.qualifiedName(), version, response).map(RawSchema::valueOf); }
@Override public Optional<RawSchema> getLatestSchema(TopicName topic) { final String version = "latest"; Response response = target.path("subjects") .path(topic.qualifiedName()) .path("versions") .path(version) .request() .get(); return extractSchema(topic.qualifiedName(), version, response).map(RawSchema::valueOf); }
@Override public List<SchemaVersion> getVersions(TopicName topic) { Response response = target.path(topic.qualifiedName()) .path("all") .request() .accept(MediaType.APPLICATION_JSON_TYPE) .get(); return extractSchemaVersions(topic.qualifiedName(), response); }
private SchemaRegistryCompatibilityResponse toSchemaRegistryValidationResponse(TopicName topic, String validationResultStr, int status) { try { return objectMapper.readValue(validationResultStr, SchemaRegistryCompatibilityResponse.class); } catch (IOException e) { logger.error("Could not parse schema validation response from schema registry", e); throw new InternalSchemaRepositoryException(topic.qualifiedName(), status, validationResultStr); } } }
@Override public Optional<RawSchema> getSchema(TopicName topic, SchemaVersion version) { String versionString = Integer.toString(version.value()); Response response = target.path("subjects") .path(topic.qualifiedName()) .path("versions") .path(versionString) .request() .get(); return extractSchema(topic.qualifiedName(), versionString, response).map(RawSchema::valueOf); }
@Override public Optional<RawSchema> getSchema(TopicName topic, SchemaVersion version) { String subject = topic.qualifiedName(); String versionString = Integer.toString(version.value()); Response response = target.path(subject) .path("id") .path(versionString) .request() .get(); return extractSchema(subject, versionString, response).map(RawSchema::valueOf); }
public List<String> listQualifiedTopicNames(String groupName) { return topicRepository.listTopicNames(groupName).stream() .map(topicName -> new TopicName(groupName, topicName).qualifiedName()) .collect(toList()); }
@Override public void onTopicRemoved(Topic topic) { if (topicCache.containsKey(topic.getName().qualifiedName())) { Topic cachedTopic = topicCache.get(topic.getName().qualifiedName()).getTopic(); if (cachedTopic.equals(topic)) { topicCache.remove(topic.getName().qualifiedName()); } else { logger.warn("Received event about removed topic but cache contains different topic under the same name." + "Cached topic {}, removed topic {}", cachedTopic, topic); } } }
private void checkValidation(TopicName topic, RawSchema schema) { Response response = target.path("subjects") .path(topic.qualifiedName()) .path("validation") .request() .accept(MediaType.APPLICATION_JSON_TYPE) .post(Entity.entity(SchemaRegistryRequest.fromRawSchema(schema), SCHEMA_REPO_CONTENT_TYPE)); checkValidationResponse(topic, response); }
@Override public void logError(final String messageId, final TopicName topicName, final String reason, final String hostname) { repositories.forEach(r -> r.logError(messageId, clock.millis(), topicName.qualifiedName(), reason, hostname)); }
private void validateSuccessfulCompatibilityResult(TopicName topic, Response response) { String validationResultStr = response.readEntity(String.class); SchemaRegistryCompatibilityResponse validationResponse = toSchemaRegistryValidationResponse(topic, validationResultStr, response.getStatus()); if (!validationResponse.isCompatible()) { throw new BadSchemaRequestException(topic.qualifiedName(), response.getStatus(), validationResultStr); } }
private void validateSuccessfulCompatibilityResult(TopicName topic, Response response) { String validationResultStr = response.readEntity(String.class); SchemaRegistryCompatibilityResponse validationResponse = toSchemaRegistryValidationResponse(topic, validationResultStr, response.getStatus()); if (!validationResponse.isCompatible()) { throw new BadSchemaRequestException(topic.qualifiedName(), response.getStatus(), validationResultStr); } }
private void validateSuccessfulValidationResult(TopicName topic, Response response) { SchemaRegistryValidationResponse validationResponse = response.readEntity(SchemaRegistryValidationResponse.class); if (!validationResponse.isValid()) { throw new BadSchemaRequestException(topic.qualifiedName(), BAD_REQUEST.getStatusCode(), validationResponse.getErrorsMessage()); } }
public void updateTopic(TopicName topicName, PatchData patch) { Topic beforeUpdate = endpoints.topic().get(topicName.qualifiedName()); Topic reference = Patch.apply(beforeUpdate, patch); assertThat(endpoints.topic().update(topicName.qualifiedName(), patch).getStatus()).isEqualTo(OK.getStatusCode()); wait.untilTopicUpdated(reference); }
@Override public void touchTopic(TopicName topicName) { ensureTopicExists(topicName); logger.info("Touching topic: " + topicName.qualifiedName()); touch(paths.topicPath(topicName)); }
public TopicWithSchema getTopicWithSchema(TopicName topicName) { Topic topic = getTopicDetails(topicName); Optional<RawSchema> schema = Optional.empty(); if (AVRO.equals(topic.getContentType())) { schema = schemaService.getSchema(topicName.qualifiedName()); } return schema .map(s -> topicWithSchema(topic, s.value())) .orElseGet(() -> topicWithSchema(topic)); }
@Override public void registerSchema(TopicName topic, RawSchema rawSchema) { String topicName = topic.qualifiedName(); if (!isSubjectRegistered(topicName)) { registerSubject(topicName); } registerSchema(topicName, rawSchema.value()); }
@Test public void shouldConvertQualifiedName() { // given TopicName topicName = new TopicName("group1", "topic1"); // when & then assertThat(TopicName.fromQualifiedName(topicName.qualifiedName())).isEqualTo(topicName); }