Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 7cb61fa

Browse files
authored
Merge branch 'master' into master
2 parents b46a3ac + cb809c9 commit 7cb61fa

File tree

145 files changed

+1790
-1032
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+1790
-1032
lines changed

.travis/deploy.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fi
3636

3737
# are we building the docs?
3838
if [ "${DOCS}" != "" ]; then
39-
if [ -z "${TRAVIS_TAG}" ]; then
39+
if [ -z "${TRAVIS_TAG}" ]; then
4040
DOCS="full"
4141
else
4242
DOCS="unstable"
@@ -51,8 +51,8 @@ npm config set registry https://registry.npmjs.org/
5151
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
5252

5353
# Set the GitHub deploy key we will use to publish.
54-
set-up-ssh --key "$encrypted_568b95f14ac3_key" \
55-
--iv "$encrypted_568b95f14ac3_iv" \
54+
set-up-ssh --key "$encrypted_8496d53a6fac_key" \
55+
--iv "$encrypted_8496d53a6fac_iv" \
5656
--path-encrypted-key ".travis/github_deploy_key.enc"
5757

5858
# Change from HTTPS to SSH.
@@ -103,6 +103,7 @@ if [ -z "${TRAVIS_TAG}" ]; then
103103
cf push fabric-composer-next-unstable -c "node cli.js" -i 2 -m 128M --no-start
104104
cf set-env fabric-composer-next-unstable CLIENT_ID ${GH_NEXT_UNSTABLE_OAUTH_CLIENT_ID}
105105
cf set-env fabric-composer-next-unstable CLIENT_SECRET ${GH_NEXT_UNSTABLE_OAUTH_CLIENT_SECRET}
106+
cf set-env fabric-composer-next-unstable USABILLA_ID ${USABILLA_ID}
106107
cf start fabric-composer-next-unstable
107108
popd
108109

@@ -143,12 +144,13 @@ else
143144
cf push fabric-composer-next -c "node cli.js" -i 2 -m 128M --no-start
144145
cf set-env fabric-composer-next CLIENT_ID ${GH_NEXT_OAUTH_CLIENT_ID}
145146
cf set-env fabric-composer-next CLIENT_SECRET ${GH_NEXT_OAUTH_CLIENT_SECRET}
147+
cf set-env fabric-composer-next USABILLA_ID ${USABILLA_ID}
146148
cf start fabric-composer-next
147149
popd
148150

149151
# Configure the Git repository and clean any untracked and unignored build files.
150-
git config user.name "Travis CI"
151-
git config user.email "[email protected]"
152+
git config user.name "${GH_USER_NAME}"
153+
git config user.email "${GH_USER_EMAIL}"
152154
git checkout -b master
153155
git reset --hard
154156
git clean -d -f

.travis/deploy_docs.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ set -o pipefail
88
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
99
date
1010
# Set the GitHub deploy key we will use to publish.
11-
set-up-ssh --key "$encrypted_f19708b15817_key" \
12-
--iv "$encrypted_f19708b15817_iv" \
13-
--path-encrypted-key ".travis/github_deploy_docs_key.enc"
11+
set-up-ssh --key "$encrypted_8496d53a6fac_key" \
12+
--iv "$encrypted_8496d53a6fac_iv" \
13+
--path-encrypted-key ".travis/github_deploy_key.enc"
1414

1515
# push the html documents
1616
# Configure the Git repository and clean any untracked and unignored build files.
17-
git config user.name "Travis CI"
18-
git config user.email "[email protected]"
17+
git config user.name "${GH_USER_NAME}"
18+
git config user.email "${GH_USER_EMAIL}"
1919
git config push.default simple
2020

2121
echo ${DIR}
@@ -27,15 +27,15 @@ git clone [email protected]:fabric-composer/${REPO}.git
2727
git remote set-url origin ${REPO}.git
2828

