Search in sources :

Example 1 with PartitionHealthStatus

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());
        }
    }
}
Also used : AddressesEncoder(io.camunda.zeebe.protocol.record.BrokerInfoEncoder.AddressesEncoder) PartitionLeaderTermsEncoder(io.camunda.zeebe.protocol.record.BrokerInfoEncoder.PartitionLeaderTermsEncoder) PartitionHealthStatus(io.camunda.zeebe.protocol.record.PartitionHealthStatus) PartitionRole(io.camunda.zeebe.protocol.record.PartitionRole) PartitionHealthEncoder(io.camunda.zeebe.protocol.record.BrokerInfoEncoder.PartitionHealthEncoder) MutableDirectBuffer(org.agrona.MutableDirectBuffer) DirectBuffer(org.agrona.DirectBuffer) PartitionRolesEncoder(io.camunda.zeebe.protocol.record.BrokerInfoEncoder.PartitionRolesEncoder)

Example 2 with PartitionHealthStatus

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);
}
Also used : DirectBuffer(org.agrona.DirectBuffer) PartitionHealthStatus(io.camunda.zeebe.protocol.record.PartitionHealthStatus) HashMap(java.util.HashMap) PartitionRole(io.camunda.zeebe.protocol.record.PartitionRole) BrokerInfo(io.camunda.zeebe.protocol.impl.encoding.BrokerInfo) Test(org.junit.jupiter.api.Test)

Example 3 with PartitionHealthStatus

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());
        }
    }
}
Also used : AddressesEncoder(io.camunda.zeebe.protocol.record.BrokerInfoEncoder.AddressesEncoder) PartitionLeaderTermsEncoder(io.camunda.zeebe.protocol.record.BrokerInfoEncoder.PartitionLeaderTermsEncoder) PartitionHealthStatus(io.camunda.zeebe.protocol.record.PartitionHealthStatus) PartitionRole(io.camunda.zeebe.protocol.record.PartitionRole) PartitionHealthEncoder(io.camunda.zeebe.protocol.record.BrokerInfoEncoder.PartitionHealthEncoder) MutableDirectBuffer(org.agrona.MutableDirectBuffer) DirectBuffer(org.agrona.DirectBuffer) PartitionRolesEncoder(io.camunda.zeebe.protocol.record.BrokerInfoEncoder.PartitionRolesEncoder)

Example 4 with PartitionHealthStatus

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);
}
Also used : DirectBuffer(org.agrona.DirectBuffer) PartitionHealthStatus(io.camunda.zeebe.protocol.record.PartitionHealthStatus) HashMap(java.util.HashMap) PartitionRole(io.camunda.zeebe.protocol.record.PartitionRole) BrokerInfo(io.camunda.zeebe.protocol.impl.encoding.BrokerInfo) Test(org.junit.jupiter.api.Test)

Example 5 with PartitionHealthStatus

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());
        }
    }
}
Also used : AddressesEncoder(io.camunda.zeebe.protocol.record.BrokerInfoEncoder.AddressesEncoder) PartitionLeaderTermsEncoder(io.camunda.zeebe.protocol.record.BrokerInfoEncoder.PartitionLeaderTermsEncoder) PartitionHealthStatus(io.camunda.zeebe.protocol.record.PartitionHealthStatus) PartitionRole(io.camunda.zeebe.protocol.record.PartitionRole) PartitionHealthEncoder(io.camunda.zeebe.protocol.record.BrokerInfoEncoder.PartitionHealthEncoder) MutableDirectBuffer(org.agrona.MutableDirectBuffer) DirectBuffer(org.agrona.DirectBuffer) PartitionRolesEncoder(io.camunda.zeebe.protocol.record.BrokerInfoEncoder.PartitionRolesEncoder)

Aggregations

PartitionHealthStatus (io.camunda.zeebe.protocol.record.PartitionHealthStatus)6 PartitionRole (io.camunda.zeebe.protocol.record.PartitionRole)6 DirectBuffer (org.agrona.DirectBuffer)6 BrokerInfo (io.camunda.zeebe.protocol.impl.encoding.BrokerInfo)3 AddressesEncoder (io.camunda.zeebe.protocol.record.BrokerInfoEncoder.AddressesEncoder)3 PartitionHealthEncoder (io.camunda.zeebe.protocol.record.BrokerInfoEncoder.PartitionHealthEncoder)3 PartitionLeaderTermsEncoder (io.camunda.zeebe.protocol.record.BrokerInfoEncoder.PartitionLeaderTermsEncoder)3 PartitionRolesEncoder (io.camunda.zeebe.protocol.record.BrokerInfoEncoder.PartitionRolesEncoder)3 HashMap (java.util.HashMap)3 MutableDirectBuffer (org.agrona.MutableDirectBuffer)3 Test (org.junit.jupiter.api.Test)3