Skip to content

Commit

Permalink
Restore environment variable settings in the main branch
Browse files Browse the repository at this point in the history
Signed-off-by: YoungHypo <haiboyang@smail.nju.edu.cn>
  • Loading branch information
YoungHypo committed Nov 25, 2024
1 parent c04f1bd commit 7867eca
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 66 deletions.
24 changes: 7 additions & 17 deletions src/agent/docker-rest-agent/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import os
import ast

logging.basicConfig(level=logging.INFO)

app = Flask(__name__)
PASS_CODE = 'OK'
FAIL_CODE = 'Fail'
Expand Down Expand Up @@ -54,7 +52,7 @@ def create_node():
'CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE': 'cello-net',
'FABRIC_LOGGING_SPEC': 'INFO',
'CORE_PEER_TLS_ENABLED': 'true',
'CORE_PEER_PROFILE_ENABLED': 'false',
'CORE_PEER_PROFILE_ENABLED': 'true',
'CORE_PEER_TLS_CERT_FILE': '/etc/hyperledger/fabric/tls/server.crt',
'CORE_PEER_TLS_KEY_FILE': '/etc/hyperledger/fabric/tls/server.key',
'CORE_PEER_TLS_ROOTCERT_FILE': '/etc/hyperledger/fabric/tls/ca.crt',
Expand All @@ -65,37 +63,30 @@ def create_node():
'CORE_PEER_CHAINCODELISTENADDRESS':'0.0.0.0:7052',
'CORE_PEER_GOSSIP_BOOTSTRAP': node_name+":7051",
'CORE_PEER_GOSSIP_EXTERNALENDPOINT': node_name+":7051",
'CORE_PEER_LOCALMSPID': node_name.split('.')[1].capitalize()+'MSP',
'CORE_PEER_MSPCONFIGPATH': '/etc/hyperledger/fabric/msp',
'CORE_OPERATIONS_LISTENADDRESS': node_name+":9444",
'CORE_METRICS_PROVIDER': 'prometheus'
'CORE_OPERATIONS_LISTENADDRESS': '0.0.0.0:17051'
}
env.update(peer_envs)
else:
order_envs = {
'FABRIC_LOGGING_SPEC':'INFO',
'FABRIC_LOGGING_SPEC':'DEBUG',
'ORDERER_GENERAL_LISTENADDRESS': '0.0.0.0',
'ORDERER_GENERAL_LISTENPORT': '7050',
'ORDERER_GENERAL_LOCALMSPID': 'OrdererMSP',
'ORDERER_GENERAL_LOCALMSPDIR': '/etc/hyperledger/fabric/msp',
'ORDERER_GENERAL_TLS_ENABLED': 'true',
'ORDERER_GENERAL_TLS_PRIVATEKEY':'/etc/hyperledger/fabric/tls/server.key',
'ORDERER_GENERAL_TLS_CERTIFICATE':'/etc/hyperledger/fabric/tls/server.crt',
'ORDERER_GENERAL_TLS_ROOTCAS': '[/etc/hyperledger/fabric/tls/ca.crt]',
'ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE': '/etc/hyperledger/fabric/tls/server.crt',
'ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY': '/etc/hyperledger/fabric/tls/server.key',
'ORDERER_GENERAL_CLUSTER_ROOTCAS': '[/etc/hyperledger/fabric/tls/ca.crt]',
"ORDERER_GENERAL_BOOTSTRAPMETHOD": "none",
"ORDERER_CHANNELPARTICIPATION_ENABLED": "true",
'ORDERER_GENERAL_LOCALMSPDIR': '/etc/hyperledger/fabric/msp',
'ORDERER_GENERAL_LOCALMSPID': 'OrdererMSP',

"ORDERER_ADMIN_LISTENADDRESS": "0.0.0.0:7053",
"ORDERER_ADMIN_TLS_ENABLED": "true",
"ORDERER_ADMIN_TLS_CERTIFICATE": "/etc/hyperledger/fabric/tls/server.crt",
"ORDERER_ADMIN_TLS_PRIVATEKEY": "/etc/hyperledger/fabric/tls/server.key",
"ORDERER_ADMIN_TLS_ROOTCAS": "[/etc/hyperledger/fabric/tls/ca.crt]",
"ORDERER_ADMIN_TLS_CLIENTROOTCAS": "[/etc/hyperledger/fabric/tls/ca.crt]",
"ORDERER_ADMIN_LISTENADDRESS": "0.0.0.0:7053",
"ORDERER_OPERATIONS_LISTENADDRESS": node_name+":9443",
"ORDERER_METRICS_PROVIDER": "prometheus"
"ORDERER_ADMIN_TLS_CLIENTAUTHREQUIRED": "true"
}
env.update(order_envs)
try:
Expand Down Expand Up @@ -126,7 +117,6 @@ def create_node():
res['data']['public-grpc'] = '127.0.0.1:7050' # TODO: read the info from config file
res['data']['public-raft'] = '127.0.0.1:7052'
res['msg'] = 'node created'

