Search in sources :

Example 1 with Subjects

use of io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects in project hopsworks by logicalclocks.

the class ServingUtil method validateKafkaTopicSchema.

private void validateKafkaTopicSchema(Project project, Serving serving, TopicDTO topic) throws ServingException {
    // if an existing topic, check schema
    if (topic != null && !topic.getName().equals("NONE") && !topic.getName().equals("CREATE")) {
        ProjectTopics projectTopic = projectTopicsFacade.findTopicByNameAndProject(project, topic.getName()).orElseThrow(() -> new ServingException(RESTCodes.ServingErrorCode.KAFKA_TOPIC_NOT_FOUND, Level.SEVERE, null));
        Subjects subjects = projectTopic.getSubjects();
        if (!subjects.getSubject().equalsIgnoreCase(Settings.INFERENCE_SCHEMANAME)) {
            throw new ServingException(RESTCodes.ServingErrorCode.KAFKA_TOPIC_NOT_VALID, Level.FINE, "Inference logging" + " requires a Kafka topic with schema '" + Settings.INFERENCE_SCHEMANAME + "'");
        }
    }
}
Also used : ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) ServingException(io.hops.hopsworks.exceptions.ServingException) Subjects(io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects)

Example 2 with Subjects

use of io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects in project hopsworks by logicalclocks.

the class SubjectsController method deleteSubjectsVersion.

public Integer deleteSubjectsVersion(Project project, String subject, String version) throws SchemaException, KafkaException {
    validateSubject(subject, false);
    validateVersion(version);
    if (!subjectsFacade.getListOfSubjects(project).contains(subject)) {
        throw new SchemaException(RESTCodes.SchemaRegistryErrorCode.SUBJECT_NOT_FOUND, Level.FINE, "subject=" + 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);
    }
    Integer versionToDelete = optional.get().getVersion();
    if (!projectTopicsFacade.findTopiscBySubjectAndVersion(project, subject, versionToDelete).isEmpty()) {
        throw new KafkaException(RESTCodes.KafkaErrorCode.SCHEMA_IN_USE, Level.FINE, "project=" + project.getName() + ", subject=" + subject + ", version=" + versionToDelete);
    }
    subjectsFacade.remove(optional.get());
    subjectsCompatibilityFacade.getSubjectCompatibility(project, subject).ifPresent(sc -> subjectsCompatibilityFacade.remove(sc));
    return versionToDelete;
}
Also used : BigInteger(java.math.BigInteger) SchemaException(io.hops.hopsworks.exceptions.SchemaException) KafkaException(io.hops.hopsworks.exceptions.KafkaException) Subjects(io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects)

Example 3 with Subjects

use of io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects in project hopsworks by logicalclocks.

the class SubjectsController method isCompatible.

private boolean isCompatible(Project project, String subject, Schema schema) throws SchemaException {
    SchemaCompatibility sc = getSubjectOrProjectCompatibility(project, subject);
    if (sc.equals(SchemaCompatibility.NONE)) {
        return true;
    }
    SchemaValidator validator = getSchemaValidator(sc);
    List<Schema> previousSchemas = subjectsFacade.findSubjectByName(project, subject).stream().sorted(Comparator.comparing(Subjects::getVersion).reversed()).map(s -> new Schema.Parser().parse(s.getSchema().getSchema())).collect(Collectors.toList());
    try {
        validator.validate(schema, previousSchemas);
    } catch (SchemaValidationException e) {
        return false;
    }
    return true;
}
Also used : Arrays(java.util.Arrays) SubjectDTO(io.hops.hopsworks.common.dao.kafka.schemas.SubjectDTO) Schemas(io.hops.hopsworks.persistence.entity.kafka.schemas.Schemas) CompatibilityCheck(io.hops.hopsworks.common.dao.kafka.schemas.CompatibilityCheck) Project(io.hops.hopsworks.persistence.entity.project.Project) Level(java.util.logging.Level) ProjectTopicsFacade(io.hops.hopsworks.common.dao.kafka.ProjectTopicsFacade) SubjectsCompatibility(io.hops.hopsworks.persistence.entity.kafka.schemas.SubjectsCompatibility) Settings(io.hops.hopsworks.common.util.Settings) TransactionAttributeType(javax.ejb.TransactionAttributeType) TransactionAttribute(javax.ejb.TransactionAttribute) SubjectsFacade(io.hops.hopsworks.common.dao.kafka.schemas.SubjectsFacade) SubjectsCompatibilityFacade(io.hops.hopsworks.common.dao.kafka.schemas.SubjectsCompatibilityFacade) BigInteger(java.math.BigInteger) EJB(javax.ejb.EJB) SchemaCompatibility(io.hops.hopsworks.persistence.entity.kafka.schemas.SchemaCompatibility) Stateless(javax.ejb.Stateless) Schema(org.apache.avro.Schema) SchemaValidator(org.apache.avro.SchemaValidator) SchemaValidationException(org.apache.avro.SchemaValidationException) SchemaException(io.hops.hopsworks.exceptions.SchemaException) RESTCodes(io.hops.hopsworks.restutils.RESTCodes) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) List(java.util.List) Subjects(io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects) SchemaValidatorBuilder(org.apache.avro.SchemaValidatorBuilder) Optional(java.util.Optional) SchemaParseException(org.apache.avro.SchemaParseException) Comparator(java.util.Comparator) KafkaException(io.hops.hopsworks.exceptions.KafkaException) Collections(java.util.Collections) SchemaValidationException(org.apache.avro.SchemaValidationException) SchemaCompatibility(io.hops.hopsworks.persistence.entity.kafka.schemas.SchemaCompatibility) Schema(org.apache.avro.Schema) SchemaValidator(org.apache.avro.SchemaValidator) Subjects(io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects)

