Skip to content

Commit 473a650

Browse files
authored
feat: Update solo to load remote config near entry point (#1176)
Signed-off-by: Ivo Yankov <[email protected]>
1 parent fe42edd commit 473a650

File tree

6 files changed

+52
-50
lines changed

6 files changed

+52
-50
lines changed

src/commands/mirror_node.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ export class MirrorNodeCommand extends BaseCommand {
305305
return ListrLease.newAcquireLeaseTask(lease, task);
306306
},
307307
},
308-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
309308
{
310309
title: 'Enable mirror-node',
311310
task: (_, parentTask) => {
@@ -624,7 +623,6 @@ export class MirrorNodeCommand extends BaseCommand {
624623
return ListrLease.newAcquireLeaseTask(lease, task);
625624
},
626625
},
627-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
628626
{
629627
title: 'Destroy mirror-node',
630628
task: async ctx => {

src/commands/network.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,6 @@ export class NetworkCommand extends BaseCommand {
509509
return ListrLease.newAcquireLeaseTask(lease, task);
510510
},
511511
},
512-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
513512
{
514513
title: 'Copy gRPC TLS Certificates',
515514
task: (ctx, parentTask) =>

src/commands/node/handlers.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ export class NodeCommandHandlers implements CommandHandlers {
104104
deletePrepareTaskList(argv: any, lease: Lease) {
105105
return [
106106
this.tasks.initialize(argv, deleteConfigBuilder.bind(this), lease),
107-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
108107
this.validateSingleNodeState({excludedStates: []}),
109108
this.tasks.identifyExistingNodes(),
110109
this.tasks.loadAdminKey(),
@@ -148,7 +147,6 @@ export class NodeCommandHandlers implements CommandHandlers {
148147
addPrepareTasks(argv: any, lease: Lease) {
149148
return [
150149
this.tasks.initialize(argv, addConfigBuilder.bind(this), lease),
151-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
152150
this.validateSingleNodeState({excludedStates: []}),
153151
this.tasks.checkPVCsEnabled(),
154152
this.tasks.identifyExistingNodes(),
@@ -201,7 +199,6 @@ export class NodeCommandHandlers implements CommandHandlers {
201199
updatePrepareTasks(argv, lease: Lease) {
202200
return [
203201
this.tasks.initialize(argv, updateConfigBuilder.bind(this), lease),
204-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
205202
this.validateSingleNodeState({excludedStates: []}),
206203
this.tasks.identifyExistingNodes(),
207204
this.tasks.loadAdminKey(),
@@ -246,7 +243,6 @@ export class NodeCommandHandlers implements CommandHandlers {
246243
upgradePrepareTasks(argv, lease: Lease) {
247244
return [
248245
this.tasks.initialize(argv, upgradeConfigBuilder.bind(this), lease),
249-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
250246
this.validateSingleNodeState({excludedStates: []}),
251247
this.tasks.identifyExistingNodes(),
252248
this.tasks.loadAdminKey(),
@@ -282,7 +278,6 @@ export class NodeCommandHandlers implements CommandHandlers {
282278
const action = this.parent.commandActionBuilder(
283279
[
284280
this.tasks.initialize(argv, prepareUpgradeConfigBuilder.bind(this), lease),
285-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
286281
this.tasks.prepareUpgradeZip(),
287282
this.tasks.sendPrepareUpgradeTransaction(),
288283
],
@@ -304,7 +299,6 @@ export class NodeCommandHandlers implements CommandHandlers {
304299
const action = this.parent.commandActionBuilder(
305300
[
306301
this.tasks.initialize(argv, prepareUpgradeConfigBuilder.bind(this), null),
307-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
308302
this.tasks.prepareUpgradeZip(),
309303
this.tasks.sendFreezeUpgradeTransaction(),
310304
],
@@ -328,7 +322,6 @@ export class NodeCommandHandlers implements CommandHandlers {
328322
const action = this.parent.commandActionBuilder(
329323
[
330324
this.tasks.initialize(argv, downloadGeneratedFilesConfigBuilder.bind(this), lease),
331-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
332325
this.tasks.identifyExistingNodes(),
333326
this.tasks.downloadNodeGeneratedFiles(),
334327
],
@@ -394,7 +387,6 @@ export class NodeCommandHandlers implements CommandHandlers {
394387
const action = this.parent.commandActionBuilder(
395388
[
396389
this.tasks.initialize(argv, updateConfigBuilder.bind(this), lease),
397-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
398390
this.tasks.loadContextData(argv, NodeCommandHandlers.UPDATE_CONTEXT_FILE, NodeHelper.updateLoadContextParser),
399391
...this.updateSubmitTransactionsTasks(argv),
400392
],
@@ -416,7 +408,6 @@ export class NodeCommandHandlers implements CommandHandlers {
416408
const action = this.parent.commandActionBuilder(
417409
[
418410
this.tasks.initialize(argv, updateConfigBuilder.bind(this), lease, false),
419-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
420411
this.tasks.loadContextData(argv, NodeCommandHandlers.UPDATE_CONTEXT_FILE, NodeHelper.updateLoadContextParser),
421412
...this.updateExecuteTasks(argv),
422413
],
@@ -457,7 +448,6 @@ export class NodeCommandHandlers implements CommandHandlers {
457448
const action = this.parent.commandActionBuilder(
458449
[
459450
this.tasks.initialize(argv, upgradeConfigBuilder.bind(this), lease),
460-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
461451
this.tasks.loadContextData(argv, NodeCommandHandlers.UPGRADE_CONTEXT_FILE, NodeHelper.upgradeLoadContextParser),
462452
...this.upgradeSubmitTransactionsTasks(argv),
463453
],
@@ -479,7 +469,6 @@ export class NodeCommandHandlers implements CommandHandlers {
479469
const action = this.parent.commandActionBuilder(
480470
[
481471
this.tasks.initialize(argv, upgradeConfigBuilder.bind(this), lease, false),
482-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
483472
this.tasks.loadContextData(argv, NodeCommandHandlers.UPGRADE_CONTEXT_FILE, NodeHelper.upgradeLoadContextParser),
484473
...this.upgradeExecuteTasks(argv),
485474
],
@@ -654,7 +643,6 @@ export class NodeCommandHandlers implements CommandHandlers {
654643
const action = this.parent.commandActionBuilder(
655644
[
656645
this.tasks.initialize(argv, addConfigBuilder.bind(this), lease),
657-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
658646
this.tasks.loadContextData(argv, NodeCommandHandlers.ADD_CONTEXT_FILE, helpers.addLoadContextParser),
659647
...this.addSubmitTransactionsTasks(argv),
660648
],
@@ -678,7 +666,6 @@ export class NodeCommandHandlers implements CommandHandlers {
678666
const action = this.parent.commandActionBuilder(
679667
[
680668
this.tasks.initialize(argv, addConfigBuilder.bind(this), lease, false),
681-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
682669
this.tasks.identifyExistingNodes(),
683670
this.tasks.loadContextData(argv, NodeCommandHandlers.ADD_CONTEXT_FILE, helpers.addLoadContextParser),
684671
...this.addExecuteTasks(argv),
@@ -698,11 +685,7 @@ export class NodeCommandHandlers implements CommandHandlers {
698685
async logs(argv: any) {
699686
argv = helpers.addFlagsToArgv(argv, NodeFlags.LOGS_FLAGS);
700687
const action = this.parent.commandActionBuilder(
701-
[
702-
this.tasks.initialize(argv, logsConfigBuilder.bind(this), null),
703-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
704-
this.tasks.getNodeLogsAndConfigs(),
705-
],
688+
[this.tasks.initialize(argv, logsConfigBuilder.bind(this), null), this.tasks.getNodeLogsAndConfigs()],
706689
{
707690
concurrent: false,
708691
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION,
@@ -740,7 +723,6 @@ export class NodeCommandHandlers implements CommandHandlers {
740723
const action = this.parent.commandActionBuilder(
741724
[
742725
this.tasks.initialize(argv, refreshConfigBuilder.bind(this), lease),
743-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
744726
this.validateAllNodeStates({
745727
acceptedStates: [ConsensusNodeStates.STARTED, ConsensusNodeStates.SETUP, ConsensusNodeStates.INITIALIZED],
746728
}),
@@ -794,7 +776,6 @@ export class NodeCommandHandlers implements CommandHandlers {
794776
const action = this.parent.commandActionBuilder(
795777
[
796778
this.tasks.initialize(argv, stopConfigBuilder.bind(this), lease),
797-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
798779
this.validateAllNodeStates({
799780
acceptedStates: [ConsensusNodeStates.STARTED, ConsensusNodeStates.SETUP],
800781
}),
@@ -822,7 +803,6 @@ export class NodeCommandHandlers implements CommandHandlers {
822803
const action = this.parent.commandActionBuilder(
823804
[
824805
this.tasks.initialize(argv, startConfigBuilder.bind(this), lease),
825-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
826806
this.validateAllNodeStates({acceptedStates: [ConsensusNodeStates.SETUP]}),
827807
this.tasks.identifyExistingNodes(),
828808
this.tasks.uploadStateFiles((ctx: any) => ctx.config.stateFile.length === 0),
@@ -853,7 +833,6 @@ export class NodeCommandHandlers implements CommandHandlers {
853833
const action = this.parent.commandActionBuilder(
854834
[
855835
this.tasks.initialize(argv, setupConfigBuilder.bind(this), lease),
856-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
857836
this.validateAllNodeStates({
858837
acceptedStates: [ConsensusNodeStates.INITIALIZED],
859838
}),

src/commands/relay.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ export class RelayCommand extends BaseCommand {
238238
return ListrLease.newAcquireLeaseTask(lease, task);
239239
},
240240
},
241-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
242241
{
243242
title: 'Prepare chart values',
244243
task: async ctx => {
@@ -369,7 +368,6 @@ export class RelayCommand extends BaseCommand {
369368
return ListrLease.newAcquireLeaseTask(lease, task);
370369
},
371370
},
372-
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
373371
{
374372
title: 'Destroy JSON RPC Relay',
375373
task: async ctx => {

src/core/config/remote/remote_config_manager.ts

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -184,39 +184,50 @@ export class RemoteConfigManager {
184184
/* ---------- Listr Task Builders ---------- */
185185

186186
/**
187-
* Builds a task for loading the remote configuration, intended for use with Listr task management.
187+
* Performs the loading of the remote configuration.
188188
* Checks if the configuration is already loaded, otherwise loads and adds the command to history.
189189
*
190190
* @param argv - arguments containing command input for historical reference.
191-
* @returns a Listr task which loads the remote configuration.
192191
*/
193-
public buildLoadTask(argv: {_: string[]}): SoloListrTask<EmptyContextConfig> {
192+
public async loadAndValidate(argv: {_: string[]}) {
194193
const self = this;
194+
try {
195+
self.setDefaultNamespaceIfNotSet();
196+
self.setDefaultContextIfNotSet();
197+
} catch (e) {
198+
self.logger.showUser(chalk.red(e.message));
199+
return;
200+
}
195201

196-
return {
197-
title: 'Load remote config',
198-
task: async (_, task): Promise<void> => {
199-
try {
200-
self.setDefaultNamespaceIfNotSet();
201-
self.setDefaultContextIfNotSet();
202-
} catch {
203-
return; // TODO
204-
}
202+
if (!(await self.load())) {
203+
self.logger.showUser(chalk.red('remote config not found'));
204+
205+
// TODO see if this should be disabled to make it an optional feature
206+
return;
207+
// throw new SoloError('Failed to load remote config')
208+
}
205209

206-
if (!(await self.load())) {
207-
task.title = `${task.title} - ${chalk.red('remote config not found')}`;
210+
await RemoteConfigValidator.validateComponents(self.remoteConfig.components, self.k8);
208211

209-
// TODO see if this should be disabled to make it an optional feature
210-
return;
211-
// throw new SoloError('Failed to load remote config')
212-
}
212+
const currentCommand = argv._.join(' ');
213+
self.remoteConfig!.addCommandToHistory(currentCommand);
213214

214-
await RemoteConfigValidator.validateComponents(self.remoteConfig.components, self.k8);
215+
await self.save();
216+
}
215217

216-
const currentCommand = argv._.join(' ');
217-
self.remoteConfig!.addCommandToHistory(currentCommand);
218+
/**
219+
* Builds a listr task for loading the remote configuration.
220+
*
221+
* @param argv - arguments containing command input for historical reference.
222+
* @returns a Listr task which loads the remote configuration.
223+
*/
224+
public buildLoadTask(argv: {_: string[]}): SoloListrTask<EmptyContextConfig> {
225+
const self = this;
218226

219-
await self.save();
227+
return {
228+
title: 'Load remote config',
229+
task: async (_, task): Promise<void> => {
230+
await self.loadAndValidate(argv);
220231
},
221232
};
222233
}

src/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,23 @@ export function main(argv: any) {
132132
return argv;
133133
};
134134

135+
const loadRemoteConfig = async (argv: any, yargs: any): Promise<any> => {
136+
const command = argv._[0];
137+
const subCommand = argv._[1];
138+
const skip =
139+
command === 'init' ||
140+
(command === 'node' && subCommand === 'keys') ||
141+
(command === 'cluster' && subCommand === 'connect') ||
142+
(command === 'cluster' && subCommand === 'info') ||
143+
(command === 'cluster' && subCommand === 'list') ||
144+
(command === 'deployment' && subCommand === 'create');
145+
if (!skip) {
146+
await remoteConfigManager.loadAndValidate(argv);
147+
}
148+
149+
return argv;
150+
};
151+
135152
return (
136153
yargs(hideBin(argv))
137154
.scriptName('')
@@ -146,7 +163,7 @@ export function main(argv: any) {
146163
.wrap(120)
147164
.demand(1, 'Select a command')
148165
// @ts-ignore
149-
.middleware(processArguments, false) // applyBeforeValidate = false as otherwise middleware is called twice
166+
.middleware([processArguments, loadRemoteConfig], false) // applyBeforeValidate = false as otherwise middleware is called twice
150167
.parse()
151168
);
152169
} catch (e: Error | any) {

0 commit comments

Comments
 (0)