Skip to content

Commit e2a3b7b

Browse files
mchoukairprovHaaroleanIlya Kuramshin
authored
Added host & port brokers endpoint (backend) (provectus#1553)
* Added port to endpoint brokers - Issue:1521 * Added port to endpoint brokers - Issue:1521 * Fixed code style - Issue:1521 * Fixed checkStyle violations - Issue:1521 * Issue provectus#1521 added port to mapper Co-authored-by: Roman Zabaluev <[email protected]> Co-authored-by: Ilya Kuramshin <[email protected]>
1 parent d473fb2 commit e2a3b7b

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

kafka-ui-api/src/main/java/com/provectus/kafka/ui/mapper/ConsumerGroupMapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private static <T extends ConsumerGroupDTO> T convertToConsumerGroup(
9393
}
9494

9595
private static BrokerDTO mapCoordinator(Node node) {
96-
return new BrokerDTO().host(node.host()).id(node.id());
96+
return new BrokerDTO().host(node.host()).id(node.id()).port(node.port());
9797
}
9898

9999
private static ConsumerGroupStateDTO mapConsumerGroupState(

kafka-ui-api/src/main/java/com/provectus/kafka/ui/service/BrokerService.java

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public Flux<BrokerDTO> getBrokers(KafkaCluster cluster) {
7878
BrokerDTO broker = new BrokerDTO();
7979
broker.setId(node.id());
8080
broker.setHost(node.host());
81+
broker.setPort(node.port());
8182
return broker;
8283
}).collect(Collectors.toList()))
8384
.flatMapMany(Flux::fromIterable);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.provectus.kafka.ui.service;
2+
3+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4+
5+
import com.provectus.kafka.ui.AbstractBaseTest;
6+
import com.provectus.kafka.ui.mapper.ClusterMapperImpl;
7+
import com.provectus.kafka.ui.mapper.DescribeLogDirsMapper;
8+
import com.provectus.kafka.ui.model.BrokerDTO;
9+
import com.provectus.kafka.ui.model.KafkaCluster;
10+
import java.util.Properties;
11+
import org.junit.jupiter.api.BeforeEach;
12+
import org.junit.jupiter.api.Test;
13+
import org.springframework.test.context.ContextConfiguration;
14+
import reactor.test.StepVerifier;
15+
16+
@ContextConfiguration(initializers = {AbstractBaseTest.Initializer.class})
17+
class BrokerServiceTest extends AbstractBaseTest {
18+
private final KafkaCluster kafkaCluster =
19+
KafkaCluster.builder()
20+
.name(LOCAL)
21+
.bootstrapServers(kafka.getBootstrapServers())
22+
.properties(new Properties())
23+
.build();
24+
25+
private BrokerService brokerService;
26+
27+
@BeforeEach
28+
void init() {
29+
AdminClientServiceImpl adminClientService = new AdminClientServiceImpl();
30+
adminClientService.setClientTimeout(5_000);
31+
brokerService =
32+
new BrokerService(new MetricsCache(), adminClientService, new DescribeLogDirsMapper(), new ClusterMapperImpl());
33+
}
34+
35+
@Test
36+
void getBrokersNominal() {
37+
BrokerDTO brokerdto = new BrokerDTO();
38+
brokerdto.setId(1);
39+
brokerdto.setHost("localhost");
40+
String port = kafka.getBootstrapServers().substring(kafka.getBootstrapServers().lastIndexOf(":") + 1);
41+
brokerdto.setPort(Integer.parseInt(port));
42+
43+
StepVerifier.create(brokerService.getBrokers(kafkaCluster))
44+
.expectNext(brokerdto)
45+
.verifyComplete();
46+
}
47+
48+
@Test
49+
void getBrokersNull() {
50+
assertThatThrownBy(() -> brokerService.getBrokers(null)).isInstanceOf(NullPointerException.class);
51+
}
52+
53+
@Test
54+
void getBrokersEmpty() {
55+
assertThatThrownBy(() -> brokerService.getBrokers(KafkaCluster.builder().build())).isInstanceOf(
56+
NullPointerException.class);
57+
}
58+
59+
}

kafka-ui-contract/src/main/resources/swagger/kafka-ui-api.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -1910,6 +1910,8 @@ components:
19101910
type: integer
19111911
host:
19121912
type: string
1913+
port:
1914+
type: integer
19131915
required:
19141916
- id
19151917

0 commit comments

Comments
 (0)