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;
}
Aggregations