Skip to content

Commit

Permalink
Allow docker-agent to update node config (hyperledger-cello#485)
Browse files Browse the repository at this point in the history
* Allow docker-agent to update node config

Implement the methods to request docker-agent to update config,
and restart the node.

Also fix a bug in node APIs that disallows the JSON post request.

Signed-off-by: Xichen Pan <xichen.pan@gmail.com>

* Fix code format issue

End file with a new line.

Signed-off-by: Xichen Pan <xichen.pan@gmail.com>

* Fix code format issue

End file with a new line.

Signed-off-by: Xichen Pan <xichen.pan@gmail.com>

Signed-off-by: Xichen Pan <xichen.pan@gmail.com>
  • Loading branch information
xichen1 authored Sep 5, 2022
1 parent 36dfe80 commit 0ed95e2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/api-engine/api/lib/agent/docker/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,20 @@ def get(self, *args, **kwargs):
raise response.reason
except Exception as e:
raise e

def update_config(self, config_file, node_type):
try:
cmd = 'bash /tmp/update.sh "{} node start"'.format(node_type)
data = {
'peer_config_file': config_file,
'orderer_config_file': config_file,
'action': 'update',
'cmd': cmd
}
response = post('{}/api/v1/nodes/{}'.format(self._urls, self._cname), data=data)
if response.status_code == 200:
return True
else:
raise response.reason
except Exception as e:
raise e
5 changes: 5 additions & 0 deletions src/api-engine/api/lib/agent/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,8 @@ def stop(self):
self._agent.stop()

return True

def update_config(self, config_file, node_type):
self._agent.update_config(config_file, node_type)

return True
7 changes: 5 additions & 2 deletions src/api-engine/api/routes/node/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from rest_framework import viewsets, status
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework.parsers import MultiPartParser
from rest_framework.parsers import MultiPartParser, FormParser, JSONParser
from rest_framework_jwt.authentication import JSONWebTokenAuthentication

from api.common.enums import AgentOperation
Expand Down Expand Up @@ -67,7 +67,7 @@

class NodeViewSet(viewsets.ViewSet):
authentication_classes = (JSONWebTokenAuthentication, TokenAuth)
parser_classes = [MultiPartParser]
parser_classes = [MultiPartParser, FormParser, JSONParser]

# Only operator can update node info
# def get_permissions(self):
Expand Down Expand Up @@ -741,6 +741,9 @@ def node_config(self, request, pk=None):
cfg = base64.b64encode(f_cfg.read())
node.config_file = cfg
node.save()
infos = self._agent_params(pk)
agent = AgentHandler(infos)
agent.update_config(cfg, node.type)
return Response(status=status.HTTP_202_ACCEPTED)
except Exception as e:
raise e
Expand Down

0 comments on commit 0ed95e2

Please sign in to comment.