use of io.hops.hopsworks.persistence.entity.kafka.SharedTopics in project hopsworks by logicalclocks.
the class SharedTopicsFacade method shareTopic.
public void shareTopic(Project owningProject, String topicName, Integer projectId) {
SharedTopics st = new SharedTopics(topicName, owningProject.getId(), projectId);
em.persist(st);
em.flush();
}
use of io.hops.hopsworks.persistence.entity.kafka.SharedTopics in project hopsworks by logicalclocks.
the class KafkaController method findSharedTopicsByProject.
/**
* Get all shared Topics for the given project.
*
* @param projectId
* @return
*/
public List<TopicDTO> findSharedTopicsByProject(Integer projectId) {
List<SharedTopics> res = sharedTopicsFacade.findSharedTopicsByProject(projectId);
List<TopicDTO> topics = new ArrayList<>();
for (SharedTopics pt : res) {
projectTopicsFacade.findTopicByName(pt.getSharedTopicsPK().getTopicName()).map(topic -> new TopicDTO(pt.getSharedTopicsPK().getTopicName(), pt.getProjectId(), topic.getSubjects().getSubject(), topic.getSubjects().getVersion(), topic.getSubjects().getSchema().getSchema(), true, pt.getAccepted())).ifPresent(topics::add);
}
return topics;
}
use of io.hops.hopsworks.persistence.entity.kafka.SharedTopics in project hopsworks by logicalclocks.
the class KafkaController method shareTopicWithProject.
public SharedTopicsDTO shareTopicWithProject(Project project, String topicName, Integer destProjectId) throws ProjectException, KafkaException, UserException {
if (project.getId().equals(destProjectId)) {
throw new KafkaException(RESTCodes.KafkaErrorCode.DESTINATION_PROJECT_IS_TOPIC_OWNER, Level.FINE);
}
if (!projectTopicsFacade.findTopicByNameAndProject(project, topicName).isPresent()) {
throw new KafkaException(RESTCodes.KafkaErrorCode.PROJECT_IS_NOT_THE_OWNER_OF_THE_TOPIC, Level.FINE);
}
if (!projectTopicsFacade.findTopicByNameAndProject(project, topicName).isPresent()) {
throw new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_FOUND, Level.FINE, "topic: " + topicName);
}
if (!Optional.ofNullable(projectFacade.find(destProjectId)).isPresent()) {
throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "Could not find project: " + destProjectId);
}
sharedTopicsFacade.shareTopic(project, topicName, destProjectId);
Optional<SharedTopics> optionalSt = sharedTopicsFacade.findSharedTopicByTopicAndProjectIds(topicName, project.getId(), destProjectId);
SharedTopicsDTO dto = new SharedTopicsDTO();
optionalSt.ifPresent(st -> {
dto.setProjectId(st.getProjectId());
dto.setSharedTopicsPK(st.getSharedTopicsPK());
});
return dto;
}
use of io.hops.hopsworks.persistence.entity.kafka.SharedTopics 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);
}
}
Aggregations