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