Search in sources :

Example 11 with SocketAddress

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());
}
Also used : MembersEncoder(io.zeebe.clustering.management.InvitationRequestEncoder.MembersEncoder) SocketAddress(io.zeebe.transport.SocketAddress)

Example 12 with SocketAddress

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;
}
Also used : MutableDirectBuffer(org.agrona.MutableDirectBuffer) DirectBuffer(org.agrona.DirectBuffer) SocketAddress(io.zeebe.transport.SocketAddress)

Example 13 with SocketAddress

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);
}
Also used : Member(io.zeebe.broker.clustering.member.Member) PartitionRequest(io.zeebe.broker.topic.TestPartitionManager.PartitionRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TopologyBroker(io.zeebe.broker.clustering.handler.TopologyBroker) IntIterator(io.zeebe.util.collection.IntIterator) SocketAddress(io.zeebe.transport.SocketAddress) Duration(java.time.Duration) TypedStreamProcessor(io.zeebe.broker.logstreams.processor.TypedStreamProcessor) Before(org.junit.Before) TopicEvent(io.zeebe.broker.system.log.TopicEvent) TransportHeaderDescriptor(io.zeebe.transport.impl.TransportHeaderDescriptor) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) ResolvePendingPartitionsCommand(io.zeebe.broker.system.log.ResolvePendingPartitionsCommand) TopicsIndex(io.zeebe.broker.system.log.TopicsIndex) PendingPartitionsIndex(io.zeebe.broker.system.log.PendingPartitionsIndex) Test(org.junit.Test) SystemPartitionManager(io.zeebe.broker.system.log.SystemPartitionManager) Instant(java.time.Instant) TestUtil.doRepeatedly(io.zeebe.test.util.TestUtil.doRepeatedly) Collectors(java.util.stream.Collectors) TopicState(io.zeebe.broker.system.log.TopicState) PartitionState(io.zeebe.broker.system.log.PartitionState) List(java.util.List) TypedStreamEnvironment(io.zeebe.broker.logstreams.processor.TypedStreamEnvironment) Assertions.fail(org.assertj.core.api.Assertions.fail) Stream(java.util.stream.Stream) Rule(org.junit.Rule) Ignore(org.junit.Ignore) StreamProcessorRule(io.zeebe.broker.util.StreamProcessorRule) BufferUtil(io.zeebe.util.buffer.BufferUtil) Optional(java.util.Optional) TypedEvent(io.zeebe.broker.logstreams.processor.TypedEvent) PartitionEvent(io.zeebe.broker.system.log.PartitionEvent) RequestResponseHeaderDescriptor(io.zeebe.transport.impl.RequestResponseHeaderDescriptor) IntIterator(io.zeebe.util.collection.IntIterator) PartitionRequest(io.zeebe.broker.topic.TestPartitionManager.PartitionRequest) SocketAddress(io.zeebe.transport.SocketAddress) Member(io.zeebe.broker.clustering.member.Member) Test(org.junit.Test)

Example 14 with SocketAddress

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();
    }
}
Also used : TypedBatchWriter(io.zeebe.broker.logstreams.processor.TypedBatchWriter) SocketAddress(io.zeebe.transport.SocketAddress)

Example 15 with SocketAddress

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));
}
Also used : Raft(io.zeebe.raft.Raft) SocketAddress(io.zeebe.transport.SocketAddress) Test(org.junit.Test)

Aggregations

SocketAddress (io.zeebe.transport.SocketAddress)21 Test (org.junit.Test)13 TopologyBroker (io.zeebe.client.clustering.impl.TopologyBroker)6 TaskEvent (io.zeebe.client.event.TaskEvent)3 DirectBuffer (org.agrona.DirectBuffer)3 TopologyBroker (io.zeebe.broker.clustering.handler.TopologyBroker)2 TypedBatchWriter (io.zeebe.broker.logstreams.processor.TypedBatchWriter)2 Raft (io.zeebe.raft.Raft)2 TestUtil.doRepeatedly (io.zeebe.test.util.TestUtil.doRepeatedly)2 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 MutableDirectBuffer (org.agrona.MutableDirectBuffer)2 Before (org.junit.Before)2 Topology (io.zeebe.broker.clustering.handler.Topology)1 Member (io.zeebe.broker.clustering.member.Member)1 ClientRule (io.zeebe.broker.it.ClientRule)1 BROKER_1_CLIENT_ADDRESS (io.zeebe.broker.it.clustering.ClusteringRule.BROKER_1_CLIENT_ADDRESS)1 TypedEvent (io.zeebe.broker.logstreams.processor.TypedEvent)1 TypedStreamEnvironment (io.zeebe.broker.logstreams.processor.TypedStreamEnvironment)1