Search in sources :

Example 6 with SubjectDTO

use of io.hops.hopsworks.common.dao.kafka.schemas.SubjectDTO in project hopsworks by logicalclocks.

the class SubjectsController method checkIfSchemaRegistered.

public SubjectDTO checkIfSchemaRegistered(Project project, String subject, String schemaContent) throws SchemaException {
    if (!subjectsFacade.getListOfSubjects(project).contains(subject)) {
        throw new SchemaException(RESTCodes.SchemaRegistryErrorCode.SUBJECT_NOT_FOUND, Level.FINE, "subject=" + subject);
    }
    Schema schema;
    try {
        schema = new Schema.Parser().parse(schemaContent);
    } catch (SchemaParseException e) {
        throw new SchemaException(RESTCodes.SchemaRegistryErrorCode.INVALID_AVRO_SCHEMA, Level.FINE, "schema=" + schemaContent);
    }
    Optional<Subjects> optional = subjectsFacade.findSubjectByNameAndSchema(project, subject, schema.toString());
    if (!optional.isPresent()) {
        throw new SchemaException(RESTCodes.SchemaRegistryErrorCode.SCHEMA_NOT_FOUND, Level.FINE, "schema=" + schema.toString());
    }
    return new SubjectDTO(optional.get());
}
Also used : SchemaException(io.hops.hopsworks.exceptions.SchemaException) SubjectDTO(io.hops.hopsworks.common.dao.kafka.schemas.SubjectDTO) SchemaParseException(org.apache.avro.SchemaParseException) Schema(org.apache.avro.Schema) Subjects(io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects)

Example 7 with SubjectDTO

use of io.hops.hopsworks.common.dao.kafka.schemas.SubjectDTO in project hopsworks by logicalclocks.

the class SubjectsController method getSubjectDetails.

public SubjectDTO getSubjectDetails(Project project, String subject, String version) throws SchemaException {
    validateVersion(version);
    if (subjectsFacade.findSubjectByName(project, subject).isEmpty()) {
        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()) {
        Subjects res = optional.get();
        return new SubjectDTO(res.getSchema().getId(), res.getSubject(), res.getVersion(), res.getSchema().getSchema());
    } else {
        throw new SchemaException(RESTCodes.SchemaRegistryErrorCode.VERSION_NOT_FOUND, Level.FINE, "subject=" + subject + ", version=" + version);
    }
}
Also used : SchemaException(io.hops.hopsworks.exceptions.SchemaException) SubjectDTO(io.hops.hopsworks.common.dao.kafka.schemas.SubjectDTO) Subjects(io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects)

Aggregations

SubjectDTO (io.hops.hopsworks.common.dao.kafka.schemas.SubjectDTO)7 SchemaException (io.hops.hopsworks.exceptions.SchemaException)4 Subjects (io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects)3 Schema (org.apache.avro.Schema)2 SchemaParseException (org.apache.avro.SchemaParseException)2 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)1 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)1 TopicDTO (io.hops.hopsworks.common.dao.kafka.TopicDTO)1 SchemaRegistryError (io.hops.hopsworks.common.dao.kafka.schemas.SchemaRegistryError)1 KafkaException (io.hops.hopsworks.exceptions.KafkaException)1 ProjectException (io.hops.hopsworks.exceptions.ProjectException)1 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)1 ProjectTopics (io.hops.hopsworks.persistence.entity.kafka.ProjectTopics)1 SharedTopics (io.hops.hopsworks.persistence.entity.kafka.SharedTopics)1 Schemas (io.hops.hopsworks.persistence.entity.kafka.schemas.Schemas)1 Project (io.hops.hopsworks.persistence.entity.project.Project)1 ApiOperation (io.swagger.annotations.ApiOperation)1 BigInteger (java.math.BigInteger)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1