Skip to content

Commit 52c4a97

Browse files
authored
Merge pull request #660 from YoungHypo/issue-unify_environment_variable
update environment variables for nodes
2 parents 0fa36fe + 7213761 commit 52c4a97

File tree

4 files changed

+65
-22
lines changed

4 files changed

+65
-22
lines changed

src/agent/docker-rest-agent/server.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import os
66
import ast
77

8+
logging.basicConfig(level=logging.INFO)
9+
810
app = Flask(__name__)
911
PASS_CODE = 'OK'
1012
FAIL_CODE = 'Fail'
@@ -52,7 +54,7 @@ def create_node():
5254
'CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE': 'cello-net',
5355
'FABRIC_LOGGING_SPEC': 'INFO',
5456
'CORE_PEER_TLS_ENABLED': 'true',
55-
'CORE_PEER_PROFILE_ENABLED': 'true',
57+
'CORE_PEER_PROFILE_ENABLED': 'false',
5658
'CORE_PEER_TLS_CERT_FILE': '/etc/hyperledger/fabric/tls/server.crt',
5759
'CORE_PEER_TLS_KEY_FILE': '/etc/hyperledger/fabric/tls/server.key',
5860
'CORE_PEER_TLS_ROOTCERT_FILE': '/etc/hyperledger/fabric/tls/ca.crt',
@@ -63,30 +65,37 @@ def create_node():
6365
'CORE_PEER_CHAINCODELISTENADDRESS':'0.0.0.0:7052',
6466
'CORE_PEER_GOSSIP_BOOTSTRAP': node_name+":7051",
6567
'CORE_PEER_GOSSIP_EXTERNALENDPOINT': node_name+":7051",
66-
'CORE_OPERATIONS_LISTENADDRESS': '0.0.0.0:17051'
68+
'CORE_PEER_LOCALMSPID': node_name.split('.')[1].capitalize()+'MSP',
69+
'CORE_PEER_MSPCONFIGPATH': '/etc/hyperledger/fabric/msp',
70+
'CORE_OPERATIONS_LISTENADDRESS': node_name+":9444",
71+
'CORE_METRICS_PROVIDER': 'prometheus'
6772
}
6873
env.update(peer_envs)
6974
else:
7075
order_envs = {
71-
'FABRIC_LOGGING_SPEC':'DEBUG',
76+
'FABRIC_LOGGING_SPEC':'INFO',
7277
'ORDERER_GENERAL_LISTENADDRESS': '0.0.0.0',
7378
'ORDERER_GENERAL_LISTENPORT': '7050',
79+
'ORDERER_GENERAL_LOCALMSPID': 'OrdererMSP',
80+
'ORDERER_GENERAL_LOCALMSPDIR': '/etc/hyperledger/fabric/msp',
7481
'ORDERER_GENERAL_TLS_ENABLED': 'true',
7582
'ORDERER_GENERAL_TLS_PRIVATEKEY':'/etc/hyperledger/fabric/tls/server.key',
7683
'ORDERER_GENERAL_TLS_CERTIFICATE':'/etc/hyperledger/fabric/tls/server.crt',
7784
'ORDERER_GENERAL_TLS_ROOTCAS': '[/etc/hyperledger/fabric/tls/ca.crt]',
7885
'ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE': '/etc/hyperledger/fabric/tls/server.crt',
7986
'ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY': '/etc/hyperledger/fabric/tls/server.key',
8087
'ORDERER_GENERAL_CLUSTER_ROOTCAS': '[/etc/hyperledger/fabric/tls/ca.crt]',
81-
'ORDERER_GENERAL_LOCALMSPDIR': '/etc/hyperledger/fabric/msp',
82-
'ORDERER_GENERAL_LOCALMSPID': 'OrdererMSP',
88+
"ORDERER_GENERAL_BOOTSTRAPMETHOD": "none",
89+
"ORDERER_CHANNELPARTICIPATION_ENABLED": "true",
8390

84-
"ORDERER_ADMIN_LISTENADDRESS": "0.0.0.0:7053",
8591
"ORDERER_ADMIN_TLS_ENABLED": "true",
8692
"ORDERER_ADMIN_TLS_CERTIFICATE": "/etc/hyperledger/fabric/tls/server.crt",
8793
"ORDERER_ADMIN_TLS_PRIVATEKEY": "/etc/hyperledger/fabric/tls/server.key",
94+
"ORDERER_ADMIN_TLS_ROOTCAS": "[/etc/hyperledger/fabric/tls/ca.crt]",
8895
"ORDERER_ADMIN_TLS_CLIENTROOTCAS": "[/etc/hyperledger/fabric/tls/ca.crt]",
89-
"ORDERER_ADMIN_TLS_CLIENTAUTHREQUIRED": "true"
96+
"ORDERER_ADMIN_LISTENADDRESS": "0.0.0.0:7053",
97+
"ORDERER_OPERATIONS_LISTENADDRESS": node_name+":9443",
98+
"ORDERER_METRICS_PROVIDER": "prometheus"
9099
}
91100
env.update(order_envs)
92101
try:
@@ -117,6 +126,7 @@ def create_node():
117126
res['data']['public-grpc'] = '127.0.0.1:7050' # TODO: read the info from config file
118127
res['data']['public-raft'] = '127.0.0.1:7052'
119128
res['msg'] = 'node created'
129+
120130
return jsonify(res)
121131

