From 3387cc0949e4bdab00a22732473ad68dbba0bb83 Mon Sep 17 00:00:00 2001 From: xichen1 Date: Tue, 16 Aug 2022 17:29:56 -0600 Subject: [PATCH] Implement endpoint for node query Implement the api, enable querying the node's status through node_id. Signed-off-by: xichen1 --- src/api-engine/api/routes/node/serializers.py | 11 ++++ src/api-engine/api/routes/node/views.py | 29 +++++----- ...r Cello Api Engine.postman_collection.json | 55 +++++++++++++++++++ 3 files changed, 81 insertions(+), 14 deletions(-) diff --git a/src/api-engine/api/routes/node/serializers.py b/src/api-engine/api/routes/node/serializers.py index 32c8b3611..f21361506 100644 --- a/src/api-engine/api/routes/node/serializers.py +++ b/src/api-engine/api/routes/node/serializers.py @@ -244,6 +244,17 @@ class Meta: "created_at": {"required": True, "read_only": False}, } +class NodeStatusSerializer(NodeIDSerializer, serializers.ModelSerializer): + class Meta: + model = Node + fields = ( + "status", + ) + extra_kwargs = { + "id": {"required": True, "read_only": False}, + "created_at": {"required": True, "read_only": False}, + } + class NodeCreateBody(serializers.ModelSerializer): num = serializers.IntegerField(help_text="number of node") diff --git a/src/api-engine/api/routes/node/views.py b/src/api-engine/api/routes/node/views.py index 6e046c6c4..52024a6e9 100644 --- a/src/api-engine/api/routes/node/views.py +++ b/src/api-engine/api/routes/node/views.py @@ -36,7 +36,8 @@ NodeListSerializer, NodeUpdateBody, # NodeFileCreateSerializer, - NodeInfoSerializer, + # NodeInfoSerializer, + NodeStatusSerializer, NodeUserCreateSerializer, NodeUserIDSerializer, NodeUserPatchSerializer, @@ -636,7 +637,7 @@ def update(self, request, pk=None): @swagger_auto_schema( responses=with_common_response( - with_common_response({status.HTTP_200_OK: NodeInfoSerializer}) + with_common_response({status.HTTP_200_OK: NodeStatusSerializer}) ) ) def retrieve(self, request, pk=None): @@ -654,18 +655,18 @@ def retrieve(self, request, pk=None): except ObjectDoesNotExist: raise ResourceNotFound else: - # Set file url of node - if node.file: - node.file = request.build_absolute_uri(node.file.url) - ports = Port.objects.filter(node=node) - node.links = [ - { - "internal_port": port.internal, - "url": "%s:%s" % (node.agent.ip, port.external), - } - for port in ports - ] - response = NodeInfoSerializer(node) + # Set file url of node, we only need node status for now + # if node.file: + # node.file = request.build_absolute_uri(node.file.url) + # ports = Port.objects.filter(node=node) + # node.links = [ + # { + # "internal_port": port.internal, + # "url": "%s:%s" % (node.agent.ip, port.external), + # } + # for port in ports + # ] + response = NodeStatusSerializer(node) return Response(ok(data=response.data), status=status.HTTP_200_OK) except Exception as e: return Response( diff --git a/tests/postman/test/Hyperledger Cello Api Engine.postman_collection.json b/tests/postman/test/Hyperledger Cello Api Engine.postman_collection.json index 36dab5463..aa0bb5b2f 100644 --- a/tests/postman/test/Hyperledger Cello Api Engine.postman_collection.json +++ b/tests/postman/test/Hyperledger Cello Api Engine.postman_collection.json @@ -2591,6 +2591,61 @@ } }, "response": [] + }, + { + "name": "Retrieve Channel", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Authorization", + "value": "JWT {{token}}", + "type": "text" + } + ], + "url": { + "raw": "http://127.0.0.1:8080/api/v1/nodes/:node_id", + "protocol": "http", + "host": [ + "127", + "0", + "0", + "1" + ], + "port": "8080", + "path": [ + "api", + "v1", + "nodes", + ":node_id" + ], + "variable": [ + { + "key": "node_id", + "value": "953bcca2-77c4-42e1-a496-d8efe0ea4ecc" + } + ] + } + }, + "response": [] } ], "event": [