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

Implement endpoint for node query #481

Merged
merged 1 commit into from
Aug 18, 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
11 changes: 11 additions & 0 deletions src/api-engine/api/routes/node/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
29 changes: 15 additions & 14 deletions src/api-engine/api/routes/node/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
NodeListSerializer,
NodeUpdateBody,
# NodeFileCreateSerializer,
NodeInfoSerializer,
# NodeInfoSerializer,
NodeStatusSerializer,
NodeUserCreateSerializer,
NodeUserIDSerializer,
NodeUserPatchSerializer,
Expand Down Expand Up @@ -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):
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down