Search in sources :

Example 1 with MirrorProperties

use of com.hedera.mirror.importer.MirrorProperties in project hedera-mirror-node by hashgraph.

the class AccountBalanceLineParserV2Test method setup.

@BeforeEach
void setup() {
    mirrorProperties = new MirrorProperties();
    parser = new AccountBalanceLineParserV2(mirrorProperties);
}
Also used : MirrorProperties(com.hedera.mirror.importer.MirrorProperties) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with MirrorProperties

use of com.hedera.mirror.importer.MirrorProperties in project hedera-mirror-node by hashgraph.

the class MirrorDateRangePropertiesProcessor method getLastStreamFile.

/**
 * Gets the latest stream file for downloader based on startDate in MirrorProperties, the startDateAdjustment and
 * last valid downloaded stream file.
 *
 * @param streamType What type of stream to retrieve
 * @return The latest stream file from the database or a dummy stream file if it calculated a different effective
 * start date
 */
public <T extends StreamFile> Optional<T> getLastStreamFile(StreamType streamType) {
    Instant startDate = mirrorProperties.getStartDate();
    Optional<T> streamFile = findLatest(streamType);
    Instant lastFileInstant = streamFile.map(StreamFile::getConsensusStart).map(nanos -> Instant.ofEpochSecond(0, nanos)).orElse(null);
    Instant effectiveStartDate = STARTUP_TIME;
    boolean hasStreamFile = lastFileInstant != null;
    if (startDate != null) {
        effectiveStartDate = max(startDate, hasStreamFile ? lastFileInstant : Instant.EPOCH);
    } else if (hasStreamFile) {
        effectiveStartDate = lastFileInstant;
    } else if (mirrorProperties.getNetwork() == MirrorProperties.HederaNetwork.DEMO) {
        // Demo network contains only data in the past, so don't default to now
        effectiveStartDate = Instant.EPOCH;
    }
    Instant endDate = mirrorProperties.getEndDate();
    if (startDate != null && startDate.compareTo(endDate) > 0) {
        throw new InvalidConfigurationException(String.format("Date range constraint violation: " + "startDate (%s) > endDate (%s)", startDate, endDate));
    }
    if (effectiveStartDate.compareTo(endDate) > 0) {
        throw new InvalidConfigurationException(String.format("Date range constraint violation for %s downloader: effective startDate (%s) > endDate (%s)", streamType, effectiveStartDate, endDate));
    }
    if (!effectiveStartDate.equals(lastFileInstant)) {
        Instant verifyHashAfter = mirrorProperties.getVerifyHashAfter();
        if (verifyHashAfter == null || verifyHashAfter.isBefore(effectiveStartDate)) {
            mirrorProperties.setVerifyHashAfter(effectiveStartDate);
            log.debug("Set verifyHashAfter to {}", effectiveStartDate);
        }
        String filename = StreamFilename.getFilename(streamType, DATA, effectiveStartDate);
        T effectiveStreamFile = (T) ReflectUtils.newInstance(streamType.getStreamFileClass());
        effectiveStreamFile.setConsensusStart(DomainUtils.convertToNanosMax(effectiveStartDate));
        effectiveStreamFile.setName(filename);
        effectiveStreamFile.setIndex(streamFile.map(StreamFile::getIndex).orElse(null));
        streamFile = Optional.of(effectiveStreamFile);
    }
    log.info("{}: downloader will download files in time range ({}, {}]", streamType, effectiveStartDate, mirrorProperties.getEndDate());
    return streamFile;
}
Also used : DownloaderProperties(com.hedera.mirror.importer.downloader.DownloaderProperties) InvalidConfigurationException(com.hedera.mirror.importer.exception.InvalidConfigurationException) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Value(lombok.Value) StreamFilename(com.hedera.mirror.importer.domain.StreamFilename) Duration(java.time.Duration) Map(java.util.Map) Named(javax.inject.Named) Utility(com.hedera.mirror.importer.util.Utility) DomainUtils(com.hedera.mirror.common.util.DomainUtils) ObjectUtils.max(org.apache.commons.lang3.ObjectUtils.max) EventFileRepository(com.hedera.mirror.importer.repository.EventFileRepository) ReflectUtils(org.springframework.cglib.core.ReflectUtils) DATA(com.hedera.mirror.importer.domain.StreamFilename.FileType.DATA) StreamType(com.hedera.mirror.common.domain.StreamType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StreamFile(com.hedera.mirror.common.domain.StreamFile) Instant(java.time.Instant) AccountBalanceFileRepository(com.hedera.mirror.importer.repository.AccountBalanceFileRepository) List(java.util.List) MirrorProperties(com.hedera.mirror.importer.MirrorProperties) RecordFileRepository(com.hedera.mirror.importer.repository.RecordFileRepository) Log4j2(lombok.extern.log4j.Log4j2) Optional(java.util.Optional) StreamFileRepository(com.hedera.mirror.importer.repository.StreamFileRepository) Instant(java.time.Instant) StreamFile(com.hedera.mirror.common.domain.StreamFile) InvalidConfigurationException(com.hedera.mirror.importer.exception.InvalidConfigurationException)

Example 3 with MirrorProperties

use of com.hedera.mirror.importer.MirrorProperties in project hedera-mirror-node by hashgraph.

the class AddressBookServiceImplTest method startupWithOtherNetwork.

@Test
void startupWithOtherNetwork() {
    // copy other addressbook to file system
    FileCopier fileCopier = FileCopier.create(testPath, dataPath).from("").filterFiles("test-v1").to("");
    fileCopier.copy();
    MirrorProperties otherNetworkMirrorProperties = new MirrorProperties();
    otherNetworkMirrorProperties.setDataPath(dataPath);
    otherNetworkMirrorProperties.setInitialAddressBook(dataPath.resolve("test-v1"));
    otherNetworkMirrorProperties.setNetwork(MirrorProperties.HederaNetwork.OTHER);
    AddressBookService customAddressBookService = new AddressBookServiceImpl(addressBookRepository, fileDataRepository, otherNetworkMirrorProperties, transactionTemplate);
    AddressBook addressBook = customAddressBookService.getCurrent();
    assertThat(addressBook.getStartConsensusTimestamp()).isEqualTo(1L);
    assertEquals(1, addressBookRepository.count());
}
Also used : AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) MirrorProperties(com.hedera.mirror.importer.MirrorProperties) FileCopier(com.hedera.mirror.importer.FileCopier) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 4 with MirrorProperties