return jsonify(res)

@app.route('/api/v1/nodes/<id>', methods=['GET', 'POST'])
Expand Down
58 changes: 15 additions & 43 deletions src/api-engine/api/routes/node/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@
)
from api.utils.node_config import NodeConfig
from api.lib.agent import AgentHandler
from api.lib.peer.channel import Channel as PeerChannel
from api.utils.port_picker import set_ports_mapping, find_available_ports
from api.common import ok, err
from api.routes.channel.views import init_env_vars
from api.routes.channel.views import init_env_vars, join_peers

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -347,16 +346,12 @@ def _set_port(self, type, node, agent):
set_ports_mapping(
node.id,
[{"internal": 7051, "external": ports[0]}, {
"internal": 9444, "external": ports[1]}],
"internal": 7053, "external": ports[1]}],
True)
else:
ports = find_available_ports(ip, node.id, agent.id, 3)
ports = find_available_ports(ip, node.id, agent.id, 1)
set_ports_mapping(
node.id,
[{"internal": 7050, "external": ports[0]}, {
"internal": 7053, "external": ports[1]}, {
"internal": 9443, "external": ports[2]}],
True)
node.id, [{"internal": 7050, "external": ports[0]}], True)

def _conversion_msp_tls_cfg(self, type, org, node):
"""
Expand Down Expand Up @@ -399,7 +394,7 @@ def _conversion_msp_tls_cfg(self, type, org, node):

def _generate_config(self, type, org, node):
"""
generate config for node (core.yaml, orderer.yaml)
generate config for node
:param org: organization name
:param type: node type
Expand All @@ -410,41 +405,20 @@ def _generate_config(self, type, org, node):
"""
args = {}
if type == "peer":
args.update({"peer_id": "{}.{}".format(node, org)})
args.update({"peer_address": "{}.{}:{}".format(node, org, 7051)})
args.update(
{"peer_gossip_externalEndpoint": "{}.{}:{}".format(node, org, 7051)})
args.update(
{"peer_chaincodeAddress": "{}.{}:{}".format(node, org, 7052)})
args.update({"peer_tls_enabled": True})
args.update({"operations_listenAddress": node + "." + org + ":9444"})
args.update({"peer_address": node + "." + org + ":7051"})
args.update({"peer_gossip_bootstrap": node + "." + org + ":7051"})
args.update({"peer_gossip_externalEndpoint": node + "." + org + ":7051"})
args.update({"peer_id": node + "." + org})
args.update({"peer_localMspId": org.capitalize() + "MSP"})
args.update({"peer_mspConfigPath": "/etc/hyperledger/fabric/msp"})
args.update({"peer_tls_cert_file": "/etc/hyperledger/fabric/tls/server.crt"})
args.update({"peer_tls_key_file": "/etc/hyperledger/fabric/tls/server.key"})
args.update({"peer_tls_rootcert_file": "/etc/hyperledger/fabric/tls/ca.crt"})
args.update({"vm_docker_hostConfig_NetworkMode": "cello_net"})
args.update({"vm_endpoint": 'unix:///host/var/run/docker.sock'})
args.update({"peer_localMspId": "{}MSP".format(org.capitalize())})

a = NodeConfig(org)
a.peer(node, **args)
else:
args.update({"Admin_TLS_Enabled": True})
args.update({"Admin_ListenAddress": "0.0.0.0:7053"})
args.update({"Admin_TLS_Certificate": "/etc/hyperledger/fabric/tls/server.crt"})
args.update({"Admin_TLS_PrivateKey": "/etc/hyperledger/fabric/tls/server.key"})
args.update({"ChannelParticipation_Enabled": True})
args.update({"General_Cluster_ClientCertificate": "/etc/hyperledger/fabric/tls/server.crt"})
args.update({"General_Cluster_ClientPrivateKey": "/etc/hyperledger/fabric/tls/server.key"})
args.update({"General_ListenAddress": "0.0.0.0"})
args.update({"General_ListenPort": 7050})
args.update({"General_LocalMSPID": "OrdererMSP"})
args.update({"General_LocalMSPDir": "/etc/hyperledger/fabric/msp"})
args.update({"General_TLS_Enabled": True})
args.update({"General_TLS_Certificate": "/etc/hyperledger/fabric/tls/server.crt"})
args.update({"General_TLS_PrivateKey": "/etc/hyperledger/fabric/tls/server.key"})
args.update({"General_TLS_RootCAs": "[/etc/hyperledger/fabric/tls/ca.crt]"})
args.update({"General_BootstrapMethod": "none"})
args.update({"Metrics_Provider": "prometheus"})
args.update({"Operations_ListenAddress": node + "." + org.split(".", 1)[1] + ":9443"})
args.update({"ChannelParticipation_Enabled": True})

a = NodeConfig(org)
a.orderer(node, **args)
Expand Down Expand Up @@ -835,9 +809,7 @@ def block_file(self, request, pk=None):
with open(block_path, 'wb+') as f:
for chunk in uploaded_block_file.chunks():
f.write(chunk)
peer_channel_cli = PeerChannel(**envs)
peer_channel_cli.join(
block_path)
join_peers(envs, block_path)
os.remove(block_path)
return Response(status=status.HTTP_202_ACCEPTED)
except Exception as e:
Expand Down Expand Up @@ -985,4 +957,4 @@ def patch_user(self, request, pk=None, user_pk=None):
except Exception as e:
return Response(
err(e.args), status=status.HTTP_400_BAD_REQUEST
)
)
5 changes: 1 addition & 4 deletions src/api-engine/api/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ def zip_dir(dirpath, outFullName):
for filename in filenames:
zdir.write(os.path.join(path, filename),
os.path.join(fpath, filename))
for dirname in dirnames:
zdir.write(os.path.join(path, dirname),
os.path.join(fpath, dirname))
zdir.close()


Expand Down Expand Up @@ -151,4 +148,4 @@ def parse_block_file(data):


def to_dict(data):
return loads(data)
return loads(data)
4 changes: 2 additions & 2 deletions src/api-engine/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pyparsing==2.4.7
pyrsistent==0.17.3
python-dateutil==2.8.1
python3-openid==3.2.0
PyYAML==5.3.1
PyYAML==5.4
redis==4.4.4
requests==2.32.2
requests-oauthlib==1.3.0
Expand All @@ -56,4 +56,4 @@ urllib3==1.26.19
uWSGI==2.0.22
validate-email==1.3
watchdog==0.10.2
websocket-client==0.57.0
websocket-client==0.57.0

0 comments on commit 7867eca

Please sign in to comment.