Skip to content

Commit

Permalink
FAB-8550 NodeSDK - add client metadataPath
Browse files Browse the repository at this point in the history
Add the metadataPath parameter to the Client.installChaincode()
api.

Change-Id: Id64fb6c859ed8b64f0705c489c070f1b603ce9d5
Signed-off-by: Bret Harrison <[email protected]>
  • Loading branch information
harrisob committed Feb 27, 2018
1 parent 1a37371 commit 3664921
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 26 deletions.
7 changes: 6 additions & 1 deletion fabric-client/lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,8 @@ var Client = class extends BaseClient {
* the source code of the chaincode. If the chaincode type is golang,
* then this path is the fully qualified package name, such as
* 'mycompany.com/myproject/mypackage/mychaincode'
* @property {string} metadataPath - Optional. The path to the top-level
* directory containing metadata descriptors.
* @property {string} chaincodeId - Required. Name of the chaincode
* @property {string} chaincodeVersion - Required. Version string of the
* chaincode, such as 'v1'
Expand Down Expand Up @@ -1819,8 +1821,11 @@ function readFile(path) {
function _getChaincodePackageData(request, devMode) {
return new Promise((resolve,reject) => {
if (!request.chaincodePackage) {
resolve(Packager.package(request.chaincodePath, request.chaincodeType, devMode));
logger.debug('_getChaincodePackageData - build package with chaincodepath %s, chaincodeType %s, devMode %s, metadataPath %s',
request.chaincodePath, request.chaincodeType, devMode, request.metadataPath);
resolve(Packager.package(request.chaincodePath, request.chaincodeType, devMode, request.metadataPath));
} else {
logger.debug('_getChaincodePackageData - working with included chaincodePackage');
resolve(request.chaincodePackage);
}
});
Expand Down
12 changes: 7 additions & 5 deletions fabric-client/lib/Packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ var logger = utils.getLogger('packager');
/**
* Utility function to package a chaincode. The contents will be returned as a byte array.
*
* @param {string} chaincodePath required - String of the path to location of
* @param {string} chaincodePath - required - String of the path to location of
* the source code of the chaincode
* @param {string} [chaincodeType] String of the type of chaincode
* @param {string} chaincodeType - String of the type of chaincode
* ['golang', 'node', 'car', 'java'] (default 'golang')
* @param {boolean} [devmode] Set to true to use chaincode development mode
* @param {string} [metadataPath] The path to the top-level directory containing metadata descriptors
* @param {boolean} devmode -Set to true to use chaincode development mode
* @param {string} metadataPath - Optional.
* The path to the top-level directory containing metadata descriptors
* @returns {Promise} A promise for the data as a byte array
*/
module.exports.package = function(chaincodePath, chaincodeType, devmode, metadataPath) {
logger.debug('packager: chaincodePath: %s, chaincodeType: %s, devmode: %s',chaincodePath,chaincodeType,devmode);
logger.debug('packager: chaincodePath: %s, chaincodeType: %s, devmode: %s, metadataPath: %s',
chaincodePath,chaincodeType,devmode, metadataPath);
return new Promise(function(resolve, reject) {
if (devmode) {
logger.debug('packager: Skipping chaincode packaging due to devmode configuration');
Expand Down
3 changes: 2 additions & 1 deletion test/integration/e2e/e2eUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function init() {
}
}

function installChaincode(org, chaincode_path, version, language, t, get_admin) {
function installChaincode(org, chaincode_path, metadata_path, version, language, t, get_admin) {
init();
Client.setConfigSetting('request-timeout', 60000);
var channel_name = Client.getConfigSetting('E2E_CONFIGTX_CHANNEL_NAME', testUtil.END2END.channel);
Expand Down Expand Up @@ -121,6 +121,7 @@ function installChaincode(org, chaincode_path, version, language, t, get_admin)
var request = {
targets: targets,
chaincodePath: chaincode_path,
metadataPath: metadata_path,
chaincodeId: cc_id,
chaincodeType: language,
chaincodeVersion: version
Expand Down
8 changes: 4 additions & 4 deletions test/integration/e2e/install-chaincode-fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ var testUtil = require('../../unit/util.js');
test('\n\n***** End-to-end flow: chaincode install *****\n\n', (t) => {
testUtil.setupChaincodeDeploy();

e2eUtils.installChaincode('org1', testUtil.CHAINCODE_PATH, 'v0', 'golang', t, false)
e2eUtils.installChaincode('org1', testUtil.CHAINCODE_PATH, null, 'v0', 'golang', t, false)
.then(() => {
t.fail('Successfully installed chaincode in peers of organization "org1"');
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_PATH, 'v0', 'golang', t, false);
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_PATH, null, 'v0', 'golang', t, false);
}, (err) => {
t.pass('Failed to install chaincode in peers of organization "org1". ' + err.stack ? err.stack : err);
logger.error('Failed to install chaincode in peers of organization "org1". ');
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_PATH, 'v0', 'golang', t, false);
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_PATH, null, 'v0', 'golang', t, false);
}).then(() => {
t.fail('Successfully installed chaincode in peers of organization "org2"');
t.end();
Expand All @@ -50,4 +50,4 @@ test('\n\n***** End-to-end flow: chaincode install *****\n\n', (t) => {
t.fail('Test failed due to unexpected reasons. ' + err.stack ? err.stack : err);
t.end();
});
});
});
8 changes: 4 additions & 4 deletions test/integration/e2e/install-chaincode.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ var version = 'v0';
test('\n\n***** End-to-end flow: chaincode install *****\n\n', (t) => {
testUtil.setupChaincodeDeploy();

e2eUtils.installChaincode('org1', testUtil.CHAINCODE_PATH, version, 'golang', t, true)
e2eUtils.installChaincode('org1', testUtil.CHAINCODE_PATH, testUtil.METADATA_PATH, version, 'golang', t, true)
.then(() => {
t.pass('Successfully installed chaincode in peers of organization "org1"');
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_PATH, version, 'golang', t, true);
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_PATH, testUtil.METADATA_PATH, version, 'golang', t, true);
}, (err) => {
t.fail('Failed to install chaincode in peers of organization "org1". ' + err.stack ? err.stack : err);
logger.error('Failed to install chaincode in peers of organization "org1". ');
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_PATH, version, 'golang', t, true);
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_PATH, testUtil.METADATA_PATH, version, 'golang', t, true);
}).then(() => {
t.pass('Successfully installed chaincode in peers of organization "org2"');
t.end();
Expand All @@ -52,4 +52,4 @@ test('\n\n***** End-to-end flow: chaincode install *****\n\n', (t) => {
t.fail('Test failed due to unexpected reasons. ' + err.stack ? err.stack : err);
t.end();
});
});
});
4 changes: 2 additions & 2 deletions test/integration/e2e/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ var chaincodeId = testUtil.END2END.chaincodeId;
test('\n\n***** U P G R A D E flow: chaincode install *****\n\n', (t) => {
testUtil.setupChaincodeDeploy();

e2eUtils.installChaincode('org1', testUtil.CHAINCODE_UPGRADE_PATH, 'v1', 'golang', t, true)
e2eUtils.installChaincode('org1', testUtil.CHAINCODE_UPGRADE_PATH, null, 'v1', 'golang', t, true)
.then(() => {
t.pass('Successfully installed chaincode in peers of organization "org1"');
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_UPGRADE_PATH, 'v1', 'golang', t, true);
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_UPGRADE_PATH, null, 'v1', 'golang', t, true);
}, (err) => {
t.fail('Failed to install chaincode in peers of organization "org1". ' + err.stack ? err.stack : err);
t.end();
Expand Down
4 changes: 2 additions & 2 deletions test/integration/grpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ test('\n\n*** GRPC communication tests ***\n\n', (t) => {
utils.setConfigSetting('grpc-max-send-message-length', 1024 * 1024);
// now that we have set the config setting, create a new peer so that it will
// pick up the settings which are only done when the peer is created.
e2eUtils.installChaincode('org1', testUtil.CHAINCODE_PATH, 'v2', 'golang', t, true)
e2eUtils.installChaincode('org1', testUtil.CHAINCODE_PATH, null, 'v2', 'golang', t, true)
.then(() => {
t.fail('Should have failed because the file size is too big for grpc send messages');
t.end();
Expand All @@ -88,7 +88,7 @@ test('\n\n*** GRPC communication tests ***\n\n', (t) => {
utils.setConfigSetting('grpc.max_send_message_length', 1024 * 1024 * 2);
// be sure to create a new peer to pick up the new settings

return e2eUtils.installChaincode('org1', testUtil.CHAINCODE_PATH, 'v2', 'golang', t, true);
return e2eUtils.installChaincode('org1', testUtil.CHAINCODE_PATH, null, 'v2', 'golang', t, true);
}).then(() => {
t.pass('Successfully tested setting grpc send limit');

Expand Down
6 changes: 3 additions & 3 deletions test/integration/nodechaincode/install-chaincode.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ var testUtil = require('../../unit/util.js');
var version = 'v0';

test('\n\n***** Node-Chaincode End-to-end flow: chaincode install *****\n\n', (t) => {
e2eUtils.installChaincode('org1', testUtil.NODE_CHAINCODE_PATH, version, 'node', t, true)
e2eUtils.installChaincode('org1', testUtil.NODE_CHAINCODE_PATH, testUtil.METADATA_PATH, version, 'node', t, true)
.then(() => {
t.pass('Successfully installed chaincode in peers of organization "org1"');
return e2eUtils.installChaincode('org2', testUtil.NODE_CHAINCODE_PATH, version, 'node', t, true);
return e2eUtils.installChaincode('org2', testUtil.NODE_CHAINCODE_PATH, testUtil.METADATA_PATH, version, 'node', t, true);
}, (err) => {
t.fail('Failed to install chaincode in peers of organization "org1". ' + err.stack ? err.stack : err);
logger.error('Failed to install chaincode in peers of organization "org1". ');
return e2eUtils.installChaincode('org2', testUtil.NODE_CHAINCODE_PATH, version, 'node', t, true);
return e2eUtils.installChaincode('org2', testUtil.NODE_CHAINCODE_PATH, testUtil.METADATA_PATH, version, 'node', t, true);
}).then(() => {
t.pass('Successfully installed chaincode in peers of organization "org2"');
t.end();
Expand Down
4 changes: 2 additions & 2 deletions test/integration/nodechaincode/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ var chaincodeId = testUtil.NODE_END2END.chaincodeId;
var version = 'v1';

test('\n\n***** Node-Chaincode U P G R A D E flow: chaincode install *****\n\n', (t) => {
e2eUtils.installChaincode('org1', testUtil.NODE_CHAINCODE_UPGRADE_PATH, version, 'node', t, true)
e2eUtils.installChaincode('org1', testUtil.NODE_CHAINCODE_UPGRADE_PATH, null, version, 'node', t, true)
.then(() => {
t.pass('Successfully installed chaincode in peers of organization "org1"');
return e2eUtils.installChaincode('org2', testUtil.NODE_CHAINCODE_UPGRADE_PATH, version, 'node', t, true);
return e2eUtils.installChaincode('org2', testUtil.NODE_CHAINCODE_UPGRADE_PATH, null, version, 'node', t, true);
}, (err) => {
t.fail('Failed to install chaincode in peers of organization "org1". ' + err.stack ? err.stack : err);
t.end();
Expand Down
4 changes: 2 additions & 2 deletions test/integration/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ test('\n\n **** Testing re-initializing states during upgrade ****', (t) => {
let tx_id = client.newTransactionID();
let VER = 'v3';

e2eUtils.installChaincode('org1', testUtil.CHAINCODE_UPGRADE_PATH_V2, VER, 'golang', t, true)
e2eUtils.installChaincode('org1', testUtil.CHAINCODE_UPGRADE_PATH_V2, null, VER, 'golang', t, true)
.then(() => {
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_UPGRADE_PATH_V2, VER, 'golang', t, true);
return e2eUtils.installChaincode('org2', testUtil.CHAINCODE_UPGRADE_PATH_V2, null, VER, 'golang', t, true);
}, (err) => {
t.fail('Failed to install chaincode in peers of organization "org1". ' + err.stack ? err.stack : err);
t.end();
Expand Down
2 changes: 2 additions & 0 deletions test/unit/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ var Constants = require('./constants.js');

var logger = require('fabric-client/lib/utils.js').getLogger('TestUtil');

module.exports.METADATA_PATH = path.resolve(__dirname, '../fixtures/metadata');

module.exports.CHAINCODE_PATH = 'github.com/example_cc';
module.exports.CHAINCODE_UPGRADE_PATH = 'github.com/example_cc1';
module.exports.CHAINCODE_UPGRADE_PATH_V2 = 'github.com/example_cc2';
Expand Down

0 comments on commit 3664921

Please sign in to comment.