Skip to content

Commit 4bfd998

Browse files
committed
added logic for setting the value file
Signed-off-by: instamenta <[email protected]>
1 parent 59b156c commit 4bfd998

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

src/commands/network.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ export class NetworkCommand extends BaseCommand {
169169
valuesArg += this.prepareValuesFiles(this.profileValuesFile);
170170
}
171171

172+
const genesisNetworkDataFile = await this.profileManager.prepareValuesForGenesisNetwork(config.genesisNetworkData);
173+
if (genesisNetworkDataFile) {
174+
valuesArg += this.prepareValuesFiles(genesisNetworkDataFile);
175+
}
176+
172177
// do not deploy mirror node until after we have the updated address book
173178
valuesArg += ` --set "telemetry.prometheus.svcMonitor.enabled=${config.enablePrometheusSvcMonitor}"`;
174179

src/core/profile_manager.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ import * as helpers from './helpers.js';
3030
import {getNodeAccountMap} from './helpers.js';
3131
import type {SemVer} from 'semver';
3232
import type {SoloLogger} from './logging.js';
33-
import type {AnyObject, NodeAlias, NodeAliases, Path} from '../types/aliases.js';
33+
import type {AnyObject, DirPath, NodeAlias, NodeAliases, Path} from '../types/aliases.js';
3434
import type {GenesisNetworkDataConstructor} from './models/genesisNetworkDataConstructor.js';
35+
import type {Optional} from '../types/index.js';
3536

3637
const consensusSidecars = [
3738
'recordStreamUploader',
@@ -44,12 +45,12 @@ const consensusSidecars = [
4445
export class ProfileManager {
4546
private readonly logger: SoloLogger;
4647
private readonly configManager: ConfigManager;
47-
private readonly cacheDir: string;
48+
private readonly cacheDir: DirPath;
4849

4950
private profiles: Map<string, AnyObject>;
50-
private profileFile: string | undefined;
51+
private profileFile: Optional<string>;
5152

52-
constructor(logger: SoloLogger, configManager: ConfigManager, cacheDir = constants.SOLO_VALUES_DIR) {
53+
constructor(logger: SoloLogger, configManager: ConfigManager, cacheDir: DirPath = constants.SOLO_VALUES_DIR) {
5354
if (!logger) throw new MissingArgumentError('An instance of core/SoloLogger is required');
5455
if (!configManager) throw new MissingArgumentError('An instance of core/ConfigManager is required');
5556

@@ -176,7 +177,7 @@ export class ProfileManager {
176177
for (const key in dotItems) {
177178
let itemKey = key;
178179

179-
// if it is an array key like extraEnv[0].JAVA_OPTS, convert it into dot separated key as extraEnv.0.JAVA_OPTS
180+
// if it is an array key like extraEnv[0].JAVA_OPTS, convert it into a dot separated key as extraEnv.0.JAVA_OPTS
180181
if (key.indexOf('[') !== -1) {
181182
itemKey = key.replace('[', '.').replace(']', '');
182183
}
@@ -370,10 +371,13 @@ export class ProfileManager {
370371
return this.writeToYaml(cachedValuesFile, yamlRoot);
371372
}
372373

373-
public setValueForGenesisNetwork(path: string) {
374+
public prepareValuesForGenesisNetwork(genesisNetworkData: GenesisNetworkDataConstructor): Promise<string> {
374375
const yamlRoot = {};
375376

376-
this._setFileContentsAsValue('hedera.configMaps.genesisNetworkJson', path, yamlRoot);
377+
this._setValue('hedera.configMaps.genesisNetworkJson', genesisNetworkData.toJSON(), yamlRoot);
378+
379+
const cachedValuesFile = path.join(this.cacheDir, 'genesis-network.yaml');
380+
return this.writeToYaml(cachedValuesFile, yamlRoot);
377381
}
378382

379383
/**
@@ -484,12 +488,15 @@ export class ProfileManager {
484488
chainId = constants.HEDERA_CHAIN_ID,
485489
genesisNetworkData?: GenesisNetworkDataConstructor,
486490
) {
487-
if (!nodeAccountMap || nodeAccountMap.size === 0)
491+
if (!nodeAccountMap || nodeAccountMap.size === 0) {
488492
throw new MissingArgumentError('nodeAccountMap the map of node IDs to account IDs is required');
493+
}
494+
489495
if (!releaseTag) throw new MissingArgumentError('release tag is required');
490496

491-
if (!fs.existsSync(destPath))
497+
if (!fs.existsSync(destPath)) {
492498
throw new IllegalArgumentError(`config destPath does not exist: ${destPath}`, destPath);
499+
}
493500

494501
// init variables
495502
const internalPort = +constants.HEDERA_NODE_INTERNAL_GOSSIP_PORT;
@@ -516,11 +523,11 @@ export class ProfileManager {
516523
nodeDataWrapper.weight = nodeStakeAmount;
517524
nodeDataWrapper.accountId = account;
518525

519-
// Add gossip endpoints
526+
//? Add gossip endpoints
520527
nodeDataWrapper.addGossipEndpoint(externalIP, externalPort);
521528
nodeDataWrapper.addGossipEndpoint(internalIP, internalPort);
522529

523-
// Add service endpoints
530+
//? Add service endpoints
524531
nodeDataWrapper.addServiceEndpoint(internalIP, internalPort);
525532
}
526533

src/types/aliases.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,7 @@ export type IP = string;
4646
export type JsonString = string;
4747

4848
export type Path = string;
49+
export type FilePath = string;
50+
export type DirPath = string;
4951

5052
export type AnyObject = Record<any, any>;

0 commit comments

Comments
 (0)