Added host & port brokers endpoint (backend) (#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 #1521 added port to mapper Co-authored-by: Roman Zabaluev <rzabaluev@provectus.com> Co-authored-by: Ilya Kuramshin <ilia-2k@rambler.ru>
This commit is contained in:
parent
d473fb2b05
commit
e2a3b7b263
4 changed files with 63 additions and 1 deletions
|
@ -93,7 +93,7 @@ public class ConsumerGroupMapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BrokerDTO mapCoordinator(Node node) {
|
private static BrokerDTO mapCoordinator(Node node) {
|
||||||
return new BrokerDTO().host(node.host()).id(node.id());
|
return new BrokerDTO().host(node.host()).id(node.id()).port(node.port());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ConsumerGroupStateDTO mapConsumerGroupState(
|
private static ConsumerGroupStateDTO mapConsumerGroupState(
|
||||||
|
|
|
@ -78,6 +78,7 @@ public class BrokerService {
|
||||||
BrokerDTO broker = new BrokerDTO();
|
BrokerDTO broker = new BrokerDTO();
|
||||||
broker.setId(node.id());
|
broker.setId(node.id());
|
||||||
broker.setHost(node.host());
|
broker.setHost(node.host());
|
||||||
|
broker.setPort(node.port());
|
||||||
return broker;
|
return broker;
|
||||||
}).collect(Collectors.toList()))
|
}).collect(Collectors.toList()))
|
||||||
.flatMapMany(Flux::fromIterable);
|
.flatMapMany(Flux::fromIterable);
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
package com.provectus.kafka.ui.service;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
|
import com.provectus.kafka.ui.AbstractBaseTest;
|
||||||
|
import com.provectus.kafka.ui.mapper.ClusterMapperImpl;
|
||||||
|
import com.provectus.kafka.ui.mapper.DescribeLogDirsMapper;
|
||||||
|
import com.provectus.kafka.ui.model.BrokerDTO;
|
||||||
|
import com.provectus.kafka.ui.model.KafkaCluster;
|
||||||
|
import java.util.Properties;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import reactor.test.StepVerifier;
|
||||||
|
|
||||||
|
@ContextConfiguration(initializers = {AbstractBaseTest.Initializer.class})
|
||||||
|
class BrokerServiceTest extends AbstractBaseTest {
|
||||||
|
private final KafkaCluster kafkaCluster =
|
||||||
|
KafkaCluster.builder()
|
||||||
|
.name(LOCAL)
|
||||||
|
.bootstrapServers(kafka.getBootstrapServers())
|
||||||
|
.properties(new Properties())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
private BrokerService brokerService;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void init() {
|
||||||
|
AdminClientServiceImpl adminClientService = new AdminClientServiceImpl();
|
||||||
|
adminClientService.setClientTimeout(5_000);
|
||||||
|
brokerService =
|
||||||
|
new BrokerService(new MetricsCache(), adminClientService, new DescribeLogDirsMapper(), new ClusterMapperImpl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getBrokersNominal() {
|
||||||
|
BrokerDTO brokerdto = new BrokerDTO();
|
||||||
|
brokerdto.setId(1);
|
||||||
|
brokerdto.setHost("localhost");
|
||||||
|
String port = kafka.getBootstrapServers().substring(kafka.getBootstrapServers().lastIndexOf(":") + 1);
|
||||||
|
brokerdto.setPort(Integer.parseInt(port));
|
||||||
|
|
||||||
|
StepVerifier.create(brokerService.getBrokers(kafkaCluster))
|
||||||
|
.expectNext(brokerdto)
|
||||||
|
.verifyComplete();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getBrokersNull() {
|
||||||
|
assertThatThrownBy(() -> brokerService.getBrokers(null)).isInstanceOf(NullPointerException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getBrokersEmpty() {
|
||||||
|
assertThatThrownBy(() -> brokerService.getBrokers(KafkaCluster.builder().build())).isInstanceOf(
|
||||||
|
NullPointerException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1910,6 +1910,8 @@ components:
|
||||||
type: integer
|
type: integer
|
||||||
host:
|
host:
|
||||||
type: string
|
type: string
|
||||||
|
port:
|
||||||
|
type: integer
|
||||||
required:
|
required:
|
||||||
- id
|
- id
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue