1
1
# !/usr/bin/tclsh
2
2
3
3
# Copyright IBM Corp. 2016. All Rights Reserved.
4
- #
4
+ #
5
5
# Licensed under the Apache License, Version 2.0 (the "License");
6
6
# you may not use this file except in compliance with the License.
7
7
# You may obtain a copy of the License at
8
- #
8
+ #
9
9
# http://www.apache.org/licenses/LICENSE-2.0
10
- #
10
+ #
11
11
# Unless required by applicable law or agreed to in writing, software
12
12
# distributed under the License is distributed on an "AS IS" BASIS,
13
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,18 +19,18 @@ set usage {
19
19
20
20
The 'busy' script runs commands on one or more peers in a busywork network,
21
21
printing the salient portion of the response on stdout. 'busy' can be seen as
22
- an easier-to-use version of the Hyperledger fabric command-line-interface
23
- (CLI) in that 'busy' takes care of various kinds of bookkeeping and
24
- boilerplate code behind the scenes. 'busy' is probably best used as a tool for
25
- small scipts, or for issuing a few interactive commands to a peer
26
- network. Alhough complex test scripts could be implemented entirely as 'busy'
27
- calls, the performance of a test implemented this way would likely suffer from
28
- the process-creation overhead of each 'busy' invocation.
22
+ an easier-to-use, enhanced version of the Hyperledger fabric
23
+ command-line-interface (CLI) in that 'busy' takes care of various kinds of
24
+ bookkeeping and boilerplate code behind the scenes. 'busy' is probably best
25
+ used as a tool for small scipts, or for issuing a few interactive commands to
26
+ a peer network. Alhough complex test scripts could be implemented entirely as
27
+ 'busy' calls, the performance of a test implemented this way would likely
28
+ suffer from the process-creation overhead of each 'busy' invocation.
29
29
30
30
If the 'busy' command targets a single peer (see below) then the response from
31
- that peer is printed. If multiple peers are targeted, then the results are
32
- collected and printed as a JSON object, where each result is keyed by the peer
33
- name, e.g.,
31
+ or for that peer is printed. If multiple peers are targeted, then the results
32
+ are collected and printed as a JSON object, where each result is keyed by the
33
+ peer name, e.g.,
34
34
35
35
{
36
36
" vp0" : <VP0 response>,
@@ -39,8 +39,8 @@ name, e.g.,
39
39
" vp<N>" : <VP<N> response>
40
40
}
41
41
42
- Use -json to force results from operations on a single peer to print as a JSON
43
- object.
42
+ Include the -json option to force results from operations on a single peer to
43
+ print as a JSON object.
44
44
45
45
'busy' is only supported for peer networks described by a 'network' file in
46
46
the BUSYWORK_HOME directory. The <peers> to target are named by the peer IDs
@@ -76,6 +76,9 @@ The following command and argument forms are supported:
76
76
77
77
ping <peers> <user-chaincode-id>
78
78
79
+ pid <peers>
80
+ ps <peers> <List of ps display keywords>
81
+
79
82
The 'network' and 'chaincodes' commands simply print the current 'network' and
80
83
'chaincodes' files respectively from the implied $BUSYWORK_HOME .
81
84
@@ -110,6 +113,17 @@ queries fail. If the ping query succeeds then the output of the ping queries
110
113
is returned. This function currently assumes that the chaincode implments a
111
114
'ping' query function with no parameters.
112
115
116
+ The 'pid' command simply returns the PID of each of the <peers>.
117
+
118
+ The 'ps' command is used to obtain 'ps' information from one or more
119
+ peers. For each peer implied by the <peers> specification, the result returned
120
+ is the result from executing 'ps' as follows, where <pid> is the PID of each
121
+ of the <peers>:
122
+
123
+ ps -p <pid> -ww --noheader -o <List of ps display keywords>
124
+
125
+ Note that leading/trailing whitespace is removed from the result.
126
+
113
127
Examples:
114
128
115
129
busy chaincodes
@@ -124,6 +138,9 @@ Examples:
124
138
125
139
busy ping " *" cc2
126
140
141
+ busy pid vp0
142
+ busy ps vp0 etime,cputime
143
+
127
144
Optional arguments, with defaults after the colon:
128
145
129
146
-h | -help | --help : N/A
@@ -149,12 +166,12 @@ Optional arguments, with defaults after the colon:
149
166
150
167
The -waitFor option is supported for the 'deploy', 'invoke' and 'ping'
151
168
commands only. The semantics are explained below in the section headed
152
- " Semantics of -waitFor"
169
+ " Semantics of -waitFor"
153
170
154
171
-json : See below
155
172
156
173
Select -json to force even single-peer operations to print as a JSON
157
- object, rather than simply as a value. This opiton is ignored for the
174
+ object, rather than simply as a value. This option is ignored for the
158
175
'chaincodes' and 'network' commands.
159
176
160
177
@@ -191,6 +208,14 @@ proc singletonCommand {cmd} {
191
208
}
192
209
193
210
211
+ proc fixedArgs {cmd nArgs} {
212
+
213
+ if {[llength [parms args]] != $nArgs } {
214
+ errorExit " The '$cmd ' command expects $nArgs arguments."
215
+ }
216
+ }
217
+
218
+
194
219
proc chaincodes {} {
195
220
196
221
singletonCommand chaincodes
@@ -294,7 +319,7 @@ proc invoke {} {
294
319
" Deployed IDs are $a(ids) "
295
320
}
296
321
set name $a($ccId.name)
297
-
322
+
298
323
if {![null [parms waitFor]]} {
299
324
set heights \
300
325
[mapeach address [parms restAddresses] {
@@ -322,7 +347,7 @@ proc invoke {} {
322
347
}
323
348
}
324
349
325
-
350
+
326
351
proc query {} {
327
352
328
353
waitForNotOK query
@@ -344,7 +369,7 @@ proc query {} {
344
369
errorExit
345
370
}
346
371
set name $a($ccId.name)
347
-
372
+
348
373
parms results \
349
374
[mapeach address [parms restAddresses] {
350
375
return [fabric::query $address [parms user] $name $function $args ]
@@ -369,7 +394,7 @@ proc ping {} {
369
394
errorExit
370
395
}
371
396
set name $a($ccId.name)
372
-
397
+
373
398
proc _ping {name} {
374
399
set results {}
375
400
foreach address [parms restAddresses] {
@@ -395,7 +420,33 @@ proc ping {} {
395
420
}
396
421
}
397
422
398
-
423
+
424
+ proc pid {} {
425
+
426
+ waitForNotOK pid
427
+ fixedArgs pid 0
428
+
429
+ parms results [mapeach peer [parms peers] {
430
+ return [parms network.peer.$peer .pid]
431
+ }]
432
+ }
433
+
434
+
435
+ proc ps {} {
436
+
437
+ waitForNotOK ps
438
+ fixedArgs ps 1
439
+
440
+ parms results [mapeach peer [parms peers] {
441
+ set pid [parms network.peer.$peer .pid]
442
+ if {[catch {exec ps -p $pid -ww --noheader -o [parms args]} result]} {
443
+ errorExit " Exec of 'ps' failed : $result "
444
+ }
445
+ return [string trim $result ]; # Remove leading/trailing whitespace
446
+ }]
447
+ }
448
+
449
+
399
450
# ###########################################################################
400
451
# The script
401
452
# ###########################################################################
@@ -410,11 +461,11 @@ setLoggingLevel {} warn
410
461
set options {
411
462
{enum {-h -help --help} parms(help) 0 p_help}
412
463
{key -home parms(home) {}}
413
- {bool -user parms(user) {} p_user}
464
+ {key -user parms(user) {} p_user}
414
465
{key -waitFor parms(waitFor) {}}
415
466
{bool -json parms(json) 0}
416
467
}
417
-
468
+
418
469
mapKeywordArgs $argv $options parms(other)
419
470
420
471
if {$p_help } {
@@ -430,7 +481,7 @@ parms command [first [parms other]]
430
481
switch [parms command] {
431
482
chaincodes {chaincodes}
432
483
network {network}
433
- }
484
+ }
434
485
435
486
parms peers [busywork::peersFromSpec [second [parms other]]]
436
487
parms args [restn [parms other] 2]
@@ -459,6 +510,8 @@ switch [parms command] {
459
510
invoke {invoke}
460
511
query {query}
461
512
ping {ping}
513
+ pid {pid }
514
+ ps {ps}
462
515
default {errorExit " Unrecognized command: [ parms command] " }
463
516
}
464
517
@@ -489,9 +542,3 @@ if {[parms json] || [expr {[llength [parms results]] > 1}]} {
489
542
490
543
puts [first [parms results]]
491
544
}
492
-
493
-
494
-
495
-
496
-
497
-
0 commit comments