Search in sources :

Example 1 with AclDTO

use of io.hops.hopsworks.common.dao.kafka.AclDTO in project hopsworks by logicalclocks.

the class KafkaResource method getTopicAcls.

@ApiOperation(value = "Get all ACLs for a specified topic.")
@GET
@Path("/topics/{topic}/acls")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.KAFKA }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getTopicAcls(@Context UriInfo uriInfo, @PathParam("topic") String topicName, @BeanParam Pagination pagination, @BeanParam AclsBeanParam aclsBeanParam, @Context SecurityContext sc) {
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.KAFKA);
    resourceRequest.setOffset(pagination.getOffset());
    resourceRequest.setLimit(pagination.getLimit());
    resourceRequest.setSort(aclsBeanParam.getSortBySet());
    resourceRequest.setFilter(aclsBeanParam.getFilter());
    AclDTO dto = aclBuilder.build(uriInfo, project, topicName, resourceRequest);
    return Response.ok().entity(dto).build();
}
Also used : AclDTO(io.hops.hopsworks.common.dao.kafka.AclDTO) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 2 with AclDTO

use of io.hops.hopsworks.common.dao.kafka.AclDTO in project hopsworks by logicalclocks.

the class AclBuilder method build.

private AclDTO build(TopicAcls acl, UriBuilder uriBuilder) {
    AclDTO dto = new AclDTO();
    dto.setHost(acl.getHost());
    dto.setId(acl.getId());
    dto.setOperationType(acl.getOperationType());
    dto.setPermissionType(acl.getPermissionType());
    dto.setProjectName(KafkaConst.getProjectNameFromPrincipal(acl.getPrincipal()));
    dto.setRole(acl.getRole());
    dto.setUserEmail(acl.getUser().getEmail());
    dto.setHref(uriBuilder.clone().path(Integer.toString(acl.getId())).build());
    return dto;
}
Also used : AclDTO(io.hops.hopsworks.common.dao.kafka.AclDTO)

Example 3 with AclDTO

use of io.hops.hopsworks.common.dao.kafka.AclDTO in project hopsworks by logicalclocks.

the class AclBuilder method build.

public AclDTO build(UriInfo uriInfo, TopicAcls acl) {
    AclDTO dto = new AclDTO(acl.getId(), KafkaConst.getProjectNameFromPrincipal(acl.getPrincipal()), acl.getUser().getEmail(), acl.getPermissionType(), acl.getOperationType(), acl.getHost(), acl.getRole());
    dto.setHref(uriInfo.getAbsolutePathBuilder().path(Integer.toString(acl.getId())).build());
    return dto;
}
Also used : AclDTO(io.hops.hopsworks.common.dao.kafka.AclDTO)

Example 4 with AclDTO

use of io.hops.hopsworks.common.dao.kafka.AclDTO in project hopsworks by logicalclocks.

the class KafkaController method addFullPermissionAclsToTopic.

private void addFullPermissionAclsToTopic(String aclProjectName, String topicName, Integer projectId) throws ProjectException, KafkaException, UserException {
    Project p = projectFacade.findByName(aclProjectName);
    if (p == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "Could not find project: " + aclProjectName);
    }
    List<AclDTO> acls = p.getProjectTeamCollection().stream().map(member -> member.getUser().getEmail()).map(email -> new AclDTO(p.getName(), email, "allow", Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD)).collect(Collectors.toList());
    for (AclDTO acl : acls) {
        addAclsToTopic(topicName, projectId, acl);
    }
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) 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) Project(io.hops.hopsworks.persistence.entity.project.Project) AclDTO(io.hops.hopsworks.common.dao.kafka.AclDTO)

Example 5 with AclDTO

use of io.hops.hopsworks.common.dao.kafka.AclDTO 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)

Aggregations

AclDTO (io.hops.hopsworks.common.dao.kafka.AclDTO)9 TopicDTO (io.hops.hopsworks.common.dao.kafka.TopicDTO)3 TopicAcls (io.hops.hopsworks.persistence.entity.kafka.TopicAcls)3 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)2 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)2 KafkaException (io.hops.hopsworks.exceptions.KafkaException)2 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)2 ProjectTopics (io.hops.hopsworks.persistence.entity.kafka.ProjectTopics)2 SharedTopics (io.hops.hopsworks.persistence.entity.kafka.SharedTopics)2 ProjectTeam (io.hops.hopsworks.persistence.entity.project.team.ProjectTeam)2 ApiOperation (io.swagger.annotations.ApiOperation)2 Strings (com.google.common.base.Strings)1 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)1 AbstractFacade (io.hops.hopsworks.common.dao.AbstractFacade)1 CertsFacade (io.hops.hopsworks.common.dao.certificates.CertsFacade)1 AclUser (io.hops.hopsworks.common.dao.kafka.AclUser)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