Skip to content

Commit

Permalink
WIP: working directory start and stop
Browse files Browse the repository at this point in the history
Signed-off-by: Iliya Savov <isavov@users.noreply.github.com>
  • Loading branch information
isavov committed Dec 19, 2023
1 parent 9219dc3 commit 4f0928f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ yargs(hideBin(process.argv))
)
.command(
"stop",
"Stops the local hedera network and delete all the existing data.",
async () => {
"Stops the local hedera network and delete all the existing data.",
(yargs: yargs.Argv<{}>) => {
ServiceLocator.Current.get<CLIService>(CLIService.name).loadStartupOptions(yargs);
},
async (argv: yargs.ArgumentsCamelCase<{}>) => {
ServiceLocator.Current.get<CLIService>(CLIService.name).setCurrentArgv(argv);
await new StateController("stop").startStateMachine();
}
)
Expand Down
22 changes: 11 additions & 11 deletions src/state/InitState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ export class InitState implements IState{
}

this.logger.info(`Setting configuration for ${this.cliOptions.network} network with latest images on host ${this.cliOptions.host} with dev mode turned ${this.cliOptions.devMode ? 'on' : 'off'} using ${this.cliOptions.fullMode? 'full': 'turbo'} mode in ${this.cliOptions.multiNode? 'multi' : 'single'} node configuration...`, this.stateName);
this.prepareWorkingDirectory();
const workingDirConfiguration = [
{ key: "NETWORK_NODE_LOGS_ROOT_PATH", value: join(this.cliOptions.workingDir, "network-logs", "node") },
{ key: "APPLICATION_CONFIG_PATH", value: join(this.cliOptions.workingDir, "compose-network","network-node","data","config") },
this.prepareWorkDirectory();
const workDirConfiguration = [
{ key: "NETWORK_NODE_LOGS_ROOT_PATH", value: join(this.cliOptions.workDir, "network-logs", "node") },
{ key: "APPLICATION_CONFIG_PATH", value: join(this.cliOptions.workDir, "compose-network","network-node","data","config") },
];
configurationData.envConfiguration = configurationData.envConfiguration?.concat(workingDirConfiguration);
configurationData.envConfiguration = configurationData.envConfiguration?.concat(workDirConfiguration);

this.configureEnvVariables(configurationData.imageTagConfiguration, configurationData.envConfiguration);
this.configureNodeProperties(configurationData.nodeConfiguration?.properties);
Expand All @@ -88,15 +88,15 @@ export class InitState implements IState{
this.observer!.update(EventType.Finish);
}

private prepareWorkingDirectory() {
this.logger.info(`Local Node Working directory set to ${this.cliOptions.workingDir}`,this.stateName);
this.ensureDirectoryExists(this.cliOptions.workingDir);
this.ensureDirectoryExists(join(this.cliOptions.workingDir, "network-logs","node"));
private prepareWorkDirectory() {
this.logger.info(`Local Node Working directory set to ${this.cliOptions.workDir}`,this.stateName);
this.ensureDirectoryExists(this.cliOptions.workDir);
this.ensureDirectoryExists(join(this.cliOptions.workDir, "network-logs","node"));
const configDir = join(__dirname, '../../compose-network/network-node/data/config/');
const configDirMirrorNode = join(__dirname, '../../compose-network/mirror-node/application.yml');
const configFiles = {
[configDir]: `${this.cliOptions.workingDir}/compose-network/network-node/data/config`,
[configDirMirrorNode]: `${this.cliOptions.workingDir}/compose-network/mirror-node/application.yml`
[configDir]: `${this.cliOptions.workDir}/compose-network/network-node/data/config`,
[configDirMirrorNode]: `${this.cliOptions.workDir}/compose-network/mirror-node/application.yml`
}
this.copyDirectories(configFiles);
// throw new Error('Method not implemented.');
Expand Down
9 changes: 8 additions & 1 deletion src/state/StopState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,29 @@
*/

import shell from 'shelljs';
import { join } from 'path';
import { IOBserver } from '../controller/IObserver';
import { LoggerService } from '../services/LoggerService';
import { ServiceLocator } from '../services/ServiceLocator';
import { IState } from './IState';
import { EventType } from '../types/EventType';
import { IS_WINDOWS } from '../constants';
import { CLIOptions } from '../types/CLIOptions';
import { CLIService } from '../services/CLIService';

export class StopState implements IState{
private logger: LoggerService;

private observer: IOBserver | undefined;

private cliOptions: CLIOptions;

private stateName: string;

constructor() {
this.stateName = StopState.name;
this.logger = ServiceLocator.Current.get<LoggerService>(LoggerService.name);
this.cliOptions = ServiceLocator.Current.get<CLIService>(CLIService.name).getCurrentArgv();
this.logger.trace('Stop State Initialized!', this.stateName);
}

Expand All @@ -57,6 +63,7 @@ export class StopState implements IState{
shell.exec(`docker compose down -v --remove-orphans 2>${nullOutput}`);
this.logger.trace('Cleaning the volumes and temp files...', this.stateName);
shell.exec(`rm -rf network-logs/* >${nullOutput} 2>&1`);
shell.exec(`rm -rf ${join(this.cliOptions.workDir, "network-logs")} >${nullOutput} 2>&1`);
shell.exec(`docker network prune -f 2>${nullOutput}`);
shell.cd(rootPath);
this.logger.info('Hedera Local Node was stopped successfully.', this.stateName);
Expand Down

0 comments on commit 4f0928f

Please sign in to comment.