Search in sources :

Example 1 with BrokerClusterState

use of io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState in project zeebe by zeebe-io.

the class LongPollingActivateJobsHandler method activateJobsUnchecked.

private void activateJobsUnchecked(final InFlightLongPollingActivateJobsRequestsState state, final LongPollingActivateJobsRequest request) {
    final BrokerClusterState topology = brokerClient.getTopologyManager().getTopology();
    if (topology != null) {
        state.addActiveRequest(request);
        final int partitionsCount = topology.getPartitionsCount();
        activateJobsHandler.activateJobs(partitionsCount, request.getRequest(), request.getMaxJobsToActivate(), request.getType(), response -> onResponse(request, response), error -> onError(request, error), (remainingAmount, containedResourceExhaustedResponse) -> onCompleted(state, request, remainingAmount, containedResourceExhaustedResponse));
    }
}
Also used : BrokerClusterState(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState)

Example 2 with BrokerClusterState

use of io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState in project zeebe by zeebe-io.

the class RoundRobinActivateJobsHandler method activateJobs.

@Override
public void activateJobs(final ActivateJobsRequest request, final ServerStreamObserver<ActivateJobsResponse> responseObserver) {
    final BrokerClusterState topology = brokerClient.getTopologyManager().getTopology();
    if (topology != null) {
        final int partitionsCount = topology.getPartitionsCount();
        activateJobs(partitionsCount, RequestMapper.toActivateJobsRequest(request), request.getMaxJobsToActivate(), request.getType(), responseObserver::onNext, responseObserver::onError, (remainingAmount, resourceExhaustedWasPresent) -> responseObserver.onCompleted());
    }
}
Also used : BrokerClusterState(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState)

Example 3 with BrokerClusterState

use of io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState in project zeebe by camunda.

the class EmbeddedBrokerRule method startBroker.

public void startBroker(final PartitionListener... listeners) {
    if (brokerCfg == null) {
        try (final InputStream configStream = configSupplier.get()) {
            if (configStream == null) {
                brokerCfg = new BrokerCfg();
            } else {
                brokerCfg = new TestConfigurationFactory().create(null, "zeebe.broker", configStream, BrokerCfg.class);
            }
            configureBroker(brokerCfg);
        } catch (final IOException e) {
            throw new RuntimeException("Unable to open configuration", e);
        }
    }
    systemContext = new SystemContext(brokerCfg, newTemporaryFolder.getAbsolutePath(), controlledActorClock);
    systemContext.getScheduler().start();
    final var additionalListeners = new ArrayList<>(Arrays.asList(listeners));
    final CountDownLatch latch = new CountDownLatch(brokerCfg.getCluster().getPartitionsCount());
    additionalListeners.add(new LeaderPartitionListener(latch));
    broker = new Broker(systemContext, springBrokerBridge, additionalListeners);
    broker.start().join();
    try {
        latch.await(INSTALL_TIMEOUT, INSTALL_TIMEOUT_UNIT);
    } catch (final InterruptedException e) {
        LOG.info("Broker was not started in 15 seconds", e);
        Thread.currentThread().interrupt();
    }
    final EmbeddedGatewayService embeddedGatewayService = broker.getBrokerContext().getEmbeddedGatewayService();
    if (embeddedGatewayService != null) {
        final BrokerClient brokerClient = embeddedGatewayService.get().getBrokerClient();
        waitUntil(() -> {
            final BrokerTopologyManager topologyManager = brokerClient.getTopologyManager();
            final BrokerClusterState topology = topologyManager.getTopology();
            return topology != null && topology.getLeaderForPartition(1) >= 0;
        });
    }
    dataDirectory = broker.getSystemContext().getBrokerConfiguration().getData().getDirectory();
}
Also used : Broker(io.camunda.zeebe.broker.Broker) TestConfigurationFactory(io.camunda.zeebe.test.util.TestConfigurationFactory) SystemContext(io.camunda.zeebe.broker.system.SystemContext) InputStream(java.io.InputStream) BrokerTopologyManager(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerTopologyManager) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) BrokerClient(io.camunda.zeebe.gateway.impl.broker.BrokerClient) BrokerCfg(io.camunda.zeebe.broker.system.configuration.BrokerCfg) EmbeddedGatewayService(io.camunda.zeebe.broker.system.EmbeddedGatewayService) BrokerClusterState(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState)

