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

Allow docker-agent to update node config #485

Merged
merged 3 commits into from
Sep 5, 2022
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
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