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