Skip to content

Commit c6cc393

Browse files
committed
todos
Signed-off-by: Jeromy Cannon <[email protected]>
1 parent b03268e commit c6cc393

File tree

1 file changed

+56
-90
lines changed

1 file changed

+56
-90
lines changed

src/commands/node.mjs

Lines changed: 56 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class NodeCommand extends BaseCommand {
4040
if (!opts || !opts.keytoolDepManager) throw new IllegalArgumentError('An instance of KeytoolDependencyManager is required', opts.keytoolDepManager)
4141

4242
this.downloader = opts.downloader
43-
this.plaformInstaller = opts.platformInstaller
43+
this.platformInstaller = opts.platformInstaller
4444
this.keyManager = opts.keyManager
4545
this.accountManager = opts.accountManager
4646
this.keytoolDepManager = opts.keytoolDepManager
@@ -312,6 +312,51 @@ export class NodeCommand extends BaseCommand {
312312
}
313313
}
314314

315+
async initializeSetup (config, configManager, k8) {
316+
// compute other config parameters
317+
config.releasePrefix = Templates.prepareReleasePrefix(config.releaseTag)
318+
config.buildZipFile = `${config.cacheDir}/${config.releasePrefix}/build-${config.releaseTag}.zip`
319+
config.keysDir = path.join(config.cacheDir, 'keys')
320+
config.stagingDir = Templates.renderStagingDir(configManager, flags)
321+
config.stagingKeysDir = path.join(config.stagingDir, 'keys')
322+
323+
if (!await k8.hasNamespace(config.namespace)) {
324+
throw new FullstackTestingError(`namespace ${config.namespace} does not exist`)
325+
}
326+
327+
// prepare staging keys directory
328+
if (!fs.existsSync(config.stagingKeysDir)) {
329+
fs.mkdirSync(config.stagingKeysDir, { recursive: true })
330+
}
331+
332+
// create cached keys dir if it does not exist yet
333+
if (!fs.existsSync(config.keysDir)) {
334+
fs.mkdirSync(config.keysDir)
335+
}
336+
}
337+
338+
fetchPlatformSoftware (ctx, task, platformInstaller) {
339+
const config = ctx.config
340+
341+
const subTasks = []
342+
for (const nodeId of ctx.config.nodeIds) {
343+
const podName = ctx.config.podNames[nodeId]
344+
subTasks.push({
345+
title: `Node: ${chalk.yellow(nodeId)}`,
346+
task: () =>
347+
platformInstaller.fetchPlatform(podName, config.releaseTag)
348+
})
349+
}
350+
351+
// set up the sub-tasks
352+
return task.newListr(subTasks, {
353+
concurrent: true, // since we download in the container directly, we want this to be in parallel across all nodes
354+
rendererOptions: {
355+
collapseSubtasks: false
356+
}
357+
})
358+
}
359+
315360
async setup (argv) {
316361
const self = this
317362

@@ -345,26 +390,7 @@ export class NodeCommand extends BaseCommand {
345390
curDate: new Date()
346391
}
347392

348-
// compute other config parameters
349-
config.releasePrefix = Templates.prepareReleasePrefix(config.releaseTag)
350-
config.buildZipFile = `${config.cacheDir}/${config.releasePrefix}/build-${config.releaseTag}.zip`
351-
config.keysDir = path.join(config.cacheDir, 'keys')
352-
config.stagingDir = Templates.renderStagingDir(self.configManager, flags)
353-
config.stagingKeysDir = path.join(config.stagingDir, 'keys')
354-
355-
if (!await this.k8.hasNamespace(config.namespace)) {
356-
throw new FullstackTestingError(`namespace ${config.namespace} does not exist`)
357-
}
358-
359-
// prepare staging keys directory
360-
if (!fs.existsSync(config.stagingKeysDir)) {
361-
fs.mkdirSync(config.stagingKeysDir, { recursive: true })
362-
}
363-
364-
// create cached keys dir if it does not exist yet
365-
if (!fs.existsSync(config.keysDir)) {
366-
fs.mkdirSync(config.keysDir)
367-
}
393+
await self.initializeSetup(config, self.configManager, self.k8)
368394

369395
// set config in the context for later tasks to use
370396
ctx.config = config
@@ -474,7 +500,7 @@ export class NodeCommand extends BaseCommand {
474500
const config = ctx.config
475501
const configTxtPath = `${config.stagingDir}/config.txt`
476502
const template = `${constants.RESOURCES_DIR}/templates/config.template`
477-
await self.plaformInstaller.prepareConfigTxt(config.nodeIds, configTxtPath, config.releaseTag, config.chainId, template)
503+
await self.platformInstaller.prepareConfigTxt(config.nodeIds, configTxtPath, config.releaseTag, config.chainId, template)
478504
}
479505
}
480506
]
@@ -489,25 +515,7 @@ export class NodeCommand extends BaseCommand {
489515
title: 'Fetch platform software into network nodes',
490516
task:
491517
async (ctx, task) => {
492-
const config = ctx.config
493-
494-
const subTasks = []
495-
for (const nodeId of ctx.config.nodeIds) {
496-
const podName = ctx.config.podNames[nodeId]
497-
subTasks.push({
498-
title: `Node: ${chalk.yellow(nodeId)}`,
499-
task: () =>
500-
self.plaformInstaller.fetchPlatform(podName, config.releaseTag)
501-
})
502-
}
503-
504-
// set up the sub-tasks
505-
return task.newListr(subTasks, {
506-
concurrent: true, // since we download in the container directly, we want this to be in parallel across all nodes
507-
rendererOptions: {
508-
collapseSubtasks: false
509-
}
510-
})
518+
return self.fetchPlatformSoftware(ctx, task, self.platformInstaller)
511519
}
512520
},
513521
{
@@ -521,7 +529,7 @@ export class NodeCommand extends BaseCommand {
521529
subTasks.push({
522530
title: `Node: ${chalk.yellow(nodeId)}`,
523531
task: () =>
524-
self.plaformInstaller.taskInstall(podName, config.buildZipFile, config.stagingDir, config.nodeIds, config.keyFormat, config.force)
532+
self.platformInstaller.taskInstall(podName, config.buildZipFile, config.stagingDir, config.nodeIds, config.keyFormat, config.force)
525533
})
526534
}
527535

@@ -879,45 +887,22 @@ export class NodeCommand extends BaseCommand {
879887
flags.nodeIDs,
880888
flags.releaseTag,
881889
flags.cacheDir,
882-
flags.chainId,
883890
flags.keyFormat
884-
]) // TODO verify we need all of these
891+
])
885892