use of com.hedera.mirror.importer.MirrorProperties in project hedera-mirror-node by hashgraph.

the class AbstractStreamFileHealthIndicatorTest method setup.

@BeforeEach
void setup() {
    doReturn(true).when(leaderService).isLeader();
    doReturn(0.0).when(streamCloseLatencyDurationTimer).mean(any());
    doReturn(0L).when(streamFileParseDurationTimer).count();
    doReturn(streamCloseLatencyDurationTimer).when(streamCloseLatencySearch).timer();
    doReturn(streamFileParseDurationTimer).when(streamParseDurationSearch).timer();
    doReturn(streamCloseLatencySearch).when(streamCloseLatencySearch).tags(anyIterable());
    doReturn(streamParseDurationSearch).when(streamParseDurationSearch).tags(anyIterable());
    doReturn(streamCloseLatencySearch).when(meterRegistry).find(STREAM_CLOSE_LATENCY_METRIC_NAME);
    doReturn(streamParseDurationSearch).when(meterRegistry).find(STREAM_PARSE_DURATION_METRIC_NAME);
    mirrorProperties = new MirrorProperties();
    mirrorProperties.setEndDate(Instant.MAX);
    parserProperties = getParserProperties();
    streamFileHealthIndicator = new StreamFileHealthIndicator(leaderService, meterRegistry, mirrorProperties, parserProperties);
}
Also used : MirrorProperties(com.hedera.mirror.importer.MirrorProperties) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with MirrorProperties

use of com.hedera.mirror.importer.MirrorProperties in project hedera-mirror-node by hashgraph.

the class AbstractDownloaderTest method initProperties.

private void initProperties() {
    mirrorProperties = new MirrorProperties();
    mirrorProperties.setDataPath(dataPath);
    mirrorProperties.setStartBlockNumber(101L);
    mirrorProperties.setNetwork(MirrorProperties.HederaNetwork.TESTNET);
    commonDownloaderProperties = new CommonDownloaderProperties(mirrorProperties);
    commonDownloaderProperties.setEndpointOverride("http://localhost:" + S3_PROXY_PORT);
    downloaderProperties = getDownloaderProperties();
}
Also used : MirrorProperties(com.hedera.mirror.importer.MirrorProperties)

Aggregations

MirrorProperties (com.hedera.mirror.importer.MirrorProperties)8 BeforeEach (org.junit.jupiter.api.BeforeEach)4 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)2 Test (org.junit.jupiter.api.Test)2 StreamFile (com.hedera.mirror.common.domain.StreamFile)1 StreamType (com.hedera.mirror.common.domain.StreamType)1 AddressBook (com.hedera.mirror.common.domain.addressbook.AddressBook)1 DomainUtils (com.hedera.mirror.common.util.DomainUtils)1 FileCopier (com.hedera.mirror.importer.FileCopier)1 StreamFilename (com.hedera.mirror.importer.domain.StreamFilename)1 DATA (com.hedera.mirror.importer.domain.StreamFilename.FileType.DATA)1 CommonDownloaderProperties (com.hedera.mirror.importer.downloader.CommonDownloaderProperties)1 DownloaderProperties (com.hedera.mirror.importer.downloader.DownloaderProperties)1 BalanceDownloaderProperties (com.hedera.mirror.importer.downloader.balance.BalanceDownloaderProperties)1 EventDownloaderProperties (com.hedera.mirror.importer.downloader.event.EventDownloaderProperties)1 RecordDownloaderProperties (com.hedera.mirror.importer.downloader.record.RecordDownloaderProperties)1 InvalidConfigurationException (com.hedera.mirror.importer.exception.InvalidConfigurationException)1 AccountBalanceFileRepository (com.hedera.mirror.importer.repository.AccountBalanceFileRepository)1 EventFileRepository (com.hedera.mirror.importer.repository.EventFileRepository)1 RecordFileRepository (com.hedera.mirror.importer.repository.RecordFileRepository)1