2929
cd "${DIR}/packages/composer-website/out/${REPO}"
30-
30+
3131
if [ "${DOCS}" == "full" ]; then
3232
rm -rf ${DIR}/packages/composer-website/out/${REPO}/*
33-
cp -rf ${DIR}/packages/composer-website/jekylldocs/_site/* .
33+
cp -rf ${DIR}/packages/composer-website/jekylldocs/_site/* .
3434
fi
3535

3636
mkdir -p ${DIR}/packages/composer-website/out/${REPO}/unstable
3737
rm -rf ${DIR}/packages/composer-website/out/${REPO}/unstable/*
38-
cp -rf ${DIR}/packages/composer-website/jekylldocs/_site/* ./unstable
38+
cp -rf ${DIR}/packages/composer-website/jekylldocs/_site/* ./unstable
3939

4040
git add .
4141

.travis/github_deploy_docs_key.enc

-3.17 KB
Binary file not shown.

.travis/github_deploy_key.enc

0 Bytes
Binary file not shown.
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
# Diagnostic logging
2+
Fabric-composer has a functional logger that can be used for both informational and diagnostic log messages. It also permits customization for different logging 'back-ends'.
3+
4+
## Log points
5+
Log points are added throughout the codebase, and should be very similar to other logging systems. The following APIs match to the standard log levels of *debug, verbose, info, warn, error* Note that *silly* isnt' being used.
6+
7+
```javascript
8+
debug(method, msg, data);
9+
verbose(method, msg, data);
10+
info(method, msg, data);
11+
warn(method, msg, data);
12+
error(method, msg, data);
13+
```
14+
15+
In addition there are `entry` and `exit` APIs for use to indicate the entry and exit of functions - these are logged at the *debug* level.
16+
17+
```javascript
18+
entry(method, data);
19+
entry(method, data);
20+
```
21+
22+
These methods are called on a `logger` object. To obtain one of these the following code at the top of the file should be used.
23+
24+
```javascript
25+
\\ For the businessnetworkdefinition.js file in the composer-common module
26+
const LOG = Logger.getLog('common/BusinessNetworkDefinition');
27+
```
28+
29+
## Usage within the code.
30+
31+
Taking the `businessnetworkdefinition.js` file as an example, these are some real log statements:
32+
33+
```javascript
34+
constructor(identifier, description, packageJson, readme) {
35+
const method = 'constructor';
36+
LOG.entry(method, identifier, description);
37+
38+
// ----
39+
LOG.info(method, 'Created package.json' + JSON.stringify(packageJson));
40+
// ----
41+
LOG.debug(method, 'Found model file, loading it', file.name);
42+
// ----
43+
44+
LOG.exit(method);
45+
}
46+
```
47+
48+
All the log APIs can take a variable number of data arguments for logging. Any *error* object is logged will have it's stack trace located.
49+
50+
## Enabling the logging
51+
52+
In commong with other node.js applications the `DEBUG` environment variable is used. This takes a comma separated list of the modules that need to be logged.
53+
54+
Examples
55+
56+
- `DEBUG=*` Logs everything from everything (not just Fabric-Composer)
57+
- `DEBUG=composer:*` Logs everything from just Fabric-Composer
58+
- `DEBUG=*,!composer:*` Logs everything from everything with the exception of Fabric-Composer
59+
- `DEBUG=composer:common` Logs everything from the Fabric-Composer common module (the composer-common npm module)
60+
- `DEBUG=composer:client,composer:common` Logs everything from the Fabric-Composer common module (the composer-common npm module), and the client module
61+
- `DEBUG=composer:common:businessnetworkdefinition` Logs the businessnetworkdefinition ONLY
62+
63+
## Controling the level and output
64+
65+
The structure of the Fabric-Composer log code is that it delegates the actually logging to a back-end service. This service can swapped by using configuration (see below) but by default uses the Winston library.
66+
67+
### Default configuration
68+
There are two streams setup in the default configuration - one to write log events to a file, the other to the console.
69+
70+
If log is not enabled for Fabric-Composer no events are sent to the Console but info events are sent to the file
71+
If the log is enabled then info events are sent to the console and all level of events are sent to the file.
72+
73+
The file by default is written to a directory off the current working directory called `logs` with the name `trace_<processid>.log`
74+
75+
### Configuring the default logger
76+
77+
Configuration is handled by using the config package - a config file called default.json is unless the code has specified something else.
78+
As an example - the default configuration of the logger would be represented in this file as
79+
80+
```
81+
$ cat ./config/default.json
82+
{
83+
84+
85+
86+
"fabric-composer": {
87+
"debug": {
88+
"logger": "./winstonInjector.js",
89+
"config": {
90+
'console': {
91+
'enabledLevel': 'info',
92+
'alwaysLevel': 'none'
93+
94+
},
95+
'file': {
96+
97+
'filename': 'trace_PID.log',
98+
'enabledLevel': 'silly',
99+
'alwaysLevel': 'info'
100+
}
101+
}
102+
}
103+
}
104+
105+
}
106+
```
107+
### Modyifing the Winston logger
108+
Here are two examples of how to change the back-end logger simply using Winston's changeable transport feature.
109+
110+
Two cloud hosted application log sites are *Loggly.com* and *Papertrailapp.com*
111+
112+
#### Logger class
113+
Create a new js file, eg `winstonPapertrailInjector.js`
114+
115+
```javascript
116+
'use strict';
117+
118+
const fs = require('fs-extra');
119+
const winston = require('winston');
120+
const sprintf = require('sprintf-js').sprintf;
121+
122+
//
123+
// Requiring `winston-papertrail` will expose
124+
// `winston.transports.Papertrail`
125+
//
126+
require('winston-papertrail').Papertrail;
127+
128+
/** The json structure that has been specified in the configuration
129+
* @private
130+
* @param {Object} config JSON structure with specific configuration information
131+
* @param {Array} configElements array with the DEBUG env variables for composer
132+
*
133+
* @returns {Object} object that is the logger to use
134+
*/
135+
exports.getLogger = function (config,configElements){
136+
137+
let consoleLevel;
138+
let logglyLevel;
139+
140+
if (configElements.debug.length === 0){
141+
consoleLevel='error';
142+
logglyLevel='info';
143+
} else {
144+
papertrailLevel=config.papertrail.enabledLevel;
145+
consoleLevel=config.console.enabledLevel;
146+
}
147+
148+
let formatterFn = function(options) {
149+
// Return string will be passed to logger.
150+
return sprintf('%s %-7s %-20s %s'
151+
,options.timestamp()
152+
,options.level.toUpperCase()
153+
,options.message
154+
,(JSON.stringify(options.meta,null,'') +'$')
155+
);
156+
157+
};
158+
159+
let timestampFn = function() {
160+
return new Date(Date.now()).toISOString();
161+
};
162+
163+
// this is the key part to route to Papertrail - the host and port
164+
let newWinstonLogger = {
165+
transports: [
166+
new(winston.transports.Papertrail)( {
167+
name:'papertrail',
168+
host: 'logs5.papertrailapp.com',
169+
port: '34662',
170+
timestamp: timestampFn,
171+
formatter: formatterFn ,
172+
level: papertrailLevel,
173+
json:true
174+
})
175+
176+
]
177+
};
178+
179+
winston.loggers.add('Fabric-Composer',newWinstonLogger);
180+
return winston.loggers.get('Fabric-Composer');
181+
182+
183+
};
184+
185+
```
186+
187+
and in a configuration file - where the logger is a reference to the code above.
188+
189+
```
190+
{
191+
"fabric-composer": {
192+
"debug": {
193+
"logger": "/home/matthew/github/waste-notes/winstonPapertrailInjector.js",
194+
"config": {
195+
"console": {
196+
"enabledLevel": "info",
197+
"alwaysLevel": "none"
198+
},"papertrail": {
199+
"enabledLevel": "silly",
200+
"alwaysLevel": "info"
201+
}
202+
}
203+
}
204+
}
205+
}
206+
```

packages/composer-connector-hlfv1/lib/hlfconnection.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ class HLFConnection extends Connection {
160160
// Set the user object that the client will use.
161161
LOG.debug(method, 'Persisting user context into key value store');
162162
this.user = user;
163-
this.user.mspImpl._id = 'Org1MSP';
164163
return this.client.setUserContext(user);
165164

166165
})
@@ -216,7 +215,6 @@ class HLFConnection extends Connection {
216215
let result = new HLFSecurityContext(this);
217216
result.setUser(enrollmentID);
218217
this.user = user;
219-
this.user.mspImpl._id = 'Org1MSP';
220218
LOG.exit(method, result);
221219
return result;
222220

@@ -383,8 +381,9 @@ class HLFConnection extends Connection {
383381
}
384382

385383
proposalResponses.forEach((proposalResponse) => {
386-
if (proposalResponse.error) {
387-
throw proposalResponse.error;
384+
if (proposalResponse instanceof Error) {
385+
console.log('throwing proposal response');
386+
throw proposalResponse;
388387
} else if (proposalResponse.response.status === 200) {
389388
return true;
390389
}
@@ -552,6 +551,10 @@ class HLFConnection extends Connection {
552551
throw new Error('No payloads were returned from the query request:' + functionName);
553552
}
554553
const payload = payloads[0];
554+
if (payload instanceof Error) {
555+
// will be handled by the catch block
556+
throw payload;
557+
}
555558
LOG.exit(payload);
556559
return payload;
557560
})

packages/composer-connector-hlfv1/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"dependencies": {
4343
"composer-common": "^0.5.2",
4444
"composer-runtime-hlfv1": "^0.5.2",
45-
"fabric-client": "^0.2.1",
46-
"fabric-ca-client": "^0.2.1",
45+
"fabric-client": "0.2.3",
46+
"fabric-ca-client": "0.2.3",
4747
"fs-extra": "^1.0.0",
4848
"semver": "^5.3.0",
4949
"temp": "^0.8.3",

packages/composer-connector-hlfv1/test/hlfconnection.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ describe('HLFConnection', () => {
5454
mockCAClient = sinon.createStubInstance(FabricCAClientImpl);
5555
mockUser = sinon.createStubInstance(User);
5656

57-
// TODO: Temp code to address patch due to node-sdk not having fix yet
58-
mockUser.mspImpl = {};
59-
mockUser.mspImpl._id = '';
60-
6157
mockSecurityContext = sinon.createStubInstance(HLFSecurityContext);
6258
mockBusinessNetwork = sinon.createStubInstance(BusinessNetworkDefinition);
6359
mockBusinessNetwork.getName.returns('org.acme.biznet');
@@ -390,7 +386,7 @@ describe('HLFConnection', () => {
390386
// This is the generated nonce.
391387
sandbox.stub(utils, 'getNonce').returns('11111111-1111-1111-1111-111111111111');
392388
// This is the deployment proposal and response (from the peers).
393-
const proposalResponses = [ {'error': new Error('such error')} ];
389+
const proposalResponses = [ new Error('such error') ];
394390
const proposal = { proposal: 'i do' };
395391
const header = { header: 'gooooal' };
396392
// This is the generated transaction
@@ -729,6 +725,22 @@ describe('HLFConnection', () => {
729725
.should.be.rejectedWith(/No payloads were returned from the query request/);
730726
});
731727

728+
it('should throw any responses that are errors', () => {
729+
// This is the generated nonce.
730+
sandbox.stub(utils, 'getNonce').returns('11111111-1111-1111-1111-111111111111');
731+
// This is the generated transaction
732+
mockChain.buildTransactionID.returns('00000000-0000-0000-0000-000000000000');
733+
// mock out getUserContext version in case we need to return to using this one
734+
mockChain.buildTransactionID_getUserContext.resolves('00000000-0000-0000-0000-000000000000');
735+
// This is the transaction proposal and response (from the peers).
736+
const response = [ new Error('such error') ];
737+
// This is the response from the chaincode.
738+
mockChain.queryByChaincode.resolves(response);
739+
return connection.queryChainCode(mockSecurityContext, 'myfunc', ['arg1', 'arg2'])
740+
.should.be.rejectedWith(/such error/);
741+
742+
});
743+
732744
});
733745

734746
describe('#invokeChainCode', () => {
@@ -821,7 +833,7 @@ describe('HLFConnection', () => {
821833
// mock out getUserContext version in case we need to return to using this one
822834
mockChain.buildTransactionID_getUserContext.resolves('00000000-0000-0000-0000-000000000000');
823835
// This is the transaction proposal and response (from the peers).
824-
const proposalResponses = [ {'error': new Error('such error')} ];
836+
const proposalResponses = [ new Error('such error') ];
825837
const proposal = { proposal: 'i do' };
826838
const header = { header: 'gooooal' };
827839
mockChain.sendTransactionProposal.resolves([ proposalResponses, proposal, header ]);

0 commit comments

Comments
 (0)