-
Notifications
You must be signed in to change notification settings - Fork 10
/
gen_network.sh
executable file
·253 lines (213 loc) · 6.54 KB
/
gen_network.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
#
# usage: ./gen_network.sh [opt] [value]
#
function printHelp {
echo "Usage: "
echo " ./gen_network.sh [opt] [value] "
echo " network variables"
echo " -a: action [create|add], default=create"
echo " -p: number of peers per organization, default=1"
echo " -o: number of orderers, default=1"
echo " -k: number of brokers, default=0"
echo " -z: number of zookeeper, default=0"
echo " -r: number of organiztions, default=1"
echo " -S: TLS enablement [enabled|disabled], default=disabled "
echo " -x: number of ca, default=0"
echo " -F: local MSP base directory, default=$GOPATH/src/github.com/hyperledger/fabric-test/fabric/common/tools/cryptogen/crypto-config"
echo " -G: src MSP base directory, default=/opt/hyperledger/fabric/msp/crypto-config"
echo " -C: company name, default=example.com"
echo " "
echo " peer environment variables"
echo " -l: core logging level [(default = not set)|CRITICAL|ERROR|WARNING|NOTICE|INFO|DEBUG]"
echo " -d: core ledger state DB [goleveldb|couchdb], default=goleveldb"
echo " "
echo " orderer environment variables"
echo " -t: orderer type [solo|kafka] "
echo " "
echo "Example:"
echo " ./gen_network.sh -a create -x 2 -p 2 -r 2 -o 1 -k 1 -z 1 -t kafka -d goleveldb -F /root/gopath/src/github.com/hyperledger/fabric-test/fabric/common/tools/cryptogen/crypto-config -G /opt/hyperledger/fabric/msp/crypto-config "
echo " ./gen_network.sh -a create -x 2 -p 2 -r 2 -o 1 -k 1 -z 1 -t kafka -d goleveldb -F /root/gopath/src/github.com/hyperledger/fabric-test/fabric/common/tools/cryptogen/crypto-config -G /opt/hyperledger/fabric/msp/crypto-config -S enabled "
echo " "
exit
}
#init var
Req="create"
nBroker=0
nZoo=0
nPeerPerOrg=1
nOrg=1
nOrderer=1
nCA=0
MSPDIR="$GOPATH/src/github.com/hyperledger/fabric-test/fabric/common/tools/cryptogen/crypto-config"
SRCMSPDIR="/opt/hyperledger/fabric/msp/crypto-config"
TLSEnabled="disabled"
db="goleveldb"
comName="example.com"
while getopts ":x:z:l:d:t:a:o:k:p:r:F:G:S:C:" opt; do
case $opt in
# peer environment options
S)
TLSEnabled=$OPTARG
export TLSEnabled=$TLSEnabled
echo "TLSEnabled: $TLSEnabled"
;;
x)
nCA=$OPTARG
echo "number of CA: $nCA"
;;
l)
CORE_LOGGING_LEVEL=$OPTARG
export CORE_LOGGING_LEVEL=$CORE_LOGGING_LEVEL
echo "CORE_LOGGING_LEVEL: $CORE_LOGGING_LEVEL"
;;
d)
db=$OPTARG
echo "ledger state database type: $db"
;;
# orderer environment options
F)
MSPDIR=$OPTARG
export MSPDIR=$MSPDIR
echo "MSPDIR: $MSPDIR"
;;
G)
SRCMSPDIR=$OPTARG
export SRCMSPDIR=$SRCMSPDIR
echo "SRCMSPDIR: $SRCMSPDIR"
;;
t)
CONFIGTX_ORDERER_ORDERERTYPE=$OPTARG
export CONFIGTX_ORDERER_ORDERERTYPE=$CONFIGTX_ORDERER_ORDERERTYPE
echo "CONFIGTX_ORDERER_ORDERERTYPE: $CONFIGTX_ORDERER_ORDERERTYPE"
if [ $nBroker == 0 ] && [ $CONFIGTX_ORDERER_ORDERERTYPE == 'kafka' ]; then
nBroker=1 # must have at least 1
fi
;;
# network options
a)
Req=$OPTARG
echo "action: $Req"
;;
k)
nBroker=$OPTARG
echo "# of Broker: $nBroker"
;;
z)
nZoo=$OPTARG
echo "number of zookeeper: $Zoo"
;;
p)
nPeerPerOrg=$OPTARG
echo "# of peer per org: $nPeerPerOrg"
;;
r)
nOrg=$OPTARG
echo "# of nOrg: $nOrg"
;;
o)
nOrderer=$OPTARG
echo "# of orderer: $nOrderer"
;;
C)
comName=$OPTARG
export comName=$comName
echo "comName: $comName"
;;
# else
\?)
echo "Invalid option: -$OPTARG" >&2
printHelp
;;
:)
echo "Option -$OPTARG requires an argument." >&2
printHelp
;;
esac
done
if [ $nBroker -gt 0 ] && [ $CONFIGTX_ORDERER_ORDERERTYPE == 'solo' ]; then
echo "reset Broker number to 0 due to the CONFIGTX_ORDERER_ORDERERTYPE=$CONFIGTX_ORDERER_ORDERERTYPE"
nBroker=0
fi
#OS
##OSName=`uname`
##echo "Operating System: $OSName"
# get current dir for CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE
CWD=${PWD##*/}
HOSTCONFIG_NETWORKMODE=$(echo $CWD | awk '{print tolower($CWD)}')
export HOSTCONFIG_NETWORKMODE=$HOSTCONFIG_NETWORKMODE
echo "HOSTCONFIG_NETWORKMODE: $HOSTCONFIG_NETWORKMODE"
dbType=`echo "$db" | awk '{print tolower($0)}'`
echo "action=$Req nPeerPerOrg=$nPeerPerOrg nBroker=$nBroker nOrderer=$nOrderer dbType=$dbType"
VP=`docker ps -a | grep 'peer node start' | wc -l`
echo "existing peers: $VP"
echo "remove old docker-composer.yml"
rm -f docker-compose.yml
#echo "docker pull https://hub.docker.com/r/rameshthoomu/fabric-ccenv-x86_64:x86_64-0.7.0-snapshot-b291705"
#docker pull rameshthoomu/fabric-ccenv-x86_64
# form json input file
if [ $nBroker == 0 ]; then
#jsonFILE="network_solo.json"
jsonFILE="network.json"
else
# jsonFILE="network_kafka.json"
jsonFILE="network.json"
fi
echo "jsonFILE $jsonFILE"
# create docker compose yml
if [ $Req == "add" ]; then
N1=$[ nPeerPerOrg * nOrg + VP]
N=$[N1]
VPN="peer"$[N-1]
else
N1=$[ nPeerPerOrg * nOrg ]
N=$[N1 - 1]
VPN="peer"$N
fi
## echo "N1=$N1 VP=$VP nPeerPerOrg=$nPeerPerOrg VPN=$VPN"
echo "node json2yml.js $jsonFILE $nPeerPerOrg $nOrderer $nBroker $nZoo $nOrg $dbType $nCA"
node json2yml.js $jsonFILE $nPeerPerOrg $nOrderer $nBroker $nZoo $nOrg $dbType $nCA
#fix CA _sk in docker-compose.yml
CWD=$PWD
echo $CWD
echo "GOPATH: $GOPATH"
OS=`uname -s`
myOS=$(echo $OS | awk '{print tolower($OS)}')
if [ $myOS == 'darwin' ]; then
sedOpt="-it"
else
sedOpt="-i"
fi
echo "OS: $OS, sedOpt: $sedOpt"
for (( i=0; i<$nCA; i++ ))
do
j=$[ i + 1 ]
Dir=$MSPDIR/peerOrganizations/org$j"."$comName"/ca"
cd $Dir
tt=`ls *sk`
cd $CWD
sed $sedOpt "s/CA_SK$i/$tt/g" docker-compose.yml
done
## sed 's/-x86_64/TEST/g' docker-compose.yml > ss.yml
## cp ss.yml docker-compose.yml
# create network
if [ $Req == "create" ]; then
#docker-compose -f docker-compose.yml up -d --force-recreate cli $VPN
docker-compose -f docker-compose.yml up -d --force-recreate
#docker-compose -f docker-compose.yml up -d --force-recreate $VPN
##docker-compose -f docker-compose.yml up -d --force-recreate $VPN
#for ((i=1; i<$nOrderer; i++))
#do
#tmpOrd="orderer"$i
#docker-compose -f docker-compose.yml up -d $tmpOrd
#done
fi
if [ $Req == "add" ]; then
docker-compose -f docker-compose.yml up -d $VPN
fi
exit