diff --git a/gen.py b/gen.py index 65a2f17..bba8e45 100644 --- a/gen.py +++ b/gen.py @@ -16,6 +16,7 @@ def jumptab(number, number1): #Part of configtx.yaml def createChannelProfile(orgName, profileName): rslt = jumptab(0, 1) + profileName + ":" + rslt += jumptab(1, 2) + "<<: *ChannelDefaults" rslt += jumptab(1, 2) + "Consortium: ComposerConsortium" rslt += jumptab(1, 2) + "Application:" rslt += jumptab(1, 3) + "<<: *ApplicationDefaults" @@ -49,9 +50,30 @@ def createOrganisations(name, opt, host): if (opt == 1): rslt = rslt + jumptab(2, 3) + "ID: " + name + "MSP" rslt = rslt + jumptab(2, 3) + "MSPDir: crypto-config/peerOrganizations/" + name + "." + host + ".com/msp" + rslt = rslt + jumptab(2, 3) + "Policies:" + rslt = rslt + jumptab(1, 4) + "Readers:" + rslt = rslt + jumptab(1, 5) + "Type: Signature" + rslt = rslt + jumptab(1, 5) + "Rule: \"OR('"+ name +"MSP.admin', '"+ name +"MSP.peer', '"+ name +"MSP.client', '"+ name +"MSP.member')\"" + rslt = rslt + jumptab(1, 4) + "Writers:" + rslt = rslt + jumptab(1, 5) + "Type: Signature" + rslt = rslt + jumptab(1, 5) + "Rule: \"OR('"+ name +"MSP.admin', '"+ name +"MSP.client', '"+ name +"MSP.member')\"" + rslt = rslt + jumptab(1, 4) + "Admins:" + rslt = rslt + jumptab(1, 5) + "Type: Signature" + rslt = rslt + jumptab(1, 5) + "Rule: \"OR('"+ name +"MSP.admin', '"+ name +"MSP.member')\"" else: rslt = rslt + jumptab(2, 3) + "ID: OrdererMSP" rslt = rslt + jumptab(2, 3) + "MSPDir: crypto-config/ordererOrganizations/" + host + ".com/msp" + rslt = rslt + jumptab(2, 3) + "Policies:" + rslt = rslt + jumptab(1, 4) + "Readers:" + rslt = rslt + jumptab(1, 5) + "Type: Signature" + rslt = rslt + jumptab(1, 5) + "Rule: \"OR('OrdererMSP.member')\"" + rslt = rslt + jumptab(1, 4) + "Writers:" + rslt = rslt + jumptab(1, 5) + "Type: Signature" + rslt = rslt + jumptab(1, 5) + "Rule: \"OR('OrdererMSP.member')\"" + rslt = rslt + jumptab(1, 4) + "Admins:" + rslt = rslt + jumptab(1, 5) + "Type: Signature" + rslt = rslt + jumptab(1, 5) + "Rule: \"OR('OrdererMSP.admin')\"" + rslt = rslt + jumptab(2, 3) + "AdminPrincipal: Role.MEMBER" if (opt == 1): rslt = rslt + jumptab(2, 3) + "AnchorPeers:" @@ -77,6 +99,21 @@ def createOrderer(typeorderer, messageCount, absoluteMaxBytes, preferredMaxBytes rslt += jumptab(1, 3) + "- kafka2:9092" rslt += jumptab(1, 3) + "- kafka3:9092" rslt += jumptab(2, 1) + "Organizations:" + rslt = rslt + jumptab(2, 1) + "Policies:" + rslt = rslt + jumptab(1, 2) + "Readers:" + rslt = rslt + jumptab(1, 3) + "Type: ImplicitMeta" + rslt = rslt + jumptab(1, 3) + "Rule: \"ANY Readers\"" + rslt = rslt + jumptab(1, 2) + "Writers:" + rslt = rslt + jumptab(1, 3) + "Type: ImplicitMeta" + rslt = rslt + jumptab(1, 3) + "Rule: \"ANY Writers\"" + rslt = rslt + jumptab(1, 2) + "Admins:" + rslt = rslt + jumptab(1, 3) + "Type: ImplicitMeta" + rslt = rslt + jumptab(1, 3) + "Rule: \"MAJORITY Admins\"" + rslt = rslt + jumptab(1, 2) + "BlockValidation:" + rslt = rslt + jumptab(1, 3) + "Type: ImplicitMeta" + rslt = rslt + jumptab(1, 3) + "Rule: \"ANY Writers\"" + rslt = rslt + jumptab(2, 1) + "Capabilities:" + rslt = rslt + jumptab(1, 2) + "<<: *OrdererCapabilities" return (rslt) #Part of configtx.yaml @@ -112,13 +149,56 @@ def ordererOrgConfig(host): rslt += jumptab(1, 3) + "- Hostname: orderer" return (rslt) +#Part of configtx.yaml +def createCapabilities(): + rslt = jumptab(2,0) +"Capabilities:" + rslt += jumptab(1,1) + "Channel: &ChannelCapabilities" + rslt += jumptab(1,2) + "V1_3: true" + rslt += jumptab(1,1) + "Orderer: &OrdererCapabilities" + rslt += jumptab(1,2) + "V1_1: true" + rslt += jumptab(1,1) + "Application: &ApplicationCapabilities" + rslt += jumptab(1,2) + "V1_3: true" + rslt += jumptab(1,2) + "V1_2: false" + rslt += jumptab(1,2) + "V1_1: false" + return (rslt) + +def createChannelDefaults(): + rslt = jumptab(2,0) +"Channel: &ChannelDefaults" + rslt = rslt + jumptab(1, 1) + "Policies:" + rslt = rslt + jumptab(1, 2) + "Readers:" + rslt = rslt + jumptab(1, 3) + "Type: ImplicitMeta" + rslt = rslt + jumptab(1, 3) + "Rule: \"ANY Readers\"" + rslt = rslt + jumptab(1, 2) + "Writers:" + rslt = rslt + jumptab(1, 3) + "Type: ImplicitMeta" + rslt = rslt + jumptab(1, 3) + "Rule: \"ANY Writers\"" + rslt = rslt + jumptab(1, 2) + "Admins:" + rslt = rslt + jumptab(1, 3) + "Type: ImplicitMeta" + rslt = rslt + jumptab(1, 3) + "Rule: \"MAJORITY Admins\"" + rslt = rslt + jumptab(1, 1) + "Capabilities:" + rslt = rslt + jumptab(1, 2) + "<<: *ChannelCapabilities" + return (rslt) + #Call functions in order to create configtx.yaml def createConfigtx(tabName): buffer = "Organizations:" buffer += setOrg(tabName) + buffer += createCapabilities() buffer += createOrderer("kafka", "10", "98 MB", "512 KB", tabName[0]) + buffer += createChannelDefaults() buffer += jumptab(2, 0) + "Application: &ApplicationDefaults" - buffer += jumptab(2, 1) + "Organizations:" + buffer += jumptab(1, 1) + "Organizations:" + buffer += jumptab(1, 1) + "Capabilities:" + buffer += jumptab(1, 2) + "<<: *ApplicationCapabilities" + buffer = buffer + jumptab(2, 1) + "Policies:" + buffer = buffer + jumptab(1, 2) + "Readers:" + buffer = buffer + jumptab(1, 3) + "Type: ImplicitMeta" + buffer = buffer + jumptab(1, 3) + "Rule: \"ANY Readers\"" + buffer = buffer + jumptab(1, 2) + "Writers:" + buffer = buffer + jumptab(1, 3) + "Type: ImplicitMeta" + buffer = buffer + jumptab(1, 3) + "Rule: \"ANY Writers\"" + buffer = buffer + jumptab(1, 2) + "Admins:" + buffer = buffer + jumptab(1, 3) + "Type: ImplicitMeta" + buffer = buffer + jumptab(1, 3) + "Rule: \"MAJORITY Admins\"" buffer += jumptab(2, 0) + "Profiles:" buffer += jumptab(2, 0) + createProfiles(tabName, "ProfileTest", "OrdererOrg") buffer += jumptab(2, 0) + createChannelProfile(tabName, "ChannelTest") @@ -167,7 +247,7 @@ def sameName(tab, name): #Docker-compose.yaml header def headerDockerFile(network): - rslt = "version: '2'" + rslt = "version: '3.4'" rslt += jumptab(2,0) + "networks:" rslt += jumptab(1, 1) + network + ":" rslt += jumptab(2, 0) + "services:" @@ -214,9 +294,11 @@ def list_value(value): def zookeeperDockerFile(network, rank): rslt = jumptab(2, 1) + "zookeeper" + str(rank) + ":" rslt += container_name("zookeeper" + str(rank)) - rslt += jumptab(1, 2) + "extends:" - rslt += jumptab(1, 4) + "file: docker-compose-base.yml" - rslt += jumptab(1, 4) + "service: zookeeper" + rslt += jumptab(1, 2) + "image: hyperledger/fabric-zookeeper" + rslt += jumptab(1, 2) + "ports:" + rslt += list_value('2181') + rslt += list_value('2888') + rslt += list_value('3888') rslt += jumptab(1, 2) + "environment:" rslt += list_value("ZOO_MY_ID=" + str((rank + 1))) rslt += list_value("ZOO_SERVERS=server.1=zookeeper0:2888:3888 server.2=zookeeper1:2888:3888 server.3=zookeeper2:2888:3888") @@ -228,10 +310,14 @@ def zookeeperDockerFile(network, rank): def kafkaDockerFile(network, rank): rslt = jumptab(2, 1) + "kafka" + str(rank) + ":" rslt += container_name("kafka" + str(rank)) - rslt += jumptab(1, 2) + "extends:" - rslt += jumptab(1, 4) + "file: docker-compose-base.yml" - rslt += jumptab(1, 4) + "service: kafka" + rslt += jumptab(1, 2) + "image: hyperledger/fabric-kafka" + rslt += jumptab(1, 2) + "ports:" + rslt += list_value('2181') rslt += jumptab(1, 2) + "environment:" + rslt += list_value("KAFKA_LOG_RETENTION_MS=-1") + rslt += list_value("KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false") + rslt += list_value("KAFKA_DEFAULT_REPLICATION_FACTOR=3") + rslt += list_value("KAFKA_MIN_INSYNC_REPLICAS=2") rslt += list_value("KAFKA_BROKER_ID=" + str(rank)) rslt += list_value("KAFKA_ZOOKEEPER_CONNECT=zookeeper0:2181,zookeeper1:2181,zookeeper2:2181") rslt += list_value("KAFKA_MESSAGE_MAX_BYTES=103809024") @@ -299,7 +385,7 @@ def peerDockerFile(hostname, rank, network, arch, idd, name): rslt += working_dir("/opt/gopath/src/github.com/hyperledger/fabric") rslt += command("peer node start") rslt += jumptab(1, 2) + "environment:" - rslt += list_value("CORE_LOGGING_LEVEL=debug") + rslt += list_value("FABRIC_LOGGING_SPEC=debug") rslt += list_value("CORE_CHAINCODE_LOGGING_LEVEL=DEBUG") rslt += list_value("CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock") rslt += list_value("CORE_PEER_ID=peer" + str(idd) + "." + hostname) @@ -309,10 +395,13 @@ def peerDockerFile(hostname, rank, network, arch, idd, name): rslt += list_value("CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/peer/msp") rslt += list_value("CORE_LEDGER_STATE_STATEDATABASE=CouchDB") rslt += list_value("CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb" + str(rank) + ":5984") + rslt += list_value("CORE_PEER_GOSSIP_BOOTSTRAP=peer" + str(idd) + "." + hostname + ":7051") + rslt += list_value("CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0." + hostname + ":7051") rslt += jumptab(1, 2) + "ports:" rslt += list_value(str((7 + rank)) + "051:7051") rslt += list_value(str((7 + rank)) + "053:7053") - rslt += jumptab(1, 2) + "volumes:" + rslt += jumptab(1, 2) + "volumes: + rslt += list_value("../chaincode:/etc/hyperledger/chaincode") rslt += list_value("/var/run/:/host/var/run/") rslt += list_value("./channel-artifacts:/etc/hyperledger/configtx") rslt += list_value("./crypto-config/peerOrganizations/" + hostname + "/peers/peer" + str(idd) + "." + hostname + "/msp:/etc/hyperledger/peer/msp") @@ -369,7 +458,7 @@ def createConst(): def createJoinChannel(tab, channelId): index = 3 orgNB = int((len(tab) - 2) / 2) - rslt = "function join_channel() {\ndocker exec peer0." + tab[2] + "." + tab[0] + ".com peer channel create -o orderer." + tab[0] + ".com:7050 -c " + channelId + " -f /etc/hyperledger/configtx/channel.tx" + rslt = "function join_channel() {\ndocker exec -e \"CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@" + tab[2] + "." + tab[0] + ".com/msp\" peer0." + tab[2] + "." + tab[0] + ".com peer channel create -o orderer." + tab[0] + ".com:7050 -c " + channelId + " -f /etc/hyperledger/configtx/channel.tx" rslt += jumptab(1, 0) + "docker exec peer0." + tab[2] + "." + tab[0] + ".com cp " + channelId + ".block /etc/hyperledger/configtx" for i in range (0, orgNB): for k in range (0, int(tab[index])):