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