Search in sources :

Example 1 with SharedTopics

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

the class KafkaController method addProjectMemberToTopics.

/**
 * Add a new project member to all project's Kafka topics.
 *
 * @param project
 * @param member
 */
public void addProjectMemberToTopics(Project project, String member) throws KafkaException, ProjectException, UserException {
    // Get all topics (shared with project as well)
    List<TopicDTO> topics = findTopicsByProject(project);
    List<SharedTopics> sharedTopics = sharedTopicsFacade.findSharedTopicsByProject(project.getId());
    // For every topic that has been shared with the current project, add the new member to its ACLs
    for (SharedTopics sharedTopic : sharedTopics) {
        addAclsToTopic(sharedTopic.getSharedTopicsPK().getTopicName(), sharedTopic.getProjectId(), new AclDTO(project.getName(), member, "allow", Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD));
    }
    // Iterate over topics and add user to ACLs
    for (TopicDTO topic : topics) {
        addAclsToTopic(topic.getName(), project.getId(), new AclDTO(project.getName(), member, "allow", Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD));
    }
}
Also used : SharedTopics(io.hops.hopsworks.persistence.entity.kafka.SharedTopics) AclDTO(io.hops.hopsworks.common.dao.kafka.AclDTO) TopicDTO(io.hops.hopsworks.common.dao.kafka.TopicDTO)

Example 2 with SharedTopics

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

the class KafkaController method getTopicSharedProjects.

public List<SharedProjectDTO> getTopicSharedProjects(String topicName, Integer ownerProjectId) {
    List<SharedTopics> projectIds = sharedTopicsFacade.findSharedTopicsByTopicAndOwnerProject(topicName, ownerProjectId);
    List<SharedProjectDTO> shareProjectDtos = new ArrayList<>();
    for (SharedTopics st : projectIds) {
        Project project = projectFacade.find(st.getSharedTopicsPK().getProjectId());
        if (project != null) {
            shareProjectDtos.add(new SharedProjectDTO(project.getName(), project.getId()));
        }
    }
    return shareProjectDtos;
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) SharedTopics(io.hops.hopsworks.persistence.entity.kafka.SharedTopics) ArrayList(java.util.ArrayList) SharedProjectDTO(io.hops.hopsworks.common.dao.kafka.SharedProjectDTO)

Example 3 with SharedTopics

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

the class KafkaController method getTopicAclUsers.

public List<AclUser> getTopicAclUsers(Project project, String topicName) {
    if (project == null || Strings.isNullOrEmpty(topicName)) {
        throw new IllegalArgumentException("ProjectId must be non-null, topic must be provided");
    }
    List<AclUser> aclUsers = new ArrayList<>();
    List<String> teamMembers = new ArrayList<>();
    for (ProjectTeam pt : project.getProjectTeamCollection()) {
        teamMembers.add(pt.getUser().getEmail());
    }
    // wildcard used for rolebased acl
    teamMembers.add("*");
    // contains project and its members
    Map<String, List<String>> projectMemberCollections = new HashMap<>();
    projectMemberCollections.put(project.getName(), teamMembers);
    // get all the projects this topic is shared with
    List<SharedTopics> sharedTopicsList = sharedTopicsFacade.findSharedTopicsByTopicName(topicName);
    List<String> sharedMembers;
    for (SharedTopics st : sharedTopicsList) {
        sharedMembers = new ArrayList<>();
        Project p = projectFacade.find(st.getSharedTopicsPK().getProjectId());
        for (ProjectTeam pt : p.getProjectTeamCollection()) {
            sharedMembers.add(pt.getUser().getEmail());
        }
        sharedMembers.add("*");
        projectMemberCollections.put(p.getName(), sharedMembers);
    }
    for (Map.Entry<String, List<String>> user : projectMemberCollections.entrySet()) {
        aclUsers.add(new AclUser(user.getKey(), new HashSet<>(user.getValue())));
    }
    return aclUsers;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AclUser(io.hops.hopsworks.common.dao.kafka.AclUser) Project(io.hops.hopsworks.persistence.entity.project.Project) ProjectTeam(io.hops.hopsworks.persistence.entity.project.team.ProjectTeam) SharedTopics(io.hops.hopsworks.persistence.entity.kafka.SharedTopics) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 4 with SharedTopics

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

the class KafkaController method getSubjectForTopic.

public SubjectDTO getSubjectForTopic(Project project, String topic) throws KafkaException, ProjectException {
    Optional<ProjectTopics> pt = projectTopicsFacade.findTopicByNameAndProject(project, topic);
    if (!pt.isPresent()) {
        SharedTopics sharedTopic = sharedTopicsFacade.findSharedTopicByProjectAndTopic(project.getId(), topic).orElseThrow(() -> new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_SHARED, Level.FINE, "topic: " + topic + ", project: " + project.getName()));
        Project sharedWithProject = projectFacade.findById(sharedTopic.getProjectId()).orElseThrow(() -> new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "projectId: " + sharedTopic.getSharedTopicsPK().getProjectId()));
        pt = projectTopicsFacade.findTopicByNameAndProject(sharedWithProject, topic);
    }
    if (!pt.isPresent()) {
        throw new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_NOT_FOUND, Level.FINE, "project=" + project.getName() + ", topic=" + topic);
    }
    return new SubjectDTO(pt.get().getSubjects());
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) SubjectDTO(io.hops.hopsworks.common.dao.kafka.schemas.SubjectDTO) SharedTopics(io.hops.hopsworks.persistence.entity.kafka.SharedTopics) KafkaException(io.hops.hopsworks.exceptions.KafkaException)

Example 5 with SharedTopics

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

the class KafkaResource method shareTopic.

@ApiOperation(value = "Share a Kafka topic with a project.")
@PUT
@Path("/topics/{topic}/shared/{destProjectName}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response shareTopic(@PathParam("topic") String topicName, @PathParam("destProjectName") String destProjectName, @Context UriInfo uriInfo, @Context SecurityContext sc) throws KafkaException, ProjectException, UserException {
    URI uri = topicsBuilder.sharedProjectUri(uriInfo, project, topicName).build();
    Integer destProjectId = projectFacade.findByName(destProjectName).getId();
    Optional<SharedTopics> st = sharedTopicsFacade.findSharedTopicByProjectAndTopic(destProjectId, topicName);
    SharedTopicsDTO dto;
    if (st.isPresent()) {
        dto = new SharedTopicsDTO(st.get().getProjectId(), st.get().getSharedTopicsPK());
        dto.setHref(uri);
        return Response.ok(uri).entity(dto).build();
    } else {
        dto = kafkaController.shareTopicWithProject(project, topicName, destProjectId);
        dto.setHref(uri);
        return Response.created(uri).entity(dto).build();
    }
}
Also used : SharedTopics(io.hops.hopsworks.persistence.entity.kafka.SharedTopics) SharedTopicsDTO(io.hops.hopsworks.common.dao.kafka.SharedTopicsDTO) URI(java.net.URI) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) PUT(javax.ws.rs.PUT)

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