Search in sources :

Example 6 with AddressBookServiceEndpoint

use of com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint in project hedera-mirror-node by hashgraph.

the class AddAddressBookServiceEndpointsMigrationTest method verifyMigrateWhenOnlyDeprecatedIpIsSet.

@Test
void verifyMigrateWhenOnlyDeprecatedIpIsSet() throws IOException {
    long consensusTimestamp = 1;
    int nodeIdCount = 3;
    int endPointPerNode = 0;
    int numEndPoints = nodeIdCount;
    insertAddressBook(AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID, consensusTimestamp, nodeIdCount);
    getAndSaveAddressBookEntries(true, consensusTimestamp, nodeIdCount, endPointPerNode);
    assertThat(addressBookEntryRepository.count()).isEqualTo(numEndPoints);
    runMigration();
    assertThat(addressBookEntryRepository.findAll()).isNotEmpty().hasSize(nodeIdCount).extracting(AddressBookEntry::getId).extracting(AddressBookEntry.Id::getNodeId).containsExactlyInAnyOrder(0L, 1L, 2L);
    assertThat(addressBookServiceEndpointRepository.findAll()).isNotEmpty().hasSize(numEndPoints).extracting(AddressBookServiceEndpoint::getId).extracting(AddressBookServiceEndpoint.Id::getPort).containsExactlyInAnyOrder(443, 444, 445);
}
Also used : AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 7 with AddressBookServiceEndpoint

use of com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint in project hedera-mirror-node by hashgraph.

the class MissingAddressBooksMigrationTest method skipMigrationPreAddressBookService.

@DisplayName("Verify skipMigration")
@ParameterizedTest(name = "with baseline {0} and target {1}")
@CsvSource({ "0, true", "1, false" })
void skipMigrationPreAddressBookService(int serviceEndpointCount, boolean result) {
    for (int j = 1; j <= serviceEndpointCount; ++j) {
        AddressBookServiceEndpoint addressBookServiceEndpoint = new AddressBookServiceEndpoint();
        addressBookServiceEndpoint.setConsensusTimestamp(j);
        addressBookServiceEndpoint.setIpAddressV4("127.0.0.1");
        addressBookServiceEndpoint.setPort(443);
        addressBookServiceEndpoint.setNodeId(100L);
        addressBookServiceEndpointRepository.save(addressBookServiceEndpoint);
    }
    assertThat(missingAddressBooksMigration.skipMigration(getConfiguration())).isEqualTo(result);
}
Also used : AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) CsvSource(org.junit.jupiter.params.provider.CsvSource) DisplayName(org.junit.jupiter.api.DisplayName) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with AddressBookServiceEndpoint

use of com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint in project hedera-mirror-node by hashgraph.

the class AddAddressBookServiceEndpointsMigrationTest method verifyAddressBookEntryDuplicatesRemoved.

@Test
void verifyAddressBookEntryDuplicatesRemoved() throws IOException {
    long consensusTimestamp = 1;
    int nodeIdCount = 3;
    AddressBookEntry.AddressBookEntryBuilder builder = AddressBookEntry.builder().consensusTimestamp(consensusTimestamp).nodeCertHash("nodeCertHash".getBytes()).nodeId(0L).publicKey("rsa+public/key");
    List<Long> nodeIds = List.of(0L, 1L, 2L);
    List<Integer> ports = List.of(80, 443, 5600);
    int numEndPoints = nodeIds.size() * ports.size();
    // populate address_book and address_book_entry
    insertAddressBook(AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID, consensusTimestamp, nodeIdCount);
    nodeIds.forEach(nodeId -> {
        ports.forEach(port -> {
            insertAddressBookEntry(builder.memo(baseAccountId + (nodeId + nodeAccountOffset)).build(), // duplicate ip per nodeId
            baseIp + nodeId, port);
        });
    });
    assertThat(addressBookEntryRepository.count()).isEqualTo(numEndPoints);
    runMigration();
    assertThat(addressBookEntryRepository.findAll()).isNotEmpty().hasSize(nodeIds.size()).extracting(AddressBookEntry::getId).extracting(AddressBookEntry.Id::getNodeId).containsExactlyInAnyOrderElementsOf(nodeIds);
    IterableAssert<AddressBookServiceEndpoint> listAssert = assertThat(addressBookServiceEndpointRepository.findAll()).isNotEmpty().hasSize(numEndPoints);
    List<Integer> allPorts = new ArrayList<>();
    allPorts.addAll(ports);
    allPorts.addAll(ports);
    allPorts.addAll(ports);
    listAssert.extracting(AddressBookServiceEndpoint::getId).extracting(AddressBookServiceEndpoint.Id::getPort).containsExactlyInAnyOrderElementsOf(allPorts);
    // verify address_book counts are updated
    assertThat(addressBookRepository.findById(consensusTimestamp)).get().returns(AddressBookServiceImpl.ADDRESS_BOOK_102_ENTITY_ID, AddressBook::getFileId).returns(nodeIds.size(), AddressBook::getNodeCount).returns(null, AddressBook::getEndConsensusTimestamp);
}
Also used : AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) AtomicLong(java.util.concurrent.atomic.AtomicLong) ArrayList(java.util.ArrayList) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 9 with AddressBookServiceEndpoint

