Skip to content

Commit 83ff877

Browse files
committed
fix: updated required flags
Signed-off-by: Ivo Yankov <[email protected]>
1 parent c52ffe2 commit 83ff877

13 files changed

+98
-79
lines changed

Diff for: src/commands/node/flags.mjs

+6-6
Original file line numberDiff line numberDiff line change
@@ -199,28 +199,28 @@ export const STOP_FLAGS = {
199199

200200
export const START_FLAGS = {
201201
requiredFlags: [
202-
flags.app,
203-
flags.debugNodeAlias,
204202
flags.namespace,
203+
],
204+
requiredFlagsWithDisabledPrompt: [
205+
flags.app,
205206
flags.nodeAliasesUnparsed,
206207
],
207-
requiredFlagsWithDisabledPrompt: [],
208208
optionalFlags: [
209-
flags.quiet
209+
flags.quiet,
210+
flags.debugNodeAlias,
210211
]
211212
}
212213

213214
export const SETUP_FLAGS = {
214215
requiredFlags: [
215-
216216
flags.cacheDir,
217217
flags.namespace,
218-
flags.nodeAliasesUnparsed,
219218
flags.releaseTag
220219
],
221220
requiredFlagsWithDisabledPrompt: [
222221
flags.app,
223222
flags.appConfig,
223+
flags.nodeAliasesUnparsed,
224224
],
225225
optionalFlags: [
226226
flags.devMode,

Diff for: src/commands/node/handlers.mjs

+22-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
updateConfigBuilder
2828
} from "./configs.mjs";
2929
import {constants} from "../../core/index.mjs";
30-
import {IllegalArgumentError, SoloError} from "../../core/errors.mjs";
30+
import {IllegalArgumentError} from "../../core/errors.mjs";
3131
import * as flags from "../flags.mjs";
3232

3333
export class NodeCommandHandlers {
@@ -42,6 +42,8 @@ export class NodeCommandHandlers {
4242

4343
this.logger = opts.logger
4444
this.tasks = opts.tasks
45+
this.accountManager = opts.accountManager
46+
this.configManager = opts.configManager
4547
}
4648

4749
/**
@@ -59,6 +61,22 @@ export class NodeCommandHandlers {
5961
}
6062

6163

64+
/**
65+
* stops and closes the port forwards
66+
* @returns {Promise<void>}
67+
*/
68+
async close () {
69+
this.accountManager.close()
70+
if (this._portForwards) {
71+
for (const srv of this._portForwards) {
72+
await this.k8.stopPortForward(srv)
73+
}
74+
}
75+
76+
this._portForwards = []
77+
}
78+
79+
6280
/********** Task Lists **********/
6381

6482
deletePrepareTaskList(argv) {
@@ -414,14 +432,14 @@ export class NodeCommandHandlers {
414432
}
415433

416434
async start (argv) {
417-
argv = helpers.addFlagsToArgv(argv, NodeFlags.STOP_FLAGS)
435+
argv = helpers.addFlagsToArgv(argv, NodeFlags.START_FLAGS)
418436
const action = helpers.commandActionBuilder([
419437
this.tasks.initialize(argv, startConfigBuilder.bind(this)),
420438
this.tasks.identifyExistingNodes(),
421439
this.tasks.startNodes('nodeAliases'),
422440
this.tasks.enablePortForwarding(),
423441
this.tasks.checkAllNodesAreActive('nodeAliases'),
424-
this.tasks.checkNodeProxiesAreActive(() => self.configManager.getFlag(flags.app) !== '' && self.configManager.getFlag(flags.app) !== constants.HEDERA_APP_NAME),
442+
this.tasks.checkNodeProxiesAreActive(() => this.configManager.getFlag(flags.app) !== '' && this.configManager.getFlag(flags.app) !== constants.HEDERA_APP_NAME),
425443
this.tasks.addNodeStakes(),
426444
], {
427445
concurrent: false,
@@ -432,7 +450,7 @@ export class NodeCommandHandlers {
432450
}
433451

434452
async setup (argv) {
435-
argv = helpers.addFlagsToArgv(argv, NodeFlags.DEFAULT_FLAGS)
453+
argv = helpers.addFlagsToArgv(argv, NodeFlags.SETUP_FLAGS)
436454
const action = helpers.commandActionBuilder([
437455
this.tasks.initialize(argv, setupConfigBuilder.bind(this)),
438456
this.tasks.identifyNetworkPods(),

Diff for: src/commands/node/index.mjs

+14-14
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,20 @@ export class NodeCommand extends BaseCommand {
6767
})
6868
}
6969

70-
// /**
71-
// * stops and closes the port forwards
72-
// * @returns {Promise<void>}
73-
// */
74-
// async close () {
75-
// this.accountManager.close()
76-
// if (this._portForwards) {
77-
// for (const srv of this._portForwards) {
78-
// await this.k8.stopPortForward(srv)
79-
// }
80-
// }
81-
//
82-
// this._portForwards = []
83-
// }
70+
/**
71+
* stops and closes the port forwards
72+
* @returns {Promise<void>}
73+
*/
74+
async close () {
75+
this.accountManager.close()
76+
if (this._portForwards) {
77+
for (const srv of this._portForwards) {
78+
await this.k8.stopPortForward(srv)
79+
}
80+
}
81+
82+
this._portForwards = []
83+
}
8484

8585
// Command Definition
8686
/**

Diff for: src/commands/node/tasks.mjs

+33-34
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,9 @@ export class NodeCommandTasks {
149149
* @returns {Listr<*, *, *>}
150150
*/
151151
_uploadPlatformSoftware (nodeAliases, podNames, task, localBuildPath) {
152-
const self = this
153152
const subTasks = []
154153

155-
self.logger.debug('no need to fetch, use local build jar files')
154+
this.logger.debug('no need to fetch, use local build jar files')
156155

157156
/** @type {Map<NodeAlias, string>} */
158157
const buildPathMap = new Map()
@@ -184,11 +183,11 @@ export class NodeCommandTasks {
184183
title: `Copy local build to Node: ${chalk.yellow(nodeAlias)} from ${localDataLibBuildPath}`,
185184
task: async () => {
186185
this.logger.debug(`Copying build files to pod: ${podName} from ${localDataLibBuildPath}`)
187-
await self.k8.copyTo(podName, constants.ROOT_CONTAINER, localDataLibBuildPath, `${constants.HEDERA_HAPI_PATH}`)
188-
const testJsonFiles = self.configManager.getFlag(flags.appConfig).split(',')
186+
await this.k8.copyTo(podName, constants.ROOT_CONTAINER, localDataLibBuildPath, `${constants.HEDERA_HAPI_PATH}`)
187+
const testJsonFiles = this.configManager.getFlag(flags.appConfig).split(',')
189188
for (const jsonFile of testJsonFiles) {
190189
if (fs.existsSync(jsonFile)) {
191-
await self.k8.copyTo(podName, constants.ROOT_CONTAINER, jsonFile, `${constants.HEDERA_HAPI_PATH}`)
190+
await this.k8.copyTo(podName, constants.ROOT_CONTAINER, jsonFile, `${constants.HEDERA_HAPI_PATH}`)
192191
}
193192
}
194193
}
@@ -385,7 +384,7 @@ _fetchPlatformSoftware (nodeAliases, podNames, releaseTag, task, platformInstall
385384
return new Task('Generate gossip keys', async (ctx, task) => {
386385
const config = ctx.config
387386
const nodeAliases = generateMultiple ? config.nodeAliases : [config.nodeAlias]
388-
const subTasks = self.keyManager.taskGenerateGossipKeys(self.keytoolDepManager, nodeAliases, config.keysDir, config.curDate)
387+
const subTasks = this.keyManager.taskGenerateGossipKeys(this.keytoolDepManager, nodeAliases, config.keysDir, config.curDate)
389388
// set up the sub-tasks
390389
return task.newListr(subTasks, {
391390
concurrent: false,
@@ -409,7 +408,7 @@ _fetchPlatformSoftware (nodeAliases, podNames, releaseTag, task, platformInstall
409408
return new Task('Generate gRPC TLS Keys', async (ctx, task) => {
410409
const config = ctx.config
411410
const nodeAliases = generateMultiple ? config.nodeAliases : [config.nodeAlias]
412-
const subTasks = self.keyManager.taskGenerateTLSKeys(nodeAliases, config.keysDir, config.curDate)
411+
const subTasks = this.keyManager.taskGenerateTLSKeys(nodeAliases, config.keysDir, config.curDate)
413412
// set up the sub-tasks
414413
return task.newListr(subTasks, {
415414
concurrent: true,
@@ -810,15 +809,15 @@ _fetchPlatformSoftware (nodeAliases, podNames, releaseTag, task, platformInstall
810809
return new Task('Check node proxies are ACTIVE', async (ctx, task) => {
811810
// this is more reliable than checking the nodes logs for ACTIVE, as the
812811
// logs will have a lot of white noise from being behind
813-
return self._checkNodesProxiesTask(ctx, task, ctx.config.nodeAliases)
812+
return this._checkNodesProxiesTask(ctx, task, ctx.config.nodeAliases)
814813
}, skip)
815814
}
816815

817816
checkAllNodeProxiesAreActive () {
818817
return new Task('Check all node proxies are ACTIVE', async (ctx, task) => {
819818
// this is more reliable than checking the nodes logs for ACTIVE, as the
820819
// logs will have a lot of white noise from being behind
821-
return self._checkNodesProxiesTask(ctx, task, ctx.config.allNodeAliases)
820+
return this._checkNodesProxiesTask(ctx, task, ctx.config.allNodeAliases)
822821
})
823822
}
824823

@@ -885,7 +884,7 @@ _fetchPlatformSoftware (nodeAliases, podNames, releaseTag, task, platformInstall
885884
const podName = ctx.config.podNames[nodeAlias]
886885
subTasks.push({
887886
title: `Stop node: ${chalk.yellow(nodeAlias)}`,
888-
task: async () => await self.k8.execContainer(podName, constants.ROOT_CONTAINER, 'systemctl stop network-node')
887+
task: async () => await this.k8.execContainer(podName, constants.ROOT_CONTAINER, 'systemctl stop network-node')
889888
})
890889
}
891890

@@ -903,9 +902,9 @@ _fetchPlatformSoftware (nodeAliases, podNames, releaseTag, task, platformInstall
903902
finalize () {
904903
return new Task('Finalize', async (ctx, task) => {
905904
// reset flags so that keys are not regenerated later
906-
self.configManager.setFlag(flags.generateGossipKeys, false)
907-
self.configManager.setFlag(flags.generateTlsKeys, false)
908-
self.configManager.persist()
905+
this.configManager.setFlag(flags.generateGossipKeys, false)
906+
this.configManager.setFlag(flags.generateTlsKeys, false)
907+
this.configManager.persist()
909908
})
910909
}
911910

@@ -918,7 +917,7 @@ _fetchPlatformSoftware (nodeAliases, podNames, releaseTag, task, platformInstall
918917
subTasks.push({
919918
title: `Node: ${chalk.yellow(nodeAlias)}`,
920919
task: async () =>
921-
await self.k8.execContainer(podName, constants.ROOT_CONTAINER, ['bash', '-c', `rm -rf ${constants.HEDERA_HAPI_PATH}/data/saved/*`])
920+
await this.k8.execContainer(podName, constants.ROOT_CONTAINER, ['bash', '-c', `rm -rf ${constants.HEDERA_HAPI_PATH}/data/saved/*`])
922921
})
923922
}
924923

@@ -940,7 +939,7 @@ _fetchPlatformSoftware (nodeAliases, podNames, releaseTag, task, platformInstall
940939

941940
checkPVCsEnabled () {
942941
return new Task('Check that PVCs are enabled', async (ctx, task) => {
943-
if (!self.configManager.getFlag(flags.persistentVolumeClaims)) {
942+
if (!this.configManager.getFlag(flags.persistentVolumeClaims)) {
944943
throw new SoloError('PVCs are not enabled. Please enable PVCs before adding a node')
945944
}
946945
})
@@ -1065,34 +1064,34 @@ _fetchPlatformSoftware (nodeAliases, podNames, releaseTag, task, platformInstall
10651064
const config = /** @type {NodeUpdateConfigClass} **/ ctx.config
10661065

10671066
const nodeId = Templates.nodeIdFromNodeAlias(config.nodeAlias) - 1
1068-
self.logger.info(`nodeId: ${nodeId}`)
1069-
self.logger.info(`config.newAccountNumber: ${config.newAccountNumber}`)
1067+
this.logger.info(`nodeId: ${nodeId}`)
1068+
this.logger.info(`config.newAccountNumber: ${config.newAccountNumber}`)
10701069

10711070
try {
10721071
const nodeUpdateTx = await new NodeUpdateTransaction()
10731072
.setNodeId(nodeId)
10741073

10751074
if (config.tlsPublicKey && config.tlsPrivateKey) {
1076-
self.logger.info(`config.tlsPublicKey: ${config.tlsPublicKey}`)
1075+
this.logger.info(`config.tlsPublicKey: ${config.tlsPublicKey}`)
10771076
const tlsCertDer = await this._loadPermCertificate(config.tlsPublicKey)
10781077
const tlsCertHash = crypto.createHash('sha384').update(tlsCertDer).digest()
10791078
nodeUpdateTx.setCertificateHash(tlsCertHash)
10801079

10811080
const publicKeyFile = Templates.renderTLSPemPublicKeyFile(config.nodeAlias)
10821081
const privateKeyFile = Templates.renderTLSPemPrivateKeyFile(config.nodeAlias)
1083-
renameAndCopyFile(config.tlsPublicKey, publicKeyFile, config.keysDir)
1084-
renameAndCopyFile(config.tlsPrivateKey, privateKeyFile, config.keysDir)
1082+
renameAndCopyFile(config.tlsPublicKey, publicKeyFile, config.keysDir, this.logger)
1083+
renameAndCopyFile(config.tlsPrivateKey, privateKeyFile, config.keysDir, this.logger)
10851084
}
10861085

10871086
if (config.gossipPublicKey && config.gossipPrivateKey) {
1088-
self.logger.info(`config.gossipPublicKey: ${config.gossipPublicKey}`)
1087+
this.logger.info(`config.gossipPublicKey: ${config.gossipPublicKey}`)
10891088
const signingCertDer = await this._loadPermCertificate(config.gossipPublicKey)
10901089
nodeUpdateTx.setGossipCaCertificate(signingCertDer)
10911090

10921091
const publicKeyFile = Templates.renderGossipPemPublicKeyFile(constants.SIGNING_KEY_PREFIX, config.nodeAlias)
10931092
const privateKeyFile = Templates.renderGossipPemPrivateKeyFile(constants.SIGNING_KEY_PREFIX, config.nodeAlias)
1094-
renameAndCopyFile(config.gossipPublicKey, publicKeyFile, config.keysDir)
1095-
renameAndCopyFile(config.gossipPrivateKey, privateKeyFile, config.keysDir)
1093+
renameAndCopyFile(config.gossipPublicKey, publicKeyFile, config.keysDir, this.logger)
1094+
renameAndCopyFile(config.gossipPrivateKey, privateKeyFile, config.keysDir, this.logger)
10961095
}
10971096

10981097
if (config.newAccountNumber) {
@@ -1215,7 +1214,7 @@ _fetchPlatformSoftware (nodeAliases, podNames, releaseTag, task, platformInstall
12151214
return new Task('Kill nodes', async (ctx, task) => {
12161215
const config = ctx.config
12171216
for (const /** @type {NetworkNodeServices} **/ service of config.serviceMap.values()) {
1218-
await self.k8.kubeClient.deleteNamespacedPod(service.nodePodName, config.namespace, undefined, undefined, 1)
1217+
await this.k8.kubeClient.deleteNamespacedPod(service.nodePodName, config.namespace, undefined, undefined, 1)
12191218
}
12201219
})
12211220
}
@@ -1224,16 +1223,16 @@ _fetchPlatformSoftware (nodeAliases, podNames, releaseTag, task, platformInstall
12241223
return new Task('Kill nodes to pick up updated configMaps', async (ctx, task) => {
12251224
const config = ctx.config
12261225
// the updated node will have a new pod ID if its account ID changed which is a label
1227-
config.serviceMap = await self.accountManager.getNodeServiceMap(
1226+
config.serviceMap = await this.accountManager.getNodeServiceMap(
12281227
config.namespace)
12291228
for (const /** @type {NetworkNodeServices} **/ service of config.serviceMap.values()) {
1230-
await self.k8.kubeClient.deleteNamespacedPod(service.nodePodName, config.namespace, undefined, undefined, 1)
1229+
await this.k8.kubeClient.deleteNamespacedPod(service.nodePodName, config.namespace, undefined, undefined, 1)
12311230
}
1232-
self.logger.info('sleep for 15 seconds to give time for pods to finish terminating')
1231+
this.logger.info('sleep for 15 seconds to give time for pods to finish terminating')
12331232
await sleep(15000)
12341233

12351234
// again, the pod names will change after the pods are killed
1236-
config.serviceMap = await self.accountManager.getNodeServiceMap(
1235+
config.serviceMap = await this.accountManager.getNodeServiceMap(
12371236
config.namespace)
12381237
config.podNames = {}
12391238
for (const service of config.serviceMap.values()) {
@@ -1281,8 +1280,8 @@ _fetchPlatformSoftware (nodeAliases, podNames, releaseTag, task, platformInstall
12811280
const node1FullyQualifiedPodName = Templates.renderNetworkPodName(config.existingNodeAliases[0])
12821281
const upgradeDirectory = `${constants.HEDERA_HAPI_PATH}/data/saved/com.hedera.services.ServicesMain/0/123`
12831282
// zip the contents of the newest folder on node1 within /opt/hgcapp/services-hedera/HapiApp2.0/data/saved/com.hedera.services.ServicesMain/0/123/
1284-
const zipFileName = await self.k8.execContainer(node1FullyQualifiedPodName, constants.ROOT_CONTAINER, ['bash', '-c', `cd ${upgradeDirectory} && mapfile -t states < <(ls -1t .) && jar cf "\${states[0]}.zip" -C "\${states[0]}" . && echo -n \${states[0]}.zip`])
1285-
await self.k8.copyFrom(node1FullyQualifiedPodName, constants.ROOT_CONTAINER, `${upgradeDirectory}/${zipFileName}`, config.stagingDir)
1283+
const zipFileName = await this.k8.execContainer(node1FullyQualifiedPodName, constants.ROOT_CONTAINER, ['bash', '-c', `cd ${upgradeDirectory} && mapfile -t states < <(ls -1t .) && jar cf "\${states[0]}.zip" -C "\${states[0]}" . && echo -n \${states[0]}.zip`])
1284+
await this.k8.copyFrom(node1FullyQualifiedPodName, constants.ROOT_CONTAINER, `${upgradeDirectory}/${zipFileName}`, config.stagingDir)
12861285
config.lastStateZipPath = path.join(config.stagingDir, zipFileName)
12871286
})
12881287
}
@@ -1294,10 +1293,10 @@ _fetchPlatformSoftware (nodeAliases, podNames, releaseTag, task, platformInstall
12941293
const nodeId = Templates.nodeIdFromNodeAlias(config.nodeAlias)
12951294
const savedStateDir = (config.lastStateZipPath.match(/\/(\d+)\.zip$/))[1]
12961295
const savedStatePath = `${constants.HEDERA_HAPI_PATH}/data/saved/com.hedera.services.ServicesMain/${nodeId}/123/${savedStateDir}`
1297-
await self.k8.execContainer(newNodeFullyQualifiedPodName, constants.ROOT_CONTAINER, ['bash', '-c', `mkdir -p ${savedStatePath}`])
1298-
await self.k8.copyTo(newNodeFullyQualifiedPodName, constants.ROOT_CONTAINER, config.lastStateZipPath, savedStatePath)
1299-
await self.platformInstaller.setPathPermission(newNodeFullyQualifiedPodName, constants.HEDERA_HAPI_PATH)
1300-
await self.k8.execContainer(newNodeFullyQualifiedPodName, constants.ROOT_CONTAINER, ['bash', '-c', `cd ${savedStatePath} && jar xf ${path.basename(config.lastStateZipPath)} && rm -f ${path.basename(config.lastStateZipPath)}`])
1296+
await this.k8.execContainer(newNodeFullyQualifiedPodName, constants.ROOT_CONTAINER, ['bash', '-c', `mkdir -p ${savedStatePath}`])
1297+
await this.k8.copyTo(newNodeFullyQualifiedPodName, constants.ROOT_CONTAINER, config.lastStateZipPath, savedStatePath)
1298+
await this.platformInstaller.setPathPermission(newNodeFullyQualifiedPodName, constants.HEDERA_HAPI_PATH)
1299+
await this.k8.execContainer(newNodeFullyQualifiedPodName, constants.ROOT_CONTAINER, ['bash', '-c', `cd ${savedStatePath} && jar xf ${path.basename(config.lastStateZipPath)} && rm -f ${path.basename(config.lastStateZipPath)}`])
13011300
})
13021301
}
13031302

Diff for: src/core/helpers.mjs

+3-2
Original file line numberDiff line numberDiff line change
@@ -329,16 +329,17 @@ export function parseIpAddressToUint8Array (ipAddress) {
329329
* @param srcFilePath
330330
* @param expectedBaseName
331331
* @param destDir
332+
* @param logger
332333
*/
333-
export function renameAndCopyFile (srcFilePath, expectedBaseName, destDir) {
334+
export function renameAndCopyFile (srcFilePath, expectedBaseName, destDir, logger) {
334335
const srcDir = path.dirname(srcFilePath)
335336
if (path.basename(srcFilePath) !== expectedBaseName) {
336337
fs.renameSync(srcFilePath, path.join(srcDir, expectedBaseName))
337338
}
338339
// copy public key and private key to key directory
339340
fs.copyFile(path.join(srcDir, expectedBaseName), path.join(destDir, expectedBaseName), (err) => {
340341
if (err) {
341-
self.logger.error(`Error copying file: ${err.message}`)
342+
logger.error(`Error copying file: ${err.message}`)
342343
throw new SoloError(`Error copying file: ${err.message}`)
343344
}
344345
})

Diff for: test/e2e/commands/network.test.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('NetworkCommand', () => {
8383
})
8484

8585
it('keys should be generated', async () => {
86-
await expect(nodeCmd.keys(argv)).resolves.toBeTruthy()
86+
await expect(nodeCmd.handlers.keys(argv)).resolves.toBeTruthy()
8787
})
8888

8989
it('network deploy command should succeed', async () => {

Diff for: test/e2e/commands/node_delete.test.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('Node delete', () => {
5959
}, 450000)
6060

6161
it('should delete a node from the network successfully', async () => {
62-
await nodeCmd.delete(argv)
62+
await nodeCmd.handlers.delete(argv)
6363
expect(nodeCmd.getUnusedConfigs(NodeCommand.DELETE_CONFIGS_NAME)).toEqual([
6464
flags.app.constName,
6565
flags.devMode.constName,

Diff for: test/e2e/commands/node_update.test.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('Node update', () => {
5959

6060
afterAll(async () => {
6161
await getNodeLogs(k8, namespace)
62-
await nodeCmd.stop(argv)
62+
await nodeCmd.handlers.stop(argv)
6363
await k8.deleteNamespace(namespace)
6464
}, 600000)
6565

@@ -89,7 +89,7 @@ describe('Node update', () => {
8989
argv[flags.tlsPublicKey.name] = tlsKeyFiles.certificateFile
9090
argv[flags.tlsPrivateKey.name] = tlsKeyFiles.privateKeyFile
9191

92-
await nodeCmd.update(argv)
92+
await nodeCmd.handlers.update(argv)
9393
expect(nodeCmd.getUnusedConfigs(NodeCommand.UPDATE_CONFIGS_NAME)).toEqual([
9494
flags.app.constName,
9595
flags.devMode.constName,

0 commit comments

Comments
 (0)