From 7867eca0452925d34f17e5050d52002ba1f55eff Mon Sep 17 00:00:00 2001 From: YoungHypo Date: Mon, 25 Nov 2024 13:19:40 -0800 Subject: [PATCH] Restore environment variable settings in the main branch Signed-off-by: YoungHypo --- src/agent/docker-rest-agent/server.py | 24 +++------- src/api-engine/api/routes/node/views.py | 58 +++++++------------------ src/api-engine/api/utils/common.py | 5 +-- src/api-engine/requirements.txt | 4 +- 4 files changed, 25 insertions(+), 66 deletions(-) diff --git a/src/agent/docker-rest-agent/server.py b/src/agent/docker-rest-agent/server.py index e06485ab4..d4522ba7b 100644 --- a/src/agent/docker-rest-agent/server.py +++ b/src/agent/docker-rest-agent/server.py @@ -5,8 +5,6 @@ import os import ast -logging.basicConfig(level=logging.INFO) - app = Flask(__name__) PASS_CODE = 'OK' FAIL_CODE = 'Fail' @@ -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', @@ -65,19 +63,14 @@ 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', @@ -85,17 +78,15 @@ def create_node(): '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: @@ -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/', methods=['GET', 'POST']) diff --git a/src/api-engine/api/routes/node/views.py b/src/api-engine/api/routes/node/views.py index 205f14e9c..e6e135b08 100644 --- a/src/api-engine/api/routes/node/views.py +++ b/src/api-engine/api/routes/node/views.py @@ -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__) @@ -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): """ @@ -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 @@ -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) @@ -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: @@ -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 - ) + ) \ No newline at end of file diff --git a/src/api-engine/api/utils/common.py b/src/api-engine/api/utils/common.py index b2638ef26..0617d145d 100644 --- a/src/api-engine/api/utils/common.py +++ b/src/api-engine/api/utils/common.py @@ -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() @@ -151,4 +148,4 @@ def parse_block_file(data): def to_dict(data): - return loads(data) + return loads(data) \ No newline at end of file diff --git a/src/api-engine/requirements.txt b/src/api-engine/requirements.txt index 2d58d3f05..fa8a13f96 100644 --- a/src/api-engine/requirements.txt +++ b/src/api-engine/requirements.txt @@ -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 @@ -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 \ No newline at end of file