Skip to content

Commit

Permalink
modify fabric config file for gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
nklincoln committed Jun 16, 2020
1 parent 3cbb0e7 commit 44e8458
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 79 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@
}
},
"license": "Apache-2.0"
}
}
4 changes: 2 additions & 2 deletions packages/caliper-core/lib/common/config/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ const keys = {
SkipCreateChannelPrefix: 'caliper-fabric-skipcreatechannel-',
Gateway: {
Discovery: 'caliper-fabric-gateway-discovery',
Enabled: 'caliper-fabric-gateway-enabled',
EventStrategy: 'caliper-fabric-gateway-eventstrategy',
GatewayLocalHost: 'caliper-fabric-gateway-gatewaylocalhost',
LocalHost: 'caliper-fabric-gateway-localhost',
QueryStrategy: 'caliper-fabric-gateway-querystrategy',
UseGateway: 'caliper-fabric-gateway-usegateway',
}
}
};
Expand Down
5 changes: 3 additions & 2 deletions packages/caliper-core/lib/common/config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ caliper:
countqueryasload: true
# Settings for the Fabric Gateway API
gateway:
usegateway: false
# Indicates whether to use the Fabric Gateway API
enabled: false
# Indicates whether to use the localhost default within the Fabric Gateway API
gatewaylocalhost: true
localhost: true
# Indicates whether to use the Fabric discovery mechanism (via Gateway API)
discovery: false
# Which event strategy to use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const { BlockchainInterface, CaliperUtils, TxStatus, ConfigUtil } = require('@hy
const logger = CaliperUtils.getLogger('adapters/fabric');

const FabricNetwork = require('../../fabricNetwork.js');
const ConfigValidator = require('../../configValidator.js');
const fs = require('fs');
const semver = require('semver');

Expand Down Expand Up @@ -132,26 +131,18 @@ const QueryStrategies = {
class Fabric extends BlockchainInterface {
/**
* Initializes the Fabric adapter.
* @param {string|object} networkConfig The relative or absolute file path, or the object itself of the Common Connection Profile settings.
* @param {object} networkObject The parsed network configuration.
* @param {string} workspace_root The absolute path to the root location for the application configuration files.
* @param {number} clientIndex the client index
*/
constructor(networkConfig, workspace_root, clientIndex) {
super(networkConfig);
constructor(networkObject, workspace_root, clientIndex) {
super(networkObject);
this.bcType = 'fabric';
this.workspaceRoot = workspace_root;
this.version = require('fabric-client/package').version;

this.network = undefined;
if (typeof networkConfig === 'string') {
const configPath = CaliperUtils.resolvePath(networkConfig, workspace_root);
this.network = CaliperUtils.parseYaml(configPath);
} else if (typeof networkConfig === 'object' && networkConfig !== null) {
// clone the object to prevent modification by other objects
this.network = CaliperUtils.parseYamlString(CaliperUtils.stringifyYaml(networkConfig));
} else {
throw new Error('[FabricNetwork.constructor] Parameter \'networkConfig\' is neither a file path nor an object');
}
// clone the object to prevent modification by other objects
this.network = CaliperUtils.parseYamlString(CaliperUtils.stringifyYaml(networkObject));

this.clientProfiles = new Map();
this.adminProfiles = new Map();
Expand Down Expand Up @@ -179,14 +170,11 @@ class Fabric extends BlockchainInterface {
this.configCountQueryAsLoad = ConfigUtil.get(ConfigUtil.keys.Fabric.CountQueryAsLoad, true);

// Gateway adaptor
this.configLocalHost = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.GatewayLocalHost, true);
this.configLocalHost = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.LocalHost, true);
this.configDiscovery = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.Discovery, false);
this.eventStrategy = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.EventStrategy, 'msp_all');
this.queryStrategy = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.QueryStrategy, 'msp_single');

ConfigValidator.validateNetwork(this.network, CaliperUtils.getFlowOptions(),
this.configDiscovery, true);

this.networkUtil = new FabricNetwork(this.network, workspace_root);
this.fileWalletPath = this.networkUtil.getFileWalletPath();
this.defaultInvoker = Array.from(this.networkUtil.getClients())[0];
Expand Down
22 changes: 5 additions & 17 deletions packages/caliper-fabric/lib/adaptor-versions/v1/fabric-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const {BlockchainInterface, CaliperUtils, TxStatus, Version, ConfigUtil} = requi
const logger = CaliperUtils.getLogger('adapters/fabric');

const FabricNetwork = require('../../fabricNetwork.js');
const ConfigValidator = require('../../configValidator.js');
const fs = require('fs');


