Skip to content

Commit

Permalink
feat: service node (#2)
Browse files Browse the repository at this point in the history
fix: renamed unit tests
  • Loading branch information
fboucquez committed Jan 27, 2022
1 parent e46f15d commit 051f735
Show file tree
Hide file tree
Showing 662 changed files with 26,736 additions and 169 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ If you are creating a Symbol node for the first time, please have look at the [s
- Node 12.0.0+
- Docker 18.3.0+
- Docker Compose 1.25.0+
- Symbol Bootstrap 1.1.3+.
- Symbol Bootstrap 1.1.4+.

# Installation

Expand All @@ -45,7 +45,7 @@ $ npm install -g symbol-network
$ symbol-network COMMAND
running command...
$ symbol-network (-v|--version|version)
symbol-network/0.0.1 linux-x64 node-v12.18.3
symbol-network/0.0.1 linux-x64 node-v12.22.1
$ symbol-network --help [COMMAND]
USAGE
$ symbol-network COMMAND
Expand Down
8,748 changes: 8,717 additions & 31 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"inquirer": "^8.2.0",
"lodash": "^4.17.21",
"remove": "^0.1.5",
"symbol-bootstrap": "^1.1.4-alpha-3f3b67b",
"symbol-bootstrap": "^1.1.4-alpha-e63d2e2",
"symbol-sdk": "^1.0.3",
"tslib": "^2.3.1",
"winston": "^3.4.0"
Expand Down
2 changes: 1 addition & 1 deletion src/commands/configureNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ This command can be executed multiple times if you need to update or upgrade you
const workingDir = Constants.defaultWorkingDir;
const keyStore = await NetworkCommandUtils.createStore(flags, logger, true, workingDir);
const nodePassword = await NetworkCommandUtils.resolveNodePassword(flags, logger);
await new NetworkService(logger, workingDir).updateNodes(keyStore, { nodePassword, offline: flags.offline, zip: flags.zip });
await new NetworkService(logger, workingDir).configureNodes(keyStore, { nodePassword, offline: flags.offline, zip: flags.zip });
}
}
5 changes: 5 additions & 0 deletions src/commands/listServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export default class ListServices extends Command {
logger.info(` - Explorer - ${NetworkUtils.resolveExplorerUrl(hostname)}`);
logger.info(` - Faucet - ${NetworkUtils.resolveFaucetUrl(hostname)}`);
}
if (metadata.services) {
//pretty hardcoded!
logger.info(` - Explorer - ${'https://explorer.' + input.domain}`);
logger.info(` - Faucet - ${'https://faucet.' + input.domain}`);
}
});
}
}
27 changes: 26 additions & 1 deletion src/model/NodeInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { CustomPreset, NodeAccount as NodeAddresses } from 'symbol-bootstrap';
import { Assembly, CustomPreset, NodeAccount as NodeAddresses } from 'symbol-bootstrap';

