Skip to content

Commit

Permalink
do not remove peer if there are no others to try
Browse files Browse the repository at this point in the history
  • Loading branch information
dshuffma-ibm committed Sep 28, 2017
1 parent c222be7 commit ce49ce9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ app_state*
/config/blockchain_creds_dev.json
/config/marbles_dev.json
/config/crypto/hsbn
/config/blockchain_creds_dev2.json
/config/marbles_dev2.json
4 changes: 2 additions & 2 deletions docs/install_chaincode_locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ There are several files, which is fine since our script will send the directory.

The script we will use is `install_chaincode.js` in the `scripts` folder.
It will read in our marbles config file and the blockchain creds file.
You can change the marbles chaincode ID or version by editing your creds file.
Open the config file readme below if you would like to edit these files and want more information.
You can change the marbles chaincode ID or version by editing the `install_chaincode.js` file.
Open the configuration and credential file readme below if you would like to edit these files and want more information on their contents.
If you are okay with the defaults, then simply leave these files alone and run the command below.

- [Configuration and Credential File Help](./config_file.md)
Expand Down
6 changes: 6 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ gulp.task('marbles_tls', ['env_tls', 'watch-sass', 'watch-server', 'server']);
gulp.task('marbles_local', ['env_local', 'watch-sass', 'watch-server', 'server']); //run with command `gulp marbles_local` for a local network
gulp.task('marbles_cs', ['env_cs', 'watch-sass', 'watch-server', 'server']); //run with command `gulp marbles_cs` for bluemix container service
gulp.task('marbles_dev', ['env_dev', 'watch-sass', 'watch-server', 'server']); //run with command `gulp marbles_dev` if you are me
gulp.task('marbles_dev2', ['env_dev2', 'watch-sass', 'watch-server', 'server']); //run with command `gulp marbles_dev` if you are me
gulp.task('build', ['watch-sass']);

// Bluemix IBM Blockchain Service
Expand All @@ -63,4 +64,9 @@ gulp.task('env_cs', function () {
// Dev
gulp.task('env_dev', function () {
env['creds_filename'] = 'marbles_dev.json';
});

// Dev 2
gulp.task('env_dev2', function () {
env['creds_filename'] = 'marbles_dev2.json';
});
28 changes: 16 additions & 12 deletions utils/fc_wrangler/high_availability.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,27 @@ module.exports = function (logger) {
logger.error('Missing options for switch_peer()');
return { error: 'Missing options for switch_peer()' };
}

try { //remove current peer
logger.debug('Removing peer from sdk ', options.peer_urls[ha.using_peer_position]);
obj.channel.removePeer(new Peer(options.peer_urls[ha.using_peer_position], options.peer_tls_opts));
} catch (e) {
logger.error('could not remove peer from sdk client', e);
}

ha.using_peer_position++;
if (ha.using_peer_position >= options.peer_urls.length) { //wrap around
ha.using_peer_position = 0;
let next_peer_position = ha.using_peer_position + 1;
if (next_peer_position >= options.peer_urls.length) { //wrap around
next_peer_position = 0;
}

if (ha.using_peer_position === ha.success_peer_position) { //we've tried all peers, error out
// --- Tried All Peers --- //
if (next_peer_position === ha.success_peer_position) { //we've tried all peers, error out
logger.error('Exhausted all peers. There are no more peers to try.');
return { error: 'Exhausted all peers.' };

} else {

try { //remove current peer
logger.debug('Removing peer from sdk ', options.peer_urls[ha.using_peer_position]);
obj.channel.removePeer(new Peer(options.peer_urls[ha.using_peer_position], options.peer_tls_opts));
} catch (e) {
logger.error('could not remove peer from sdk client', e);
}

// --- Use Next Peer --- //
ha.using_peer_position = next_peer_position;
const temp = {
peer_url: options.peer_urls[ha.using_peer_position],
peer_tls_opts: options.peer_tls_opts
Expand Down

0 comments on commit ce49ce9

Please sign in to comment.