use of com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint in project hedera-mirror-node by hashgraph.

the class AddressBookServiceImpl method getAddressBookServiceEndpoints.

private static Set<AddressBookServiceEndpoint> getAddressBookServiceEndpoints(NodeAddress nodeAddressProto, long consensusTimestamp) throws UnknownHostException {
    var nodeId = nodeAddressProto.getNodeId();
    Set<AddressBookServiceEndpoint> serviceEndpoints = new HashSet<>();
    // create an AddressBookServiceEndpoint for deprecated port and IP if populated
    AddressBookServiceEndpoint deprecatedServiceEndpoint = getAddressBookServiceEndpoint(nodeAddressProto, consensusTimestamp, nodeId);
    if (deprecatedServiceEndpoint != null) {
        serviceEndpoints.add(deprecatedServiceEndpoint);
    }
    // create an AddressBookServiceEndpoint for every ServiceEndpoint found
    for (ServiceEndpoint serviceEndpoint : nodeAddressProto.getServiceEndpointList()) {
        serviceEndpoints.add(getAddressBookServiceEndpoint(serviceEndpoint, consensusTimestamp, nodeId));
    }
    return serviceEndpoints;
}
Also used : AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) HashSet(java.util.HashSet)

Example 10 with AddressBookServiceEndpoint

use of com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint in project hedera-mirror-node by hashgraph.

the class AddressBookServiceImpl method getAddressBookServiceEndpoint.

@SuppressWarnings("deprecation")
private static AddressBookServiceEndpoint getAddressBookServiceEndpoint(NodeAddress nodeAddressProto, long consensusTimestamp, long nodeId) {
    String ip = nodeAddressProto.getIpAddress().toStringUtf8();
    if (StringUtils.isBlank(ip)) {
        return null;
    }
    AddressBookServiceEndpoint addressBookServiceEndpoint = new AddressBookServiceEndpoint();
    addressBookServiceEndpoint.setConsensusTimestamp(consensusTimestamp);
    addressBookServiceEndpoint.setIpAddressV4(ip);
    addressBookServiceEndpoint.setPort(nodeAddressProto.getPortno());
    addressBookServiceEndpoint.setNodeId(nodeId);
    return addressBookServiceEndpoint;
}
Also used : AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)

Aggregations

AddressBookServiceEndpoint (com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)13 AddressBookEntry (com.hedera.mirror.common.domain.addressbook.AddressBookEntry)7 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)4 Test (org.junit.jupiter.api.Test)4 EntityId (com.hedera.mirror.common.domain.entity.EntityId)3 HashSet (java.util.HashSet)3 ByteString (com.google.protobuf.ByteString)2 AddressBook (com.hedera.mirror.common.domain.addressbook.AddressBook)2 ServiceEndpoint (com.hederahashgraph.api.proto.java.ServiceEndpoint)2 Range (com.google.common.collect.Range)1 NodeStake (com.hedera.mirror.common.domain.addressbook.NodeStake)1 AccountBalance (com.hedera.mirror.common.domain.balance.AccountBalance)1 AccountBalanceFile (com.hedera.mirror.common.domain.balance.AccountBalanceFile)1 TokenBalance (com.hedera.mirror.common.domain.balance.TokenBalance)1 Contract (com.hedera.mirror.common.domain.contract.Contract)1 ContractLog (com.hedera.mirror.common.domain.contract.ContractLog)1 ContractResult (com.hedera.mirror.common.domain.contract.ContractResult)1 ContractStateChange (com.hedera.mirror.common.domain.contract.ContractStateChange)1 CryptoAllowance (com.hedera.mirror.common.domain.entity.CryptoAllowance)1 Entity (com.hedera.mirror.common.domain.entity.Entity)1