Skip to content

Commit

Permalink
feat: add BaseCommand.getConsensusNodes() method (#1364)
Browse files Browse the repository at this point in the history
Signed-off-by: Jeromy Cannon <[email protected]>
  • Loading branch information
jeromy-cannon authored Feb 11, 2025
1 parent ae7d44f commit 44703a4
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 218 deletions.
201 changes: 0 additions & 201 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 39 additions & 13 deletions src/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import path from 'path';
import * as constants from '../core/constants.js';
import fs from 'fs';
import {Task} from '../core/task.js';
import {ConsensusNode} from '../core/model/consensus_node.js';

export interface CommandHandlers {
parent: BaseCommand;
Expand Down Expand Up @@ -58,7 +59,7 @@ export abstract class BaseCommand extends ShellRunner {
this.remoteConfigManager = opts.remoteConfigManager;
}

async prepareChartPath(chartDir: string, chartRepo: string, chartReleaseName: string) {
public async prepareChartPath(chartDir: string, chartRepo: string, chartReleaseName: string) {
if (!chartRepo) throw new MissingArgumentError('chart repo name is required');
if (!chartReleaseName) throw new MissingArgumentError('chart release name is required');

Expand All @@ -71,7 +72,7 @@ export abstract class BaseCommand extends ShellRunner {
return `${chartRepo}/${chartReleaseName}`;
}

prepareValuesFiles(valuesFile: string) {
public prepareValuesFiles(valuesFile: string) {
let valuesArg = '';
if (valuesFile) {
const valuesFiles = valuesFile.split(',');
Expand All @@ -84,11 +85,11 @@ export abstract class BaseCommand extends ShellRunner {
return valuesArg;
}

getConfigManager(): ConfigManager {
public getConfigManager(): ConfigManager {
return this.configManager;
}

getChartManager(): ChartManager {
public getChartManager(): ChartManager {
return this.chartManager;
}

Expand All @@ -97,7 +98,7 @@ export abstract class BaseCommand extends ShellRunner {
* and extra properties, will keep track of which properties are used. Call
* getUnusedConfigs() to get an array of unused properties.
*/
getConfig(configName: string, flags: CommandFlag[], extraProperties: string[] = []): object {
public getConfig(configName: string, flags: CommandFlag[], extraProperties: string[] = []): object {
const configManager = this.configManager;

// build the dynamic class that will keep track of which properties are used
Expand Down Expand Up @@ -165,33 +166,33 @@ export abstract class BaseCommand extends ShellRunner {
return newConfigInstance;
}

getLeaseManager(): LeaseManager {
public getLeaseManager(): LeaseManager {
return this.leaseManager;
}

/**
* Get the list of unused configurations that were not accessed
* @returns an array of unused configurations
*/
getUnusedConfigs(configName: string): string[] {
public getUnusedConfigs(configName: string): string[] {
return this._configMaps.get(configName).getUnusedConfigs();
}

getK8Factory() {
public getK8Factory() {
return this.k8Factory;
}

getLocalConfig() {
public getLocalConfig() {
return this.localConfig;
}

getRemoteConfigManager() {
public getRemoteConfigManager() {
return this.remoteConfigManager;
}

abstract close(): Promise<void>;

commandActionBuilder(actionTasks: any, options: any, errorString: string, lease: Lease | null) {
public commandActionBuilder(actionTasks: any, options: any, errorString: string, lease: Lease | null) {
return async function (argv: any, commandDef: CommandHandlers) {
const tasks = new Listr([...actionTasks], options);

Expand All @@ -215,7 +216,7 @@ export abstract class BaseCommand extends ShellRunner {
* Setup home directories
* @param dirs a list of directories that need to be created in sequence
*/
setupHomeDirectory(
public setupHomeDirectory(
dirs: string[] = [
constants.SOLO_HOME_DIR,
constants.SOLO_LOGS_DIR,
Expand All @@ -240,9 +241,34 @@ export abstract class BaseCommand extends ShellRunner {
return dirs;
}

setupHomeDirectoryTask() {
public setupHomeDirectoryTask() {
return new Task('Setup home directory', async () => {
this.setupHomeDirectory();
});
}

/**
* Get the consensus nodes from the remoteConfigManager and use the localConfig to get the context
* @returns an array of ConsensusNode objects
*/
public getConsensusNodes(): ConsensusNode[] {
const consensusNodes: ConsensusNode[] = [];

// using the remoteConfigManager to get the consensus nodes
Object.values(this.getRemoteConfigManager().components.consensusNodes).forEach(node => {
consensusNodes.push(
new ConsensusNode(
node.name,
node.nodeId,
node.namespace,
node.cluster,
// use local config to get the context
this.getLocalConfig().clusterRefs[node.cluster],
),
);
});

// return the consensus nodes
return consensusNodes;
}
}
13 changes: 13 additions & 0 deletions src/core/model/consensus_node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* SPDX-License-Identifier: Apache-2.0
*/

export class ConsensusNode {
constructor(
public readonly name: string,
public readonly nodeId: number,
public readonly namespace: string,
public readonly cluster: string,
public readonly context: string,
) {}
}
Loading

0 comments on commit 44703a4

Please sign in to comment.