Skip to content

Commit

Permalink
Merge pull request #520 from xichen1/delete-node-without-network
Browse files Browse the repository at this point in the history
Allow deleting node w/o docker container
  • Loading branch information
yeasy authored Mar 18, 2023
2 parents 29fc9a3 + 9f7f8ee commit 6fc4d91
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/api-engine/api/lib/agent/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ def update_config(self, config_file, node_type):
self._agent.update_config(config_file, node_type)

return True

def get(self):
try:
return self._agent.get()
except Exception as e:
return False
26 changes: 24 additions & 2 deletions src/api-engine/api/routes/node/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,15 +555,37 @@ def destroy(self, request, pk=None):
node = Node.objects.get(id=pk)
infos = self._agent_params(pk)
agent = AgentHandler(infos)
agent_exist = agent.get()
node.status = "removing"
node.save()
if node.type == "orderer":
orderer_cnt = Node.objects.filter(
type="orderer", organization__network=node.organization.network).count()
if orderer_cnt == 1:
raise ResourceInUse
agent.stop()
res = True if agent.delete() else False
res = False
# if agent not exist or no continer is created for node, do not try to stop/delete container
if not agent_exist or not node.cid:
res = True
else:
# try to stop/delete container 3 times
# TODO: optimize the retry logic
for i in range(3):
LOG.info("Retry to stop/delete container %d time(s).", i + 1)
try:
response = agent.stop()
if response != True:
LOG.error("Failed when agent stops/deletes container: %s", response)
continue
response = agent.delete()
if response != True:
LOG.error("Failed when agent stops/deletes container: %s", response)
continue
res = True
except Exception as e:
LOG.error("Exception when agent stops/deletes container: %s", e)
continue
break
if res:
fabric_path = "{}/{}".format(FABRIC_NODE,
infos["container_name"])
Expand Down

0 comments on commit 6fc4d91

Please sign in to comment.