122132
@app.route('/api/v1/nodes/<id>', methods=['GET', 'POST'])

src/api-engine/api/routes/node/views.py

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@
5959
)
6060
from api.utils.node_config import NodeConfig
6161
from api.lib.agent import AgentHandler
62+
from api.lib.peer.channel import Channel as PeerChannel
6263
from api.utils.port_picker import set_ports_mapping, find_available_ports
6364
from api.common import ok, err
64-
from api.routes.channel.views import init_env_vars, join_peers
65+
from api.routes.channel.views import init_env_vars
6566

6667
LOG = logging.getLogger(__name__)
6768

@@ -346,12 +347,17 @@ def _set_port(self, type, node, agent):
346347
set_ports_mapping(
347348
node.id,
348349
[{"internal": 7051, "external": ports[0]}, {
349-
"internal": 7053, "external": ports[1]}],
350+
"internal": 9444, "external": ports[1]}],
350351
True)
351352
else:
352-
ports = find_available_ports(ip, node.id, agent.id, 1)
353+
# unify the port mapping for orderer
354+
ports = find_available_ports(ip, node.id, agent.id, 3)
353355
set_ports_mapping(
354-
node.id, [{"internal": 7050, "external": ports[0]}], True)
356+
node.id,
357+
[{"internal": 7050, "external": ports[0]}, {
358+
"internal": 7053, "external": ports[1]}, {
359+
"internal": 9443, "external": ports[2]}],
360+
True)
355361

