use of io.zeebe.transport.SocketAddress in project zeebe by zeebe-io.
the class InvitationRequest method write.
@Override
public void write(final MutableDirectBuffer buffer, int offset) {
headerEncoder.wrap(buffer, offset).blockLength(bodyEncoder.sbeBlockLength()).templateId(bodyEncoder.sbeTemplateId()).schemaId(bodyEncoder.sbeSchemaId()).version(bodyEncoder.sbeSchemaVersion());
offset += headerEncoder.encodedLength();
final int size = members.size();
final MembersEncoder encoder = bodyEncoder.wrap(buffer, offset).partitionId(partitionId).term(term).membersCount(size);
for (int i = 0; i < size; i++) {
final SocketAddress member = members.get(i);
encoder.next().port(member.port()).putHost(member.getHostBuffer(), 0, member.hostLength());
}
bodyEncoder.putTopicName(topicName, 0, topicName.capacity());
}
use of io.zeebe.transport.SocketAddress in project zeebe by zeebe-io.
the class RaftPersistentFileStorage method getMembers.
public List<SocketAddress> getMembers() {
final List<SocketAddress> members = new ArrayList<>();
final Iterator<RaftConfigurationMetadataMember> iterator = configuration.membersProp.iterator();
while (iterator.hasNext()) {
final RaftConfigurationMetadataMember member = iterator.next();
final DirectBuffer hostBuffer = member.getHost();
final SocketAddress socketAddress = new SocketAddress();
socketAddress.host(hostBuffer, 0, hostBuffer.capacity());
socketAddress.setPort(member.getPort());
members.add(socketAddress);
}
return members;
}
use of io.zeebe.transport.SocketAddress in project zeebe by zeebe-io.
the class CreateTopicStreamProcessorTest method shouldSkipMembersWithoutManagmenetApiWhenDistributePartitionsRoundRobin.
@Test
public void shouldSkipMembersWithoutManagmenetApiWhenDistributePartitionsRoundRobin() {
// given
partitionManager.addMember(SOCKET_ADDRESS1);
partitionManager.addMember(SOCKET_ADDRESS2);
// last member has no management endpoint set yet
partitionManager.currentMembers.add(new Member() {
@Override
public SocketAddress getManagementAddress() {
return null;
}
@Override
public IntIterator getLeadingPartitions() {
return null;
}
});
rule.runStreamProcessor(this::buildStreamProcessor);
// when
rule.writeEvent(createTopic("foo", 4));
waitUntil(() -> partitionEventsInState(PartitionState.CREATING).count() == 4);
// then
final List<PartitionRequest> requests = partitionManager.getPartitionRequests();
assertThat(requests).extracting(r -> r.endpoint).containsOnly(SOCKET_ADDRESS1, SOCKET_ADDRESS2, SOCKET_ADDRESS1, SOCKET_ADDRESS2);
}
use of io.zeebe.transport.SocketAddress in project zeebe by zeebe-io.
the class CreateTopicProcessor method writeEvent.
@Override
public long writeEvent(TypedEvent<TopicEvent> event, TypedStreamWriter writer) {
final TopicEvent value = event.getValue();
if (value.getState() == TopicState.CREATE_REJECTED) {
return writer.writeFollowupEvent(event.getKey(), event.getValue());
} else {
final TypedBatchWriter batchWriter = writer.newBatch();
for (int i = 0; i < value.getPartitions(); i++) {
// in contrast to choosing the partition ID, choosing the creator
// does not have to be deterministic (e.g. when this method is invoked multiple times due to backpressure),
// so it is ok to choose the creator here and not in #processEvent
final SocketAddress nextCreator = creatorStrategy.selectBrokerForNewPartition();
if (nextCreator == null) {
return -1;
}
partitionEvent.reset();
partitionEvent.setState(PartitionState.CREATE);
partitionEvent.setTopicName(value.getName());
partitionEvent.setId(idGenerator.currentId(i));
partitionEvent.setCreator(nextCreator.getHostBuffer(), nextCreator.port());
batchWriter.addNewEvent(partitionEvent);
}
return batchWriter.write();
}
}
use of io.zeebe.transport.SocketAddress in project zeebe by zeebe-io.
the class BrokerRestartTest method shouldLoadRaftConfiguration.
@Test
public void shouldLoadRaftConfiguration() {
// given
final int testTerm = 8;
final ServiceName<Raft> serviceName = ClusterServiceNames.raftServiceName(clientRule.getDefaultTopic() + "." + clientRule.getDefaultPartition());
Raft raft = brokerRule.getService(serviceName);
waitUntil(raft::isInitialEventCommitted);
raft.setTerm(testTerm);
// when
restartBroker();
raft = brokerRule.getService(serviceName);
waitUntil(raft::isInitialEventCommitted);
// then
assertThat(raft.getState()).isEqualTo(RaftState.LEADER);
assertThat(raft.getTerm()).isEqualTo(testTerm + 1);
assertThat(raft.getMembers()).isEmpty();
assertThat(raft.getVotedFor()).isEqualTo(new SocketAddress("localhost", 51017));
}
Aggregations