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