886893
const config = {
887894
namespace: self.configManager.getFlag(flags.namespace),
888895
nodeIds: helpers.parseNodeIDs(self.configManager.getFlag(flags.nodeIDs)),
889896
releaseTag: self.configManager.getFlag(flags.releaseTag),
890897
cacheDir: self.configManager.getFlag(flags.cacheDir),
891898
force: self.configManager.getFlag(flags.force),
892-
chainId: self.configManager.getFlag(flags.chainId),
893899
applicationEnv: self.configManager.getFlag(flags.applicationEnv),
894900
keyFormat: self.configManager.getFlag(flags.keyFormat),
895901
de3vMode: self.configManager.getFlag(flags.devMode),
896902
curDate: new Date()
897903
}
898904

899-
// compute other config parameters
900-
// TODO DRY
901-
self.logger.debug(`[cacheDir=${config.cacheDir}]`)
902-
config.releasePrefix = Templates.prepareReleasePrefix(config.releaseTag)
903-
config.buildZipFile = `${config.cacheDir}/${config.releasePrefix}/build-${config.releaseTag}.zip`
904-
config.keysDir = path.join(config.cacheDir, 'keys')
905-
config.stagingDir = Templates.renderStagingDir(self.configManager, flags)
906-
config.stagingKeysDir = path.join(config.stagingDir, 'keys')
907-
908-
if (!await this.k8.hasNamespace(config.namespace)) {
909-
throw new FullstackTestingError(`namespace ${config.namespace} does not exist`)
910-
}
911-
912-
// prepare staging keys directory
913-
if (!fs.existsSync(config.stagingKeysDir)) {
914-
fs.mkdirSync(config.stagingKeysDir, { recursive: true })
915-
}
916-
917-
// create cached keys dir if it does not exist yet
918-
if (!fs.existsSync(config.keysDir)) {
919-
fs.mkdirSync(config.keysDir)
920-
}
905+
await self.initializeSetup(config, self.configManager, self.k8)
921906

922907
// set config in the context for later tasks to use
923908
ctx.config = config
@@ -952,32 +937,14 @@ export class NodeCommand extends BaseCommand {
952937
})
953938
}
954939
},
955-
{ // TODO DRY
940+
{
956941
title: 'Fetch platform software into network nodes',
957942
task:
958943
async (ctx, task) => {
959-
const config = ctx.config
960-
961-
const subTasks = []
962-
for (const nodeId of ctx.config.nodeIds) {
963-
const podName = ctx.config.podNames[nodeId]
964-
subTasks.push({
965-
title: `Node: ${chalk.yellow(nodeId)}`,
966-
task: () =>
967-
self.plaformInstaller.fetchPlatform(podName, config.releaseTag)
968-
})
969-
}
970-
971-
// set up the sub-tasks
972-
return task.newListr(subTasks, {
973-
concurrent: true, // since we download in the container directly, we want this to be in parallel across all nodes
974-
rendererOptions: {
975-
collapseSubtasks: false
976-
}
977-
})
944+
return self.fetchPlatformSoftware(ctx, task, self.platformInstaller)
978945
}
979946
},
980-
{ // TODO DRY
947+
{
981948
title: 'Setup network nodes',
982949
task: async (ctx, parentTask) => {
983950
const config = ctx.config
@@ -993,7 +960,7 @@ export class NodeCommand extends BaseCommand {
993960
subTasks.push({
994961
title: `Node: ${chalk.yellow(nodeId)}`,
995962
task: () =>
996-
self.plaformInstaller.taskInstall(podName, config.buildZipFile,
963+
self.platformInstaller.taskInstall(podName, config.buildZipFile,
997964
config.stagingDir, nodeList, config.keyFormat, config.force)
998965
})
999966
}
@@ -1218,7 +1185,6 @@ export class NodeCommand extends BaseCommand {
12181185
flags.nodeIDs,
12191186
flags.releaseTag,
12201187
flags.cacheDir,
1221-
flags.chainId,
12221188
flags.applicationEnv,
12231189
flags.keyFormat
12241190
),

0 commit comments

Comments
 (0)