Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 58 additions & 11 deletions solo/src/commands/flags.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,6 @@ export const namespace = {
}
}

export const kubeContext = {
name: 'kube-context',
definition: {
describe: 'Kube context',
defaultValue: '',
type: 'string'
}
}

export const deployMirrorNode = {
name: 'mirror-node',
definition: {
Expand Down Expand Up @@ -343,12 +334,56 @@ export const fstChartVersion = {
}
}

export const applicationProperties = {
name: 'application-properties',
definition: {
describe: 'application.properties file for node',
defaultValue: `${constants.SOLO_CACHE_DIR}/templates/application.properties`,
type: 'string'
}
}

export const apiPermissionProperties = {
name: 'api-permission-properties',
definition: {
describe: 'api-permission.properties file for node',
defaultValue: `${constants.SOLO_CACHE_DIR}/templates/api-permission.properties`,
type: 'string'
}
}

export const bootstrapProperties = {
name: 'bootstrap-properties',
definition: {
describe: 'bootstrap.properties file for node',
defaultValue: `${constants.SOLO_CACHE_DIR}/templates/bootstrap.properties`,
type: 'string'
}
}

export const settingTxt = {
name: 'settings-txt',
definition: {
describe: 'settings.txt file for node',
defaultValue: `${constants.SOLO_CACHE_DIR}/templates/settings.txt`,
type: 'string'
}
}

export const log4j2Xml = {
name: 'log4j2-xml',
definition: {
describe: 'log4j2.xml file for node',
defaultValue: `${constants.SOLO_CACHE_DIR}/templates/log4j2.xml`,
type: 'string'
}
}

export const allFlags = [
devMode,
clusterName,
clusterSetupNamespace,
namespace,
kubeContext,
deployMirrorNode,
deployHederaExplorer,
deployJsonRpcRelay,
Expand All @@ -375,7 +410,19 @@ export const allFlags = [
hederaExplorerTlsLoadBalancerIp,
hederaExplorerTlsHostName,
deletePvcs,
fstChartVersion
fstChartVersion,
applicationProperties,
apiPermissionProperties,
bootstrapProperties,
settingTxt,
log4j2Xml
]

export const allFlagsMap = new Map(allFlags.map(f => [f.name, f]))
export const nodeConfigFileFlags = new Map([
applicationProperties,
apiPermissionProperties,
bootstrapProperties,
settingTxt,
log4j2Xml
].map(f => [f.name, f]))
38 changes: 36 additions & 2 deletions solo/src/commands/init.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*
*/
import { Listr } from 'listr2'
import path from 'path'
import { BaseCommand } from './base.mjs'
import * as core from '../core/index.mjs'
import { constants } from '../core/index.mjs'
import * as fs from 'fs'
import { FullstackTestingError } from '../core/errors.mjs'
import * as flags from './flags.mjs'
import chalk from 'chalk'

/**
* Defines the core functionalities of 'init' command
Expand Down Expand Up @@ -69,7 +71,7 @@ export class InitCommand extends BaseCommand {
{
title: 'Setup config manager',
task: async (ctx, _) => {
ctx.config = this.configManager.load(argv, true)
this.configManager.load(argv, true)
}
},
{
Expand All @@ -94,11 +96,43 @@ export class InitCommand extends BaseCommand {
title: 'Setup chart manager',
task: async (ctx, _) => {
ctx.repoURLs = await this.chartManager.setup()
}
},
{
title: 'Copy configuration file templates',
task: (ctx, _) => {
let cacheDir = this.configManager.getFlag(flags.cacheDir)
if (!cacheDir) {
cacheDir = constants.SOLO_CACHE_DIR
}

const templatesDir = `${cacheDir}/templates`
if (!fs.existsSync(templatesDir)) {
fs.mkdirSync(templatesDir)
}

const configFiles = [
`${constants.RESOURCES_DIR}/templates/application.properties`,
`${constants.RESOURCES_DIR}/templates/api-permission.properties`,
`${constants.RESOURCES_DIR}/templates/bootstrap.properties`,
`${constants.RESOURCES_DIR}/templates/settings.txt`,
`${constants.RESOURCES_DIR}/templates/log4j2.xml`
]

for (const filePath of configFiles) {
const fileName = path.basename(filePath)
fs.cpSync(`${filePath}`, `${templatesDir}/${fileName}`, { recursive: true })
}

if (argv.dev) {
self.logger.showList('Home Directories', ctx.dirs)
self.logger.showList('Chart Repository', ctx.repoURLs)
self.logger.showJSON('Cached Config', ctx.config)
}

self.logger.showUser(chalk.grey('\n***************************************************************************************'))
self.logger.showUser(chalk.grey(`Note: solo stores various artifacts (config, logs, keys etc.) in its home directory: ${constants.SOLO_HOME_DIR}\n` +
'If a full reset is needed, delete the directory or relevant sub-directories before running \'solo init\'.'))
self.logger.showUser(chalk.grey('***************************************************************************************'))
}
}
], {
Expand Down
21 changes: 16 additions & 5 deletions solo/src/commands/node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,16 @@ export class NodeCommand extends BaseCommand {
const config = ctx.config
const subTasks = [
{
title: 'Copy default files and templates',
title: 'Copy configuration files',
task: () => {
for (const item of ['properties', 'config.template', 'log4j2.xml', 'settings.txt']) {
fs.cpSync(`${constants.RESOURCES_DIR}/templates/${item}`, `${config.stagingDir}/templates/${item}`, { recursive: true })
for (const flag of flags.nodeConfigFileFlags.values()) {
const filePath = self.configManager.getFlag(flag)
if (!filePath) {
throw new FullstackTestingError(`Configuration file path is missing for: ${flag.name}`)
}

const fileName = path.basename(filePath)
fs.cpSync(`${filePath}`, `${config.stagingDir}/templates/${fileName}`, { recursive: true })
}
}
},
Expand Down Expand Up @@ -323,7 +329,7 @@ export class NodeCommand extends BaseCommand {
task: async (ctx, _) => {
const config = ctx.config
const configTxtPath = `${config.stagingDir}/config.txt`
const template = `${config.stagingDir}/templates/config.template`
const template = `${constants.RESOURCES_DIR}/templates/config.template`
await self.plaformInstaller.prepareConfigTxt(config.nodeIds, configTxtPath, config.releaseTag, config.chainId, template)
}
}
Expand Down Expand Up @@ -688,7 +694,12 @@ export class NodeCommand extends BaseCommand {
flags.cacheDir,
flags.chainId,
flags.force,
flags.keyFormat
flags.keyFormat,
flags.applicationProperties,
flags.apiPermissionProperties,
flags.bootstrapProperties,
flags.settingTxt,
flags.log4j2Xml
),
handler: argv => {
nodeCmd.logger.debug("==== Running 'node setup' ===")
Expand Down
8 changes: 4 additions & 4 deletions solo/src/core/platform_installer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,16 @@ export class PlatformInstaller {
const fileList1 = await self.copyFiles(podName, srcFilesSet1, constants.HEDERA_HAPI_PATH)

const srcFilesSet2 = [
`${stagingDir}/templates/properties/api-permission.properties`,
`${stagingDir}/templates/properties/application.properties`,
`${stagingDir}/templates/properties/bootstrap.properties`
`${stagingDir}/templates/api-permission.properties`,
`${stagingDir}/templates/application.properties`,
`${stagingDir}/templates/bootstrap.properties`
]

const fileList2 = await self.copyFiles(podName, srcFilesSet2, `${constants.HEDERA_HAPI_PATH}/data/config`)

return fileList1.concat(fileList2)
} catch (e) {
throw new FullstackTestingError(`failed to copy config files to pod '${podName}'`, e)
throw new FullstackTestingError(`failed to copy config files to pod '${podName}': ${e.message}`, e)
}
}

Expand Down
5 changes: 5 additions & 0 deletions solo/test/e2e/commands/node.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ describe.each([
argv[flags.chainId.name] = constants.HEDERA_CHAIN_ID
argv[flags.generateGossipKeys.name] = false
argv[flags.generateTlsKeys.name] = true
argv[flags.applicationProperties.name] = flags.applicationProperties.definition.defaultValue
argv[flags.apiPermissionProperties.name] = flags.apiPermissionProperties.definition.defaultValue
argv[flags.bootstrapProperties.name] = flags.bootstrapProperties.definition.defaultValue
argv[flags.settingTxt.name] = flags.settingTxt.definition.defaultValue
argv[flags.log4j2Xml.name] = flags.log4j2Xml.definition.defaultValue

const nodeIds = argv[flags.nodeIDs.name].split(',')

Expand Down