use of io.hops.hopsworks.persistence.entity.kafka.schemas.Schemas in project hopsworks by logicalclocks.
the class SchemasController method addNewSchema.
public Schemas addNewSchema(Project project, String schemaString) throws SchemaException {
Schema schema = validateSchema(project, schemaString);
Optional<Schemas> current = schemasFacade.findBySchema(project, schema.toString());
if (current.isPresent()) {
return current.get();
} else {
Schemas s = new Schemas(schema.toString(), project);
schemasFacade.save(s);
return s;
}
}
use of io.hops.hopsworks.persistence.entity.kafka.schemas.Schemas in project hopsworks by logicalclocks.
the class SubjectsController method registerNewSubject.
public SubjectDTO registerNewSubject(Project project, String subject, String schemaContent, boolean isEnablingKafkaService) throws KafkaException, SchemaException {
validateSubject(subject, isEnablingKafkaService);
Schema schema;
try {
schema = new Schema.Parser().parse(schemaContent);
} catch (SchemaParseException e) {
throw new SchemaException(RESTCodes.SchemaRegistryErrorCode.INVALID_AVRO_SCHEMA, Level.FINE, "schema=" + schemaContent);
}
// check if schema exists - return current id
Optional<Subjects> optionalSubject = subjectsFacade.findSubjectByNameAndSchema(project, subject, schema.toString());
if (optionalSubject.isPresent()) {
Subjects subjects = optionalSubject.get();
return new SubjectDTO(subjects.getSchema().getId(), subjects.getSubject(), subjects.getVersion());
}
// check if schema compatible - return 409 of not
if (!isCompatible(project, subject, schema)) {
throw new SchemaException(RESTCodes.SchemaRegistryErrorCode.INCOMPATIBLE_AVRO_SCHEMA, Level.FINE, "Subject=" + subject + ", project=" + project.getName());
}
Integer latestVersion = subjectsFacade.findSubjectByName(project, subject).stream().map(Subjects::getVersion).max(Integer::compareTo).orElse(0);
Schemas schemas = schemasController.addNewSchema(project, schema.toString());
Integer id = subjectsFacade.insertNewSubject(project, subject, schemas, latestVersion + 1);
return new SubjectDTO(id, subject, latestVersion + 1);
}
Aggregations