Search in sources :

Example 1 with SystemContext

use of io.camunda.zeebe.broker.system.SystemContext 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 2 with SystemContext

use of io.camunda.zeebe.broker.system.SystemContext in project zeebe by camunda.

the class EmbeddedBrokerRule method startBroker.

public void startBroker() {
    systemContext = new SystemContext(brokerCfg, newTemporaryFolder.getAbsolutePath(), controlledActorClock);
    systemContext.getScheduler().start();
    final CountDownLatch latch = new CountDownLatch(brokerCfg.getCluster().getPartitionsCount());
    broker = new Broker(systemContext, springBrokerBridge, Collections.singletonList(new LeaderPartitionListener(latch)));
    broker.start().join();
    try {
        final boolean hasLeaderPartition = latch.await(timeout.toMillis(), TimeUnit.MILLISECONDS);
        assertThat(hasLeaderPartition).describedAs("Expected the broker to have a leader of the partition within %s", timeout).isTrue();
    } catch (final InterruptedException e) {
        LOG.info("Timeout. Broker was not started within {}", timeout, 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;
        });
    }
}
Also used : Broker(io.camunda.zeebe.broker.Broker) EmbeddedGatewayService(io.camunda.zeebe.broker.system.EmbeddedGatewayService) SystemContext(io.camunda.zeebe.broker.system.SystemContext) BrokerClusterState(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState) BrokerTopologyManager(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerTopologyManager) CountDownLatch(java.util.concurrent.CountDownLatch) BrokerClient(io.camunda.zeebe.gateway.impl.broker.BrokerClient)

Example 3 with SystemContext

use of io.camunda.zeebe.broker.system.SystemContext in project zeebe by zeebe-io.

the class ClusteringRule method createBroker.

private Broker createBroker(final int nodeId) {
    final File brokerBase = getBrokerBase(nodeId);
    final BrokerCfg brokerCfg = getBrokerCfg(nodeId);
    final var systemContext = new SystemContext(brokerCfg, brokerBase.getAbsolutePath(), controlledClock);
    systemContexts.put(nodeId, systemContext);
    systemContext.getScheduler().start();
    final Broker broker = new Broker(systemContext, getSpringBrokerBridge(nodeId), Collections.singletonList(new LeaderListener(partitionLatch, nodeId)));
    new Thread(() -> {
        broker.start();
    }).start();
    return broker;
}
Also used : BrokerCfg(io.camunda.zeebe.broker.system.configuration.BrokerCfg) Broker(io.camunda.zeebe.broker.Broker) SystemContext(io.camunda.zeebe.broker.system.SystemContext) File(java.io.File)

Example 4 with SystemContext

use of io.camunda.zeebe.broker.system.SystemContext in project zeebe by zeebe-io.

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 5 with SystemContext

use of io.camunda.zeebe.broker.system.SystemContext in project zeebe by camunda-cloud.

the class ClusteringRule method createBroker.

private Broker createBroker(final int nodeId) {
    final File brokerBase = getBrokerBase(nodeId);
    final BrokerCfg brokerCfg = getBrokerCfg(nodeId);
    final var systemContext = new SystemContext(brokerCfg, brokerBase.getAbsolutePath(), controlledClock);
    systemContexts.put(nodeId, systemContext);
    systemContext.getScheduler().start();
    final Broker broker = new Broker(systemContext, getSpringBrokerBridge(nodeId), Collections.singletonList(new LeaderListener(partitionLatch, nodeId)));
    new Thread(() -> {
        broker.start();
    }).start();
    return broker;
}
Also used : BrokerCfg(io.camunda.zeebe.broker.system.configuration.BrokerCfg) Broker(io.camunda.zeebe.broker.Broker) SystemContext(io.camunda.zeebe.broker.system.SystemContext) File(java.io.File)

Aggregations

Broker (io.camunda.zeebe.broker.Broker)9 SystemContext (io.camunda.zeebe.broker.system.SystemContext)9 BrokerCfg (io.camunda.zeebe.broker.system.configuration.BrokerCfg)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 EmbeddedGatewayService (io.camunda.zeebe.broker.system.EmbeddedGatewayService)5 BrokerClient (io.camunda.zeebe.gateway.impl.broker.BrokerClient)5 BrokerClusterState (io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState)5 BrokerTopologyManager (io.camunda.zeebe.gateway.impl.broker.cluster.BrokerTopologyManager)5 TestConfigurationFactory (io.camunda.zeebe.test.util.TestConfigurationFactory)3 File (java.io.File)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3