Search in sources :

Example 6 with AclDTO

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

the class KafkaResource method addAclsToTopic.

@ApiOperation(value = "Add a new ACL for a specified topic.")
@POST
@Path("/topics/{topic}/acls")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.KAFKA }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response addAclsToTopic(@Context UriInfo uriInfo, @PathParam("topic") String topicName, AclDTO aclDto, @Context SecurityContext sc) throws KafkaException, ProjectException, UserException {
    Pair<TopicAcls, Response.Status> aclTuple = kafkaController.addAclsToTopic(topicName, project.getId(), aclDto);
    AclDTO dto = aclBuilder.build(uriInfo, aclTuple.getLeft());
    return Response.status(aclTuple.getRight()).entity(dto).build();
}
Also used : AclDTO(io.hops.hopsworks.common.dao.kafka.AclDTO) TopicAcls(io.hops.hopsworks.persistence.entity.kafka.TopicAcls) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) 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 7 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, Project project, String topicName, ResourceRequest resourceRequest) {
    AclDTO dto = new AclDTO();
    aclUri(dto, uriInfo, project, topicName);
    expand(dto, resourceRequest);
    if (dto.isExpand()) {
        AbstractFacade.CollectionInfo collectionInfo = topicAclsFacade.findByTopicName(resourceRequest.getOffset(), resourceRequest.getLimit(), resourceRequest.getFilter(), resourceRequest.getSort(), topicName);
        dto.setCount(collectionInfo.getCount());
        UriBuilder uriBuilder = getAclUri(uriInfo, project, topicName);
        collectionInfo.getItems().forEach((acl) -> dto.addItem(build((TopicAcls) acl, uriBuilder)));
    }
    return dto;
}
Also used : AclDTO(io.hops.hopsworks.common.dao.kafka.AclDTO) AbstractFacade(io.hops.hopsworks.common.dao.AbstractFacade) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 8 with AclDTO

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

the class AclBuilder method getAclByTopicAndId.

public AclDTO getAclByTopicAndId(UriInfo uriInfo, Project project, String topicName, Integer aclId) throws KafkaException {
    AclDTO dto = new AclDTO();
    URI uri = getAclUri(uriInfo, project, topicName, aclId).build();
    dto.setHref(uri);
    Optional<TopicAcls> aclsOptional = kafkaController.findAclByIdAndTopic(topicName, aclId);
    if (aclsOptional.isPresent()) {
        TopicAcls acl = aclsOptional.get();
        dto.setId(acl.getId());
        dto.setProjectName(KafkaConst.getProjectNameFromPrincipal(acl.getPrincipal()));
        dto.setUserEmail(acl.getUser().getEmail());
        dto.setPermissionType(acl.getPermissionType());
        dto.setOperationType(acl.getOperationType());
        dto.setHost(acl.getHost());
        dto.setRole(acl.getRole());
    }
    return dto;
}
Also used : AclDTO(io.hops.hopsworks.common.dao.kafka.AclDTO) TopicAcls(io.hops.hopsworks.persistence.entity.kafka.TopicAcls) URI(java.net.URI)

Example 9 with AclDTO

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

the class KafkaServingHelper method setupKafkaTopic.

private ProjectTopics setupKafkaTopic(Project project, ServingWrapper servingWrapper) throws KafkaException, UserException, ProjectException, InterruptedException, ExecutionException {
    try {
        // Check that the user is not trying to create a topic with  more replicas than brokers.
        if (servingWrapper.getKafkaTopicDTO().getNumOfReplicas() != null && (servingWrapper.getKafkaTopicDTO().getNumOfReplicas() <= 0 || servingWrapper.getKafkaTopicDTO().getNumOfReplicas() > kafkaBrokers.getBrokerEndpoints().size())) {
            throw new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_REPLICATION_ERROR, Level.FINE);
        } else if (servingWrapper.getKafkaTopicDTO().getNumOfReplicas() == null) {
            // set default value
            servingWrapper.getKafkaTopicDTO().setNumOfReplicas(settings.getKafkaDefaultNumReplicas());
        }
    } catch (IOException | KeeperException | InterruptedException e) {
        throw new KafkaException(RESTCodes.KafkaErrorCode.BROKER_METADATA_ERROR, Level.SEVERE, "", e.getMessage(), e);
    }
    // Check that the user is not trying to create a topic with negative partitions
    if (servingWrapper.getKafkaTopicDTO().getNumOfPartitions() != null && servingWrapper.getKafkaTopicDTO().getNumOfPartitions() <= 0) {
        throw new KafkaException(RESTCodes.KafkaErrorCode.BAD_NUM_PARTITION, Level.FINE, "less than 0");
    } else if (servingWrapper.getKafkaTopicDTO().getNumOfPartitions() == null) {
        // set default value
        servingWrapper.getKafkaTopicDTO().setNumOfPartitions(settings.getKafkaDefaultNumPartitions());
    }
    String servingTopicName = getServingTopicName(servingWrapper);
    TopicDTO topicDTO = new TopicDTO(servingTopicName, servingWrapper.getKafkaTopicDTO().getNumOfReplicas(), servingWrapper.getKafkaTopicDTO().getNumOfPartitions(), Settings.INFERENCE_SCHEMANAME, Settings.INFERENCE_SCHEMAVERSION);
    ProjectTopics pt = kafkaController.createTopicInProject(project, topicDTO);
    // Add the ACLs for this topic. By default all users should be able to do everything
    for (ProjectTeam projectTeam : project.getProjectTeamCollection()) {
        AclDTO aclDto = new AclDTO(project.getName(), projectTeam.getUser().getEmail(), "allow", Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD);
        kafkaController.addAclsToTopic(topicDTO.getName(), project.getId(), aclDto);
    }
    return pt;
}
Also used : ProjectTeam(io.hops.hopsworks.persistence.entity.project.team.ProjectTeam) ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) AclDTO(io.hops.hopsworks.common.dao.kafka.AclDTO) KafkaException(io.hops.hopsworks.exceptions.KafkaException) TopicDTO(io.hops.hopsworks.common.dao.kafka.TopicDTO) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

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