IBM-Blockchain-Archive / ibm-container-service

IBM Blockchain Platform for Developers on IBM Container Service
Apache License 2.0
89 stars 73 forks source link

monitoring chain events in the kube cluster #78

Closed rddill-IBM closed 6 years ago

rddill-IBM commented 6 years ago

I have a routine on my nodejs server which monitors blockchain events and displays selected information when chain events occur. The code for this routine follows. This code does not work in the kube cluster and I expect that the reason is that the pem file used for admin in the original docker container is no longer valid. Is there are recommended way for me to now connect to hyperledger fabric to monitor events similar to the code below? This is part of a demonstration environment and the blockchain event data is used to display what's happening during the demo.

Appreciate any insight into resolving this.

exports.getChainEvents = function(req, res, next)
{
    if (chainEvents) {res.send({'port': svc.cs_socketAddr});}
    else
    {
        let channel = {};
        let client = null;
        let wallet_path = path.join(__dirname, 'creds');
        Promise.resolve().then(() => {
            client = new hfc();
            return hfc.newDefaultKeyValueStore({ path: wallet_path })
            .then((wallet) => {
                client.setStateStore(wallet);
                return client.getUserContext(config.composer.PeerAdmin, true);})
                .then((user) => {
                    if (user === null || user === undefined || user.isEnrolled() === false)
                    {console.error('User not defined, or not enrolled - error');}
                    channel = client.newChannel(config.fabric.channelName);
                    channel.addPeer(client.newPeer(config.fabric.peerRequestURL));
                    channel.addOrderer(client.newOrderer(config.fabric.ordererURL));
                    // change Admin in following line to admin
                    let pemPath = path.join(__dirname,'creds','admin@org.hyperledger.composer.system-cert.pem');
                    let adminPEM = fs.readFileSync(pemPath);
                    let bcEvents = new hfcEH(client);
                    bcEvents.setPeerAddr(config.fabric.peerEventURL, {pem: adminPEM});
                    bcEvents.connect();
                    svc.createChainSocket();
                    bcEvents.registerBlockEvent(function(event) {svc.cs_connection.sendUTF(JSON.stringify(event));});
                    chainEvents = true;
                    res.send({'port': svc.cs_socketAddr});
                });
        });
    }
};
rddill-IBM commented 6 years ago

The root cause of the problem for this issue turns out to be a combination of (1) Configuration changes between the Docker deploy and the Kubernetes deploy. the changes are: