Skip to content

Commit

Permalink
Rename MirrorProperties to ImporterProperties (hashgraph#7381)
Browse files Browse the repository at this point in the history
Follow up to hashgraph#7380. Provide consistency in naming by renaming `Mirror` prefixed classes that are not common to all modules.

* Rename `MirrorProperties` to `ImporterProperties`
* Remove `DownloaderProperties.getMirrorProperties()`

Signed-off-by: Steven Sheehy <[email protected]>
  • Loading branch information
steven-sheehy authored Dec 13, 2023
1 parent 9e76bc4 commit ad75a33
Show file tree
Hide file tree
Showing 76 changed files with 381 additions and 367 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@Data
@Validated
@ConfigurationProperties("hedera.mirror.importer")
public class MirrorProperties {
public class ImporterProperties {

public static final String STREAMS = "streams";
static final String NETWORK_PREFIX_DELIMITER = "-";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import com.hedera.mirror.common.domain.file.FileData;
import com.hedera.mirror.common.domain.transaction.TransactionType;
import com.hedera.mirror.common.util.DomainUtils;
import com.hedera.mirror.importer.MirrorProperties;
import com.hedera.mirror.importer.MirrorProperties.ConsensusMode;
import com.hedera.mirror.importer.ImporterProperties;
import com.hedera.mirror.importer.ImporterProperties.ConsensusMode;
import com.hedera.mirror.importer.exception.InvalidDatasetException;
import com.hedera.mirror.importer.repository.AddressBookRepository;
import com.hedera.mirror.importer.repository.FileDataRepository;
Expand Down Expand Up @@ -80,7 +80,7 @@ public class AddressBookServiceImpl implements AddressBookService {

private final AddressBookRepository addressBookRepository;
private final FileDataRepository fileDataRepository;
private final MirrorProperties mirrorProperties;
private final ImporterProperties importerProperties;
private final NodeStakeRepository nodeStakeRepository;
private final TransactionTemplate transactionTemplate;

Expand Down Expand Up @@ -135,7 +135,7 @@ public Collection<ConsensusNode> getNodes() {
var totalStake = new AtomicLong(0L);
var nodes = new TreeSet<ConsensusNode>();
var nodeStakes = new HashMap<Long, NodeStake>();
var consensusMode = mirrorProperties.getConsensusMode();
var consensusMode = importerProperties.getConsensusMode();
var nodesInAddressBook = addressBook.getEntries().stream()
.map(AddressBookEntry::getNodeId)
.collect(Collectors.toSet());
Expand Down Expand Up @@ -531,12 +531,12 @@ private FileData getInitialAddressBookFileData() {

// retrieve bootstrap address book from filesystem or classpath
try {
Path initialAddressBook = mirrorProperties.getInitialAddressBook();
Path initialAddressBook = importerProperties.getInitialAddressBook();
if (initialAddressBook != null) {
log.info("Loading bootstrap address book from {}", initialAddressBook);
addressBookBytes = Files.readAllBytes(initialAddressBook);
} else {
var resourcePath = String.format("/addressbook/%s", mirrorProperties.getNetwork());
var resourcePath = String.format("/addressbook/%s", importerProperties.getNetwork());
log.info("Loading bootstrap address book from {}", resourcePath);
Resource resource = new ClassPathResource(resourcePath, getClass());
addressBookBytes = resource.getInputStream().readAllBytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.hedera.mirror.common.domain.StreamFile;
import com.hedera.mirror.common.domain.StreamType;
import com.hedera.mirror.common.util.DomainUtils;
import com.hedera.mirror.importer.MirrorProperties;
import com.hedera.mirror.importer.ImporterProperties;
import com.hedera.mirror.importer.domain.StreamFilename;
import com.hedera.mirror.importer.exception.InvalidConfigurationException;
import com.hedera.mirror.importer.repository.AccountBalanceFileRepository;
Expand All @@ -46,7 +46,7 @@ public class DateRangeCalculator {

static final Instant STARTUP_TIME = Instant.now();

private final MirrorProperties mirrorProperties;
private final ImporterProperties importerProperties;
private final AccountBalanceFileRepository accountBalanceFileRepository;
private final EventFileRepository eventFileRepository;
private final RecordFileRepository recordFileRepository;
Expand All @@ -69,8 +69,8 @@ public DateRangeFilter getFilter(StreamType type) {
}

private DateRangeFilter newDateRangeFilter(StreamType streamType) {
Instant startDate = mirrorProperties.getStartDate();
Instant endDate = mirrorProperties.getEndDate();
Instant startDate = importerProperties.getStartDate();
Instant endDate = importerProperties.getEndDate();
Instant lastFileInstant = findLatest(streamType)
.map(StreamFile::getConsensusStart)
.map(nanos -> Instant.ofEpochSecond(0, nanos))
Expand All @@ -85,7 +85,7 @@ private DateRangeFilter newDateRangeFilter(StreamType streamType) {
if (startDate != null) {
filterStartDate = max(startDate, lastFileInstant);
} else {
if (!MirrorProperties.HederaNetwork.DEMO.equalsIgnoreCase(mirrorProperties.getNetwork())
if (!ImporterProperties.HederaNetwork.DEMO.equalsIgnoreCase(importerProperties.getNetwork())
&& lastFileInstant == null) {
filterStartDate = STARTUP_TIME;
}
Expand All @@ -98,15 +98,15 @@ private DateRangeFilter newDateRangeFilter(StreamType streamType) {
}

/**
* Gets the latest stream file for downloader based on startDate in MirrorProperties, the startDateAdjustment and
* Gets the latest stream file for downloader based on startDate in ImporterProperties, 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();
Instant startDate = importerProperties.getStartDate();
Optional<T> streamFile = findLatest(streamType);
Instant lastFileInstant = streamFile
.map(StreamFile::getConsensusStart)
Expand All @@ -120,11 +120,11 @@ public <T extends StreamFile<?>> Optional<T> getLastStreamFile(StreamType stream
effectiveStartDate = max(startDate, hasStreamFile ? lastFileInstant : Instant.EPOCH);
} else if (hasStreamFile) {
effectiveStartDate = lastFileInstant;
} else if (MirrorProperties.HederaNetwork.DEMO.equalsIgnoreCase(mirrorProperties.getNetwork())) {
} else if (ImporterProperties.HederaNetwork.DEMO.equalsIgnoreCase(importerProperties.getNetwork())) {
effectiveStartDate = Instant.EPOCH; // Demo network contains only data in the past, so don't default to now
}

Instant endDate = mirrorProperties.getEndDate();
Instant endDate = importerProperties.getEndDate();
if (startDate != null && startDate.compareTo(endDate) > 0) {
throw new InvalidConfigurationException(String.format(
"Date range constraint violation: " + "startDate (%s) > endDate (%s)", startDate, endDate));
Expand All @@ -149,7 +149,7 @@ public <T extends StreamFile<?>> Optional<T> getLastStreamFile(StreamType stream
"{}: downloader will download files in time range ({}, {}]",
streamType,
effectiveStartDate,
mirrorProperties.getEndDate());
importerProperties.getEndDate());
return streamFile;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.hedera.mirror.importer.config;

import com.hedera.mirror.importer.MirrorProperties;
import com.hedera.mirror.importer.ImporterProperties;
import com.hedera.mirror.importer.leader.LeaderService;
import com.hedera.mirror.importer.parser.ParserProperties;
import io.micrometer.core.instrument.MeterRegistry;
Expand All @@ -36,7 +36,7 @@
class HealthCheckConfiguration {

private final LeaderService leaderService;
private final MirrorProperties mirrorProperties;
private final ImporterProperties importerProperties;
private final Collection<ParserProperties> parserProperties;

@Bean
Expand All @@ -45,7 +45,7 @@ CompositeHealthContributor streamFileActivity(MeterRegistry meterRegistry) {
Map<String, HealthIndicator> healthIndicators = parserProperties.stream()
.collect(Collectors.toMap(
k -> k.getStreamType().toString(),
v -> new StreamFileHealthIndicator(leaderService, registry, mirrorProperties, v)));
v -> new StreamFileHealthIndicator(leaderService, registry, importerProperties, v)));

return CompositeHealthContributor.fromMap(healthIndicators);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.hedera.mirror.importer.config;

import com.hedera.mirror.importer.MirrorProperties;
import com.hedera.mirror.importer.ImporterProperties;
import com.hedera.mirror.importer.leader.LeaderAspect;
import com.hedera.mirror.importer.leader.LeaderService;
import lombok.CustomLog;
Expand All @@ -43,7 +43,7 @@
@AutoConfigureBefore(FlywayAutoConfiguration.class) // Since this configuration creates FlywayConfigurationCustomizer
class ImporterConfiguration {

private final MirrorProperties mirrorProperties;
private final ImporterProperties importerProperties;

@Bean
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
Expand All @@ -61,9 +61,9 @@ LeaderService leaderService() {
@Bean
FlywayConfigurationCustomizer flywayConfigurationCustomizer() {
return configuration -> {
Long timestamp = mirrorProperties.getTopicRunningHashV2AddedTimestamp();
Long timestamp = importerProperties.getTopicRunningHashV2AddedTimestamp();
if (timestamp == null) {
if (MirrorProperties.HederaNetwork.MAINNET.equalsIgnoreCase(mirrorProperties.getNetwork())) {
if (ImporterProperties.HederaNetwork.MAINNET.equalsIgnoreCase(importerProperties.getNetwork())) {
timestamp = 1592499600000000000L;
} else {
timestamp = 1588706343553042000L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static com.hedera.mirror.importer.downloader.Downloader.STREAM_CLOSE_LATENCY_METRIC_NAME;
import static com.hedera.mirror.importer.parser.AbstractStreamFileParser.STREAM_PARSE_DURATION_METRIC_NAME;

import com.hedera.mirror.importer.MirrorProperties;
import com.hedera.mirror.importer.ImporterProperties;
import com.hedera.mirror.importer.leader.LeaderService;
import com.hedera.mirror.importer.parser.ParserProperties;
import io.micrometer.core.instrument.MeterRegistry;
Expand Down Expand Up @@ -60,7 +60,7 @@ public class StreamFileHealthIndicator implements HealthIndicator {

private final LeaderService leaderService;
private final MeterRegistry meterRegistry;
private final MirrorProperties mirrorProperties;
private final ImporterProperties importerProperties;
private final ParserProperties parserProperty;

@Override
Expand All @@ -73,7 +73,7 @@ public Health health() {
}

// consider case where endTime has been passed
if (mirrorProperties.getEndDate().isBefore(currentInstant)) {
if (importerProperties.getEndDate().isBefore(currentInstant)) {
return endDateInPastHealth;
}

Expand Down Expand Up @@ -111,9 +111,9 @@ public Health health() {
}

private Instant getStartTime() {
return mirrorProperties.getStartDate() == null
return importerProperties.getStartDate() == null
? DateRangeCalculator.STARTUP_TIME
: mirrorProperties.getStartDate();
: importerProperties.getStartDate();
}

private Health getResolvedHealthWhenNoStreamFilesParsed(Instant currentInstant, Instant lastCheck) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package com.hedera.mirror.importer.downloader;

import com.hedera.mirror.importer.MirrorProperties;
import com.hedera.mirror.importer.MirrorProperties.HederaNetwork;
import com.hedera.mirror.importer.ImporterProperties;
import com.hedera.mirror.importer.ImporterProperties.HederaNetwork;
import jakarta.annotation.PostConstruct;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
Expand Down Expand Up @@ -46,7 +46,7 @@ public class CommonDownloaderProperties {

private static final MathContext MATH_CONTEXT = new MathContext(19, RoundingMode.DOWN);

private final MirrorProperties mirrorProperties;
private final ImporterProperties importerProperties;

private String accessKey;

Expand Down Expand Up @@ -92,9 +92,9 @@ public class CommonDownloaderProperties {
@PostConstruct
public void init() {
if (StringUtils.isBlank(bucketName)
&& StringUtils.isBlank(HederaNetwork.getBucketName(mirrorProperties.getNetwork()))) {
&& StringUtils.isBlank(HederaNetwork.getBucketName(importerProperties.getNetwork()))) {
throw new IllegalArgumentException(
"Must define bucketName for network named '%s'".formatted(mirrorProperties.getNetwork()));
"Must define bucketName for network named '%s'".formatted(importerProperties.getNetwork()));
}

StreamSourceProperties.SourceCredentials credentials = null;
Expand Down Expand Up @@ -134,13 +134,13 @@ private void validateRatios() {
public String getBucketName() {
return StringUtils.isNotBlank(bucketName)
? bucketName
: HederaNetwork.getBucketName(mirrorProperties.getNetwork());
: HederaNetwork.getBucketName(importerProperties.getNetwork());
}

public boolean isAnonymousCredentials() {
return allowAnonymousAccess != null
? allowAnonymousAccess
: HederaNetwork.isAllowAnonymousAccess(mirrorProperties.getNetwork());
: HederaNetwork.isAllowAnonymousAccess(importerProperties.getNetwork());
}

public enum PathType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.hedera.mirror.common.domain.StreamFile;
import com.hedera.mirror.common.domain.StreamItem;
import com.hedera.mirror.common.domain.StreamType;
import com.hedera.mirror.importer.MirrorProperties;
import com.hedera.mirror.importer.ImporterProperties;
import com.hedera.mirror.importer.addressbook.ConsensusNode;
import com.hedera.mirror.importer.addressbook.ConsensusNodeService;
import com.hedera.mirror.importer.config.DateRangeCalculator;
Expand Down Expand Up @@ -89,6 +89,7 @@ public abstract class Downloader<T extends StreamFile<I>, I extends StreamItem>

protected final Logger log = LoggerFactory.getLogger(getClass());
protected final DownloaderProperties downloaderProperties;
protected final ImporterProperties importerProperties;
protected final NodeSignatureVerifier nodeSignatureVerifier;
protected final SignatureFileReader signatureFileReader;
protected final StreamFileProvider streamFileProvider;
Expand All @@ -98,7 +99,6 @@ public abstract class Downloader<T extends StreamFile<I>, I extends StreamItem>
protected final AtomicReference<Optional<T>> lastStreamFile = new AtomicReference<>(Optional.empty());

private final ConsensusNodeService consensusNodeService;
private final MirrorProperties mirrorProperties;
private final StreamType streamType;

// Metrics
Expand All @@ -113,6 +113,7 @@ public abstract class Downloader<T extends StreamFile<I>, I extends StreamItem>
protected Downloader(
ConsensusNodeService consensusNodeService,
DownloaderProperties downloaderProperties,
ImporterProperties importerProperties,
MeterRegistry meterRegistry,
DateRangeCalculator dateRangeCalculator,
NodeSignatureVerifier nodeSignatureVerifier,
Expand All @@ -122,14 +123,14 @@ protected Downloader(
StreamFileReader<T, ?> streamFileReader) {
this.consensusNodeService = consensusNodeService;
this.downloaderProperties = downloaderProperties;
this.importerProperties = importerProperties;
this.meterRegistry = meterRegistry;
this.dateRangeCalculator = dateRangeCalculator;
this.nodeSignatureVerifier = nodeSignatureVerifier;
this.signatureFileReader = signatureFileReader;
this.streamFileProvider = streamFileProvider;
this.streamFileReader = streamFileReader;
this.streamFileNotifier = streamFileNotifier;
this.mirrorProperties = downloaderProperties.getMirrorProperties();
this.streamType = downloaderProperties.getStreamType();

// Metrics
Expand Down Expand Up @@ -167,7 +168,7 @@ protected void downloadNextBatch() {

// Following is a cost optimization to not unnecessarily list the public demo bucket once complete
if (sigFilesMap.isEmpty()
&& MirrorProperties.HederaNetwork.DEMO.equalsIgnoreCase(mirrorProperties.getNetwork())) {
&& ImporterProperties.HederaNetwork.DEMO.equalsIgnoreCase(importerProperties.getNetwork())) {
downloaderProperties.setEnabled(false);
log.warn("Disabled polling after downloading all files in demo bucket");
}
Expand All @@ -191,7 +192,7 @@ protected void setStreamFileIndex(T streamFile) {
.get()
.map(StreamFile::getIndex)
.map(v -> v + 1)
.or(() -> Optional.ofNullable(mirrorProperties.getStartBlockNumber()))
.or(() -> Optional.ofNullable(importerProperties.getStartBlockNumber()))
.orElse(0L);
streamFile.setIndex(index);
}
Expand Down Expand Up @@ -338,7 +339,7 @@ private void verifySigsAndDownloadDataFiles(Multimap<StreamFilename, StreamFileS
}

private boolean verifySignatures(Collection<StreamFileSignature> signatures) {
Instant endDate = mirrorProperties.getEndDate();
Instant endDate = importerProperties.getEndDate();

for (var signature : signatures) {
// Ignore signatures that didn't validate or weren't in the majority
Expand All @@ -360,11 +361,11 @@ private boolean verifySignatures(Collection<StreamFileSignature> signatures) {

if (downloaderProperties.isWriteFiles()) {
Utility.archiveFile(
streamFileData.getFilePath(), streamFile.getBytes(), mirrorProperties.getStreamPath());
streamFileData.getFilePath(), streamFile.getBytes(), importerProperties.getStreamPath());
}

if (downloaderProperties.isWriteSignatures()) {
var destination = mirrorProperties.getStreamPath();
var destination = importerProperties.getStreamPath();
signatures.forEach(
s -> Utility.archiveFile(s.getFilename().getFilePath(), s.getBytes(), destination));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.hedera.mirror.importer.downloader;

import com.hedera.mirror.common.domain.StreamType;
import com.hedera.mirror.importer.MirrorProperties;
import java.time.Duration;

public interface DownloaderProperties {
Expand All @@ -26,8 +25,6 @@ public interface DownloaderProperties {

Duration getFrequency();

MirrorProperties getMirrorProperties();

StreamType getStreamType();

boolean isEnabled();
Expand Down
Loading

0 comments on commit ad75a33

Please sign in to comment.