Search in sources :

Example 6 with SharedTopics

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();
}
Also used : SharedTopics(io.hops.hopsworks.persistence.entity.kafka.SharedTopics)

Example 7 with SharedTopics

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;
}
Also used : SubjectDTO(io.hops.hopsworks.common.dao.kafka.schemas.SubjectDTO) TimeoutException(java.util.concurrent.TimeoutException) SharedTopics(io.hops.hopsworks.persistence.entity.kafka.SharedTopics) Settings(io.hops.hopsworks.common.util.Settings) TransactionAttributeType(javax.ejb.TransactionAttributeType) Pair(org.apache.commons.lang3.tuple.Pair) SharedTopicsDTO(io.hops.hopsworks.common.dao.kafka.SharedTopicsDTO) Map(java.util.Map) SubjectsFacade(io.hops.hopsworks.common.dao.kafka.schemas.SubjectsFacade) ProjectException(io.hops.hopsworks.exceptions.ProjectException) Stateless(javax.ejb.Stateless) Set(java.util.Set) RESTCodes(io.hops.hopsworks.restutils.RESTCodes) KafkaFuture(org.apache.kafka.common.KafkaFuture) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) TopicAclsFacade(io.hops.hopsworks.common.dao.kafka.TopicAclsFacade) ProjectController(io.hops.hopsworks.common.project.ProjectController) HopsKafkaAdminClient(io.hops.hopsworks.common.dao.kafka.HopsKafkaAdminClient) TopicDefaultValueDTO(io.hops.hopsworks.common.dao.kafka.TopicDefaultValueDTO) List(java.util.List) Response(javax.ws.rs.core.Response) UserCerts(io.hops.hopsworks.persistence.entity.certificates.UserCerts) AclDTO(io.hops.hopsworks.common.dao.kafka.AclDTO) Optional(java.util.Optional) Node(org.apache.kafka.common.Node) KafkaException(io.hops.hopsworks.exceptions.KafkaException) ProjectFacade(io.hops.hopsworks.common.dao.project.ProjectFacade) SharedProjectDTO(io.hops.hopsworks.common.dao.kafka.SharedProjectDTO) UserFacade(io.hops.hopsworks.common.dao.user.UserFacade) AclUser(io.hops.hopsworks.common.dao.kafka.AclUser) HashMap(java.util.HashMap) CertsFacade(io.hops.hopsworks.common.dao.certificates.CertsFacade) Project(io.hops.hopsworks.persistence.entity.project.Project) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) ProjectTopicsFacade(io.hops.hopsworks.common.dao.kafka.ProjectTopicsFacade) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) TransactionAttribute(javax.ejb.TransactionAttribute) CreateTopicsResult(org.apache.kafka.clients.admin.CreateTopicsResult) EJB(javax.ejb.EJB) TopicDTO(io.hops.hopsworks.common.dao.kafka.TopicDTO) TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) KeeperException(org.apache.zookeeper.KeeperException) ProjectTeam(io.hops.hopsworks.persistence.entity.project.team.ProjectTeam) KafkaConst(io.hops.hopsworks.common.dao.kafka.KafkaConst) TopicAcls(io.hops.hopsworks.persistence.entity.kafka.TopicAcls) NewTopic(org.apache.kafka.clients.admin.NewTopic) FileOutputStream(java.io.FileOutputStream) SchemaException(io.hops.hopsworks.exceptions.SchemaException) IOException(java.io.IOException) SharedTopicsFacade(io.hops.hopsworks.common.dao.kafka.SharedTopicsFacade) ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) PartitionDetailsDTO(io.hops.hopsworks.common.dao.kafka.PartitionDetailsDTO) File(java.io.File) UserException(io.hops.hopsworks.exceptions.UserException) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Subjects(io.hops.hopsworks.persistence.entity.kafka.schemas.Subjects) Users(io.hops.hopsworks.persistence.entity.user.Users) Comparator(java.util.Comparator) Collections(java.util.Collections) SharedTopics(io.hops.hopsworks.persistence.entity.kafka.SharedTopics) ArrayList(java.util.ArrayList) TopicDTO(io.hops.hopsworks.common.dao.kafka.TopicDTO)

Example 8 with SharedTopics

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;
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) SharedTopics(io.hops.hopsworks.persistence.entity.kafka.SharedTopics) SharedTopicsDTO(io.hops.hopsworks.common.dao.kafka.SharedTopicsDTO) KafkaException(io.hops.hopsworks.exceptions.KafkaException)

Example 9 with SharedTopics

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);
    }
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) SharedTopics(io.hops.hopsworks.persistence.entity.kafka.SharedTopics) ArrayList(java.util.ArrayList) KafkaException(io.hops.hopsworks.exceptions.KafkaException)

Aggregations

SharedTopics (io.hops.hopsworks.persistence.entity.kafka.SharedTopics)9 Project (io.hops.hopsworks.persistence.entity.project.Project)5 KafkaException (io.hops.hopsworks.exceptions.KafkaException)4 ProjectException (io.hops.hopsworks.exceptions.ProjectException)4 ArrayList (java.util.ArrayList)4 SharedTopicsDTO (io.hops.hopsworks.common.dao.kafka.SharedTopicsDTO)3 ProjectTopics (io.hops.hopsworks.persistence.entity.kafka.ProjectTopics)3 AclDTO (io.hops.hopsworks.common.dao.kafka.AclDTO)2 AclUser (io.hops.hopsworks.common.dao.kafka.AclUser)2 SharedProjectDTO (io.hops.hopsworks.common.dao.kafka.SharedProjectDTO)2 TopicDTO (io.hops.hopsworks.common.dao.kafka.TopicDTO)2 SubjectDTO (io.hops.hopsworks.common.dao.kafka.schemas.SubjectDTO)2 ProjectTeam (io.hops.hopsworks.persistence.entity.project.team.ProjectTeam)2 Strings (com.google.common.base.Strings)1 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)1 CertsFacade (io.hops.hopsworks.common.dao.certificates.CertsFacade)1 HopsKafkaAdminClient (io.hops.hopsworks.common.dao.kafka.HopsKafkaAdminClient)1 KafkaConst (io.hops.hopsworks.common.dao.kafka.KafkaConst)1 PartitionDetailsDTO (io.hops.hopsworks.common.dao.kafka.PartitionDetailsDTO)1 ProjectTopicsFacade (io.hops.hopsworks.common.dao.kafka.ProjectTopicsFacade)1