356362
def _conversion_msp_tls_cfg(self, type, org, node):
357363
"""
@@ -394,7 +400,7 @@ def _conversion_msp_tls_cfg(self, type, org, node):
394400

395401
def _generate_config(self, type, org, node):
396402
"""
397-
generate config for node
403+
generate config for node (core.yaml, orderer.yaml)
398404
399405
:param org: organization name
400406
:param type: node type
@@ -405,20 +411,41 @@ def _generate_config(self, type, org, node):
405411
"""
406412
args = {}
407413
if type == "peer":
408-
args.update({"peer_id": "{}.{}".format(node, org)})
409-
args.update({"peer_address": "{}.{}:{}".format(node, org, 7051)})
410-
args.update(
411-
{"peer_gossip_externalEndpoint": "{}.{}:{}".format(node, org, 7051)})
412-
args.update(
413-
{"peer_chaincodeAddress": "{}.{}:{}".format(node, org, 7052)})
414414
args.update({"peer_tls_enabled": True})
415-
args.update({"peer_localMspId": "{}MSP".format(org.capitalize())})
415+
args.update({"operations_listenAddress": node + "." + org + ":9444"})
416+
args.update({"peer_address": node + "." + org + ":7051"})
417+
args.update({"peer_gossip_bootstrap": node + "." + org + ":7051"})
418+
args.update({"peer_gossip_externalEndpoint": node + "." + org + ":7051"})
419+
args.update({"peer_id": node + "." + org})
420+
args.update({"peer_localMspId": org.capitalize() + "MSP"})
421+
args.update({"peer_mspConfigPath": "/etc/hyperledger/fabric/msp"})
422+
args.update({"peer_tls_cert_file": "/etc/hyperledger/fabric/tls/server.crt"})
423+
args.update({"peer_tls_key_file": "/etc/hyperledger/fabric/tls/server.key"})
424+
args.update({"peer_tls_rootcert_file": "/etc/hyperledger/fabric/tls/ca.crt"})
425+
args.update({"vm_docker_hostConfig_NetworkMode": "cello_net"})
426+
args.update({"vm_endpoint": 'unix:///host/var/run/docker.sock'})
416427

417428
a = NodeConfig(org)
418429
a.peer(node, **args)
419430
else:
420-
args.update({"General_BootstrapMethod": "none"})
431+
args.update({"Admin_TLS_Enabled": True})
432+
args.update({"Admin_ListenAddress": "0.0.0.0:7053"})
433+
args.update({"Admin_TLS_Certificate": "/etc/hyperledger/fabric/tls/server.crt"})
434+
args.update({"Admin_TLS_PrivateKey": "/etc/hyperledger/fabric/tls/server.key"})
421435
args.update({"ChannelParticipation_Enabled": True})
436+
args.update({"General_Cluster_ClientCertificate": "/etc/hyperledger/fabric/tls/server.crt"})
437+
args.update({"General_Cluster_ClientPrivateKey": "/etc/hyperledger/fabric/tls/server.key"})
438+
args.update({"General_ListenAddress": "0.0.0.0"})
439+
args.update({"General_ListenPort": 7050})
440+
args.update({"General_LocalMSPID": "OrdererMSP"})
441+
args.update({"General_LocalMSPDir": "/etc/hyperledger/fabric/msp"})
442+
args.update({"General_TLS_Enabled": True})
443+
args.update({"General_TLS_Certificate": "/etc/hyperledger/fabric/tls/server.crt"})
444+
args.update({"General_TLS_PrivateKey": "/etc/hyperledger/fabric/tls/server.key"})
445+
args.update({"General_TLS_RootCAs": "[/etc/hyperledger/fabric/tls/ca.crt]"})
446+
args.update({"General_BootstrapMethod": "none"})
447+
args.update({"Metrics_Provider": "prometheus"})
448+
args.update({"Operations_ListenAddress": node + "." + org.split(".", 1)[1] + ":9443"})
422449

423450
a = NodeConfig(org)
424451
a.orderer(node, **args)
@@ -809,7 +836,9 @@ def block_file(self, request, pk=None):
809836
with open(block_path, 'wb+') as f:
810837
for chunk in uploaded_block_file.chunks():
811838
f.write(chunk)
812-
join_peers(envs, block_path)
839+
peer_channel_cli = PeerChannel(**envs)
840+
peer_channel_cli.join(
841+
block_path)
813842
os.remove(block_path)
814843
return Response(status=status.HTTP_202_ACCEPTED)
815844
except Exception as e:

src/api-engine/api/utils/common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ def zip_dir(dirpath, outFullName):
118118
for filename in filenames:
119119
zdir.write(os.path.join(path, filename),
120120
os.path.join(fpath, filename))
121+
# zip empty folder
122+
for dirname in dirnames:
123+
zdir.write(os.path.join(path, dirname),
124+
os.path.join(fpath, dirname))
121125
zdir.close()
122126

123127

src/api-engine/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pyparsing==2.4.7
3939
pyrsistent==0.17.3
4040
python-dateutil==2.8.1
4141
python3-openid==3.2.0
42-
PyYAML==5.4
42+
PyYAML==5.3.1
4343
redis==4.4.4
4444
requests==2.32.2
4545
requests-oauthlib==1.3.0

0 commit comments

Comments
 (0)