Search in sources :

Example 11 with Subjects

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

the class KafkaController method createTopicInProject.

public ProjectTopics createTopicInProject(Project project, TopicDTO topicDto) throws KafkaException {
    Subjects schema = subjectsFacade.findSubjectByNameAndVersion(project, topicDto.getSchemaName(), topicDto.getSchemaVersion()).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.SCHEMA_NOT_FOUND, Level.FINE, "topic: " + topicDto.getName()));
    // create the topic in kafka
    try {
        if (createTopicInKafka(topicDto).get(3000, TimeUnit.MILLISECONDS) == null) {
            throw new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_ALREADY_EXISTS_IN_ZOOKEEPER, Level.INFO, "topic name: " + topicDto.getName());
        }
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        throw new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_FETCH_FAILED, Level.WARNING, "Topic name: " + topicDto.getName(), e.getMessage(), e);
    }
    /*
     * What is the possibility of the program failing here? The topic is created
     * on
     * zookeeper, but not persisted onto db. User cannot access the topic,
     * cannot
     * create a topic of the same name. In such scenario, the zk timer should
     * remove the topic from zk.
     *
     * One possibility is: schema has a global name space, it is not project
     * specific.
     * While the schema is selected by this topic, it could be deleted by
     * another
     * user. Hence the above schema query will be empty.
     */
    ProjectTopics pt = new ProjectTopics(topicDto.getName(), project, schema);
    projectTopicsFacade.save(pt);
    return pt;
}
Also used : ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) KafkaException(io.hops.hopsworks.exceptions.KafkaException) ExecutionException(java.util.concurrent.ExecutionException) Subjects(io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects) TimeoutException(java.util.concurrent.TimeoutException)

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