From 6625b7186fe9aa8520161e048eb3fc8e0acc59dd Mon Sep 17 00:00:00 2001 From: "nkl199@yahoo.co.uk" Date: Tue, 18 Feb 2020 12:26:10 +0000 Subject: [PATCH] Provide cli command to spawn a distributed client that uses a non-process comms method Signed-off-by: nkl199@yahoo.co.uk --- packages/caliper-burrow/index.js | 2 +- ...{burrowClientWorker.js => burrowWorker.js} | 0 .../caliper-burrow/lib/burrowWorkerFactory.js | 35 +++++++++++ packages/caliper-cli/caliper.js | 7 ++- .../lib/benchmark/lib/runBenchmark.js | 5 +- .../lib/benchmark/runBenchmarkCommand.js | 14 +---- packages/caliper-cli/lib/bind/bind.js | 27 +++++++-- packages/caliper-cli/lib/bindCommand.js | 22 +++---- .../lib/utility/utils.js} | 25 ++++---- packages/caliper-cli/lib/worker/lib/launch.js | 58 +++++++++++++++++++ .../lib/worker/workerLaunchCommand.js | 48 +++++++++++++++ packages/caliper-cli/lib/workerCommand.js | 23 ++++++++ packages/caliper-cli/package.json | 2 +- .../caliper-core/lib/common/config/Config.js | 3 +- .../lib/common/config/default.yaml | 2 + .../orchestrators/worker-orchestrator.js | 3 +- packages/caliper-core/package.json | 2 +- packages/caliper-ethereum/index.js | 2 +- ...ereumClientWorker.js => ethereumWorker.js} | 0 .../lib/ethereumWorkerFactory.js} | 10 ++-- packages/caliper-fabric/index.js | 2 +- ...{fabricClientWorker.js => fabricWorker.js} | 0 .../caliper-fabric/lib/fabricWorkerFactory.js | 35 +++++++++++ packages/caliper-fisco-bcos/index.js | 2 +- ...BcosClientWorker.js => fiscoBcosWorker.js} | 0 .../lib/fiscoBcosWorkerFactory.js} | 8 +-- packages/caliper-fisco-bcos/package.json | 2 +- .../generator-caliper/package.json | 2 +- packages/caliper-iroha/index.js | 2 +- .../{irohaClientWorker.js => irohaWorker.js} | 0 ...ClientFactory.js => irohaWorkerFactory.js} | 8 +-- packages/caliper-publish/package.json | 2 +- packages/caliper-sawtooth/index.js | 2 +- .../lib/sawtoothClientFactory.js | 35 ----------- ...toothClientWorker.js => sawtoothWorker.js} | 0 .../lib/sawtoothWorkerFactory.js} | 8 +-- 36 files changed, 287 insertions(+), 111 deletions(-) rename packages/caliper-burrow/lib/{burrowClientWorker.js => burrowWorker.js} (100%) create mode 100644 packages/caliper-burrow/lib/burrowWorkerFactory.js rename packages/{caliper-fisco-bcos/lib/fiscoBcosClientFactory.js => caliper-cli/lib/utility/utils.js} (51%) create mode 100644 packages/caliper-cli/lib/worker/lib/launch.js create mode 100644 packages/caliper-cli/lib/worker/workerLaunchCommand.js create mode 100644 packages/caliper-cli/lib/workerCommand.js rename packages/caliper-ethereum/lib/{ethereumClientWorker.js => ethereumWorker.js} (100%) rename packages/{caliper-burrow/lib/burrowClientFactory.js => caliper-ethereum/lib/ethereumWorkerFactory.js} (80%) rename packages/caliper-fabric/lib/{fabricClientWorker.js => fabricWorker.js} (100%) create mode 100644 packages/caliper-fabric/lib/fabricWorkerFactory.js rename packages/caliper-fisco-bcos/lib/{fiscoBcosClientWorker.js => fiscoBcosWorker.js} (100%) rename packages/{caliper-ethereum/lib/ethereumClientFactory.js => caliper-fisco-bcos/lib/fiscoBcosWorkerFactory.js} (82%) rename packages/caliper-iroha/lib/{irohaClientWorker.js => irohaWorker.js} (100%) rename packages/caliper-iroha/lib/{irohaClientFactory.js => irohaWorkerFactory.js} (83%) delete mode 100644 packages/caliper-sawtooth/lib/sawtoothClientFactory.js rename packages/caliper-sawtooth/lib/{sawtoothClientWorker.js => sawtoothWorker.js} (100%) rename packages/{caliper-fabric/lib/fabricClientFactory.js => caliper-sawtooth/lib/sawtoothWorkerFactory.js} (82%) diff --git a/packages/caliper-burrow/index.js b/packages/caliper-burrow/index.js index 8ef0612c4..95bf06e47 100644 --- a/packages/caliper-burrow/index.js +++ b/packages/caliper-burrow/index.js @@ -15,4 +15,4 @@ 'use strict'; module.exports.AdminClient = require('./lib/burrow'); -module.exports.ClientFactory = require('./lib/burrowClientFactory'); +module.exports.WorkerFactory = require('./lib/burrowWorkerFactory'); diff --git a/packages/caliper-burrow/lib/burrowClientWorker.js b/packages/caliper-burrow/lib/burrowWorker.js similarity index 100% rename from packages/caliper-burrow/lib/burrowClientWorker.js rename to packages/caliper-burrow/lib/burrowWorker.js diff --git a/packages/caliper-burrow/lib/burrowWorkerFactory.js b/packages/caliper-burrow/lib/burrowWorkerFactory.js new file mode 100644 index 000000000..840549ac9 --- /dev/null +++ b/packages/caliper-burrow/lib/burrowWorkerFactory.js @@ -0,0 +1,35 @@ +/* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +const childProcess = require('child_process'); +const path = require('path'); + +/** + * Class used to spawn burrow workers + */ +class BurrowWorkerFactory { + + /** + * Spawn the worker + * @returns {Object} the child process + */ + async spawnWorker() { + const child = childProcess.fork(path.join(__dirname, './burrowWorker.js'), process.argv.slice(2), { env: process.env}); + return child; + } +} + +module.exports = BurrowWorkerFactory; diff --git a/packages/caliper-cli/caliper.js b/packages/caliper-cli/caliper.js index d397e5979..ad0a9b529 100755 --- a/packages/caliper-cli/caliper.js +++ b/packages/caliper-cli/caliper.js @@ -16,24 +16,27 @@ 'use strict'; process.env.SUPPRESS_NO_CONFIG_WARNING = true; +const { CaliperUtils } = require('@hyperledger/caliper-core'); +const Logger = CaliperUtils.getLogger('cli'); const yargs = require('yargs'); const version = 'v' + require('./package.json').version; let results = yargs .commandDir('./lib') .help() - .example('caliper bind\ncaliper benchmark run\ncaliper zooclient start\ncaliper zooservice start ') + .example('caliper bind\ncaliper benchmark run\n caliper worker launch') .demand(1) .wrap(null) - .strict() .epilogue('For more information on Hyperledger Caliper: https://hyperledger.github.io/caliper/') .alias('v', 'version') .version(version) .describe('v', 'show version information') + .strict(false) .argv; results.thePromise.then( () => { process.exit(0); }).catch((error) => { + Logger.error(error); process.exit(1); }); diff --git a/packages/caliper-cli/lib/benchmark/lib/runBenchmark.js b/packages/caliper-cli/lib/benchmark/lib/runBenchmark.js index 5ce367053..58ae694ff 100644 --- a/packages/caliper-cli/lib/benchmark/lib/runBenchmark.js +++ b/packages/caliper-cli/lib/benchmark/lib/runBenchmark.js @@ -70,11 +70,10 @@ class RunBenchmark { logger.info(`Set network configuration path: ${networkConfigPath}`); logger.info(`Detected SUT type: ${blockchainType}`); - const {AdminClient, ClientFactory} = require(`@hyperledger/caliper-${blockchainType}`); + const {AdminClient, WorkerFactory} = require(`@hyperledger/caliper-${blockchainType}`); const blockchainAdapter = new AdminClient(networkConfigPath, workspacePath); - const workerFactory = new ClientFactory(); - const engine = new CaliperEngine(benchmarkConfig, networkConfig, blockchainAdapter, workerFactory); + const engine = new CaliperEngine(benchmarkConfig, networkConfig, blockchainAdapter, WorkerFactory); const response = await engine.run(); if (response === 0) { diff --git a/packages/caliper-cli/lib/benchmark/runBenchmarkCommand.js b/packages/caliper-cli/lib/benchmark/runBenchmarkCommand.js index 36d090326..40e9efa3d 100644 --- a/packages/caliper-cli/lib/benchmark/runBenchmarkCommand.js +++ b/packages/caliper-cli/lib/benchmark/runBenchmarkCommand.js @@ -15,17 +15,12 @@ 'use strict'; const RunBenchmark = require ('./lib/runBenchmark'); +const Utils = require('../utility/utils'); // enforces singletons const checkFn = (argv, options) => { - - ['caliper-benchconfig','caliper-networkconfig','caliper-workspace'].forEach((e)=>{ - if (Array.isArray(argv[e])){ - throw new Error(`Option ${e} can only be specified once`); - } - }); - - return true; + const uniqueArgs = ['caliper-benchconfig','caliper-networkconfig','caliper-workspace']; + return Utils.checkSingleton(argv, uniqueArgs); }; module.exports._checkFn = checkFn; module.exports.command = 'run [options]'; @@ -39,9 +34,6 @@ module.exports.builder = function (yargs){ }); yargs.usage('caliper benchmark run --caliper-workspace ~/myCaliperProject --caliper-benchconfig my-app-test-config.yaml --caliper-networkconfig my-sut-config.yaml'); - // enforce the option after these options - yargs.requiresArg(['caliper-benchconfig','caliper-networkconfig','caliper-workspace']); - // enforce singletons yargs.check(checkFn); diff --git a/packages/caliper-cli/lib/bind/bind.js b/packages/caliper-cli/lib/bind/bind.js index f65b2aff9..3ed9ef048 100644 --- a/packages/caliper-cli/lib/bind/bind.js +++ b/packages/caliper-cli/lib/bind/bind.js @@ -15,6 +15,8 @@ 'use strict'; const { CaliperUtils, ConfigUtil } = require('@hyperledger/caliper-core'); + +const fs = require('fs'); const path = require('path'); const logger = CaliperUtils.getLogger('bind'); @@ -34,31 +36,46 @@ class Bind { let sdk = ConfigUtil.get(ConfigUtil.keys.Bind.Sdk, undefined); let cwd = ConfigUtil.get(ConfigUtil.keys.Bind.Cwd, undefined); let userArgs = ConfigUtil.get(ConfigUtil.keys.Bind.Args, undefined); + let file = ConfigUtil.get(ConfigUtil.keys.Bind.File, undefined); + + let bindOptions; + const defaultBindOpts = CaliperUtils.parseYaml(path.join(__dirname, './config.yaml')); - let bindOptions = CaliperUtils.parseYaml(path.join(__dirname, './config.yaml')); + if (file) { + // User has passed a configuration file to bind + if (!fs.existsSync(file)) { + let msg = `Passed bind file ${file} does not exist`; + logger.error(msg); + throw new Error(msg); + } else { + bindOptions = CaliperUtils.parseYaml(file); + } + } else { + bindOptions = defaultBindOpts; + } let sutList = Object.keys(bindOptions.sut); if (!sut) { - let msg = `SUT name is not specified. Available SUTs: ${sutList.join(' | ')}`; + let msg = `SUT name is not specified. Available SUTs: ${Object.keys(defaultBindOpts.sut).join(' | ')}`; logger.error(msg); throw new Error(msg); } if (!sutList.includes(sut)) { - let msg = `Unknown SUT name "${sut}". Available SUTs: ${sutList.join(' | ')}`; + let msg = `Unknown SUT name "${sut}". Available SUTs: ${Object.keys(defaultBindOpts.sut).join(' | ')}`; logger.error(msg); throw new Error(msg); } let sutSdkList = Object.keys(bindOptions.sut[sut]); if (!sdk) { - let msg = `"${sut}" SDK version is not specified. Available versions: ${sutSdkList.join(' | ')}`; + let msg = `"${sut}" SDK version is not specified. Available versions: ${Object.keys(defaultBindOpts.sut[sut]).join(' | ')}`; logger.error(msg); throw new Error(msg); } if (!sutSdkList.includes(sdk)) { - let msg = `Unknown "${sut}" SDK version "${sdk}". Available versions: ${sutSdkList.join(' | ')}`; + let msg = `Unknown "${sut}" SDK version "${sdk}". Available versions: ${Object.keys(defaultBindOpts.sut[sut]).join(' | ')}`; logger.error(msg); throw new Error(msg); } diff --git a/packages/caliper-cli/lib/bindCommand.js b/packages/caliper-cli/lib/bindCommand.js index fd6e4891d..4e9a2cdee 100644 --- a/packages/caliper-cli/lib/bindCommand.js +++ b/packages/caliper-cli/lib/bindCommand.js @@ -14,19 +14,15 @@ 'use strict'; -const Bind = require ('./bind/bind.js'); +const Bind = require('./bind/bind.js'); +const Utils = require('./utility/utils'); // enforces singletons -const checkFn = (argv, options) => { - - ['caliper-bind-sut','caliper-bind-sdk', 'caliper-bind-args', 'caliper-bind-cwd'].forEach((e)=>{ - if (Array.isArray(argv[e])){ - throw new Error(`Option ${e} can only be specified once`); - } - }); - - return true; +const checkFn = (argv) => { + const uniqueArgs = ['caliper-bind-sut','caliper-bind-sdk', 'caliper-bind-args', 'caliper-bind-cwd', 'caliper-bind-file']; + return Utils.checkSingleton(argv, uniqueArgs); }; + module.exports._checkFn = checkFn; module.exports.command = 'bind [options]'; module.exports.describe = 'Bind Caliper to a specific SUT and its SDK version'; @@ -35,11 +31,11 @@ module.exports.builder = function (yargs){ yargs.options({ 'caliper-bind-sut' : {describe: 'The name of the platform to bind to', type: 'string' }, 'caliper-bind-sdk' : {describe: 'Version of the platform SDK to bind to', type: 'string'}, - 'caliper-bind-cwd' : {describe: 'The working directory for performing the SDK install', type: 'string'}, - 'caliper-bind-args' : {describe: 'Additional arguments to pass to "npm install". Use the "=" notation when setting this parameter', type: 'string'} + 'caliper-bind-cwd' : {describe: 'The working directory for performing the SDK install', type: 'string' }, + 'caliper-bind-args' : {describe: 'Additional arguments to pass to "npm install". Use the "=" notation when setting this parameter', type: 'string' }, + 'caliper-bind-file' : {describe: 'Yaml file to override default (supported) package versions when binding an SDK', type: 'string' } }); yargs.usage('Usage:\n caliper bind --caliper-bind-sut fabric --caliper-bind-sdk 1.4.1 --caliper-bind-cwd ./ --caliper-bind-args="-g"'); - // enforce the option after these options yargs.requiresArg(['caliper-bind-sut','caliper-bind-sdk','caliper-bind-args', 'caliper-bind-cwd']); diff --git a/packages/caliper-fisco-bcos/lib/fiscoBcosClientFactory.js b/packages/caliper-cli/lib/utility/utils.js similarity index 51% rename from packages/caliper-fisco-bcos/lib/fiscoBcosClientFactory.js rename to packages/caliper-cli/lib/utility/utils.js index fe665eafb..adeda34c7 100644 --- a/packages/caliper-fisco-bcos/lib/fiscoBcosClientFactory.js +++ b/packages/caliper-cli/lib/utility/utils.js @@ -14,22 +14,25 @@ 'use strict'; -const childProcess = require('child_process'); -const path = require('path'); - /** - * Class used to spawn FISCO BCOS client workers + * utility functions for CLI */ -class FiscoBcosClientFactory { +class Utils { /** - * Spawn the worker and perform required init - * @returns {Object} the child process + * Utility function to check for singleton values + * @param {string[]} passedArgs arguments passed by user + * @param {string[]} uniqueArgs arguments that must be unique + * @returns {boolean} boolean true if passes check */ - spawnWorker() { - const child = childProcess.fork(path.join(__dirname, './fiscoBcosClientWorker.js'), process.argv.slice(2), { env: process.env }); - return child; + static checkSingleton(passedArgs, uniqueArgs) { + uniqueArgs.forEach((e) => { + if (Array.isArray(passedArgs[e])) { + throw new Error(`Option [${e}] can only be specified once`); + } + }); + return true; } } -module.exports = FiscoBcosClientFactory; +module.exports = Utils; diff --git a/packages/caliper-cli/lib/worker/lib/launch.js b/packages/caliper-cli/lib/worker/lib/launch.js new file mode 100644 index 000000000..e94748a83 --- /dev/null +++ b/packages/caliper-cli/lib/worker/lib/launch.js @@ -0,0 +1,58 @@ +/* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +const { CaliperUtils, ConfigUtil } = require('@hyperledger/caliper-core'); +const Bind = require('../../bind/bind'); +const logger = CaliperUtils.getLogger('launch'); + +/** + * Caliper worker Launch command + * @private + */ +class Launch { + + /** + * Command process for the Launch command. + * @param {string} argv Argument list from the caliper Launch command. Unused, relying on ConfigUtil instead. + */ + static async handler(argv) { + let sut = ConfigUtil.get(ConfigUtil.keys.Bind.Sut, undefined); + let sdk = ConfigUtil.get(ConfigUtil.keys.Bind.Sdk, undefined); + + // only valid command if distributed workers + if (!ConfigUtil.get(ConfigUtil.keys.Worker.Remote, false)) { + const msg = 'Configuration definition indicates that worker is not remote: worker launch is invalid in this mode'; + throw new Error(msg); + } + + // not valid for process communications + if (ConfigUtil.get(ConfigUtil.keys.Worker.Communication.Method, 'process').localeCompare('process') === 0) { + const msg = 'Configuration definition indicates that worker is based on process communications: worker launch is invalid in this mode'; + throw new Error(msg); + } + + // bind first + logger.info(`Binding worker to SDK ${sdk}`); + await Bind.handler(argv); + + // Launch target worker + logger.info(`Launching worker for sut ${sut}`); + const { WorkerFactory} = require(`@hyperledger/caliper-${sut}`); + WorkerFactory.spawnWorker(); + } +} + +module.exports = Launch; diff --git a/packages/caliper-cli/lib/worker/workerLaunchCommand.js b/packages/caliper-cli/lib/worker/workerLaunchCommand.js new file mode 100644 index 000000000..f5f22022f --- /dev/null +++ b/packages/caliper-cli/lib/worker/workerLaunchCommand.js @@ -0,0 +1,48 @@ +/* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +const Launch = require('./lib/launch.js'); +const Utils = require('../utility/utils'); + +// enforces singletons +const checkFn = (argv) => { + const uniqueArgs = ['caliper-bind-sut','caliper-bind-sdk', 'caliper-bind-args', 'caliper-bind-cwd', 'caliper-bind-file']; + return Utils.checkSingleton(argv, uniqueArgs); +}; + +module.exports._checkFn = checkFn; +module.exports.command = 'launch [options]'; +module.exports.describe = 'Launch a Caliper worker for a target SUT with a bound SDK version'; +module.exports.builder = function (yargs){ + + yargs.options({ + 'caliper-bind-sut' : {describe: 'The name of the platform to bind to', type: 'string' }, + 'caliper-bind-sdk' : {describe: 'Version of the platform SDK to bind to', type: 'string'}, + 'caliper-bind-cwd' : {describe: 'The working directory for performing the SDK install', type: 'string' }, + 'caliper-bind-args' : {describe: 'Additional arguments to pass to "npm install". Use the "=" notation when setting this parameter', type: 'string' }, + 'caliper-bind-file' : {describe: 'Yaml file to override default (supported) package versions when binding an SDK', type: 'string' } + }); + yargs.usage('Usage:\n caliper worker launch --caliper-bind-sut fabric --caliper-bind-sdk 1.4.1 --caliper-bind-cwd ./ --caliper-bind-args="-g"'); + + // enforce singletons + yargs.check(checkFn); + + return yargs; +}; + +module.exports.handler = (argv) => { + return argv.thePromise = Launch.handler(argv); +}; diff --git a/packages/caliper-cli/lib/workerCommand.js b/packages/caliper-cli/lib/workerCommand.js new file mode 100644 index 000000000..d6fe5322d --- /dev/null +++ b/packages/caliper-cli/lib/workerCommand.js @@ -0,0 +1,23 @@ +/* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +module.exports.command = 'worker '; +module.exports.describe = 'Caliper worker command'; +module.exports.builder = function (yargs){ + + return yargs.demandCommand(1, 'Incorrect command. Please see the list of commands above, or enter "caliper worker --help".') + .commandDir('./worker'); +}; diff --git a/packages/caliper-cli/package.json b/packages/caliper-cli/package.json index 5fbb0fa3e..a28f0a6c3 100644 --- a/packages/caliper-cli/package.json +++ b/packages/caliper-cli/package.json @@ -33,7 +33,7 @@ "@hyperledger/caliper-sawtooth": "0.3.0-unstable", "@hyperledger/caliper-ethereum": "0.3.0-unstable", "@hyperledger/caliper-fisco-bcos": "0.3.0-unstable", - "yargs": "10.0.3" + "yargs": "15.1.0" }, "devDependencies": { "chai": "^3.5.0", diff --git a/packages/caliper-core/lib/common/config/Config.js b/packages/caliper-core/lib/common/config/Config.js index 10dcf2fcb..a57f4bd8a 100644 --- a/packages/caliper-core/lib/common/config/Config.js +++ b/packages/caliper-core/lib/common/config/Config.js @@ -25,7 +25,8 @@ const keys = { Sut: 'caliper-bind-sut', Sdk: 'caliper-bind-sdk', Args: 'caliper-bind-args', - Cwd: 'caliper-bind-cwd' + Cwd: 'caliper-bind-cwd', + File: 'caliper-bind-file' }, Report: { Path: 'caliper-report-path', diff --git a/packages/caliper-core/lib/common/config/default.yaml b/packages/caliper-core/lib/common/config/default.yaml index 1eab8f373..0ab7f3b92 100644 --- a/packages/caliper-core/lib/common/config/default.yaml +++ b/packages/caliper-core/lib/common/config/default.yaml @@ -23,6 +23,8 @@ caliper: cwd: # The additional args to pass to the binding (i.e., npm install) command args: + # The file to use when binding (replace supported defaults) + file: # Report file-related options report: # The absolute or workspace-relative path of the report file. diff --git a/packages/caliper-core/lib/master/orchestrators/worker-orchestrator.js b/packages/caliper-core/lib/master/orchestrators/worker-orchestrator.js index 50a43cb3b..088223da1 100644 --- a/packages/caliper-core/lib/master/orchestrators/worker-orchestrator.js +++ b/packages/caliper-core/lib/master/orchestrators/worker-orchestrator.js @@ -46,7 +46,7 @@ class WorkerOrchestrator { /** * Constructor * @param {object} benchmarkConfig The benchmark configuration object. - * @param {object} workerFactory The factory for the worker processes. + * @param {WorkerFactory} workerFactory The factory for the worker processes. * @param {object[]} workerArguments List of adaptor specific arguments to pass for each worker processes. */ constructor(benchmarkConfig, workerFactory, workerArguments) { @@ -538,7 +538,6 @@ class WorkerOrchestrator { // Collect the launched process so it can be killed later this.workerObjects.push(worker); - } /** diff --git a/packages/caliper-core/package.json b/packages/caliper-core/package.json index 7741bb68f..249001029 100644 --- a/packages/caliper-core/package.json +++ b/packages/caliper-core/package.json @@ -25,7 +25,7 @@ "color-scheme": "^1.0.1", "compare-versions": "^3.4.0", "dockerode": "^2.5.0", - "fs-extra": "^8.0.1", + "fs-extra": "8.1.0", "js-yaml": "^3.12.0", "mustache": "^2.3.0", "mqtt": "3.0.0", diff --git a/packages/caliper-ethereum/index.js b/packages/caliper-ethereum/index.js index e2c14574b..88353a8cd 100644 --- a/packages/caliper-ethereum/index.js +++ b/packages/caliper-ethereum/index.js @@ -15,4 +15,4 @@ 'use strict'; module.exports.AdminClient = require('./lib/ethereum'); -module.exports.ClientFactory = require('./lib/ethereumClientFactory'); +module.exports.WorkerFactory = require('./lib/ethereumWorkerFactory'); diff --git a/packages/caliper-ethereum/lib/ethereumClientWorker.js b/packages/caliper-ethereum/lib/ethereumWorker.js similarity index 100% rename from packages/caliper-ethereum/lib/ethereumClientWorker.js rename to packages/caliper-ethereum/lib/ethereumWorker.js diff --git a/packages/caliper-burrow/lib/burrowClientFactory.js b/packages/caliper-ethereum/lib/ethereumWorkerFactory.js similarity index 80% rename from packages/caliper-burrow/lib/burrowClientFactory.js rename to packages/caliper-ethereum/lib/ethereumWorkerFactory.js index 9d2abd7fc..0ee9d203a 100644 --- a/packages/caliper-burrow/lib/burrowClientFactory.js +++ b/packages/caliper-ethereum/lib/ethereumWorkerFactory.js @@ -18,18 +18,18 @@ const childProcess = require('child_process'); const path = require('path'); /** - * Class used to spawn fabric client workers + * Class used to spawn ethereum workers */ -class BurrowClientFactory { +class EthereumWorkerFactory { /** * Spawn the worker and perform required init * @returns {Object} the child process */ - async spawnWorker() { - const child = childProcess.fork(path.join(__dirname, './burrowClientWorker.js'), process.argv.slice(2), { env: process.env}); + static spawnWorker() { + const child = childProcess.fork(path.join(__dirname, './ethereumWorker.js'), process.argv.slice(2), { env: process.env}); return child; } } -module.exports = BurrowClientFactory; +module.exports = EthereumWorkerFactory; diff --git a/packages/caliper-fabric/index.js b/packages/caliper-fabric/index.js index 8eb47471c..9936616ba 100644 --- a/packages/caliper-fabric/index.js +++ b/packages/caliper-fabric/index.js @@ -15,4 +15,4 @@ 'use strict'; module.exports.AdminClient = require('./lib/fabric'); -module.exports.ClientFactory = require('./lib/fabricClientFactory'); +module.exports.WorkerFactory = require('./lib/fabricWorkerFactory'); diff --git a/packages/caliper-fabric/lib/fabricClientWorker.js b/packages/caliper-fabric/lib/fabricWorker.js similarity index 100% rename from packages/caliper-fabric/lib/fabricClientWorker.js rename to packages/caliper-fabric/lib/fabricWorker.js diff --git a/packages/caliper-fabric/lib/fabricWorkerFactory.js b/packages/caliper-fabric/lib/fabricWorkerFactory.js new file mode 100644 index 000000000..b259d12b7 --- /dev/null +++ b/packages/caliper-fabric/lib/fabricWorkerFactory.js @@ -0,0 +1,35 @@ +/* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +const childProcess = require('child_process'); +const path = require('path'); + +/** + * Class used to spawn fabric workers + */ +class FabricWorkerFactory { + + /** + * Spawn the worker and perform required init + * @returns {Object} the child process + */ + static spawnWorker() { + const child = childProcess.fork(path.join(__dirname, './fabricWorker.js'), process.argv.slice(2), { env: process.env}); + return child; + } +} + +module.exports = FabricWorkerFactory; diff --git a/packages/caliper-fisco-bcos/index.js b/packages/caliper-fisco-bcos/index.js index 50cebd937..89c0d7076 100644 --- a/packages/caliper-fisco-bcos/index.js +++ b/packages/caliper-fisco-bcos/index.js @@ -15,4 +15,4 @@ 'use strict'; module.exports.AdminClient = require('./lib/fiscoBcos'); -module.exports.ClientFactory = require('./lib/fiscoBcosClientFactory'); +module.exports.WorkerFactory = require('./lib/fiscoBcosWorkerFactory'); diff --git a/packages/caliper-fisco-bcos/lib/fiscoBcosClientWorker.js b/packages/caliper-fisco-bcos/lib/fiscoBcosWorker.js similarity index 100% rename from packages/caliper-fisco-bcos/lib/fiscoBcosClientWorker.js rename to packages/caliper-fisco-bcos/lib/fiscoBcosWorker.js diff --git a/packages/caliper-ethereum/lib/ethereumClientFactory.js b/packages/caliper-fisco-bcos/lib/fiscoBcosWorkerFactory.js similarity index 82% rename from packages/caliper-ethereum/lib/ethereumClientFactory.js rename to packages/caliper-fisco-bcos/lib/fiscoBcosWorkerFactory.js index 09f4d652b..fa72b0b30 100644 --- a/packages/caliper-ethereum/lib/ethereumClientFactory.js +++ b/packages/caliper-fisco-bcos/lib/fiscoBcosWorkerFactory.js @@ -18,18 +18,18 @@ const childProcess = require('child_process'); const path = require('path'); /** - * Class used to spawn fabric client workers + * Class used to spawn FISCO BCOS workers */ -class EthereumClientFactory { +class FiscoBcosWorkerFactory { /** * Spawn the worker and perform required init * @returns {Object} the child process */ spawnWorker() { - const child = childProcess.fork(path.join(__dirname, './ethereumClientWorker.js'), process.argv.slice(2), { env: process.env}); + const child = childProcess.fork(path.join(__dirname, './fiscoBcosWorker.js'), process.argv.slice(2), { env: process.env }); return child; } } -module.exports = EthereumClientFactory; +module.exports = FiscoBcosWorkerFactory; diff --git a/packages/caliper-fisco-bcos/package.json b/packages/caliper-fisco-bcos/package.json index a08c3c23e..8dfbaf02b 100644 --- a/packages/caliper-fisco-bcos/package.json +++ b/packages/caliper-fisco-bcos/package.json @@ -25,7 +25,7 @@ "@hyperledger/caliper-core": "0.3.0-unstable", "nconf": "^0.10.0", "isarray": "^2.0.4", - "fs-extra": "^8.0.1", + "fs-extra": "8.1.0", "bn.js": "^4.11.8", "ethereumjs-util": "^6.1.0", "crypto-js": "^3.1.9-1", diff --git a/packages/caliper-generator/generator-caliper/package.json b/packages/caliper-generator/generator-caliper/package.json index 1481747a5..999ae3f08 100644 --- a/packages/caliper-generator/generator-caliper/package.json +++ b/packages/caliper-generator/generator-caliper/package.json @@ -35,7 +35,7 @@ }, "devDependencies": { "js-yaml": "^3.13.1", - "fs-extra": "^8.0.1", + "fs-extra": "8.1.0", "yeoman-assert": "^3.1.1", "yeoman-test": "^1.7.0", "mocha": "6.2.1", diff --git a/packages/caliper-iroha/index.js b/packages/caliper-iroha/index.js index 89c8c4d35..0cde25a22 100644 --- a/packages/caliper-iroha/index.js +++ b/packages/caliper-iroha/index.js @@ -15,4 +15,4 @@ 'use strict'; module.exports.AdminClient = require('./lib/iroha'); -module.exports.ClientFactory = require('./lib/irohaClientFactory'); +module.exports.WorkerFactory = require('./lib/irohaWorkerFactory'); diff --git a/packages/caliper-iroha/lib/irohaClientWorker.js b/packages/caliper-iroha/lib/irohaWorker.js similarity index 100% rename from packages/caliper-iroha/lib/irohaClientWorker.js rename to packages/caliper-iroha/lib/irohaWorker.js diff --git a/packages/caliper-iroha/lib/irohaClientFactory.js b/packages/caliper-iroha/lib/irohaWorkerFactory.js similarity index 83% rename from packages/caliper-iroha/lib/irohaClientFactory.js rename to packages/caliper-iroha/lib/irohaWorkerFactory.js index 1f469ef61..ba222ce45 100644 --- a/packages/caliper-iroha/lib/irohaClientFactory.js +++ b/packages/caliper-iroha/lib/irohaWorkerFactory.js @@ -18,18 +18,18 @@ const childProcess = require('child_process'); const path = require('path'); /** - * Class used to spawn fabric client workers + * Class used to spawn iroha workers */ -class IrohaClientFactory { +class IrohaWorkerFactory { /** * Spawn the worker and perform required init * @returns {Object} the child process */ spawnWorker() { - const child = childProcess.fork(path.join(__dirname, './irohaClientWorker.js'), process.argv.slice(2), { env: process.env}); + const child = childProcess.fork(path.join(__dirname, './irohaWorker.js'), process.argv.slice(2), { env: process.env}); return child; } } -module.exports = IrohaClientFactory; +module.exports = IrohaWorkerFactory; diff --git a/packages/caliper-publish/package.json b/packages/caliper-publish/package.json index db1c3c69b..8e44725dd 100644 --- a/packages/caliper-publish/package.json +++ b/packages/caliper-publish/package.json @@ -21,7 +21,7 @@ "npm": ">=5.6.0" }, "dependencies": { - "yargs": "14.2.0" + "yargs": "15.1.0" }, "devDependencies": { "chai": "^3.5.0", diff --git a/packages/caliper-sawtooth/index.js b/packages/caliper-sawtooth/index.js index bd6a4a1ef..e996ba21d 100644 --- a/packages/caliper-sawtooth/index.js +++ b/packages/caliper-sawtooth/index.js @@ -15,5 +15,5 @@ 'use strict'; module.exports.AdminClient = require('./lib/sawtooth'); -module.exports.ClientFactory = require('./lib/sawtoothClientFactory'); +module.exports.WorkerFactory = require('./lib/sawtoothWorkerFactory'); module.exports.BatchBuilder = require('./lib/batch/BatchBuilder'); diff --git a/packages/caliper-sawtooth/lib/sawtoothClientFactory.js b/packages/caliper-sawtooth/lib/sawtoothClientFactory.js deleted file mode 100644 index b70bc0538..000000000 --- a/packages/caliper-sawtooth/lib/sawtoothClientFactory.js +++ /dev/null @@ -1,35 +0,0 @@ -/* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -const childProcess = require('child_process'); -const path = require('path'); - -/** - * Class used to spawn fabric client workers - */ -class SawtoothClientFactory { - - /** - * Spawn the worker and perform required init - * @returns {Object} the child process - */ - spawnWorker() { - const child = childProcess.fork(path.join(__dirname, './sawtoothClientWorker.js'), process.argv.slice(2), { env: process.env}); - return child; - } -} - -module.exports = SawtoothClientFactory; diff --git a/packages/caliper-sawtooth/lib/sawtoothClientWorker.js b/packages/caliper-sawtooth/lib/sawtoothWorker.js similarity index 100% rename from packages/caliper-sawtooth/lib/sawtoothClientWorker.js rename to packages/caliper-sawtooth/lib/sawtoothWorker.js diff --git a/packages/caliper-fabric/lib/fabricClientFactory.js b/packages/caliper-sawtooth/lib/sawtoothWorkerFactory.js similarity index 82% rename from packages/caliper-fabric/lib/fabricClientFactory.js rename to packages/caliper-sawtooth/lib/sawtoothWorkerFactory.js index 893ef00c1..b7d7e21a9 100644 --- a/packages/caliper-fabric/lib/fabricClientFactory.js +++ b/packages/caliper-sawtooth/lib/sawtoothWorkerFactory.js @@ -18,18 +18,18 @@ const childProcess = require('child_process'); const path = require('path'); /** - * Class used to spawn fabric client workers + * Class used to spawn sawtooth workers */ -class FabricClientFactory { +class SawtoothWorkerFactory { /** * Spawn the worker and perform required init * @returns {Object} the child process */ spawnWorker() { - const child = childProcess.fork(path.join(__dirname, './fabricClientWorker.js'), process.argv.slice(2), { env: process.env}); + const child = childProcess.fork(path.join(__dirname, './sawtoothWorker.js'), process.argv.slice(2), { env: process.env}); return child; } } -module.exports = FabricClientFactory; +module.exports = SawtoothWorkerFactory;