Expand Down Expand Up @@ -126,26 +125,18 @@ const fs = require('fs');
class Fabric extends BlockchainInterface {
/**
* Initializes the Fabric adapter.
* @param {string|object} networkConfig The relative or absolute file path, or the object itself of the Common Connection Profile settings.
* @param {object} networkObject The parsed network configuration.
* @param {string} workspace_root The absolute path to the root location for the application configuration files.
* @param {number} clientIndex the client index
*/
constructor(networkConfig, workspace_root, clientIndex) {
super(networkConfig);
constructor(networkObject, workspace_root, clientIndex) {
super(networkObject);
this.bcType = 'fabric';
this.workspaceRoot = workspace_root;
this.version = new Version(require('fabric-client/package').version);

this.network = undefined;
if (typeof networkConfig === 'string') {
const configPath = CaliperUtils.resolvePath(networkConfig, workspace_root);
this.network = CaliperUtils.parseYaml(configPath);
} else if (typeof networkConfig === 'object' && networkConfig !== null) {
// clone the object to prevent modification by other objects
this.network = CaliperUtils.parseYamlString(CaliperUtils.stringifyYaml(networkConfig));
} else {
throw new Error('[FabricNetwork.constructor] Parameter \'networkConfig\' is neither a file path nor an object');
}
// clone the object to prevent modification by other objects
this.network = CaliperUtils.parseYamlString(CaliperUtils.stringifyYaml(networkObject));

this.clientProfiles = new Map();
this.adminProfiles = new Map();
Expand Down Expand Up @@ -174,9 +165,6 @@ class Fabric extends BlockchainInterface {
this.configClientBasedLoadBalancing = ConfigUtil.get(ConfigUtil.keys.Fabric.LoadBalancing, 'client') === 'client';
this.configCountQueryAsLoad = ConfigUtil.get(ConfigUtil.keys.Fabric.CountQueryAsLoad, true);

ConfigValidator.validateNetwork(this.network, CaliperUtils.getFlowOptions(),
this.configDiscovery, false);

this.networkUtil = new FabricNetwork(this.network, workspace_root);
this.defaultInvoker = Array.from(this.networkUtil.getClients())[0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const { DefaultEventHandlerStrategies, DefaultQueryHandlerStrategies, Gateway, W
const { BlockchainInterface, CaliperUtils, TxStatus, Version, ConfigUtil } = require('@hyperledger/caliper-core');

const FabricNetwork = require('../../fabricNetwork.js');
const ConfigValidator = require('../../configValidator.js');
const RegistrarHelper = require('./registrarHelper');

const logger = CaliperUtils.getLogger('adapters/fabric');
Expand Down Expand Up @@ -115,26 +114,18 @@ const QueryStrategies = {
class Fabric extends BlockchainInterface {
/**
* Initializes the Fabric adapter.
* @param {string|object} networkConfig The relative or absolute file path, or the object itself of the Common Connection Profile settings.
* @param {object} networkObject The parsed network configuration.
* @param {string} workspace_root The absolute path to the root location for the application configuration files.
* @param {number} clientIndex the client index
*/
constructor(networkConfig, workspace_root, clientIndex) {
super(networkConfig);
constructor(networkObject, workspace_root, clientIndex) {
super(networkObject);
this.bcType = 'fabric';
this.workspaceRoot = workspace_root;
this.version = new Version(require('fabric-network/package').version);

this.network = undefined;
if (typeof networkConfig === 'string') {
const configPath = CaliperUtils.resolvePath(networkConfig, workspace_root);
this.network = CaliperUtils.parseYaml(configPath);
} else if (typeof networkConfig === 'object' && networkConfig !== null) {
// clone the object to prevent modification by other objects
this.network = CaliperUtils.parseYamlString(CaliperUtils.stringifyYaml(networkConfig));
} else {
throw new Error('[FabricNetwork.constructor] Parameter \'networkConfig\' is neither a file path nor an object');
}
// clone the object to prevent modification by other objects
this.network = CaliperUtils.parseYamlString(CaliperUtils.stringifyYaml(networkObject));

this.clientIndex = clientIndex;
this.txIndex = -1;
Expand All @@ -152,13 +143,10 @@ class Fabric extends BlockchainInterface {
this.configCountQueryAsLoad = ConfigUtil.get(ConfigUtil.keys.Fabric.CountQueryAsLoad, true);

// Gateway adaptor
this.configLocalHost = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.GatewayLocalHost, true);
this.configLocalHost = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.LocalHost, true);
this.configDiscovery = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.Discovery, false);
this.eventStrategy = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.EventStrategy, 'msp_all');
this.queryStrategy = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.QueryStrategy, 'msp_single');

// validate the network
ConfigValidator.validateNetwork(this.network, CaliperUtils.getFlowOptions(), this.configDiscovery, true);
}

////////////////////////////////
Expand Down
22 changes: 5 additions & 17 deletions packages/caliper-fabric/lib/adaptor-versions/v2/fabric-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const {BlockchainInterface, CaliperUtils, TxStatus, Version, ConfigUtil} = requi
const logger = CaliperUtils.getLogger('adapters/fabric');

const FabricNetwork = require('../../fabricNetwork.js');
const ConfigValidator = require('../../configValidator.js');
const fs = require('fs');


Expand Down Expand Up @@ -126,26 +125,18 @@ const fs = require('fs');
class Fabric extends BlockchainInterface {
/**
* Initializes the Fabric adapter.
* @param {string|object} networkConfig The relative or absolute file path, or the object itself of the Common Connection Profile settings.
* @param {object} networkObject The parsed network configuration.
* @param {string} workspace_root The absolute path to the root location for the application configuration files.
* @param {number} clientIndex the client index
*/
constructor(networkConfig, workspace_root, clientIndex) {
super(networkConfig);
constructor(networkObject, workspace_root, clientIndex) {
super(networkObject);
this.bcType = 'fabric';
this.workspaceRoot = workspace_root;
this.version = new Version(require('fabric-client/package').version);

this.network = undefined;
if (typeof networkConfig === 'string') {
const configPath = CaliperUtils.resolvePath(networkConfig, workspace_root);
this.network = CaliperUtils.parseYaml(configPath);
} else if (typeof networkConfig === 'object' && networkConfig !== null) {
// clone the object to prevent modification by other objects
this.network = CaliperUtils.parseYamlString(CaliperUtils.stringifyYaml(networkConfig));
} else {
throw new Error('[FabricNetwork.constructor] Parameter \'networkConfig\' is neither a file path nor an object');
}
// clone the object to prevent modification by other objects
this.network = CaliperUtils.parseYamlString(CaliperUtils.stringifyYaml(networkObject));

this.clientProfiles = new Map();
this.adminProfiles = new Map();
Expand Down Expand Up @@ -174,9 +165,6 @@ class Fabric extends BlockchainInterface {
this.configClientBasedLoadBalancing = ConfigUtil.get(ConfigUtil.keys.Fabric.LoadBalancing, 'client') === 'client';
this.configCountQueryAsLoad = ConfigUtil.get(ConfigUtil.keys.Fabric.CountQueryAsLoad, true);

ConfigValidator.validateNetwork(this.network, CaliperUtils.getFlowOptions(),
this.configDiscovery, false);

this.networkUtil = new FabricNetwork(this.network, workspace_root);
this.defaultInvoker = Array.from(this.networkUtil.getClients())[0];

Expand Down
11 changes: 9 additions & 2 deletions packages/caliper-fabric/lib/fabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'use strict';

const { BlockchainInterface, CaliperUtils, ConfigUtil } = require('@hyperledger/caliper-core');
const ConfigValidator = require('./configValidator.js');
const Logger = CaliperUtils.getLogger('adapters/fabric');

const semver = require('semver');
Expand Down Expand Up @@ -42,7 +43,8 @@ const Fabric = class extends BlockchainInterface {
throw new Error(msg);
}

const useGateway = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.UseGateway, false);
const useGateway = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.Enabled, false);
const useDiscovery = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.Discovery, false);

Logger.info(`Initializing ${useGateway ? 'gateway' : 'standard' } adaptor compatible with installed SDK: ${version}`);

Expand Down Expand Up @@ -72,8 +74,13 @@ const Fabric = class extends BlockchainInterface {
const networkConfig = CaliperUtils.resolvePath(ConfigUtil.get(ConfigUtil.keys.NetworkConfig));
const workspaceRoot = path.resolve(ConfigUtil.get(ConfigUtil.keys.Workspace));

// validate the passed network file before use in underlying adaptor(s)
const configPath = CaliperUtils.resolvePath(networkConfig, workspaceRoot);
const networkObject = CaliperUtils.parseYaml(configPath);
ConfigValidator.validateNetwork(networkObject, CaliperUtils.getFlowOptions(), useDiscovery, useGateway);

const Fabric = require(modulePath);
this.fabric = new Fabric(networkConfig, workspaceRoot, workerIndex);
this.fabric = new Fabric(networkObject, workspaceRoot, workerIndex);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/caliper-tests-integration/fabric_tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ if [[ ${rc} != 0 ]]; then
fi

# PHASE 5: testing through the gateway API
${CALL_METHOD} launch master --caliper-workspace phase5 --caliper-flow-only-test --caliper-fabric-gateway-usegateway
${CALL_METHOD} launch master --caliper-workspace phase5 --caliper-flow-only-test --caliper-fabric-gateway-enabled
rc=$?
if [[ ${rc} != 0 ]]; then
echo "Failed CI step 6";
Expand All @@ -107,7 +107,7 @@ if [[ "${BIND_IN_PACKAGE_DIR}" = "true" ]]; then
fi

# PHASE 6: testing through the gateway API (v2 SDK)
${CALL_METHOD} launch master --caliper-workspace phase5 --caliper-flow-only-test --caliper-fabric-gateway-usegateway
${CALL_METHOD} launch master --caliper-workspace phase5 --caliper-flow-only-test --caliper-fabric-gateway-enabled
rc=$?
if [[ ${rc} != 0 ]]; then
echo "Failed CI step 7";
Expand Down

0 comments on commit 44e8458

Please sign in to comment.