Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added missing async/await where needed #551

Merged
merged 9 commits into from
Sep 6, 2024
12 changes: 6 additions & 6 deletions src/commands/mirror_node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -179,43 +179,43 @@ export class MirrorNodeCommand extends BaseCommand {
const subTasks = [
{
title: 'Check Postgres DB',
task: async (ctx, _) => self.k8.waitForPodReady([
task: async (ctx, _) => await self.k8.waitForPodReady([
'app.kubernetes.io/component=postgresql',
'app.kubernetes.io/name=postgres'
], 1, 300, 2000)
},
{
title: 'Check REST API',
task: async (ctx, _) => self.k8.waitForPodReady([
task: async (ctx, _) => await self.k8.waitForPodReady([
'app.kubernetes.io/component=rest',
'app.kubernetes.io/name=rest'
], 1, 300, 2000)
},
{
title: 'Check GRPC',
task: async (ctx, _) => self.k8.waitForPodReady([
task: async (ctx, _) => await self.k8.waitForPodReady([
'app.kubernetes.io/component=grpc',
'app.kubernetes.io/name=grpc'
], 1, 300, 2000)
},
{
title: 'Check Monitor',
task: async (ctx, _) => self.k8.waitForPodReady([
task: async (ctx, _) => await self.k8.waitForPodReady([
'app.kubernetes.io/component=monitor',
'app.kubernetes.io/name=monitor'
], 1, 300, 2000)
},
{
title: 'Check Importer',
task: async (ctx, _) => self.k8.waitForPodReady([
task: async (ctx, _) => await self.k8.waitForPodReady([
'app.kubernetes.io/component=importer',
'app.kubernetes.io/name=importer'
], 1, 300, 2000)
},
{
title: 'Check Hedera Explorer',
skip: (ctx, _) => !ctx.config.deployHederaExplorer,
task: async (ctx, _) => self.k8.waitForPodReady([
task: async (ctx, _) => await self.k8.waitForPodReady([
'app.kubernetes.io/component=hedera-explorer',
'app.kubernetes.io/name=hedera-explorer'
], 1, 300, 2000)
Expand Down
16 changes: 8 additions & 8 deletions src/commands/network.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ export class NetworkCommand extends BaseCommand {
for (const nodeId of config.nodeIds) {
subTasks.push({
title: `Check Node: ${chalk.yellow(nodeId)}`,
task: () =>
self.k8.waitForPods([constants.POD_PHASE_RUNNING], [
task: async () =>
await self.k8.waitForPods([constants.POD_PHASE_RUNNING], [
'fullstack.hedera.com/type=network-node',
`fullstack.hedera.com/node-name=${nodeId}`
], 1, 60 * 15, 1000) // timeout 15 minutes
Expand All @@ -394,8 +394,8 @@ export class NetworkCommand extends BaseCommand {
for (const nodeId of config.nodeIds) {
subTasks.push({
title: `Check HAProxy for: ${chalk.yellow(nodeId)}`,
task: () =>
self.k8.waitForPods([constants.POD_PHASE_RUNNING], [
task: async () =>
await self.k8.waitForPods([constants.POD_PHASE_RUNNING], [
'fullstack.hedera.com/type=haproxy'
], 1, 60 * 15, 1000) // timeout 15 minutes
})
Expand All @@ -405,8 +405,8 @@ export class NetworkCommand extends BaseCommand {
for (const nodeId of config.nodeIds) {
subTasks.push({
title: `Check Envoy Proxy for: ${chalk.yellow(nodeId)}`,
task: () =>
self.k8.waitForPods([constants.POD_PHASE_RUNNING], [
task: async () =>
await self.k8.waitForPods([constants.POD_PHASE_RUNNING], [
'fullstack.hedera.com/type=envoy-proxy'
], 1, 60 * 15, 1000) // timeout 15 minutes
})
Expand All @@ -430,8 +430,8 @@ export class NetworkCommand extends BaseCommand {
// minio
subTasks.push({
title: 'Check MinIO',
task: () =>
self.k8.waitForPodReady([
task: async () =>
await self.k8.waitForPodReady([
'v1.min.io/tenant=minio'
], 1, 60 * 5, 1000) // timeout 5 minutes
})
Expand Down
68 changes: 35 additions & 33 deletions src/commands/node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@
const podName = podNames[nodeId]
subTasks.push({
title: `Update node: ${chalk.yellow(nodeId)} [ platformVersion = ${releaseTag} ]`,
task: () =>
platformInstaller.fetchPlatform(podName, releaseTag)
task: async () =>
await platformInstaller.fetchPlatform(podName, releaseTag)
})
}

Expand Down Expand Up @@ -834,12 +834,12 @@
if (self.configManager.getFlag(flags.app) !== '' && self.configManager.getFlag(flags.app) !== constants.HEDERA_APP_NAME) {
subTasks.push({
title: `Check node: ${chalk.yellow(nodeId)}`,
task: () => self.checkNetworkNodeState(nodeId, 100, 'ACTIVE', 'output/swirlds.log')
task: async () => await self.checkNetworkNodeState(nodeId, 100, 'ACTIVE', 'output/swirlds.log')
})
} else {
subTasks.push({
title: `Check node: ${chalk.yellow(nodeId)}`,
task: () => self.checkNetworkNodeState(nodeId)
task: async () => await self.checkNetworkNodeState(nodeId)
})
}
}
Expand Down Expand Up @@ -886,7 +886,7 @@
const accountId = accountMap.get(nodeId)
subTasks.push({
title: `Adding stake for node: ${chalk.yellow(nodeId)}`,
task: () => self.addStake(ctx.config.namespace, accountId, nodeId)
task: async () => await self.addStake(ctx.config.namespace, accountId, nodeId)
})
}

Expand Down Expand Up @@ -955,7 +955,7 @@
const podName = ctx.config.podNames[nodeId]
subTasks.push({
title: `Stop node: ${chalk.yellow(nodeId)}`,
task: () => self.k8.execContainer(podName, constants.ROOT_CONTAINER, 'systemctl stop network-node')
task: async () => await self.k8.execContainer(podName, constants.ROOT_CONTAINER, 'systemctl stop network-node')
})
}

Expand Down Expand Up @@ -1235,12 +1235,12 @@
if (config.app !== '' && config.app !== constants.HEDERA_APP_NAME) {
subTasks.push({
title: `Check node: ${chalk.yellow(nodeId)}`,
task: () => self.checkNetworkNodeState(nodeId, 100, 'ACTIVE', 'output/swirlds.log')
task: async () => await self.checkNetworkNodeState(nodeId, 100, 'ACTIVE', 'output/swirlds.log')

Check warning on line 1238 in src/commands/node.mjs

View check run for this annotation

Codecov / codecov/patch

src/commands/node.mjs#L1238

Added line #L1238 was not covered by tests
})
} else {
subTasks.push({
title: `Check node: ${chalk.yellow(nodeId)}`,
task: () => self.checkNetworkNodeState(nodeId)
task: async () => await self.checkNetworkNodeState(nodeId)
})
}
}
Expand Down Expand Up @@ -1615,6 +1615,7 @@
title: 'Check existing nodes staked amount',
task: async (ctx, task) => {
const config = /** @type {NodeAddConfigClass} **/ ctx.config
self.logger.info('sleep 60 seconds for the handler to be able to trigger the network node stake weight recalculate')
await sleep(60000)
const accountMap = getNodeAccountMap(config.existingNodeIds)
for (const nodeId of config.existingNodeIds) {
Expand Down Expand Up @@ -1729,7 +1730,7 @@
for (const nodeId of config.existingNodeIds) {
subTasks.push({
title: `Check node: ${chalk.yellow(nodeId)}`,
task: () => self.checkNetworkNodeState(nodeId, 100, 'FREEZE_COMPLETE')
task: async () => await self.checkNetworkNodeState(nodeId, 100, 'FREEZE_COMPLETE')
})
}

Expand Down Expand Up @@ -1796,8 +1797,8 @@
for (const nodeId of config.allNodeIds) {
subTasks.push({
title: `Check Node: ${chalk.yellow(nodeId)}`,
task: () =>
self.k8.waitForPods([constants.POD_PHASE_RUNNING], [
task: async () =>
await self.k8.waitForPods([constants.POD_PHASE_RUNNING], [
'fullstack.hedera.com/type=network-node',
`fullstack.hedera.com/node-name=${nodeId}`
], 1, 60 * 15, 1000) // timeout 15 minutes
Expand Down Expand Up @@ -1896,12 +1897,12 @@
title: 'Check all nodes are ACTIVE',
task: async (ctx, task) => {
const subTasks = []
// sleep for 30 seconds to give time for the logs to roll over to prevent capturing an invalid "ACTIVE" string
self.logger.info('sleep for 30 seconds to give time for the logs to roll over to prevent capturing an invalid "ACTIVE" string')
await sleep(30000)
for (const nodeId of ctx.config.allNodeIds) {
subTasks.push({
title: `Check node: ${chalk.yellow(nodeId)}`,
task: () => self.checkNetworkNodeState(nodeId, 200)
task: async () => await self.checkNetworkNodeState(nodeId, 200)
})
}

Expand Down Expand Up @@ -1941,9 +1942,9 @@
},
{
title: 'Stake new node',
task: (ctx, _) => {
task: async (ctx, _) => {
const config = /** @type {NodeAddConfigClass} **/ ctx.config
self.addStake(config.namespace, ctx.newNode.accountId, config.nodeId)
await self.addStake(config.namespace, ctx.newNode.accountId, config.nodeId)
}
},
{
Expand Down Expand Up @@ -2606,7 +2607,7 @@
for (const nodeId of config.existingNodeIds) {
subTasks.push({
title: `Check node: ${chalk.yellow(nodeId)}`,
task: () => self.checkNetworkNodeState(nodeId, 100, 'FREEZE_COMPLETE')
task: async () => await self.checkNetworkNodeState(nodeId, 100, 'FREEZE_COMPLETE')
})
}

Expand Down Expand Up @@ -2669,6 +2670,9 @@
for (const /** @type {NetworkNodeServices} **/ service of config.serviceMap.values()) {
await self.k8.kubeClient.deleteNamespacedPod(service.nodePodName, config.namespace, undefined, undefined, 1)
}
self.logger.info('sleep for 15 seconds to give time for pods to finish terminating')
await sleep(15000)

// again, the pod names will change after the pods are killed
config.serviceMap = await self.accountManager.getNodeServiceMap(
config.namespace)
Expand All @@ -2679,7 +2683,7 @@
}
},
{
title: 'Check node pods are running',
title: 'Check node pods are ready',
task:
async (ctx, task) => {
const subTasks = []
Expand All @@ -2689,11 +2693,11 @@
for (const nodeId of config.allNodeIds) {
subTasks.push({
title: `Check Node: ${chalk.yellow(nodeId)}`,
task: () =>
self.k8.waitForPods([constants.POD_PHASE_RUNNING], [
'fullstack.hedera.com/type=network-node',
`fullstack.hedera.com/node-name=${nodeId}`
], 1, 60 * 15, 1000) // timeout 15 minutes
task: async () =>
await self.k8.waitForPodReady(
['fullstack.hedera.com/type=network-node',
`fullstack.hedera.com/node-name=${nodeId}`],
1, 300, 2000)
})
}

Expand All @@ -2710,9 +2714,6 @@
title: 'Fetch platform software into network nodes',
task:
async (ctx, task) => {
// without this sleep, copy software from local build to container sometimes fail
await sleep(15000)

const config = /** @type {NodeUpdateConfigClass} **/ ctx.config
return self.fetchLocalOrReleasedPlatformSoftware(config.allNodeIds, config.podNames, config.releaseTag, task, config.localBuildPath)
}
Expand Down Expand Up @@ -2761,12 +2762,12 @@
title: 'Check all nodes are ACTIVE',
task: async (ctx, task) => {
const subTasks = []
// sleep for 30 seconds to give time for the logs to roll over to prevent capturing an invalid "ACTIVE" string
self.logger.info('sleep for 30 seconds to give time for the logs to roll over to prevent capturing an invalid "ACTIVE" string')
await sleep(30000)
for (const nodeId of ctx.config.allNodeIds) {
subTasks.push({
title: `Check node: ${chalk.yellow(nodeId)}`,
task: () => self.checkNetworkNodeState(nodeId, 200)
task: async () => await self.checkNetworkNodeState(nodeId, 200)
})
}

Expand Down Expand Up @@ -3098,7 +3099,7 @@
for (const nodeId of config.existingNodeIds) {
subTasks.push({
title: `Check node: ${chalk.yellow(nodeId)}`,
task: () => self.checkNetworkNodeState(nodeId, 100, 'FREEZE_COMPLETE')
task: async () => await self.checkNetworkNodeState(nodeId, 100, 'FREEZE_COMPLETE')
})
}

Expand Down Expand Up @@ -3157,6 +3158,7 @@
title: 'Check node pods are running',
task:
async (ctx, task) => {
self.logger.info('sleep 20 seconds to give time for pods to come up after being killed')
await sleep(20000)
const subTasks = []
const config = /** @type {NodeDeleteConfigClass} **/ ctx.config
Expand All @@ -3165,8 +3167,8 @@
for (const nodeId of config.allNodeIds) {
subTasks.push({
title: `Check Node: ${chalk.yellow(nodeId)}`,
task: () =>
self.k8.waitForPods([constants.POD_PHASE_RUNNING], [
task: async () =>
await self.k8.waitForPods([constants.POD_PHASE_RUNNING], [
'fullstack.hedera.com/type=network-node',
`fullstack.hedera.com/node-name=${nodeId}`
], 1, 60 * 15, 1000) // timeout 15 minutes
Expand Down Expand Up @@ -3238,12 +3240,12 @@
title: 'Check all nodes are ACTIVE',
task: async (ctx, task) => {
const subTasks = []
// sleep for 30 seconds to give time for the logs to roll over to prevent capturing an invalid "ACTIVE" string
self.logger.info('sleep for 30 seconds to give time for the logs to roll over to prevent capturing an invalid "ACTIVE" string')
await sleep(30000)
for (const nodeId of ctx.config.allNodeIds) {
subTasks.push({
title: `Check node: ${chalk.yellow(nodeId)}`,
task: () => self.checkNetworkNodeState(nodeId, 200)
task: async () => await self.checkNetworkNodeState(nodeId, 200)
})
}

Expand Down Expand Up @@ -3285,7 +3287,7 @@
title: 'Trigger stake weight calculate',
task: async (ctx, task) => {
const config = /** @type {NodeDeleteConfigClass} **/ ctx.config
// sleep 60 seconds for the handler to be able to trigger the network node stake weight recalculate
self.logger.info('sleep 60 seconds for the handler to be able to trigger the network node stake weight recalculate')
await sleep(60000)
const accountMap = getNodeAccountMap(config.allNodeIds)
// send some write transactions to invoke the handler that will trigger the stake weight recalculate
Expand Down
1 change: 1 addition & 0 deletions src/core/account_manager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export class AccountManager {
* @returns {Promise<void>}
*/
async refreshNodeClient (namespace) {
await this.close()
const treasuryAccountInfo = await this.getTreasuryAccountKeys(namespace)
const networkNodeServicesMap = await this.getNodeServiceMap(namespace)

Expand Down
4 changes: 2 additions & 2 deletions src/core/k8.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ export class K8 {
return await this.execContainer(
podName,
containerName,
['sh', '-c', '[[ -d "' + destPath + '" ]] && echo -n "true" || echo -n "false"']
['bash', '-c', '[[ -d "' + destPath + '" ]] && echo -n "true" || echo -n "false"']
) === 'true'
}

Expand All @@ -455,7 +455,7 @@ export class K8 {
return this.execContainer(
podName,
containerName,
['sh', '-c', 'mkdir -p "' + destPath + '"']
['bash', '-c', 'mkdir -p "' + destPath + '"']
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/key_manager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ export class KeyManager {

subTasks.push({
title: `Check keytool exists (Version: ${keytoolDepManager.getKeytoolVersion()})`,
task: async () => keytoolDepManager.checkVersion(true)
task: async () => await keytoolDepManager.checkVersion(true)

})

Expand Down
12 changes: 6 additions & 6 deletions src/core/platform_installer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ export class PlatformInstaller {
return new Listr([
{
title: 'Set file permissions',
task: (_, task) =>
self.setPlatformDirPermissions(podName)
task: async (_, task) =>
await self.setPlatformDirPermissions(podName)
}
],
{
Expand Down Expand Up @@ -323,17 +323,17 @@ export class PlatformInstaller {
const subTasks = []
subTasks.push({
title: 'Copy TLS keys',
task: (_, task) =>
self.copyTLSKeys(nodeIds, stagingDir, keyFormat)
task: async (_, task) =>
await self.copyTLSKeys(nodeIds, stagingDir, keyFormat)
})

for (const nodeId of nodeIds) {
subTasks.push({
title: `Node: ${chalk.yellow(nodeId)}`,
task: () => new Listr([{
title: 'Copy Gossip keys',
task: (_, task) =>
self.copyGossipKeys(nodeId, stagingDir, nodeIds, keyFormat)
task: async (_, task) =>
await self.copyGossipKeys(nodeId, stagingDir, nodeIds, keyFormat)
}
],
{
Expand Down
Loading
Loading