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