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