Skip to content

Commit

Permalink
fix dab upgrade test
Browse files Browse the repository at this point in the history
Signed-off-by: Neeharika-Sompalli <[email protected]>
  • Loading branch information
Neeharika-Sompalli committed Jan 10, 2025
1 parent bda214e commit c4a9eb8
Showing 1 changed file with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.swirlds.platform.state.service.ReadablePlatformStateStore;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
Expand All @@ -37,6 +38,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.stream.StreamSupport;

import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -110,10 +112,11 @@ public void externalizeFreezeIfUpgradePending() {

/**
* Write a marker file.
*
* @param file the name of the marker file
* @param now the timestamp to write to the marker file
* if null, the marker file will contain the string "✓"
* if not null, the marker file will contain the string representation of the timestamp
* @param now the timestamp to write to the marker file
* if null, the marker file will contain the string "✓"
* if not null, the marker file will contain the string representation of the timestamp
*/
protected void writeMarker(@NonNull final String file, @Nullable final Timestamp now) {
requireNonNull(file);
Expand All @@ -134,6 +137,7 @@ protected void writeMarker(@NonNull final String file, @Nullable final Timestamp

/**
* Write a marker file containing the string '✓'.
*
* @param file the name of the marker file
*/
protected void writeCheckMarker(@NonNull final String file) {
Expand All @@ -143,8 +147,9 @@ protected void writeCheckMarker(@NonNull final String file) {

/**
* Write a marker file containing the string representation of the given timestamp.
*
* @param file the name of the marker file
* @param now the timestamp to write to the marker file
* @param now the timestamp to write to the marker file
*/
protected void writeSecondMarker(@NonNull final String file, @Nullable final Timestamp now) {
requireNonNull(file);
Expand All @@ -158,8 +163,9 @@ public void catchUpOnMissedSideEffects(@NonNull final ReadablePlatformStateStore

/**
* Check whether the two given hashes match.
*
* @param curSpecialFilesHash the first hash
* @param hashFromTxnBody the second hash
* @param hashFromTxnBody the second hash
* @return true if the hashes match, false otherwise
*/
public boolean isPreparedFileHashValidGiven(final byte[] curSpecialFilesHash, final byte[] hashFromTxnBody) {
Expand All @@ -168,8 +174,9 @@ public boolean isPreparedFileHashValidGiven(final byte[] curSpecialFilesHash, fi

/**
* Extract the telemetry upgrade from the given archive data.
*
* @param archiveData the archive data
* @param now the timestamp to write to the marker file
* @param now the timestamp to write to the marker file
* @return a future that completes when the extraction is done
*/
public CompletableFuture<Void> extractTelemetryUpgrade(
Expand All @@ -180,6 +187,7 @@ public CompletableFuture<Void> extractTelemetryUpgrade(

/**
* Extract the software upgrade from the given archive data.
*
* @param archiveData the archive data
* @return a future that completes when the extraction is done
*/
Expand All @@ -190,6 +198,7 @@ public CompletableFuture<Void> extractSoftwareUpgrade(@NonNull final Bytes archi

/**
* Check whether a freeze is scheduled.
*
* @param platformStateStore the platform state
* @return true if a freeze is scheduled, false otherwise
*/
Expand Down Expand Up @@ -224,7 +233,8 @@ private CompletableFuture<Void> extractNow(
executor);
}

private record ActiveNode(@NonNull Node node, @Nullable StakingNodeInfo stakingInfo) {}
private record ActiveNode(@NonNull Node node, @Nullable StakingNodeInfo stakingInfo) {
}

private List<ActiveNode> allActiveNodes() {
return StreamSupport.stream(
Expand Down Expand Up @@ -259,10 +269,11 @@ private void extractAndReplaceArtifacts(
FileUtils.cleanDirectory(keysDir);
UnzipUtility.unzip(archiveData.toByteArray(), artifactsLoc);
log.info("Finished unzipping {} bytes for {} update into {}", size, desc, artifactsLoc);
final var useRosterLifecycle = addressBookConfig.useRosterLifecycle();
if (nodes != null
&& nodesConfig.enableDAB()
&& (!addressBookConfig.useRosterLifecycle() || networkAdminConfig.exportCandidateRoster())) {
generateConfigPem(artifactsLoc, keysLoc, nodes);
&& (!useRosterLifecycle || networkAdminConfig.exportCandidateRoster())) {
generateConfigPem(artifactsLoc, keysLoc, nodes, useRosterLifecycle);
log.info("Finished generating config.txt and pem files into {}", artifactsLoc);
}
writeSecondMarker(marker, now);
Expand All @@ -278,7 +289,8 @@ private void extractAndReplaceArtifacts(
private void generateConfigPem(
@NonNull final Path artifactsLoc,
@NonNull final Path keysLoc,
@NonNull final List<ActiveNode> activeNodes) {
@NonNull final List<ActiveNode> activeNodes,
final boolean useRosterLifecycle) {
requireNonNull(artifactsLoc, "Cannot generate config.txt without a valid artifacts location");
requireNonNull(keysLoc, "Cannot generate pem files without a valid keys location");
requireNonNull(activeNodes, "Cannot generate config.txt without a valid list of active nodes");
Expand All @@ -290,22 +302,22 @@ private void generateConfigPem(
}

try (final var fw = new FileWriter(configTxt.toFile());
final var bw = new BufferedWriter(fw)) {
activeNodes.forEach(node -> writeConfigLineAndPem(node, bw, keysLoc));
final var bw = new BufferedWriter(fw)) {
activeNodes.forEach(node -> writeConfigLineAndPem(node, bw, keysLoc, useRosterLifecycle));
bw.flush();
} catch (final IOException e) {
log.error("Failed to generate {} with exception : {}", configTxt, e);
}
}

private void writeConfigLineAndPem(
@NonNull final ActiveNode activeNode, @NonNull final BufferedWriter bw, @NonNull final Path keysLoc) {
@NonNull final ActiveNode activeNode, @NonNull final BufferedWriter bw, @NonNull final Path keysLoc, final boolean useRosterLifecycle) {
requireNonNull(activeNode);
requireNonNull(bw);
requireNonNull(keysLoc);

var line = new StringBuilder();
int weight = 0;
long weight = 0;
final var node = activeNode.node();
final var name = "node" + (node.nodeId() + 1);
final var alias = nameToAlias(name);
Expand All @@ -315,7 +327,11 @@ private void writeConfigLineAndPem(

final var stakingNodeInfo = activeNode.stakingInfo();
if (stakingNodeInfo != null) {
weight = stakingNodeInfo.weight();
if (useRosterLifecycle) {
weight = stakingNodeInfo.stake();
} else {
weight = stakingNodeInfo.weight();
}
}

final var gossipEndpoints = node.gossipEndpoint();
Expand Down

0 comments on commit c4a9eb8

Please sign in to comment.