From e9e1484a0f7085171d5a45966163b529b77bf9e9 Mon Sep 17 00:00:00 2001 From: Ivo Yankov Date: Fri, 20 Sep 2024 11:50:16 +0300 Subject: [PATCH] fix: delete commands Signed-off-by: Ivo Yankov --- src/commands/node.mjs | 35 ++++++++++++++++------------------ src/core/helpers.mjs | 44 +++++++++++-------------------------------- 2 files changed, 27 insertions(+), 52 deletions(-) diff --git a/src/commands/node.mjs b/src/commands/node.mjs index 3940c34f..a4b5225c 100644 --- a/src/commands/node.mjs +++ b/src/commands/node.mjs @@ -287,7 +287,6 @@ export class NodeCommand extends BaseCommand { flags.endpointType, flags.localBuildPath, flags.namespace, - flags.nodeID, flags.releaseTag ] } @@ -1944,14 +1943,12 @@ export class NodeCommand extends BaseCommand { return { title: 'Load context data', task: async (ctx, task) => { - if (argv.importCtxData) { - const inputDir = argv[flags.inputDir.name] - if (!inputDir) { - throw new FullstackTestingError(`Path to context data not specified. Please set a value for --${flags.inputDir.name}`) - } - const ctxData = JSON.parse(fs.readFileSync(path.join(inputDir, targetFile))) - parser(ctx, ctxData) + const inputDir = argv[flags.inputDir.name] + if (!inputDir) { + throw new FullstackTestingError(`Path to context data not specified. Please set a value for --${flags.inputDir.name}`) } + const ctxData = JSON.parse(fs.readFileSync(path.join(inputDir, targetFile))) + parser(ctx, ctxData) } } } @@ -2184,7 +2181,6 @@ export class NodeCommand extends BaseCommand { async addSubmitTransactions (argv) { const self = this - argv.importCtxData = true const transactionTasks = this.getAddTransactionTasks(argv) const tasks = new Listr([ self.addInitializeTask(argv), @@ -2210,7 +2206,6 @@ export class NodeCommand extends BaseCommand { async addExecute (argv) { const self = this - argv.importCtxData = true const executeTasks = this.getAddExecuteTasks(argv) const tasks = new Listr([ self.addInitializeTask(argv), @@ -2574,7 +2569,7 @@ export class NodeCommand extends BaseCommand { .command({ command: 'delete', desc: 'Delete a node with a specific version of Hedera platform', - builder: y => flags.setCommandFlags(y, ...NodeCommand.DELETE_FLAGS_LIST), + builder: y => flags.setCommandFlags(y, ...NodeCommand.DELETE_FLAGS_LIST.concat(flags.nodeID)), handler: argv => { nodeCmd.logger.debug('==== Running \'node delete\' ===') nodeCmd.logger.debug(argv) @@ -2591,7 +2586,7 @@ export class NodeCommand extends BaseCommand { .command({ command: 'delete-prepare', desc: 'Prepares the deletion of a node with a specific version of Hedera platform', - builder: y => flags.setCommandFlags(y, ...NodeCommand.DELETE_PREPARE_FLAGS_LIST), + builder: y => flags.setCommandFlags(y, ...NodeCommand.DELETE_PREPARE_FLAGS_LIST.concat(flags.nodeID)), handler: argv => { nodeCmd.logger.debug('==== Running \'node add\' ===') nodeCmd.logger.debug(argv) @@ -3118,6 +3113,7 @@ export class NodeCommand extends BaseCommand { 'freezeAdminPrivateKey', 'keysDir', 'nodeClient', + 'nodeId', 'podNames', 'serviceMap', 'stagingDir', @@ -3125,6 +3121,7 @@ export class NodeCommand extends BaseCommand { 'treasuryKey' ]) + config.nodeId = argv.nodeId config.curDate = new Date() config.existingNodeIds = [] @@ -3192,6 +3189,13 @@ export class NodeCommand extends BaseCommand { const self = this return [ + { + title: 'Download generated files from an existing node', + task: async (ctx, task) => { + const config = /** @type {NodeDeleteConfigClass} **/ ctx.config + await this.downloadNodeGeneratedFiles(config) + } + }, { title: 'Prepare staging directory', task: async (ctx, parentTask) => { @@ -3343,13 +3347,6 @@ export class NodeCommand extends BaseCommand { await this.prepareUpgradeNetworkNodes(config.freezeAdminPrivateKey, ctx.upgradeZipHash, config.nodeClient) } }, - { - title: 'Download generated files from an existing node', - task: async (ctx, task) => { - const config = /** @type {NodeDeleteConfigClass} **/ ctx.config - await this.downloadNodeGeneratedFiles(config) - } - }, { title: 'Send freeze upgrade transaction', task: async (ctx, task) => { diff --git a/src/core/helpers.mjs b/src/core/helpers.mjs index ea0b9de7..f4017972 100644 --- a/src/core/helpers.mjs +++ b/src/core/helpers.mjs @@ -26,7 +26,7 @@ import * as semver from 'semver' import { Templates } from './templates.mjs' import { HEDERA_HAPI_PATH, ROOT_CONTAINER, SOLO_LOGS_DIR } from './constants.mjs' import { constants } from './index.mjs' -import { FileContentsQuery, FileId } from '@hashgraph/sdk' +import {FileContentsQuery, FileId, PrivateKey} from '@hashgraph/sdk' // cache current directory const CUR_FILE_DIR = paths.dirname(fileURLToPath(import.meta.url)) @@ -419,22 +419,11 @@ export function addLoadContextParser (ctx, ctxData) { export function deleteSaveContextParser (ctx) { const exportedCtx = {} - const config = /** @type {NodeAddConfigClass} **/ ctx.config - const exportedFields = [ - 'tlsCertHash', - 'upgradeZipHash', - 'newNode' - ] - - exportedCtx.signingCertDer = ctx.signingCertDer.toString() - exportedCtx.gossipEndpoints = ctx.gossipEndpoints.map(ep => `${ep.getDomainName}:${ep.getPort}`) - exportedCtx.grpcServiceEndpoints = ctx.grpcServiceEndpoints.map(ep => `${ep.getDomainName}:${ep.getPort}`) - exportedCtx.adminKey = ctx.adminKey.toString() + const config = /** @type {NodeDeleteConfigClass} **/ ctx.config + exportedCtx.adminKey = config.adminKey.toString() exportedCtx.existingNodeIds = config.existingNodeIds - - for (const prop of exportedFields) { - exportedCtx[prop] = ctx[prop] - } + exportedCtx.upgradeZipHash = ctx.upgradeZipHash + exportedCtx.nodeId = config.nodeId return exportedCtx } @@ -446,23 +435,12 @@ export function deleteSaveContextParser (ctx) { * @returns file writable object */ export function deleteLoadContextParser (ctx, ctxData) { - const config = /** @type {NodeAddConfigClass} **/ ctx.config - ctx.signingCertDer = new Uint8Array(ctxData.signingCertDer.split(',')) - ctx.gossipEndpoints = this.prepareEndpoints(ctx.config.endpointType, ctxData.gossipEndpoints, constants.HEDERA_NODE_INTERNAL_GOSSIP_PORT) - ctx.grpcServiceEndpoints = this.prepareEndpoints(ctx.config.endpointType, ctxData.grpcServiceEndpoints, constants.HEDERA_NODE_EXTERNAL_GOSSIP_PORT) - ctx.adminKey = PrivateKey.fromStringED25519(ctxData.adminKey) - config.nodeId = ctxData.newNode.name + const config = /** @type {NodeDeleteConfigClass} **/ ctx.config + config.adminKey = PrivateKey.fromStringED25519(ctxData.adminKey) + config.nodeId = ctxData.nodeId config.existingNodeIds = ctxData.existingNodeIds - config.allNodeIds = [...config.existingNodeIds, ctxData.newNode.name] - - const fieldsToImport = [ - 'tlsCertHash', - 'upgradeZipHash', - 'newNode' - ] - - for (const prop of fieldsToImport) { - ctx[prop] = ctxData[prop] - } + config.allNodeIds = ctxData.existingNodeIds + ctx.upgradeZipHash = ctxData.upgradeZipHash + config.podNames = {} }