export enum NodeMetadataType {
VotingPeer = 'VotingPeer',
Expand All @@ -24,6 +24,7 @@ export enum NodeMetadataType {
HarvestingDual = 'HarvestingDual',
HarvestingDemo = 'HarvestingDemo',
VotingNonHarvestingPeer = 'VotingNonHarvestingPeer',
Services = 'Services',
Peer = 'Peer',
Api = 'Api',
}
Expand Down Expand Up @@ -51,8 +52,10 @@ export interface NodeTypeMetadata {
harvesting: boolean;
voting: boolean;
demo: boolean;
services?: boolean;
nickName: string;
assembly?: string;
suggestedCount: number;
}

export const nodesMetadata: Record<NodeMetadataType, NodeTypeMetadata> = {
Expand All @@ -65,6 +68,7 @@ export const nodesMetadata: Record<NodeMetadataType, NodeTypeMetadata> = {
api: false,
peer: true,
nickName: 'beacon',
suggestedCount: 3,
},
VotingApi: {
name: 'Voting Api',
Expand All @@ -75,6 +79,7 @@ export const nodesMetadata: Record<NodeMetadataType, NodeTypeMetadata> = {
api: false,
peer: true,
nickName: 'beacon',
suggestedCount: 3,
},
VotingDual: {
name: 'Voting Dual',
Expand All @@ -85,6 +90,7 @@ export const nodesMetadata: Record<NodeMetadataType, NodeTypeMetadata> = {
api: true,
peer: true,
nickName: 'dual',
suggestedCount: 3,
},
HarvestingPeer: {
name: 'Harvesting Peer',
Expand All @@ -95,6 +101,7 @@ export const nodesMetadata: Record<NodeMetadataType, NodeTypeMetadata> = {
api: false,
peer: true,
nickName: 'beacon',
suggestedCount: 3,
},
HarvestingDual: {
name: 'Harvesting Dual',
Expand All @@ -105,6 +112,7 @@ export const nodesMetadata: Record<NodeMetadataType, NodeTypeMetadata> = {
api: true,
peer: true,
nickName: 'dual',
suggestedCount: 3,
},

HarvestingDemo: {
Expand All @@ -117,6 +125,7 @@ export const nodesMetadata: Record<NodeMetadataType, NodeTypeMetadata> = {
peer: true,
assembly: 'demo',
nickName: 'demo',
suggestedCount: 1,
},
Peer: {
name: 'Peer',
Expand All @@ -127,6 +136,20 @@ export const nodesMetadata: Record<NodeMetadataType, NodeTypeMetadata> = {
api: false,
peer: true,
nickName: 'peer',
suggestedCount: 3,
},
Services: {
name: 'Services',
balances: [],
voting: false,
harvesting: false,
demo: false,
api: false,
peer: false,
services: true,
nickName: 'services',
assembly: Assembly.services,
suggestedCount: 1,
},
Api: {
name: 'Api',
Expand All @@ -137,6 +160,7 @@ export const nodesMetadata: Record<NodeMetadataType, NodeTypeMetadata> = {
api: true,
peer: false,
nickName: 'api',
suggestedCount: 3,
},
VotingNonHarvestingPeer: {
name: 'Non Harvesting Voting Peer',
Expand All @@ -147,6 +171,7 @@ export const nodesMetadata: Record<NodeMetadataType, NodeTypeMetadata> = {
api: false,
peer: true,
nickName: 'peer',
suggestedCount: 3,
},
};

Expand Down
67 changes: 34 additions & 33 deletions src/services/NetworkConfigurationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import {
CryptoUtils,
CustomPreset,
DeepPartial,
FaucetPreset,
FileSystemService,
Logger,
NodePreset,
Password,
PeerInfo,
PrivateKeySecurityMode,
Expand Down Expand Up @@ -82,19 +82,21 @@ export class NetworkConfigurationService {
const metadata = nodesMetadata[nodeTypeInput.nodeType];
const assembly = NodeMetadataUtils.getAssembly(metadata);

const customPreset: CustomPreset = {
privateKeySecurityMode: PrivateKeySecurityMode.PROMPT_MAIN_TRANSPORT,
nodes: [
{
friendlyName: friendlyName,
host: hostname,
voting: metadata.voting,
harvesting: metadata.harvesting,
dockerComposeDebugMode: false,
brokerDockerComposeDebugMode: false,
},
],
};
const customPreset: CustomPreset = metadata.services
? { domain: input.domain }
: {
privateKeySecurityMode: PrivateKeySecurityMode.PROMPT_MAIN_TRANSPORT,
nodes: [
{
friendlyName: friendlyName,
host: hostname,
voting: metadata.voting,
harvesting: metadata.harvesting,
dockerComposeDebugMode: false,
brokerDockerComposeDebugMode: false,
},
],
};
if (metadata.api && nodeTypeInput.restProtocol == RestProtocol.HttpsOnly) {
customPreset.gateways = [
{
Expand Down Expand Up @@ -164,7 +166,7 @@ export class NetworkConfigurationService {
return output;
}

public async updateNodes({ nodePassword, offline, composeUser, zip }: UpdateNodesParams): Promise<void> {
public async configureNodes({ nodePassword, offline, composeUser, zip }: UpdateNodesParams): Promise<void> {
const input = await NetworkUtils.loadNetwork(this.workingDir);
const networkPreset = ConfigLoader.loadNetworkPreset(input.preset, this.workingDir);
const customNetwork = YamlUtils.isYmlFile(input.preset);
Expand All @@ -183,25 +185,20 @@ export class NetworkConfigurationService {

const toStoreCustomPreset = CryptoUtils.removePrivateKeys(node.customPreset) as CustomPreset;

const nodeCustomPreset: DeepPartial<NodePreset> | undefined = toStoreCustomPreset?.nodes?.[0];
if (!nodeCustomPreset) {
throw new Error(`Node's custom preset cannot be found!`);
}

const metadata = nodesMetadata[node.nodeType];
if (metadata.demo) {
if (metadata.demo || metadata.services) {
const faucetAccount = input.faucetBalances
? await this.keyStore.getNetworkAccount(input.networkType, 'faucet', true)
: undefined;
toStoreCustomPreset.faucets = [
_.merge(
{
repeat: faucetAccount ? 1 : 0,
privateKey: faucetAccount?.privateKey,
const faucetCustomPreset: DeepPartial<FaucetPreset> = {
repeat: faucetAccount ? 1 : 0,
compose: {
environment: {
FAUCET_PRIVATE_KEY: faucetAccount?.privateKey,
},
toStoreCustomPreset.faucets?.[0],
),
];
},
};
toStoreCustomPreset.faucets = [_.merge(faucetCustomPreset, toStoreCustomPreset.faucets?.[0])];
}

if (input.nemesisSeedFolder) {
Expand Down Expand Up @@ -241,18 +238,22 @@ export class NetworkConfigurationService {
{
user: composeUser || ConfigService.defaultParams.user,
target: bootstrapTargetFolder,
offline: offline,
upgrade: true,
workingDir: this.workingDir,
password: nodePassword as string,
},
result.presetData,
result.addresses,
);
const nodeAddresses = result.addresses.nodes?.[0];
if (!nodeAddresses) {
throw new Error('Node addresses should have been resolved!!!');
if (!metadata.services) {
const nodeAddresses = result.addresses.nodes?.[0];
if (!nodeAddresses) {
throw new Error('Node addresses should have been resolved!!!');
}
node.addresses = nodeAddresses;
}
node.addresses = nodeAddresses;

if (zip) {
const zipName = `${hostname}.zip`;
const zipDir = `${this.workingDir}/distribution`;
Expand Down
8 changes: 6 additions & 2 deletions src/services/NetworkGenesisService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ export class NetworkGenesisService {
const founderAccount = await this.keyStore.getNetworkAccount(networkType, 'founder', true);
for (const node of input.nodes) {
const metadata = nodesMetadata[node.nodeType];
if (metadata.services) {
continue;
}
const hostname = node.hostname;
const nodeId = `node-${NetworkUtils.zeroPad(node.number, 3)}`;
this.logger.info(`Generating transactions and balances for node ${nodeId} ${hostname}`);
Expand Down Expand Up @@ -270,8 +273,8 @@ export class NetworkGenesisService {
};
this.logger.info(`Generating nemesis block...`);
this.logger.info('');
const node = input.nodes.find(async (node) => {
const metadata = nodesMetadata[node.nodeType];
const node = input.nodes.find(async (n) => {
const metadata = nodesMetadata[n.nodeType];
return metadata.harvesting;
});
if (!node) {
Expand All @@ -292,6 +295,7 @@ export class NetworkGenesisService {
customPresetObject: nemesisCustomPreset,
});
await service.compose({
offline: true,
target: nemesisTargetFolder,
user: composeUser || ConfigService.defaultParams.user,
password: password || undefined,
Expand Down
4 changes: 2 additions & 2 deletions src/services/NetworkService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class NetworkService {
return new NetworkLinkService(this.logger, this.workingDir, keyStore).linkNodes(params);
}

updateNodes(keyStore: KeyStore, params: UpdateNodesParams): Promise<void> {
return new NetworkConfigurationService(this.logger, this.workingDir, keyStore).updateNodes(params);
configureNodes(keyStore: KeyStore, params: UpdateNodesParams): Promise<void> {
return new NetworkConfigurationService(this.logger, this.workingDir, keyStore).configureNodes(params);
}
}
30 changes: 15 additions & 15 deletions src/utils/InitFromFileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ export class InitFromFileService {

const logger = LoggerFactory.getLogger(LogType.Console);

console.log();
console.log(`Welcome to the ${NetworkCommandUtils.CLI_TOOL} tool. `);
console.log();
console.log('This tool will allow you creating a new network or a node cluster for an existing network.');
console.log();
console.log('The init.yml file has been provided. Cli will automatically generate the required information.');
console.log();
this.logger.info('');
this.logger.info(`Welcome to the ${NetworkCommandUtils.CLI_TOOL} tool. `);
this.logger.info('');
this.logger.info('This tool will allow you creating a new network or a node cluster for an existing network.');
this.logger.info('');
this.logger.info('The init.yml file has been provided. Cli will automatically generate the required information.');
this.logger.info('');

const networkInput: NetworkInputFile = await NetworkUtils.loadNetworkInput(this.workingDir);

Expand Down Expand Up @@ -69,18 +69,18 @@ export class InitFromFileService {
networkInput,
customNetworkPresetFile,
);
console.log();
console.log(
this.logger.info('');
this.logger.info(
`The initial network preset ${customNetworkPresetFile} for the new network has been stored. This file will be updated in the following steps.`,
);
console.log();
this.logger.info('');
}

await NetworkUtils.saveNetworkInput(this.workingDir, networkInput);
console.log();
console.log(`You have created the initial ${networkInputFile}. Have a look and once once you are happy, run: `);
console.log();
console.log(`$ ${NetworkCommandUtils.CLI_TOOL} expandNodes`);
console.log();
this.logger.info('');
this.logger.info(`You have created the initial ${networkInputFile}. Have a look and once once you are happy, run: `);
this.logger.info('');
this.logger.info(`$ ${NetworkCommandUtils.CLI_TOOL} expandNodes`);
this.logger.info('');
}
}
Loading

0 comments on commit 051f735

Please sign in to comment.