use of io.hops.hopsworks.common.dao.kafka.schemas.CompatibilityCheck in project hopsworks by logicalclocks.
the class SubjectsController method checkIfSchemaCompatible.
public CompatibilityCheck checkIfSchemaCompatible(Project project, String subject, String version, String schemaToTest) throws SchemaException {
validateVersion(version);
Schema schema;
try {
schema = new Schema.Parser().parse(schemaToTest);
} catch (SchemaParseException e) {
throw new SchemaException(RESTCodes.SchemaRegistryErrorCode.INVALID_AVRO_SCHEMA, Level.FINE, "schema=" + schemaToTest);
}
if (!subjectsFacade.getListOfSubjects(project).contains(subject)) {
throw new SchemaException(RESTCodes.SchemaRegistryErrorCode.SUBJECT_NOT_FOUND, Level.FINE, "subject=" + subject);
}
SchemaCompatibility sc = getSubjectOrProjectCompatibility(project, subject);
Optional<Subjects> optional;
if (version.equals("latest")) {
optional = subjectsFacade.findSubjectLatestVersion(project, subject);
} else {
optional = subjectsFacade.findSubjectByNameAndVersion(project, subject, Integer.valueOf(version));
}
if (!optional.isPresent()) {
throw new SchemaException(RESTCodes.SchemaRegistryErrorCode.VERSION_NOT_FOUND, Level.FINE, "project=" + project.getName() + ", subject=" + subject + ", version=" + version);
}
boolean isCompatible = isCompatible(new Schema.Parser().parse(optional.get().getSchema().getSchema()), schema, sc);
return new CompatibilityCheck(isCompatible);
}
Aggregations