Search in sources :

Example 1 with TopologyBroker

use of io.zeebe.broker.clustering.handler.TopologyBroker in project zeebe by zeebe-io.

the class TopologyCreator method createTopology.

public Topology createTopology() {
    LOG.trace("Received topology request.");
    final Iterator<MemberRaftComposite> iterator = clusterManagerContext.getMemberListService().iterator();
    final Topology topology = new Topology();
    while (iterator.hasNext()) {
        final MemberRaftComposite next = iterator.next();
        final ValueArray<TopologyBroker> brokers = topology.brokers();
        final SocketAddress clientApi = next.getClientApi();
        if (clientApi != null) {
            final TopologyBroker nextTopologyBroker = brokers.add();
            nextTopologyBroker.setHost(clientApi.getHostBuffer(), 0, clientApi.hostLength()).setPort(clientApi.port());
            final Iterator<RaftStateComposite> raftTupleIt = next.getRaftIterator();
            while (raftTupleIt.hasNext()) {
                final RaftStateComposite nextRaftState = raftTupleIt.next();
                final DirectBuffer topicName = BufferUtil.cloneBuffer(nextRaftState.getTopicName());
                nextTopologyBroker.partitionStates().add().setPartitionId(nextRaftState.getPartition()).setTopicName(topicName, 0, topicName.capacity()).setState(nextRaftState.getRaftState());
            }
        }
    }
    // LOG.debug("Send topology {} as response.", topology);
    return topology;
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Topology(io.zeebe.broker.clustering.handler.Topology) SocketAddress(io.zeebe.transport.SocketAddress) TopologyBroker(io.zeebe.broker.clustering.handler.TopologyBroker)

Example 2 with TopologyBroker

use of io.zeebe.broker.clustering.handler.TopologyBroker in project zeebe by zeebe-io.

the class CreateTopicStreamProcessorTest method shouldPersistCreatingBrokerInPartitionCreateEvent.

@Test
public void shouldPersistCreatingBrokerInPartitionCreateEvent() {
    // given
    partitionManager.addMember(SOCKET_ADDRESS1);
    final StreamProcessorControl processorControl = rule.runStreamProcessor(this::buildStreamProcessor);
    processorControl.blockAfterTopicEvent(e -> e.getValue().getState() == TopicState.CREATE);
    rule.writeEvent(createTopic("foo", 1));
    // when
    waitUntil(() -> partitionEventsInState(PartitionState.CREATE).findFirst().isPresent());
    // then
    final PartitionEvent partitionEvent = partitionEventsInState(PartitionState.CREATE).findFirst().get().getValue();
    final TopologyBroker creator = partitionEvent.getCreator();
    assertThat(creator.getHost()).isEqualTo(SOCKET_ADDRESS1.getHostBuffer());
    assertThat(creator.getPort()).isEqualTo(SOCKET_ADDRESS1.port());
}
Also used : PartitionEvent(io.zeebe.broker.system.log.PartitionEvent) TopologyBroker(io.zeebe.broker.clustering.handler.TopologyBroker) Test(org.junit.Test)

Example 3 with TopologyBroker

use of io.zeebe.broker.clustering.handler.TopologyBroker in project zeebe by zeebe-io.

the class PartitionEvent method setCreator.

public void setCreator(DirectBuffer host, int port) {
    final TopologyBroker address = creator.getValue();
    address.setHost(host, 0, host.capacity());
    address.setPort(port);
}
Also used : TopologyBroker(io.zeebe.broker.clustering.handler.TopologyBroker)

Example 4 with TopologyBroker

use of io.zeebe.broker.clustering.handler.TopologyBroker in project zeebe by zeebe-io.

the class CreatePartitionProcessor method executeSideEffects.

@Override
public boolean executeSideEffects(TypedEvent<PartitionEvent> event, TypedResponseWriter responseWriter) {
    final PartitionEvent value = event.getValue();
    final TopologyBroker creator = value.getCreator();
    final DirectBuffer creatorHost = creator.getHost();
    creatorAddress.host(creatorHost, 0, creatorHost.capacity());
    creatorAddress.port(creator.getPort());
    final ActorFuture<ClientResponse> partitionRemote = partitionManager.createPartitionRemote(creatorAddress, value.getTopicName(), value.getId());
    actor.runOnCompletion(partitionRemote, ((clientRequest, throwable) -> {
        if (throwable == null) {
            clientRequest.close();
        } else {
            Loggers.SYSTEM_LOGGER.error("Failed to create partitions request.", throwable);
        }
    }));
    return true;
}
Also used : DirectBuffer(org.agrona.DirectBuffer) ActorControl(io.zeebe.util.sched.ActorControl) ActorClock(io.zeebe.util.sched.clock.ActorClock) ActorFuture(io.zeebe.util.sched.future.ActorFuture) io.zeebe.broker.logstreams.processor(io.zeebe.broker.logstreams.processor) io.zeebe.transport(io.zeebe.transport) Duration(java.time.Duration) Loggers(io.zeebe.broker.Loggers) PartitionManager(io.zeebe.broker.clustering.management.PartitionManager) TopologyBroker(io.zeebe.broker.clustering.handler.TopologyBroker) DirectBuffer(org.agrona.DirectBuffer) TopologyBroker(io.zeebe.broker.clustering.handler.TopologyBroker)

Aggregations

TopologyBroker (io.zeebe.broker.clustering.handler.TopologyBroker)4 DirectBuffer (org.agrona.DirectBuffer)2 Loggers (io.zeebe.broker.Loggers)1 Topology (io.zeebe.broker.clustering.handler.Topology)1 PartitionManager (io.zeebe.broker.clustering.management.PartitionManager)1 io.zeebe.broker.logstreams.processor (io.zeebe.broker.logstreams.processor)1 PartitionEvent (io.zeebe.broker.system.log.PartitionEvent)1 io.zeebe.transport (io.zeebe.transport)1 SocketAddress (io.zeebe.transport.SocketAddress)1 ActorControl (io.zeebe.util.sched.ActorControl)1 ActorClock (io.zeebe.util.sched.clock.ActorClock)1 ActorFuture (io.zeebe.util.sched.future.ActorFuture)1 Duration (java.time.Duration)1 Test (org.junit.Test)1