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 + "'");
}
}
}
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;
}
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;
}
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();
}
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);
}
Aggregations