forked from hyperledger-archives/composer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Runtime code for install and start (hyperledger-archives#1583)
* Runtime code for install and start Signed-off-by: Dave Kelsey <[email protected]> * comment improvements, fix system tests when not real fabric Signed-off-by: Dave Kelsey <[email protected]> * up version to 0.10.0. Correct captilisation Signed-off-by: Dave Kelsey <[email protected]> * add install/start support to all connectors in prep for playground Signed-off-by: Dave Kelsey <[email protected]> * system tests can all try install/start Signed-off-by: Dave Kelsey <[email protected]> * resolve merge conflict Signed-off-by: Dave Kelsey <[email protected]> * missed tests for connection.js Signed-off-by: Dave Kelsey <[email protected]> * added more tests as coverage has started failing on CLI Signed-off-by: Dave Kelsey <[email protected]>
- Loading branch information
Dave Kelsey
authored and
Simon Stone
committed
Jul 18, 2017
1 parent
79689df
commit 3193e1f
Showing
29 changed files
with
1,824 additions
and
60 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
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 |
---|---|---|
|
@@ -65,6 +65,8 @@ describe('AdminConnection', () => { | |
mockConnection.disconnect.resolves(); | ||
mockConnection.login.resolves(mockSecurityContext); | ||
mockConnection.deploy.resolves(); | ||
mockConnection.install.resolves(); | ||
mockConnection.start.resolves(); | ||
mockConnection.ping.resolves(); | ||
mockConnection.queryChainCode.resolves(); | ||
mockConnection.invokeChainCode.resolves(); | ||
|
@@ -200,6 +202,59 @@ describe('AdminConnection', () => { | |
}); | ||
}); | ||
|
||
describe('#install', () => { | ||
|
||
it('should be able to install a business network definition', () => { | ||
adminConnection.connection = mockConnection; | ||
adminConnection.securityContext = mockSecurityContext; | ||
let businessNetworkDefinition = new BusinessNetworkDefinition('[email protected]'); | ||
return adminConnection.install(businessNetworkDefinition) | ||
.then(() => { | ||
sinon.assert.calledOnce(mockConnection.install); | ||
sinon.assert.calledWith(mockConnection.install, mockSecurityContext, businessNetworkDefinition); | ||
}); | ||
}); | ||
|
||
it('should be able to install a business network definition with install options', () => { | ||
adminConnection.connection = mockConnection; | ||
adminConnection.securityContext = mockSecurityContext; | ||
let businessNetworkDefinition = new BusinessNetworkDefinition('[email protected]'); | ||
return adminConnection.install(businessNetworkDefinition, {opt: 1}) | ||
.then(() => { | ||
sinon.assert.calledOnce(mockConnection.install); | ||
sinon.assert.calledWith(mockConnection.install, mockSecurityContext, businessNetworkDefinition, {opt: 1}); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
describe('#start', () => { | ||
|
||
it('should be able to start a business network definition', () => { | ||
adminConnection.connection = mockConnection; | ||
adminConnection.securityContext = mockSecurityContext; | ||
let businessNetworkDefinition = new BusinessNetworkDefinition('[email protected]'); | ||
return adminConnection.start(businessNetworkDefinition) | ||
.then(() => { | ||
sinon.assert.calledOnce(mockConnection.start); | ||
sinon.assert.calledWith(mockConnection.start, mockSecurityContext, businessNetworkDefinition); | ||
}); | ||
}); | ||
|
||
it('should be able to start a business network definition with start options', () => { | ||
adminConnection.connection = mockConnection; | ||
adminConnection.securityContext = mockSecurityContext; | ||
let businessNetworkDefinition = new BusinessNetworkDefinition('[email protected]'); | ||
return adminConnection.start(businessNetworkDefinition, {opt: 1}) | ||
.then(() => { | ||
sinon.assert.calledOnce(mockConnection.start); | ||
sinon.assert.calledWith(mockConnection.start, mockSecurityContext, businessNetworkDefinition, {opt: 1}); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
|
||
describe('#deploy', () => { | ||
|
||
it('should be able to deploy a business network definition', () => { | ||
|
@@ -212,6 +267,18 @@ describe('AdminConnection', () => { | |
sinon.assert.calledWith(mockConnection.deploy, mockSecurityContext, businessNetworkDefinition); | ||
}); | ||
}); | ||
|
||
it('should be able to deploy a business network definition with deployOptions', () => { | ||
adminConnection.connection = mockConnection; | ||
adminConnection.securityContext = mockSecurityContext; | ||
let businessNetworkDefinition = new BusinessNetworkDefinition('[email protected]'); | ||
return adminConnection.deploy(businessNetworkDefinition, {opt: 1}) | ||
.then(() => { | ||
sinon.assert.calledOnce(mockConnection.deploy); | ||
sinon.assert.calledWith(mockConnection.deploy, mockSecurityContext, businessNetworkDefinition, {opt: 1}); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
describe('#undeploy', () => { | ||
|
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,124 @@ | ||
/* | ||
* 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 Admin = require('composer-admin'); | ||
const BusinessNetworkDefinition = Admin.BusinessNetworkDefinition; | ||
const cmdUtil = require('../../utils/cmdutils'); | ||
const fs = require('fs'); | ||
|
||
const ora = require('ora'); | ||
const chalk = require('chalk'); | ||
const LogLevel = require('../../network/lib/loglevel'); | ||
|
||
|
||
/** | ||
* <p> | ||
* Composer deploy command | ||
* </p> | ||
* <p><a href="diagrams/Deploy.svg"><img src="diagrams/deploy.svg" style="width:100%;"/></a></p> | ||
* @private | ||
*/ | ||
class Start { | ||
|
||
/** | ||
* Command process for deploy command | ||
* @param {string} argv argument list from composer command | ||
* @param {boolean} updateOption true if the network is to be updated | ||
* @return {Promise} promise when command complete | ||
*/ | ||
static handler(argv, updateOption) { | ||
|
||
let updateBusinessNetwork = (updateOption === true) | ||
? true | ||
: false; | ||
let businessNetworkDefinition; | ||
|
||
let adminConnection; | ||
let businessNetworkName; | ||
let spinner; | ||
let loglevel; | ||
|
||
if (argv.loglevel) { | ||
// validate log level as yargs cannot at this time | ||
// https://github.com/yargs/yargs/issues/849 | ||
loglevel = argv.loglevel.toUpperCase(); | ||
if (!LogLevel.validLogLevel(loglevel)) { | ||
return Promise.reject(new Error('loglevel unspecified or not one of (INFO|WARNING|ERROR|DEBUG)')); | ||
} | ||
} | ||
|
||
return (() => { | ||
console.log(chalk.blue.bold('Starting business network from archive: ')+argv.archiveFile); | ||
let archiveFileContents = null; | ||
// Read archive file contents | ||
archiveFileContents = Start.getArchiveFileContents(argv.archiveFile); | ||
return BusinessNetworkDefinition.fromArchive(archiveFileContents); | ||
})() | ||
.then ((result) => { | ||
businessNetworkDefinition = result; | ||
businessNetworkName = businessNetworkDefinition.getIdentifier(); | ||
console.log(chalk.blue.bold('Business network definition:')); | ||
console.log(chalk.blue('\tIdentifier: ')+businessNetworkName); | ||
console.log(chalk.blue('\tDescription: ')+businessNetworkDefinition.getDescription()); | ||
console.log(); | ||
adminConnection = cmdUtil.createAdminConnection(); | ||
return adminConnection.connect(argv.connectionProfileName, argv.startId, argv.startSecret, updateBusinessNetwork ? businessNetworkDefinition.getName() : null); | ||
}) | ||
.then((result) => { | ||
if (updateBusinessNetwork === false) { | ||
spinner = ora('Starting business network definition. This may take a minute...').start(); | ||
let startOptions = cmdUtil.parseOptions(argv); | ||
if (loglevel) { | ||
startOptions.logLevel = loglevel; | ||
} | ||
return adminConnection.start(businessNetworkDefinition, startOptions); | ||
} else { | ||
spinner = ora('Updating business network definition. This may take a few seconds...').start(); | ||
return adminConnection.update(businessNetworkDefinition); | ||
} | ||
}).then((result) => { | ||
spinner.succeed(); | ||
console.log(); | ||
|
||
return result; | ||
}).catch((error) => { | ||
|
||
if (spinner) { | ||
spinner.fail(); | ||
} | ||
|
||
console.log(); | ||
|
||
throw error; | ||
}); | ||
} | ||
|
||
/** | ||
* Get contents from archive file | ||
* @param {string} archiveFile connection profile name | ||
* @return {String} archiveFileContents archive file contents | ||
*/ | ||
static getArchiveFileContents(archiveFile) { | ||
let archiveFileContents; | ||
if (fs.existsSync(archiveFile)) { | ||
archiveFileContents = fs.readFileSync(archiveFile); | ||
} else { | ||
throw new Error('Archive file '+archiveFile+' does not exist.'); | ||
} | ||
return archiveFileContents; | ||
} | ||
} | ||
module.exports = Start; |
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,42 @@ | ||
/* | ||
* 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 Start = require ('./lib/start.js'); | ||
|
||
module.exports.command = 'start [options]'; | ||
module.exports.describe = 'Starts a business network'; | ||
module.exports.builder = { | ||
archiveFile: {alias: 'a', required: true, describe: 'The business network archive file name', type: 'string' }, | ||
connectionProfileName: {alias: 'p', optional: true, describe: 'The connection profile name', type: 'string' }, | ||
loglevel: { alias: 'l', required: false, describe: 'The initial loglevel to set (INFO|WARNING|ERROR|DEBUG)', type: 'string' }, | ||
option: { alias: 'o', required: false, describe: 'Options that are specific specific to connection. Multiple options are specified by repeating this option', type: 'string' }, | ||
optionsFile: { alias: 'O', required: false, describe: 'A file containing options that are specific to connection', type: 'string' }, | ||
startId: { alias: 'i', required: true, describe: 'The id of the user permitted to start a network', type: 'string' }, | ||
startSecret: { alias: 's', required: false, describe: 'The secret of the user permitted to start a network, if required', type: 'string' } | ||
}; | ||
|
||
module.exports.handler = (argv) => { | ||
argv.thePromise = Start.handler(argv) | ||
.then(() => { | ||
return; | ||
}) | ||
.catch((error) => { | ||
throw error; | ||
|
||
}); | ||
|
||
return argv.thePromise; | ||
}; |
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,25 @@ | ||
/* | ||
* 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'; | ||
|
||
exports.command = 'runtime <subcommand>'; | ||
exports.desc = 'Composer runtime command'; | ||
exports.builder = function (yargs) { | ||
// apply commands in subdirectories | ||
return yargs.commandDir('runtime'); | ||
}; | ||
exports.handler = function (argv) { | ||
|
||
}; |
Oops, something went wrong.