Search in sources :

Example 1 with TopologyResponse

use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.TopologyResponse in project zeebe-process-test by camunda.

the class GrpcToLogStreamGateway method topology.

@Override
public void topology(final TopologyRequest request, final StreamObserver<TopologyResponse> responseObserver) {
    final Partition partition = GatewayOuterClass.Partition.newBuilder().setHealth(GatewayOuterClass.Partition.PartitionBrokerHealth.HEALTHY).setRole(GatewayOuterClass.Partition.PartitionBrokerRole.LEADER).setPartitionId(partitionId).build();
    final BrokerInfo brokerInfo = GatewayOuterClass.BrokerInfo.newBuilder().addPartitions(partition).setHost("0.0.0.0").setPort(port).setVersion(VersionUtil.getVersion()).build();
    final TopologyResponse topologyResponse = GatewayOuterClass.TopologyResponse.newBuilder().addBrokers(brokerInfo).setClusterSize(1).setPartitionsCount(partitionCount).setReplicationFactor(1).setGatewayVersion(VersionUtil.getVersion()).build();
    responseObserver.onNext(topologyResponse);
    responseObserver.onCompleted();
}
Also used : Partition(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.Partition) TopologyResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.TopologyResponse) BrokerInfo(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.BrokerInfo)

Example 2 with TopologyResponse

use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.TopologyResponse in project zeebe-test-container by camunda-community-hub.

the class ZeebeTopologyWaitStrategyTest method shouldWaitUntilACompleteTopologyResponse.

@Test
void shouldWaitUntilACompleteTopologyResponse() {
    // given
    final ZeebeClientFutureImpl<Topology, TopologyResponse> incompleteTopologyResponse = newTopologyResponse(newTopology(BROKERS_COUNT - 1, PARTITIONS_COUNT - 1, DEFAULT_PARTITIONER));
    final ZeebeClientFutureImpl<Topology, TopologyResponse> completeTopologyResponse = newTopologyResponse(newCompleteTopology());
    final WaitStrategyTarget target = new ReachableTarget(1);
    final ZeebeTopologyWaitStrategy strategy = newCompleteWaitStrategy();
    Mockito.when(topologyRequest.send()).thenReturn(incompleteTopologyResponse).thenReturn(completeTopologyResponse);
    strategy.forBuilder(() -> builder);
    // when
    strategy.waitUntilReady(target);
    // then
    Mockito.verify(topologyRequest, Mockito.timeout(5000).times(2)).send();
}
Also used : WaitStrategyTarget(org.testcontainers.containers.wait.strategy.WaitStrategyTarget) TopologyResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.TopologyResponse) Topology(io.camunda.zeebe.client.api.response.Topology) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with TopologyResponse

use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.TopologyResponse in project zeebe by camunda.

the class TopologyTest method shouldUpdateInactiveBroker.

@Test
public void shouldUpdateInactiveBroker() {
    // given
    final int partitionId = 3;
    final var clusterState = (BrokerClusterStateImpl) brokerClient.getTopologyManager().getTopology();
    clusterState.addPartitionInactive(partitionId, 0);
    // when
    final TopologyResponse response = client.topology(TopologyRequest.newBuilder().build());
    // then
    assertThat(response.getBrokersList()).isNotEmpty();
    assertThat(response.getBrokers(0).getPartitionsList()).isNotEmpty();
    final Optional<Partition> partition = response.getBrokers(0).getPartitionsList().stream().filter(p -> p.getPartitionId() == partitionId).findFirst();
    assertThat(partition).isPresent();
    assertThat(partition.get().getRole()).isEqualTo(PartitionBrokerRole.INACTIVE);
}
Also used : PartitionBrokerRole(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.Partition.PartitionBrokerRole) TopologyRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.TopologyRequest) BrokerClusterStateImpl(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterStateImpl) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) GatewayTest(io.camunda.zeebe.gateway.api.util.GatewayTest) PartitionHealthStatus(io.camunda.zeebe.protocol.record.PartitionHealthStatus) Partition(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.Partition) Optional(java.util.Optional) Test(org.junit.Test) PartitionBrokerHealth(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.Partition.PartitionBrokerHealth) TopologyResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.TopologyResponse) Partition(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.Partition) TopologyResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.TopologyResponse) BrokerClusterStateImpl(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterStateImpl) GatewayTest(io.camunda.zeebe.gateway.api.util.GatewayTest) Test(org.junit.Test)

