Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update environment variables for nodes #660

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/agent/docker-rest-agent/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import os
import ast

logging.basicConfig(level=logging.INFO)

app = Flask(__name__)
PASS_CODE = 'OK'
FAIL_CODE = 'Fail'
Expand Down Expand Up @@ -52,7 +54,7 @@ def create_node():
'CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE': 'cello-net',
'FABRIC_LOGGING_SPEC': 'INFO',
'CORE_PEER_TLS_ENABLED': 'true',
'CORE_PEER_PROFILE_ENABLED': 'true',
'CORE_PEER_PROFILE_ENABLED': 'false',
'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 @@ -63,30 +65,37 @@ 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_OPERATIONS_LISTENADDRESS': '0.0.0.0:17051'
'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'
}
env.update(peer_envs)
else:
order_envs = {
'FABRIC_LOGGING_SPEC':'DEBUG',
'FABRIC_LOGGING_SPEC':'INFO',
'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_LOCALMSPDIR': '/etc/hyperledger/fabric/msp',
'ORDERER_GENERAL_LOCALMSPID': 'OrdererMSP',
"ORDERER_GENERAL_BOOTSTRAPMETHOD": "none",
"ORDERER_CHANNELPARTICIPATION_ENABLED": "true",

"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_TLS_CLIENTAUTHREQUIRED": "true"
"ORDERER_ADMIN_LISTENADDRESS": "0.0.0.0:7053",
"ORDERER_OPERATIONS_LISTENADDRESS": node_name+":9443",
"ORDERER_METRICS_PROVIDER": "prometheus"
}
env.update(order_envs)
try:
Expand Down Expand Up @@ -117,6 +126,7 @@ 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
57 changes: 43 additions & 14 deletions src/api-engine/api/routes/node/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@
)
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, join_peers
from api.routes.channel.views import init_env_vars

LOG = logging.getLogger(__name__)

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

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

def _generate_config(self, type, org, node):
"""
generate config for node
generate config for node (core.yaml, orderer.yaml)

:param org: organization name
:param type: node type
Expand All @@ -405,20 +411,41 @@ 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({"peer_localMspId": "{}MSP".format(org.capitalize())})
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'})

a = NodeConfig(org)
a.peer(node, **args)
else:
args.update({"General_BootstrapMethod": "none"})
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"})

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


Expand Down
2 changes: 1 addition & 1 deletion 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.4
PyYAML==5.3.1
redis==4.4.4
requests==2.32.2
requests-oauthlib==1.3.0
Expand Down
Loading