Search in sources :

Example 1 with BrokerInfo

use of io.camunda.zeebe.protocol.impl.encoding.BrokerInfo in project zeebe by camunda.

the class TopologyUpdateTest method shouldAddBrokerOnTopologyEvenOnNotReceivedEvent.

@Test
public void shouldAddBrokerOnTopologyEvenOnNotReceivedEvent() {
    // given
    final BrokerInfo broker = createBroker(0);
    broker.setFollowerForPartition(1);
    createMemberAddedEvent(broker);
    // when
    actorClock.addTime(Duration.ofSeconds(10));
    // then
    waitUntil(() -> topologyManager.getTopology() != null);
    assertThat(topologyManager.getTopology().getFollowersForPartition(1).contains(0)).isTrue();
}
Also used : BrokerInfo(io.camunda.zeebe.protocol.impl.encoding.BrokerInfo) Test(org.junit.Test)

Example 2 with BrokerInfo

use of io.camunda.zeebe.protocol.impl.encoding.BrokerInfo in project zeebe by camunda.

the class Broker method createBrokerInfo.

private BrokerInfo createBrokerInfo(final BrokerCfg brokerCfg) {
    final var clusterCfg = brokerCfg.getCluster();
    final BrokerInfo result = new BrokerInfo(clusterCfg.getNodeId(), NetUtil.toSocketAddressString(brokerCfg.getNetwork().getCommandApi().getAdvertisedAddress()));
    result.setClusterSize(clusterCfg.getClusterSize()).setPartitionsCount(clusterCfg.getPartitionsCount()).setReplicationFactor(clusterCfg.getReplicationFactor());
    final String version = VersionUtil.getVersion();
    if (version != null && !version.isBlank()) {
        result.setVersion(version);
    }
    return result;
}
Also used : BrokerInfo(io.camunda.zeebe.protocol.impl.encoding.BrokerInfo)

Example 3 with BrokerInfo

use of io.camunda.zeebe.protocol.impl.encoding.BrokerInfo in project zeebe by camunda.

the class BrokerTopologyManagerImpl method event.

@Override
public void event(final ClusterMembershipEvent event) {
    final Member subject = event.subject();
    final Type eventType = event.type();
    final BrokerInfo brokerInfo = BrokerInfo.fromProperties(subject.properties());
    if (brokerInfo != null) {
        actor.call(() -> {
            final BrokerClusterStateImpl newTopology = new BrokerClusterStateImpl(topology.get());
            switch(eventType) {
                case MEMBER_ADDED:
                    LOG.debug("Received new broker {}.", brokerInfo);
                    newTopology.addBrokerIfAbsent(brokerInfo.getNodeId());
                    processProperties(brokerInfo, newTopology);
                    break;
                case METADATA_CHANGED:
                    LOG.debug("Received metadata change from Broker {}, partitions {}, terms {} and health {}.", brokerInfo.getNodeId(), brokerInfo.getPartitionRoles(), brokerInfo.getPartitionLeaderTerms(), brokerInfo.getPartitionHealthStatuses());
                    newTopology.addBrokerIfAbsent(brokerInfo.getNodeId());
                    processProperties(brokerInfo, newTopology);
                    break;
                case MEMBER_REMOVED:
                    LOG.debug("Received broker was removed {}.", brokerInfo);
                    newTopology.removeBroker(brokerInfo.getNodeId());
                    break;
                case REACHABILITY_CHANGED:
                default:
                    LOG.debug("Received {} for broker {}, do nothing.", eventType, brokerInfo.getNodeId());
                    break;
            }
            topology.set(newTopology);
            updateMetrics(newTopology);
        });
    }
}
Also used : Type(io.atomix.cluster.ClusterMembershipEvent.Type) Member(io.atomix.cluster.Member) BrokerInfo(io.camunda.zeebe.protocol.impl.encoding.BrokerInfo)

Example 4 with BrokerInfo

use of io.camunda.zeebe.protocol.impl.encoding.BrokerInfo in project zeebe by camunda.

the class BrokerInfoTest method shouldEncodeDecodeBrokerInfoWithEmptyMaps.

@Test
void shouldEncodeDecodeBrokerInfoWithEmptyMaps() {
    // given
    final int nodeId = 123;
    final int partitionsCount = 345;
    final int clusterSize = 567;
    final int replicationFactor = 789;
    final BrokerInfo brokerInfo = new BrokerInfo().setNodeId(nodeId).setPartitionsCount(partitionsCount).setClusterSize(clusterSize).setReplicationFactor(replicationFactor);
    // when
    encodeDecode(brokerInfo);
    // then
    assertThat(brokerInfo.getNodeId()).isEqualTo(nodeId);
    assertThat(brokerInfo.getPartitionsCount()).isEqualTo(partitionsCount);
    assertThat(brokerInfo.getClusterSize()).isEqualTo(clusterSize);
    assertThat(brokerInfo.getReplicationFactor()).isEqualTo(replicationFactor);
    assertThat(brokerInfo.getAddresses()).isEmpty();
    assertThat(brokerInfo.getPartitionRoles()).isEmpty();
    assertThat(brokerInfo.getPartitionHealthStatuses()).isEmpty();
}
Also used : BrokerInfo(io.camunda.zeebe.protocol.impl.encoding.BrokerInfo) Test(org.junit.jupiter.api.Test)

Example 5 with BrokerInfo

use of io.camunda.zeebe.protocol.impl.encoding.BrokerInfo in project zeebe by camunda.

the class BrokerInfoTest method shouldEncodeDecodeNullValues.

@Test
void shouldEncodeDecodeNullValues() {
    // given
    final BrokerInfo brokerInfo = new BrokerInfo();
    // when
    encodeDecode(brokerInfo);
    // then
    assertThat(brokerInfo.getNodeId()).isEqualTo(BrokerInfoEncoder.nodeIdNullValue());
    assertThat(brokerInfo.getPartitionsCount()).isEqualTo(BrokerInfoEncoder.partitionsCountNullValue());
    assertThat(brokerInfo.getClusterSize()).isEqualTo(BrokerInfoEncoder.clusterSizeNullValue());
    assertThat(brokerInfo.getReplicationFactor()).isEqualTo(BrokerInfoEncoder.replicationFactorNullValue());
    assertThat(brokerInfo.getAddresses()).isEmpty();
    assertThat(brokerInfo.getPartitionRoles()).isEmpty();
    assertThat(brokerInfo.getPartitionHealthStatuses()).isEmpty();
}
Also used : BrokerInfo(io.camunda.zeebe.protocol.impl.encoding.BrokerInfo) Test(org.junit.jupiter.api.Test)

Aggregations

BrokerInfo (io.camunda.zeebe.protocol.impl.encoding.BrokerInfo)63 Test (org.junit.Test)36 Member (io.atomix.cluster.Member)9 Test (org.junit.jupiter.api.Test)9 ExporterRepository (io.camunda.zeebe.broker.exporter.repo.ExporterRepository)6 BrokerHealthCheckService (io.camunda.zeebe.broker.system.monitoring.BrokerHealthCheckService)6 ActorSchedulingService (io.camunda.zeebe.util.sched.ActorSchedulingService)6 Type (io.atomix.cluster.ClusterMembershipEvent.Type)3 PartitionHealthStatus (io.camunda.zeebe.protocol.record.PartitionHealthStatus)3 PartitionRole (io.camunda.zeebe.protocol.record.PartitionRole)3 HashMap (java.util.HashMap)3 DirectBuffer (org.agrona.DirectBuffer)3