Skip to content

Commit 257ed76

Browse files
committed
saving progress
Signed-off-by: Jeromy Cannon <[email protected]>
1 parent 43ab636 commit 257ed76

File tree

5 files changed

+200
-215
lines changed

5 files changed

+200
-215
lines changed

src/commands/node.mjs

Lines changed: 70 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ import {
3636
} from '@hashgraph/sdk'
3737
import * as crypto from 'crypto'
3838

39+
/**
40+
* @typedef {Object} NodeInfo
41+
* @property {string} nodeName
42+
* @property {string} accountId
43+
*/
44+
3945
/**
4046
* Defines the core functionalities of 'node' command
4147
*/
@@ -441,6 +447,7 @@ export class NodeCommand extends BaseCommand {
441447
task: async (ctx, task) => {
442448
self.configManager.update(argv)
443449
await prompts.execute(task, self.configManager, [
450+
// TODO expand this list (maybe store in an array constant
444451
flags.namespace,
445452
flags.nodeIDs,
446453
flags.releaseTag,
@@ -548,17 +555,6 @@ export class NodeCommand extends BaseCommand {
548555
await self._copyNodeKeys(tlsKeyFiles, config.stagingKeysDir)
549556
}
550557
}
551-
},
552-
{
553-
title: 'Prepare config.txt for the network',
554-
task: async (ctx, _) => {
555-
// TODO: move this to profile manager, the flags need to go to init and network commands
556-
const config = ctx.config
557-
const configTxtPath = `${config.stagingDir}/config.txt`
558-
const template = `${constants.RESOURCES_DIR}/templates/config.template`
559-
const appName = self.configManager.getFlag(flags.app)
560-
await self.platformInstaller.prepareConfigTxt(config.nodeIds, configTxtPath, config.releaseTag, config.chainId, template, appName || undefined)
561-
}
562558
}
563559
]
564560

@@ -1122,31 +1118,38 @@ export class NodeCommand extends BaseCommand {
11221118
task: async (ctx, task) => {
11231119
self.configManager.update(argv)
11241120
await prompts.execute(task, self.configManager, [
1125-
flags.namespace,
1126-
flags.nodeIDs,
1127-
flags.releaseTag,
1121+
// TODO expand this list
1122+
flags.app,
11281123
flags.cacheDir,
11291124
flags.chainId,
1125+
flags.chartDirectory,
1126+
flags.fstChartVersion,
11301127
flags.generateGossipKeys,
11311128
flags.generateTlsKeys,
1132-
flags.keyFormat
1129+
flags.keyFormat,
1130+
flags.namespace,
1131+
flags.nodeIDs,
1132+
flags.profileName,
1133+
flags.releaseTag
11331134
])
11341135

11351136
const config = {
1136-
namespace: self.configManager.getFlag(flags.namespace),
1137-
nodeIds: helpers.parseNodeIds(self.configManager.getFlag(flags.nodeIDs)),
1138-
existingNodeIds: [],
1139-
releaseTag: self.configManager.getFlag(flags.releaseTag),
1137+
appName: self.configManager.getFlag(flags.app),
11401138
cacheDir: self.configManager.getFlag(flags.cacheDir),
1141-
force: self.configManager.getFlag(flags.force),
11421139
chainId: self.configManager.getFlag(flags.chainId),
1140+
chartDir: self.configManager.getFlag(flags.chartDirectory),
1141+
curDate: new Date(),
1142+
devMode: self.configManager.getFlag(flags.devMode),
1143+
existingNodeIds: [],
1144+
force: self.configManager.getFlag(flags.force),
1145+
fstChartVersion: self.configManager.getFlag(flags.fstChartVersion),
11431146
generateGossipKeys: self.configManager.getFlag(flags.generateGossipKeys),
11441147
generateTlsKeys: self.configManager.getFlag(flags.generateTlsKeys),
11451148
keyFormat: self.configManager.getFlag(flags.keyFormat),
1146-
devMode: self.configManager.getFlag(flags.devMode),
1147-
chartDir: self.configManager.getFlag(flags.chartDirectory),
1148-
curDate: new Date(),
1149-
fstChartVersion: self.configManager.getFlag(flags.fstChartVersion)
1149+
namespace: self.configManager.getFlag(flags.namespace),
1150+
nodeIds: helpers.parseNodeIds(self.configManager.getFlag(flags.nodeIDs)),
1151+
profileName: self.configManager.getFlag(flags.profileName),
1152+
releaseTag: self.configManager.getFlag(flags.releaseTag)
11501153
}
11511154

11521155
await self.initializeSetup(config, self.configManager, self.k8)
@@ -1179,32 +1182,48 @@ export class NodeCommand extends BaseCommand {
11791182
title: 'Deploy new network node',
11801183
task: async (ctx, task) => {
11811184
const values = { hedera: { nodes: [] } }
1182-
let maxNum
1185+
let maxAccountNumber = 0
1186+
/** @type {Map<string,NodeInfo>} **/
1187+
const nodeMap = new Map()
1188+
11831189
for (/** @type {NetworkNodeServices} **/ const networkNodeServices of ctx.config.serviceMap.values()) {
11841190
values.hedera.nodes.push({
11851191
accountId: networkNodeServices.accountId,
11861192
name: networkNodeServices.nodeName
11871193
})
1188-
maxNum = maxNum > AccountId.fromString(networkNodeServices.accountId).num
1189-
? maxNum
1194+
maxAccountNumber = maxAccountNumber > AccountId.fromString(networkNodeServices.accountId).num
1195+
? maxAccountNumber
11901196
: AccountId.fromString(networkNodeServices.accountId).num
1197+
nodeMap.set(networkNodeServices.nodeName, {
1198+
nodeName: networkNodeServices.nodeName,
1199+
accountId: networkNodeServices.accountId
1200+
})
11911201
}
1202+
11921203
for (const nodeId of ctx.config.nodeIds) {
11931204
const accountId = AccountId.fromString(values.hedera.nodes[0].accountId)
1194-
accountId.num = ++maxNum
1205+
accountId.num = ++maxAccountNumber
11951206
values.hedera.nodes.push({
11961207
accountId: accountId.toString(),
11971208
name: nodeId
11981209
})
1210+
nodeMap.set(nodeId, {
1211+
nodeName: nodeId,
1212+
accountId: accountId.toString()
1213+
})
11991214
}
12001215

12011216
let valuesArg = ''
12021217
let index = 0
1218+
12031219
for (const node of values.hedera.nodes) {
12041220
valuesArg += ` --set "hedera.nodes[${index}].accountId=${node.accountId}" --set "hedera.nodes[${index}].name=${node.name}"`
12051221
index++
12061222
}
12071223

1224+
const valuesFilePath = await this.profileManager.prepareValuesForNodeAdd(ctx.config.profileName, nodeMap)
1225+
valuesArg += this.prepareValuesFiles(valuesFilePath)
1226+
12081227
await self.chartManager.upgrade(
12091228
ctx.config.namespace,
12101229
constants.FULLSTACK_DEPLOYMENT_CHART,
@@ -1308,16 +1327,6 @@ export class NodeCommand extends BaseCommand {
13081327
await self._copyNodeKeys(tlsKeyFiles, config.stagingKeysDir)
13091328
}
13101329
}
1311-
},
1312-
{
1313-
title: 'Prepare config.txt for the network',
1314-
task: async (ctx, _) => {
1315-
// TODO: move this to profile manager, the flags need to go to init and network commands
1316-
const config = ctx.config
1317-
const configTxtPath = `${config.stagingDir}/config.txt`
1318-
const template = `${constants.RESOURCES_DIR}/templates/config.template`
1319-
await self.platformInstaller.prepareConfigTxt(config.allNodeIds, configTxtPath, config.releaseTag, config.chainId, template)
1320-
}
13211330
}
13221331
]
13231332

@@ -1577,23 +1586,23 @@ export class NodeCommand extends BaseCommand {
15771586
command: 'setup',
15781587
desc: 'Setup node with a specific version of Hedera platform',
15791588
builder: y => flags.setCommandFlags(y,
1580-
flags.namespace,
1581-
flags.nodeIDs,
1582-
flags.releaseTag,
1583-
flags.generateGossipKeys,
1584-
flags.generateTlsKeys,
1589+
flags.apiPermissionProperties, // TODO move
1590+
flags.app,
1591+
flags.appConfig,
1592+
flags.applicationProperties, // TODO move
1593+
flags.bootstrapProperties, // TODO move
15851594
flags.cacheDir,
15861595
flags.chainId,
15871596
flags.force,
1597+
flags.generateGossipKeys,
1598+
flags.generateTlsKeys,
15881599
flags.keyFormat,
1589-
flags.applicationProperties,
1590-
flags.apiPermissionProperties,
1591-
flags.bootstrapProperties,
1592-
flags.settingTxt,
15931600
flags.localBuildPath,
1594-
flags.app,
1595-
flags.appConfig,
1596-
flags.log4j2Xml
1601+
flags.log4j2Xml, // TODO move
1602+
flags.namespace,
1603+
flags.nodeIDs,
1604+
flags.releaseTag,
1605+
flags.settingTxt // TODO move
15971606
),
15981607
handler: argv => {
15991608
nodeCmd.logger.debug('==== Running \'node setup\' ===')
@@ -1717,20 +1726,21 @@ export class NodeCommand extends BaseCommand {
17171726
command: 'add',
17181727
desc: 'Adds a node with a specific version of Hedera platform',
17191728
builder: y => flags.setCommandFlags(y,
1720-
flags.namespace,
1721-
flags.nodeIDs,
1722-
flags.releaseTag,
1723-
flags.generateGossipKeys,
1724-
flags.generateTlsKeys,
1729+
// TODO expand this list?
1730+
flags.apiPermissionProperties,
1731+
flags.applicationProperties,
1732+
flags.bootstrapProperties,
17251733
flags.cacheDir,
17261734
flags.chainId,
17271735
flags.force,
1736+
flags.generateGossipKeys,
1737+
flags.generateTlsKeys,
17281738
flags.keyFormat,
1729-
flags.applicationProperties,
1730-
flags.apiPermissionProperties,
1731-
flags.bootstrapProperties,
1732-
flags.settingTxt,
1733-
flags.log4j2Xml
1739+
flags.log4j2Xml,
1740+
flags.namespace,
1741+
flags.nodeIDs,
1742+
flags.releaseTag,
1743+
flags.settingTxt
17341744
),
17351745
handler: argv => {
17361746
nodeCmd.logger.debug('==== Running \'node add\' ===')

src/core/platform_installer.mjs

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -177,36 +177,6 @@ export class PlatformInstaller {
177177
}
178178
}
179179

180-
// TODO delete this we will update profileManager.resourcesForConsensusPod to read these files and put into the values.yaml
181-
async copyPlatformConfigFiles (podName, stagingDir) {
182-
const self = this
183-
184-
if (!podName) throw new MissingArgumentError('podName is required')
185-
if (!stagingDir) throw new MissingArgumentError('stagingDir is required')
186-
187-
try {
188-
const srcFilesSet1 = [
189-
`${stagingDir}/config.txt`,
190-
`${stagingDir}/templates/log4j2.xml`,
191-
`${stagingDir}/templates/settings.txt`
192-
]
193-
194-
const fileList1 = await self.copyFiles(podName, srcFilesSet1, constants.HEDERA_HAPI_PATH)
195-
196-
const srcFilesSet2 = [
197-
`${stagingDir}/templates/api-permission.properties`,
198-
`${stagingDir}/templates/application.properties`,
199-
`${stagingDir}/templates/bootstrap.properties`
200-
]
201-
202-
const fileList2 = await self.copyFiles(podName, srcFilesSet2, `${constants.HEDERA_HAPI_PATH}/data/config`)
203-
204-
return fileList1.concat(fileList2)
205-
} catch (e) {
206-
throw new FullstackTestingError(`failed to copy config files to pod '${podName}': ${e.message}`, e)
207-
}
208-
}
209-
210180
async copyTLSKeys (podName, stagingDir) {
211181
if (!podName) throw new MissingArgumentError('podName is required')
212182
if (!stagingDir) throw new MissingArgumentError('stagingDir is required')
@@ -269,74 +239,6 @@ export class PlatformInstaller {
269239
}
270240
}
271241

272-
/**
273-
* Prepares config.txt file for the node
274-
* @param {string[]} nodeIDs node IDs
275-
* @param {string} destPath path where config.txt should be written
276-
* @param {string} releaseTag release tag e.g. v0.42.0
277-
* @param {string} template path to the config.template file
278-
* @param {string} chainId chain ID (298 for local network)
279-
* @param {string} appName the app name (default: HederaNode.jar)
280-
* @returns {Promise<string[]>}
281-
*/
282-
async prepareConfigTxt (nodeIDs, destPath, releaseTag, chainId = constants.HEDERA_CHAIN_ID, template = `${constants.RESOURCES_DIR}/templates/config.template`, appName = constants.HEDERA_APP_NAME) {
283-
// TODO: move this to profile manager
284-
// TODO: nodeIds should come from argv, it is required, it is already in profileManager.resourcesForConsensusPod
285-
if (!nodeIDs || nodeIDs.length === 0) throw new MissingArgumentError('list of node IDs is required')
286-
if (!destPath) throw new MissingArgumentError('destPath is required')
287-
if (!template) throw new MissingArgumentError('config templatePath is required')
288-
if (!releaseTag) throw new MissingArgumentError('release tag is required')
289-
290-
if (!fs.existsSync(path.dirname(destPath))) throw new IllegalArgumentError(`destPath does not exist: ${destPath}`, destPath)
291-
if (!fs.existsSync(template)) throw new IllegalArgumentError(`config templatePath does not exist: ${template}`, destPath)
292-
293-
// init variables
294-
const internalPort = constants.HEDERA_NODE_INTERNAL_GOSSIP_PORT
295-
const externalPort = constants.HEDERA_NODE_EXTERNAL_GOSSIP_PORT
296-
const nodeStakeAmount = constants.HEDERA_NODE_DEFAULT_STAKE_AMOUNT
297-
298-
const releaseVersion = semver.parse(releaseTag, { includePrerelease: true })
299-
300-
try {
301-
// TODO we need to build the config.txt prior to deploying the network
302-
const networkNodeServicesMap = await this.accountManager.getNodeServiceMap(this._getNamespace())
303-
/** @type {string[]} */
304-
const configLines = fs.readFileSync(template, 'utf-8').split('\n')
305-
configLines.push(`swirld, ${chainId}`)
306-
configLines.push(`app, ${appName}`)
307-
308-
let nodeSeq = 0
309-
for (const nodeId of nodeIDs) {
310-
const networkNodeServices = networkNodeServicesMap.get(nodeId)
311-
const nodeName = nodeId
312-
const nodeNickName = nodeId
313-
314-
const internalIP = Templates.renderFullyQualifiedNetworkPodName(this._getNamespace(), nodeId)
315-
const externalIP = Templates.renderFullyQualifiedNetworkSvcName(this._getNamespace(), nodeId)
316-
317-
// TODO yamlRoot returned from ProfileManager.resourcesForConsensusPod (called from prepareValuesForFstChart) has: { hedera.nodes.${nodeIndex}.name & hedera.nodes.${nodeIndex}.accountId } const account = networkNodeServices.accountId
318-
const account = networkNodeServices.accountId
319-
if (releaseVersion.minor >= 40) {
320-
configLines.push(`address, ${nodeSeq}, ${nodeNickName}, ${nodeName}, ${nodeStakeAmount}, ${internalIP}, ${internalPort}, ${externalIP}, ${externalPort}, ${account}`)
321-
} else {
322-
configLines.push(`address, ${nodeSeq}, ${nodeName}, ${nodeStakeAmount}, ${internalIP}, ${internalPort}, ${externalIP}, ${externalPort}, ${account}`)
323-
}
324-
325-
nodeSeq += 1
326-
}
327-
328-
if (releaseVersion.minor >= 41) {
329-
configLines.push(`nextNodeId, ${nodeSeq}`)
330-
}
331-
332-
fs.writeFileSync(destPath, configLines.join('\n'))
333-
334-
return configLines
335-
} catch (e) {
336-
throw new FullstackTestingError('failed to generate config.txt', e)
337-
}
338-
}
339-
340242
/**
341243
* Return a list of task to perform node installation
342244
*
@@ -373,11 +275,6 @@ export class PlatformInstaller {
373275
task: (_, task) =>
374276
self.copyTLSKeys(podName, stagingDir, keyFormat)
375277
},
376-
{
377-
title: 'Copy configuration files',
378-
task: (_, task) =>
379-
self.copyPlatformConfigFiles(podName, stagingDir)
380-
},
381278
{
382279
title: 'Set file permissions',
383280
task: (_, task) =>

0 commit comments

Comments
 (0)