How to use the @hyperledger/caliper-core.CaliperUtils.parseYaml function in @hyperledger/caliper-core

To help you get started, we’ve selected a few @hyperledger/caliper-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hyperledger / caliper / packages / caliper-fabric / lib / fabricNetwork.js View on Github external
constructor(networkConfig, workspace_root) {
        CaliperUtils.assertDefined(networkConfig, '[FabricNetwork.constructor] Parameter \'networkConfig\' if undefined or null');

        this.network = undefined;
        if (typeof networkConfig === 'string') {
            let 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');
        }

        this.clientConfigs = {};
        this.compatibilityMode = false; // if event URLs are detected for the peers, we're using Fabric 1.0
        this.tls = false;
        this.mutualTls = false;
        this.contractMapping = new Map();
        this._processConfiguration(workspace_root);
    }
github hyperledger / caliper / packages / caliper-cli / lib / zooclient / lib / startZooClient.js View on Github external
static async handler(argv) {
        let blockchainConfigFile = ConfigUtil.get(ConfigUtil.keys.NetworkConfig, undefined);
        let workspace = ConfigUtil.get(ConfigUtil.keys.Workspace, './');

        // Workspace is expected to be the root location of working folders
        workspace = path.resolve(workspace);
        blockchainConfigFile = path.isAbsolute(blockchainConfigFile) ? blockchainConfigFile : path.join(workspace, blockchainConfigFile);

        if(!blockchainConfigFile || !fs.existsSync(blockchainConfigFile)) {
            throw(new Error(`Network configuration file "${blockchainConfigFile || 'UNSET'}" does not exist`));
        }

        let blockchainType = '';
        let networkObject = CaliperUtils.parseYaml(blockchainConfigFile);
        if (networkObject.hasOwnProperty('caliper') && networkObject.caliper.hasOwnProperty('blockchain')) {
            blockchainType = networkObject.caliper.blockchain;
        } else {
            throw new Error('The configuration file [' + blockchainConfigFile + '] is missing its "caliper.blockchain" attribute');
        }

        try {
            cmdUtil.log(chalk.blue.bold('Starting zookeeper client of type ' + blockchainType));
            const {ClientFactory} = require('@hyperledger/caliper-' + blockchainType);
            const clientFactory = new ClientFactory(blockchainConfigFile, workspace);

            const zooClient = new CaliperZooClient(ConfigUtil.get(ConfigUtil.keys.ZooAddress, undefined), clientFactory, workspace);
            zooClient.start();
        } catch (err) {
            throw err;
        }
github hyperledger / caliper / packages / caliper-fabric / lib / fabric.js View on Github external
constructor(networkConfig, workspace_root) {
        super(networkConfig);
        this.bcType = 'fabric';
        this.workspaceRoot = workspace_root;
        this.version = new Version(require('fabric-client/package').version);

        this.network = undefined;
        if (typeof networkConfig === 'string') {
            let 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');
        }

        this.clientProfiles = new Map();
        this.adminProfiles = new Map();
        this.registrarProfiles = new Map();
        this.eventSources = [];
        this.clientIndex = 0;
        this.txIndex = -1;
        this.randomTargetPeerCache = new Map();
        this.channelEventSourcesCache = new Map();
        this.randomTargetOrdererCache = new Map();
github hyperledger / caliper / packages / caliper-fisco-bcos / lib / fiscoBcos.js View on Github external
async installSmartContract() {
        const fiscoBcosSettings = CaliperUtils.parseYaml(this.configPath)['fisco-bcos'];
        try {
            await installSmartContractImpl.run(fiscoBcosSettings, this.workspaceRoot);
        } catch (error) {
            commLogger.error(Color.error(`FISCO BCOS smart contract install failed: ${(error.stack ? error.stack : error)}`));
            throw error;
        }
    }
github hyperledger / caliper / packages / caliper-fisco-bcos / lib / fiscoBcos.js View on Github external
constructor(config_path, workspace_root) {
        super(config_path);
        this.bcType = 'fisco-bcos';
        this.workspaceRoot = workspace_root;
        this.fiscoBcosSettings = CaliperUtils.parseYaml(this.configPath)['fisco-bcos'];
    }
github hyperledger / caliper / packages / caliper-cli / lib / bind / bind.js View on Github external
static async handler(argv) {
        let sut = ConfigUtil.get(ConfigUtil.keys.Bind.Sut, undefined);
        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 bindOptions = CaliperUtils.parseYaml(path.join(__dirname, './config.yaml'));

        let sutList = Object.keys(bindOptions.sut);
        if (!sut) {
            let msg = `SUT name is not specified. Available SUTs: ${sutList.join(' | ')}`;
            logger.error(msg);
            throw new Error(msg);
        }

        if (!sutList.includes(sut)) {
            let msg = `Unknown SUT name "${sut}". Available SUTs: ${sutList.join(' | ')}`;
            logger.error(msg);
            throw new Error(msg);
        }

        let sutSdkList = Object.keys(bindOptions.sut[sut]);
        if (!sdk) {
github hyperledger / caliper / packages / caliper-cli / lib / benchmark / lib / runBenchmark.js View on Github external
networkConfigPath = CaliperUtils.resolvePath(networkConfigPath, workspacePath);

        if(!benchmarkConfigPath || !fs.existsSync(benchmarkConfigPath)) {
            let msg = `Benchmark configuration file "${benchmarkConfigPath || 'UNSET'}" does not exist`;
            logger.error(msg);
            throw new Error(msg);
        }

        if(!networkConfigPath || !fs.existsSync(networkConfigPath)) {
            let msg = `Network configuration file "${networkConfigPath || 'UNSET'}" does not exist`;
            logger.error(msg);
            throw new Error(msg);
        }

        let benchmarkConfig = CaliperUtils.parseYaml(benchmarkConfigPath);
        let networkConfig = CaliperUtils.parseYaml(networkConfigPath);

        let blockchainType = '';
        if (networkConfig.caliper && networkConfig.caliper.blockchain) {
            blockchainType = networkConfig.caliper.blockchain;
        } else {
            let msg = `Network configuration file "${networkConfigPath}" is missing its "caliper.blockchain" attribute`;
            logger.error(msg);
            throw new Error(msg);
        }

        let knownError = false;

        try {
            logger.info(`Set workspace path: ${workspacePath}`);
            logger.info(`Set benchmark configuration path: ${benchmarkConfigPath}`);
            logger.info(`Set network configuration path: ${networkConfigPath}`);
github hyperledger / caliper / packages / caliper-cli / lib / benchmark / lib / runBenchmark.js View on Github external
benchmarkConfigPath = CaliperUtils.resolvePath(benchmarkConfigPath, workspacePath);
        networkConfigPath = CaliperUtils.resolvePath(networkConfigPath, workspacePath);

        if(!benchmarkConfigPath || !fs.existsSync(benchmarkConfigPath)) {
            let msg = `Benchmark configuration file "${benchmarkConfigPath || 'UNSET'}" does not exist`;
            logger.error(msg);
            throw new Error(msg);
        }

        if(!networkConfigPath || !fs.existsSync(networkConfigPath)) {
            let msg = `Network configuration file "${networkConfigPath || 'UNSET'}" does not exist`;
            logger.error(msg);
            throw new Error(msg);
        }

        let benchmarkConfig = CaliperUtils.parseYaml(benchmarkConfigPath);
        let networkConfig = CaliperUtils.parseYaml(networkConfigPath);

        let blockchainType = '';
        if (networkConfig.caliper && networkConfig.caliper.blockchain) {
            blockchainType = networkConfig.caliper.blockchain;
        } else {
            let msg = `Network configuration file "${networkConfigPath}" is missing its "caliper.blockchain" attribute`;
            logger.error(msg);
            throw new Error(msg);
        }

        let knownError = false;

        try {
            logger.info(`Set workspace path: ${workspacePath}`);
            logger.info(`Set benchmark configuration path: ${benchmarkConfigPath}`);