Example 4 with Subjects

use of io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects in project hopsworks by logicalclocks.

the class SubjectsFacade method insertNewSubject.

public Integer insertNewSubject(Project project, String subjectName, Schemas schema, Integer version) {
    Subjects subject = new Subjects(subjectName, version, schema, project);
    save(subject);
    em.flush();
    return schema.getId();
}
Also used : Subjects(io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects)

Example 5 with Subjects

use of io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects in project hopsworks by logicalclocks.

the class KafkaController method updateTopicSubjectVersion.

public void updateTopicSubjectVersion(Project project, String topic, String subject, Integer version) throws KafkaException, SchemaException {
    ProjectTopics pt = projectTopicsFacade.findTopicByNameAndProject(project, topic).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_FOUND, Level.FINE, "topic: " + topic));
    String topicSubject = pt.getSubjects().getSubject();
    Subjects st = subjectsFacade.findSubjectByNameAndVersion(project, subject, version).orElseThrow(() -> new SchemaException(RESTCodes.SchemaRegistryErrorCode.VERSION_NOT_FOUND, Level.FINE, "schema: " + topicSubject + ", version: " + version));
    projectTopicsFacade.updateTopicSchemaVersion(pt, st);
}
Also used : SchemaException(io.hops.hopsworks.exceptions.SchemaException) ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) KafkaException(io.hops.hopsworks.exceptions.KafkaException) Subjects(io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects)

Aggregations

Subjects (io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects)11 SchemaException (io.hops.hopsworks.exceptions.SchemaException)7 KafkaException (io.hops.hopsworks.exceptions.KafkaException)5 SubjectDTO (io.hops.hopsworks.common.dao.kafka.schemas.SubjectDTO)4 ProjectTopics (io.hops.hopsworks.persistence.entity.kafka.ProjectTopics)4 Schema (org.apache.avro.Schema)4 SchemaParseException (org.apache.avro.SchemaParseException)4 BigInteger (java.math.BigInteger)3 CompatibilityCheck (io.hops.hopsworks.common.dao.kafka.schemas.CompatibilityCheck)2 SchemaCompatibility (io.hops.hopsworks.persistence.entity.kafka.schemas.SchemaCompatibility)2 Schemas (io.hops.hopsworks.persistence.entity.kafka.schemas.Schemas)2 ProjectTopicsFacade (io.hops.hopsworks.common.dao.kafka.ProjectTopicsFacade)1 SubjectsCompatibilityFacade (io.hops.hopsworks.common.dao.kafka.schemas.SubjectsCompatibilityFacade)1 SubjectsFacade (io.hops.hopsworks.common.dao.kafka.schemas.SubjectsFacade)1 Settings (io.hops.hopsworks.common.util.Settings)1 ServingException (io.hops.hopsworks.exceptions.ServingException)1 SubjectsCompatibility (io.hops.hopsworks.persistence.entity.kafka.schemas.SubjectsCompatibility)1 Project (io.hops.hopsworks.persistence.entity.project.Project)1 RESTCodes (io.hops.hopsworks.restutils.RESTCodes)1 Arrays (java.util.Arrays)1