use of io.camunda.zeebe.protocol.record.PartitionHealthStatus in project zeebe by zeebe-io.
the class BrokerInfo method write.
// TODO: This will be fixed in the https://github.com/zeebe-io/zeebe/issues/5640
@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();
bodyEncoder.wrap(buffer, offset).nodeId(nodeId).partitionsCount(partitionsCount).clusterSize(clusterSize).replicationFactor(replicationFactor);
final int addressesCount = addresses.size();
final AddressesEncoder addressesEncoder = bodyEncoder.addressesCount(addressesCount);
if (addressesCount > 0) {
for (final Entry<DirectBuffer, DirectBuffer> entry : addresses.entrySet()) {
final DirectBuffer apiName = entry.getKey();
final DirectBuffer address = entry.getValue();
addressesEncoder.next().putApiName(apiName, 0, apiName.capacity()).putAddress(address, 0, address.capacity());
}
}
final int partitionRolesCount = partitionRoles.size();
final PartitionRolesEncoder partitionRolesEncoder = bodyEncoder.partitionRolesCount(partitionRolesCount);
if (partitionRolesCount > 0) {
for (final Entry<Integer, PartitionRole> entry : partitionRoles.entrySet()) {
partitionRolesEncoder.next().partitionId(entry.getKey()).role(entry.getValue());
}
}
final int partitionLeaderTermsCount = partitionLeaderTerms.size();
final PartitionLeaderTermsEncoder partitionLeaderTermsEncoder = bodyEncoder.partitionLeaderTermsCount(partitionLeaderTermsCount);
if (partitionLeaderTermsCount > 0) {
for (final Entry<Integer, Long> entry : partitionLeaderTerms.entrySet()) {
partitionLeaderTermsEncoder.next().partitionId(entry.getKey()).term(entry.getValue());
}
}
bodyEncoder.putVersion(version, 0, version.capacity());
final int partitionHealthCount = partitionHealthStatuses.size();
final PartitionHealthEncoder partitionHealthEncoder = bodyEncoder.partitionHealthCount(partitionHealthCount);
if (partitionHealthCount > 0) {
for (final Entry<Integer, PartitionHealthStatus> entry : partitionHealthStatuses.entrySet()) {
partitionHealthEncoder.next().partitionId(entry.getKey()).healthStatus(entry.getValue());
}
}
}
use of io.camunda.zeebe.protocol.record.PartitionHealthStatus in project zeebe by zeebe-io.
the class BrokerInfoTest method shouldEncodeDecodeBrokerInfo.
@Test
void shouldEncodeDecodeBrokerInfo() {
// given
final int nodeId = 123;
final int partitionsCount = 345;
final int clusterSize = 567;
final int replicationFactor = 789;
final Map<DirectBuffer, DirectBuffer> addresses = new HashMap<>();
addresses.put(wrapString("foo"), wrapString("192.159.12.1:23"));
addresses.put(wrapString("bar"), wrapString("zeebe-0.cluster.loc:12312"));
final Map<Integer, PartitionRole> partitionRoles = new HashMap<>();
partitionRoles.put(1, PartitionRole.FOLLOWER);
partitionRoles.put(2, PartitionRole.LEADER);
partitionRoles.put(231, PartitionRole.FOLLOWER);
final Map<Integer, PartitionHealthStatus> partitionHealthStatuses = new HashMap<>();
partitionHealthStatuses.put(1, PartitionHealthStatus.HEALTHY);
partitionHealthStatuses.put(2, PartitionHealthStatus.UNHEALTHY);
partitionHealthStatuses.put(123, PartitionHealthStatus.HEALTHY);
final BrokerInfo brokerInfo = new BrokerInfo().setNodeId(nodeId).setPartitionsCount(partitionsCount).setClusterSize(clusterSize).setReplicationFactor(replicationFactor);
addresses.forEach(brokerInfo::addAddress);
partitionRoles.forEach(brokerInfo::addPartitionRole);
partitionHealthStatuses.forEach(brokerInfo::addPartitionHealth);
// 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()).containsAllEntriesOf(addresses);
assertThat(brokerInfo.getPartitionRoles()).containsAllEntriesOf(partitionRoles);
assertThat(brokerInfo.getPartitionHealthStatuses()).containsAllEntriesOf(partitionHealthStatuses);
}
use of io.camunda.zeebe.protocol.record.PartitionHealthStatus in project zeebe by camunda-cloud.
the class BrokerInfo method write.
// TODO: This will be fixed in the https://github.com/zeebe-io/zeebe/issues/5640
@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();
bodyEncoder.wrap(buffer, offset).nodeId(nodeId).partitionsCount(partitionsCount).clusterSize(clusterSize).replicationFactor(replicationFactor);
final int addressesCount = addresses.size();
final AddressesEncoder addressesEncoder = bodyEncoder.addressesCount(addressesCount);
if (addressesCount > 0) {
for (final Entry<DirectBuffer, DirectBuffer> entry : addresses.entrySet()) {
final DirectBuffer apiName = entry.getKey();
final DirectBuffer address = entry.getValue();
addressesEncoder.next().putApiName(apiName, 0, apiName.capacity()).putAddress(address, 0, address.capacity());
}
}
final int partitionRolesCount = partitionRoles.size();
final PartitionRolesEncoder partitionRolesEncoder = bodyEncoder.partitionRolesCount(partitionRolesCount);
if (partitionRolesCount > 0) {
for (final Entry<Integer, PartitionRole> entry : partitionRoles.entrySet()) {
partitionRolesEncoder.next().partitionId(entry.getKey()).role(entry.getValue());
}
}
final int partitionLeaderTermsCount = partitionLeaderTerms.size();
final PartitionLeaderTermsEncoder partitionLeaderTermsEncoder = bodyEncoder.partitionLeaderTermsCount(partitionLeaderTermsCount);
if (partitionLeaderTermsCount > 0) {
for (final Entry<Integer, Long> entry : partitionLeaderTerms.entrySet()) {
partitionLeaderTermsEncoder.next().partitionId(entry.getKey()).term(entry.getValue());
}
}
bodyEncoder.putVersion(version, 0, version.capacity());
final int partitionHealthCount = partitionHealthStatuses.size();
final PartitionHealthEncoder partitionHealthEncoder = bodyEncoder.partitionHealthCount(partitionHealthCount);
if (partitionHealthCount > 0) {
for (final Entry<Integer, PartitionHealthStatus> entry : partitionHealthStatuses.entrySet()) {
partitionHealthEncoder.next().partitionId(entry.getKey()).healthStatus(entry.getValue());
}
}
}
use of io.camunda.zeebe.protocol.record.PartitionHealthStatus in project zeebe by camunda-cloud.
the class BrokerInfoTest method shouldEncodeDecodeBrokerInfo.
@Test
void shouldEncodeDecodeBrokerInfo() {
// given
final int nodeId = 123;
final int partitionsCount = 345;
final int clusterSize = 567;
final int replicationFactor = 789;
final Map<DirectBuffer, DirectBuffer> addresses = new HashMap<>();
addresses.put(wrapString("foo"), wrapString("192.159.12.1:23"));
addresses.put(wrapString("bar"), wrapString("zeebe-0.cluster.loc:12312"));
final Map<Integer, PartitionRole> partitionRoles = new HashMap<>();
partitionRoles.put(1, PartitionRole.FOLLOWER);
partitionRoles.put(2, PartitionRole.LEADER);
partitionRoles.put(231, PartitionRole.FOLLOWER);
final Map<Integer, PartitionHealthStatus> partitionHealthStatuses = new HashMap<>();
partitionHealthStatuses.put(1, PartitionHealthStatus.HEALTHY);
partitionHealthStatuses.put(2, PartitionHealthStatus.UNHEALTHY);
partitionHealthStatuses.put(123, PartitionHealthStatus.HEALTHY);
final BrokerInfo brokerInfo = new BrokerInfo().setNodeId(nodeId).setPartitionsCount(partitionsCount).setClusterSize(clusterSize).setReplicationFactor(replicationFactor);
addresses.forEach(brokerInfo::addAddress);
partitionRoles.forEach(brokerInfo::addPartitionRole);
partitionHealthStatuses.forEach(brokerInfo::addPartitionHealth);
// 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()).containsAllEntriesOf(addresses);
assertThat(brokerInfo.getPartitionRoles()).containsAllEntriesOf(partitionRoles);
assertThat(brokerInfo.getPartitionHealthStatuses()).containsAllEntriesOf(partitionHealthStatuses);
}
use of io.camunda.zeebe.protocol.record.PartitionHealthStatus in project zeebe by camunda.
the class BrokerInfo method write.
// TODO: This will be fixed in the https://github.com/zeebe-io/zeebe/issues/5640
@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();
bodyEncoder.wrap(buffer, offset).nodeId(nodeId).partitionsCount(partitionsCount).clusterSize(clusterSize).replicationFactor(replicationFactor);
final int addressesCount = addresses.size();
final AddressesEncoder addressesEncoder = bodyEncoder.addressesCount(addressesCount);
if (addressesCount > 0) {
for (final Entry<DirectBuffer, DirectBuffer> entry : addresses.entrySet()) {
final DirectBuffer apiName = entry.getKey();
final DirectBuffer address = entry.getValue();
addressesEncoder.next().putApiName(apiName, 0, apiName.capacity()).putAddress(address, 0, address.capacity());
}
}
final int partitionRolesCount = partitionRoles.size();
final PartitionRolesEncoder partitionRolesEncoder = bodyEncoder.partitionRolesCount(partitionRolesCount);
if (partitionRolesCount > 0) {
for (final Entry<Integer, PartitionRole> entry : partitionRoles.entrySet()) {
partitionRolesEncoder.next().partitionId(entry.getKey()).role(entry.getValue());
}
}
final int partitionLeaderTermsCount = partitionLeaderTerms.size();
final PartitionLeaderTermsEncoder partitionLeaderTermsEncoder = bodyEncoder.partitionLeaderTermsCount(partitionLeaderTermsCount);
if (partitionLeaderTermsCount > 0) {
for (final Entry<Integer, Long> entry : partitionLeaderTerms.entrySet()) {
partitionLeaderTermsEncoder.next().partitionId(entry.getKey()).term(entry.getValue());
}
}
bodyEncoder.putVersion(version, 0, version.capacity());
final int partitionHealthCount = partitionHealthStatuses.size();
final PartitionHealthEncoder partitionHealthEncoder = bodyEncoder.partitionHealthCount(partitionHealthCount);
if (partitionHealthCount > 0) {
for (final Entry<Integer, PartitionHealthStatus> entry : partitionHealthStatuses.entrySet()) {
partitionHealthEncoder.next().partitionId(entry.getKey()).healthStatus(entry.getValue());
}
}
}
Aggregations