Skip to content

Commit

Permalink
Merge pull request #662 from YoungHypo/issue-chaincode_install
Browse files Browse the repository at this point in the history
Upgrade chaincode installation to Fabric V2.5.10
  • Loading branch information
YoungHypo authored Dec 14, 2024
2 parents 8eef62e + 076c2bb commit 007edcf
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 72 deletions.
3 changes: 2 additions & 1 deletion src/agent/docker-rest-agent/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def create_node():
port_map = ast.literal_eval(request.form.get("port_map"))
volumes = [
'{}/fabric/{}:/etc/hyperledger/fabric'.format(storage_path, node_name),
'{}/production/{}:/var/hyperledger/production'.format(storage_path, node_name)
'{}/production/{}:/var/hyperledger/production'.format(storage_path, node_name),
'/var/run/docker.sock:/host/var/run/docker.sock'
]
if request.form.get('type') == "peer":
peer_envs = {
Expand Down
11 changes: 9 additions & 2 deletions src/api-engine/api/lib/peer/chaincode.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import subprocess
from api.lib.peer.command import Command
from api.config import FABRIC_TOOL, FABRIC_CFG, FABRIC_VERSION
import logging

LOG = logging.getLogger(__name__)

class ChainCode(Command):
def __init__(self, version=FABRIC_VERSION, peer=FABRIC_TOOL, **kwargs):
Expand Down Expand Up @@ -39,8 +41,13 @@ def lifecycle_install(self, cc_targz):
:return: 0 means success.
"""
try:
res = os.system(
"{} lifecycle chaincode install {}".format(self.peer, cc_targz))
command = [
self.peer,
"lifecycle", "chaincode", "install",
cc_targz
]
LOG.info(" ".join(command))
res = os.system(" ".join(command))
res = res >> 8
except Exception as e:
err_msg = "install chaincode failed for {}!".format(e)
Expand Down
34 changes: 4 additions & 30 deletions src/api-engine/api/routes/chaincode/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from api.lib.peer.chaincode import ChainCode as PeerChainCode
from api.common.serializers import PageQuerySerializer
from api.utils.common import with_common_response
from api.utils.common import with_common_response, init_env_vars
from api.exceptions import ResourceNotFound

from api.routes.chaincode.serializers import (
Expand All @@ -33,7 +33,9 @@
from api.common import ok, err
import threading
import hashlib
import logging

LOG = logging.getLogger(__name__)

class ChainCodeViewSet(viewsets.ViewSet):
"""Class represents Channel related operations."""
Expand Down Expand Up @@ -239,8 +241,8 @@ def install(self, request):
if not qs.exists():
raise ResourceNotFound
peer_node = qs.first()
envs = init_env_vars(peer_node, org)

envs = init_env_vars(peer_node, org)
peer_channel_cli = PeerChainCode(**envs)
res = peer_channel_cli.lifecycle_install(cc_targz)
if res != 0:
Expand Down Expand Up @@ -551,31 +553,3 @@ def query_committed(self, request):
return Response(
ok(chaincodes_commited), status=status.HTTP_200_OK
)


def init_env_vars(node, org):
"""
Initialize environment variables for peer channel CLI.
:param node: Node object
:param org: Organization object.
:return env: dict
"""
org_name = org.name
org_domain = org_name.split(".", 1)[1]
dir_certificate = "{}/{}/crypto-config/ordererOrganizations/{}".format(
CELLO_HOME, org_name, org_domain)
dir_node = "{}/{}/crypto-config/peerOrganizations".format(
CELLO_HOME, org_name)

envs = {
"CORE_PEER_TLS_ENABLED": "true",
# "Org1.cello.comMSP"
"CORE_PEER_LOCALMSPID": "{}MSP".format(org_name.capitalize()),
"CORE_PEER_TLS_ROOTCERT_FILE": "{}/{}/peers/{}/tls/ca.crt".format(dir_node, org_name, node.name + "." + org_name),
"CORE_PEER_ADDRESS": "{}:{}".format(
node.name + "." + org_name, str(7051)),
"CORE_PEER_MSPCONFIGPATH": "{}/{}/users/Admin@{}/msp".format(dir_node, org_name, org_name),
"FABRIC_CFG_PATH": "{}/{}/peers/{}/".format(dir_node, org_name, node.name + "." + org_name),
"ORDERER_CA": "{}/msp/tlscacerts/tlsca.{}-cert.pem".format(dir_certificate, org_domain)
}
return envs
39 changes: 1 addition & 38 deletions src/api-engine/api/routes/channel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from api.config import CELLO_HOME
from api.common.serializers import PageQuerySerializer
from api.utils.common import with_common_response, parse_block_file, to_dict, json_filter, json_add_anchor_peer, json_create_envelope
from api.utils.common import with_common_response, parse_block_file, to_dict, json_filter, json_add_anchor_peer, json_create_envelope, init_env_vars
from api.lib.configtxgen import ConfigTX, ConfigTxGen
from api.lib.peer.channel import Channel as PeerChannel
from api.lib.configtxlator.configtxlator import ConfigTxLator
Expand Down Expand Up @@ -549,40 +549,3 @@ def peer_channel_update(name, org, anchor_peer, ordering_node, channel_artifacts
orderer_url="{}.{}:{}".format(
ordering_node.name, org.name.split(".", 1)[1], str(7050)),
)


def init_env_vars(node, org):
"""
Initialize environment variables for peer channel CLI.
:param node: Node object
:param org: Organization object.
:return env: dict
"""
org_name = org.name
org_domain = org_name.split(".", 1)[1]
dir_certificate = "{}/{}/crypto-config/ordererOrganizations/{}".format(
CELLO_HOME, org_name, org_domain)
dir_node = "{}/{}/crypto-config/peerOrganizations".format(
CELLO_HOME, org_name)

envs = {}

if(node.type == "orderer"):
envs = {
"CORE_PEER_TLS_ENABLED": "true",
"ORDERER_CA": "{}/orderers/{}/msp/tlscacerts/tlsca.{}-cert.pem".format(dir_certificate, node.name + "." + org_domain, org_domain),
"ORDERER_ADMIN_TLS_SIGN_CERT": "{}/orderers/{}/tls/server.crt".format(dir_certificate, node.name + "." + org_domain),
"ORDERER_ADMIN_TLS_PRIVATE_KEY": "{}/orderers/{}/tls/server.key".format(dir_certificate, node.name + "." + org_domain)
}
elif(node.type == "peer"):
envs = {
"CORE_PEER_TLS_ENABLED": "true",
"CORE_PEER_LOCALMSPID": "{}MSP".format(org_name.split(".")[0].capitalize()),
"CORE_PEER_TLS_ROOTCERT_FILE": "{}/{}/peers/{}/tls/ca.crt".format(dir_node, org_name, node.name + "." + org_name),
"CORE_PEER_MSPCONFIGPATH": "{}/{}/users/Admin@{}/msp".format(dir_node, org_name, org_name),
"CORE_PEER_ADDRESS": "{}:{}".format(
node.name + "." + org_name, str(7051)),
"FABRIC_CFG_PATH": "{}/{}/peers/{}/".format(dir_node, org_name, node.name + "." + org_name)
}

return envs
39 changes: 38 additions & 1 deletion src/api-engine/api/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import uuid
from zipfile import ZipFile
from json import loads
from api.config import CELLO_HOME
import json
import logging

Expand Down Expand Up @@ -261,4 +262,40 @@ def json_create_envelope(input, output, channel):

except Exception as e:
LOG.error("Failed to create config update envelope: {}".format(str(e)))
raise
raise

def init_env_vars(node, org):
"""
Initialize environment variables for peer channel CLI.
:param node: Node object
:param org: Organization object.
:return env: dict
"""
org_name = org.name
org_domain = org_name.split(".", 1)[1]
dir_certificate = "{}/{}/crypto-config/ordererOrganizations/{}".format(
CELLO_HOME, org_name, org_domain)
dir_node = "{}/{}/crypto-config/peerOrganizations".format(
CELLO_HOME, org_name)

envs = {}

if(node.type == "orderer"):
envs = {
"CORE_PEER_TLS_ENABLED": "true",
"ORDERER_CA": "{}/orderers/{}/msp/tlscacerts/tlsca.{}-cert.pem".format(dir_certificate, node.name + "." + org_domain, org_domain),
"ORDERER_ADMIN_TLS_SIGN_CERT": "{}/orderers/{}/tls/server.crt".format(dir_certificate, node.name + "." + org_domain),
"ORDERER_ADMIN_TLS_PRIVATE_KEY": "{}/orderers/{}/tls/server.key".format(dir_certificate, node.name + "." + org_domain)
}
elif(node.type == "peer"):
envs = {
"CORE_PEER_TLS_ENABLED": "true",
"CORE_PEER_LOCALMSPID": "{}MSP".format(org_name.split(".")[0].capitalize()),
"CORE_PEER_TLS_ROOTCERT_FILE": "{}/{}/peers/{}/tls/ca.crt".format(dir_node, org_name, node.name + "." + org_name),
"CORE_PEER_MSPCONFIGPATH": "{}/{}/users/Admin@{}/msp".format(dir_node, org_name, org_name),
"CORE_PEER_ADDRESS": "{}:{}".format(
node.name + "." + org_name, str(7051)),
"FABRIC_CFG_PATH": "{}/{}/peers/{}/".format(dir_node, org_name, node.name + "." + org_name)
}

return envs

0 comments on commit 007edcf

Please sign in to comment.