-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #734 from nklincoln/spawn-client-cli
Provide cli command to spawn a distributed worker
- Loading branch information
Showing
36 changed files
with
287 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <subcommand>'; | ||
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'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.