Search in sources :

Example 1 with CompatibilityCheck

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);
}
Also used : CompatibilityCheck(io.hops.hopsworks.common.dao.kafka.schemas.CompatibilityCheck) SchemaException(io.hops.hopsworks.exceptions.SchemaException) SchemaParseException(org.apache.avro.SchemaParseException) SchemaCompatibility(io.hops.hopsworks.persistence.entity.kafka.schemas.SchemaCompatibility) Schema(org.apache.avro.Schema) Subjects(io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects)

Aggregations

CompatibilityCheck (io.hops.hopsworks.common.dao.kafka.schemas.CompatibilityCheck)1 SchemaException (io.hops.hopsworks.exceptions.SchemaException)1 SchemaCompatibility (io.hops.hopsworks.persistence.entity.kafka.schemas.SchemaCompatibility)1 Subjects (io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects)1 Schema (org.apache.avro.Schema)1 SchemaParseException (org.apache.avro.SchemaParseException)1