Example 4 with BrokerClusterState

use of io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState in project zeebe by camunda.

the class LivenessClusterAwarenessHealthIndicatorAutoConfigurationTest method shouldCreateHealthIndicatorThatReportsHealthBasedOnResultOfRegisteredClusterStateSupplier.

@Test
public void shouldCreateHealthIndicatorThatReportsHealthBasedOnResultOfRegisteredClusterStateSupplier() {
    // given
    final BrokerClusterState mockClusterState = mock(BrokerClusterState.class);
    when(mockClusterState.getBrokers()).thenReturn(List.of(1));
    final Supplier<Optional<BrokerClusterState>> stateSupplier = () -> Optional.of(mockClusterState);
    final var healthIndicator = sutAutoConfig.gatewayClusterAwarenessHealthIndicator(helperGatewayBridge);
    // when
    helperGatewayBridge.registerClusterStateSupplier(stateSupplier);
    final Health actualHealth = healthIndicator.health();
    // then
    assertThat(actualHealth).isNotNull();
    assertThat(actualHealth.getStatus()).isSameAs(Status.UP);
}
Also used : Optional(java.util.Optional) BrokerClusterState(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState) Health(org.springframework.boot.actuate.health.Health) Test(org.junit.Test)

Example 5 with BrokerClusterState

use of io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState in project zeebe by camunda.

the class BrokerRequestManager method determinePartitionIdForPublishMessageRequest.

private void determinePartitionIdForPublishMessageRequest(final BrokerPublishMessageRequest request) {
    final BrokerClusterState topology = topologyManager.getTopology();
    if (topology == null || topology.getPartitionsCount() == 0) {
        throw new NoTopologyAvailableException(String.format("Expected to pick partition for message with correlation key '%s', but no topology is available", BufferUtil.bufferAsString(request.getCorrelationKey())));
    }
    final int partitionId = SubscriptionUtil.getSubscriptionPartitionId(request.getCorrelationKey(), topology.getPartitionsCount());
    request.setPartitionId(partitionId);
}
Also used : NoTopologyAvailableException(io.camunda.zeebe.gateway.cmd.NoTopologyAvailableException) BrokerClusterState(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState)

Aggregations

BrokerClusterState (io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState)51 Optional (java.util.Optional)30 Test (org.junit.Test)30 Health (org.springframework.boot.actuate.health.Health)12 Broker (io.camunda.zeebe.broker.Broker)5 EmbeddedGatewayService (io.camunda.zeebe.broker.system.EmbeddedGatewayService)5 SystemContext (io.camunda.zeebe.broker.system.SystemContext)5 BrokerClient (io.camunda.zeebe.gateway.impl.broker.BrokerClient)5 BrokerTopologyManager (io.camunda.zeebe.gateway.impl.broker.cluster.BrokerTopologyManager)5 ArrayList (java.util.ArrayList)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 NoTopologyAvailableException (io.camunda.zeebe.gateway.cmd.NoTopologyAvailableException)3 BrokerInfo (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.BrokerInfo)3 Builder (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.BrokerInfo.Builder)3 TopologyResponse (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.TopologyResponse)3 BrokerCfg (io.camunda.zeebe.broker.system.configuration.BrokerCfg)2 TestConfigurationFactory (io.camunda.zeebe.test.util.TestConfigurationFactory)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 StatusRuntimeException (io.grpc.StatusRuntimeException)1