Example 4 with TopologyResponse

use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.TopologyResponse in project zeebe by zeebe-io.

the class EndpointManager method topology.

public void topology(final ServerStreamObserver<TopologyResponse> responseObserver) {
    final TopologyResponse.Builder topologyResponseBuilder = TopologyResponse.newBuilder();
    final BrokerClusterState topology = topologyManager.getTopology();
    final String gatewayVersion = VersionUtil.getVersion();
    if (gatewayVersion != null && !gatewayVersion.isBlank()) {
        topologyResponseBuilder.setGatewayVersion(gatewayVersion);
    }
    final ArrayList<BrokerInfo> brokers = new ArrayList<>();
    if (topology != null) {
        topologyResponseBuilder.setClusterSize(topology.getClusterSize()).setPartitionsCount(topology.getPartitionsCount()).setReplicationFactor(topology.getReplicationFactor());
        topology.getBrokers().forEach(brokerId -> {
            final Builder brokerInfo = BrokerInfo.newBuilder();
            addBrokerInfo(brokerInfo, brokerId, topology);
            addPartitionInfoToBrokerInfo(brokerInfo, brokerId, topology);
            brokers.add(brokerInfo.build());
        });
    }
    topologyResponseBuilder.addAllBrokers(brokers);
    final TopologyResponse response = topologyResponseBuilder.build();
    responseObserver.onNext(response);
    responseObserver.onCompleted();
}
Also used : BrokerClusterState(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState) Builder(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.BrokerInfo.Builder) ArrayList(java.util.ArrayList) TopologyResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.TopologyResponse) BrokerInfo(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.BrokerInfo)

Example 5 with TopologyResponse

use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.TopologyResponse in project zeebe by zeebe-io.

the class TopologyRequestImpl method send.

@Override
public ZeebeFuture<Topology> send() {
    final TopologyRequest request = TopologyRequest.getDefaultInstance();
    final RetriableClientFutureImpl<Topology, TopologyResponse> future = new RetriableClientFutureImpl<>(TopologyImpl::new, retryPredicate, streamObserver -> send(request, streamObserver));
    send(request, future);
    return future;
}
Also used : TopologyRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.TopologyRequest) TopologyResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.TopologyResponse) RetriableClientFutureImpl(io.camunda.zeebe.client.impl.RetriableClientFutureImpl) Topology(io.camunda.zeebe.client.api.response.Topology) TopologyImpl(io.camunda.zeebe.client.impl.response.TopologyImpl)

Aggregations

TopologyResponse (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.TopologyResponse)13 BrokerInfo (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.BrokerInfo)6 TopologyRequest (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.TopologyRequest)6 Partition (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.Partition)5 Topology (io.camunda.zeebe.client.api.response.Topology)4 PartitionBrokerRole (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.Partition.PartitionBrokerRole)4 RetriableClientFutureImpl (io.camunda.zeebe.client.impl.RetriableClientFutureImpl)3 TopologyImpl (io.camunda.zeebe.client.impl.response.TopologyImpl)3 GatewayTest (io.camunda.zeebe.gateway.api.util.GatewayTest)3 BrokerClusterState (io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState)3 BrokerClusterStateImpl (io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterStateImpl)3 Builder (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.BrokerInfo.Builder)3 PartitionBrokerHealth (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.Partition.PartitionBrokerHealth)3 PartitionHealthStatus (io.camunda.zeebe.protocol.record.PartitionHealthStatus)3 ArrayList (java.util.ArrayList)3 Optional (java.util.Optional)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Test (org.junit.Test)3 StatusRuntimeException (io.grpc.StatusRuntimeException)1 Test (org.junit.jupiter.api.Test)1