use of io.hops.hopsworks.persistence.entity.kafka.ProjectTopics in project hopsworks by logicalclocks.
the class KafkaController method unshareTopic.
public void unshareTopic(Project requesterProject, String topicName, String destProjectName) throws ProjectException, KafkaException {
List<SharedTopics> list = new ArrayList<>();
Project destProject = projectFacade.findByName(destProjectName);
// check if topic exists
ProjectTopics topic = projectTopicsFacade.findTopicByName(topicName).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_FOUND, Level.FINE, "Topic:" + topicName));
// check if requesterProject is the owner of the topic
if (topic.getProject().equals(requesterProject)) {
if (destProject == null) {
list.addAll(sharedTopicsFacade.findSharedTopicsByTopicName(topicName));
} else {
SharedTopics st = sharedTopicsFacade.findSharedTopicByProjectAndTopic(destProject.getId(), topicName).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_SHARED, Level.FINE, "topic: " + topicName + ", project: " + destProject.getName()));
list.add(st);
}
} else {
if (destProject == null) {
SharedTopics st = sharedTopicsFacade.findSharedTopicByProjectAndTopic(requesterProject.getId(), topicName).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_SHARED, Level.FINE, "topic: " + topicName + ", project: " + requesterProject.getId()));
list.add(st);
}
}
for (SharedTopics st : list) {
sharedTopicsFacade.remove(st);
Project projectACLs = projectFacade.findById(st.getSharedTopicsPK().getProjectId()).orElseThrow(() -> new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "project: " + st.getSharedTopicsPK().getProjectId()));
topicAclsFacade.removeAclFromTopic(topicName, projectACLs);
}
}
use of io.hops.hopsworks.persistence.entity.kafka.ProjectTopics in project hopsworks by logicalclocks.
the class KafkaController method updateTopicSchemaVersion.
public void updateTopicSchemaVersion(Project project, String topicName, Integer schemaVersion) throws KafkaException {
ProjectTopics pt = projectTopicsFacade.findTopicByNameAndProject(project, topicName).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_FOUND, Level.FINE, "topic: " + topicName));
String schemaName = pt.getSubjects().getSubject();
Subjects st = subjectsFacade.findSubjectByNameAndVersion(project, schemaName, schemaVersion).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.SCHEMA_VERSION_NOT_FOUND, Level.FINE, "schema: " + schemaName + ", version: " + schemaVersion));
projectTopicsFacade.updateTopicSchemaVersion(pt, st);
}
use of io.hops.hopsworks.persistence.entity.kafka.ProjectTopics 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