Search in sources :

Example 1 with PartitionDetailsDTO

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

the class KafkaController method getTopicDetailsFromKafkaCluster.

private KafkaFuture<List<PartitionDetailsDTO>> getTopicDetailsFromKafkaCluster(String topicName) {
    return hopsKafkaAdminClient.describeTopics(Collections.singleton(topicName)).all().thenApply((map) -> map.getOrDefault(topicName, null)).thenApply((td) -> {
        if (td != null) {
            List<PartitionDetailsDTO> partitionDetails = new ArrayList<>();
            List<TopicPartitionInfo> partitions = td.partitions();
            for (TopicPartitionInfo partition : partitions) {
                int id = partition.partition();
                List<String> replicas = partition.replicas().stream().map(Node::host).collect(Collectors.toList());
                List<String> inSyncReplicas = partition.isr().stream().map(Node::host).collect(Collectors.toList());
                partitionDetails.add(new PartitionDetailsDTO(id, partition.leader().host(), replicas, inSyncReplicas));
            }
            partitionDetails.sort(Comparator.comparing(PartitionDetailsDTO::getId));
            return partitionDetails;
        } else {
            return Collections.emptyList();
        }
    });
}
Also used : 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) PartitionDetailsDTO(io.hops.hopsworks.common.dao.kafka.PartitionDetailsDTO) TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) ArrayList(java.util.ArrayList)

Example 2 with PartitionDetailsDTO

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

the class TopicsBuilder method buildTopicDetails.

public PartitionDetailsDTO buildTopicDetails(UriInfo uriInfo, Project project, String topicName) throws KafkaException {
    PartitionDetailsDTO dto = new PartitionDetailsDTO();
    dto.setHref(topicUri(uriInfo, project, topicName).build());
    try {
        List<PartitionDetailsDTO> list = kafkaController.getTopicDetails(project, topicName).get(3000, TimeUnit.MILLISECONDS);
        dto.setCount(Integer.toUnsignedLong(list.size()));
        list.forEach(dto::addItem);
        return dto;
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        throw new KafkaException(RESTCodes.KafkaErrorCode.TOPIC_FETCH_FAILED, Level.WARNING, "Topic name: " + topicName, e.getMessage(), e);
    }
}
Also used : PartitionDetailsDTO(io.hops.hopsworks.common.dao.kafka.PartitionDetailsDTO) KafkaException(io.hops.hopsworks.exceptions.KafkaException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

PartitionDetailsDTO (io.hops.hopsworks.common.dao.kafka.PartitionDetailsDTO)2 KafkaException (io.hops.hopsworks.exceptions.KafkaException)2 Strings (com.google.common.base.Strings)1 CertsFacade (io.hops.hopsworks.common.dao.certificates.CertsFacade)1 AclDTO (io.hops.hopsworks.common.dao.kafka.AclDTO)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 ProjectTopicsFacade (io.hops.hopsworks.common.dao.kafka.ProjectTopicsFacade)1 SharedProjectDTO (io.hops.hopsworks.common.dao.kafka.SharedProjectDTO)1 SharedTopicsDTO (io.hops.hopsworks.common.dao.kafka.SharedTopicsDTO)1 SharedTopicsFacade (io.hops.hopsworks.common.dao.kafka.SharedTopicsFacade)1 TopicAclsFacade (io.hops.hopsworks.common.dao.kafka.TopicAclsFacade)1 TopicDTO (io.hops.hopsworks.common.dao.kafka.TopicDTO)1 TopicDefaultValueDTO (io.hops.hopsworks.common.dao.kafka.TopicDefaultValueDTO)1 SubjectDTO (io.hops.hopsworks.common.dao.kafka.schemas.SubjectDTO)1 SubjectsFacade (io.hops.hopsworks.common.dao.kafka.schemas.SubjectsFacade)1 ProjectFacade (io.hops.hopsworks.common.dao.project.ProjectFacade)1 UserFacade (io.hops.hopsworks.common.dao.user.UserFacade)1 ProjectController (io.hops.hopsworks.common.project.ProjectController)1