Search in sources :

Example 1 with TopicDTO

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

the class KafkaResource method getTopics.

@ApiOperation(value = "Retrieve Kafka topics metadata .")
@GET
@Path("/topics")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.KAFKA }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getTopics(@Context UriInfo uriInfo, @BeanParam Pagination pagination, @BeanParam TopicsBeanParam topicsBeanParam, @Context SecurityContext sc) {
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.KAFKA);
    resourceRequest.setOffset(pagination.getOffset());
    resourceRequest.setLimit(pagination.getLimit());
    resourceRequest.setSort(topicsBeanParam.getSortBySet());
    resourceRequest.setFilter(topicsBeanParam.getFilter());
    TopicDTO dto = topicsBuilder.build(uriInfo, resourceRequest, project);
    return Response.ok().entity(dto).build();
}
Also used : TopicDTO(io.hops.hopsworks.common.dao.kafka.TopicDTO) 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 TopicDTO

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

the class TopicsBuilder method build.

public TopicDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Project project) {
    URI href = uriInfo.getBaseUriBuilder().path(ResourceRequest.Name.KAFKA.toString().toLowerCase()).path(Integer.toString(project.getId())).path(ResourceRequest.Name.KAFKA.toString().toLowerCase()).path(ResourceRequest.Name.TOPICS.toString().toLowerCase()).build();
    TopicDTO dto = new TopicDTO();
    dto.setHref(href);
    expand(dto, resourceRequest);
    if (dto.isExpand()) {
        List<TopicDTO> list = buildItems(project, resourceRequest);
        dto.setCount(Integer.toUnsignedLong(list.size()));
        list.forEach(topic -> dto.addItem(build(uriInfo, resourceRequest, topic, project)));
    }
    return dto;
}
Also used : TopicDTO(io.hops.hopsworks.common.dao.kafka.TopicDTO) URI(java.net.URI)

Example 3 with TopicDTO

use of io.hops.hopsworks.common.dao.kafka.TopicDTO 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 4 with TopicDTO

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

the class KafkaController method findTopicsByProject.

public List<TopicDTO> findTopicsByProject(Project project) {
    List<ProjectTopics> ptList = projectTopicsFacade.findTopicsByProject(project);
    List<TopicDTO> topics = new ArrayList<>();
    for (ProjectTopics pt : ptList) {
        topics.add(new TopicDTO(pt.getTopicName(), pt.getSubjects().getSubject(), pt.getSubjects().getVersion(), false));
    }
    return topics;
}
Also used : ProjectTopics(io.hops.hopsworks.persistence.entity.kafka.ProjectTopics) ArrayList(java.util.ArrayList) TopicDTO(io.hops.hopsworks.common.dao.kafka.TopicDTO)

Example 5 with TopicDTO

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

the class TopicsBuilder method sortTopics.

@Override
protected List<TopicDTO> sortTopics(List<TopicDTO> list, Set<? extends AbstractFacade.SortBy> sortBySet) {
    Iterator<? extends AbstractFacade.SortBy> it = sortBySet.iterator();
    Comparator<TopicDTO> comparator = null;
    while (it.hasNext()) {
        AbstractFacade.SortBy sort = it.next();
        Comparator order = sort.getParam().getValue().equals("DESC") ? Comparator.reverseOrder() : Comparator.naturalOrder();
        switch(ProjectTopicsFacade.TopicsSorts.valueOf(sort.getValue())) {
            case NAME:
                if (comparator == null) {
                    comparator = Comparator.comparing(TopicDTO::getName, order);
                } else {
                    comparator = comparator.thenComparing(TopicDTO::getName, order);
                }
                break;
            case SCHEMA_NAME:
                if (comparator == null) {
                    comparator = Comparator.comparing(TopicDTO::getSchemaName, order);
                } else {
                    comparator = comparator.thenComparing(TopicDTO::getSchemaName, order);
                }
                break;
        }
    }
    if (comparator != null) {
        list.sort(comparator);
    }
    return list;
}
Also used : AbstractFacade(io.hops.hopsworks.common.dao.AbstractFacade) TopicDTO(io.hops.hopsworks.common.dao.kafka.TopicDTO) Comparator(java.util.Comparator)

Aggregations

TopicDTO (io.hops.hopsworks.common.dao.kafka.TopicDTO)8 AclDTO (io.hops.hopsworks.common.dao.kafka.AclDTO)3 ProjectTopics (io.hops.hopsworks.persistence.entity.kafka.ProjectTopics)3 SubjectDTO (io.hops.hopsworks.common.dao.kafka.schemas.SubjectDTO)2 KafkaException (io.hops.hopsworks.exceptions.KafkaException)2 SharedTopics (io.hops.hopsworks.persistence.entity.kafka.SharedTopics)2 ProjectTeam (io.hops.hopsworks.persistence.entity.project.team.ProjectTeam)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 KeeperException (org.apache.zookeeper.KeeperException)2 Strings (com.google.common.base.Strings)1 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)1 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)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